Explorar el Código

Client Open Socket on play

Nikatlas hace 6 años
padre
commit
4751ccc9ab
Se han modificado 4 ficheros con 367 adiciones y 235 borrados
  1. 343 233
      package-lock.json
  2. 2 1
      package.json
  3. 15 0
      src/Game/services/SocketService.js
  4. 7 1
      src/Game/views/buildings/Menu.js

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 343 - 233
package-lock.json


+ 2 - 1
package.json

@@ -13,8 +13,9 @@
     "pixi.js": "^4.6.2",
     "react": "^16.2.0",
     "react-dom": "^16.2.0",
-    "react-scripts": "1.0.17",
+    "react-scripts": "^1.1.4",
     "reactstrap": "^5.0.0-alpha.4",
+    "socket.io-client": "^2.1.1",
     "wolfy87-eventemitter": "^5.2.4"
   },
   "scripts": {

+ 15 - 0
src/Game/services/SocketService.js

@@ -0,0 +1,15 @@
+import Net from './Net.js';
+import openSocket from 'socket.io-client';
+class SocketService {
+
+    constructor() {
+        
+    }
+    openSocket(channel) {
+        if(this.socket)
+            this.socket.disconnect();
+        this.socket = openSocket('http://localhost:3555/' + channel);
+    }
+}
+
+export default new SocketService();

+ 7 - 1
src/Game/views/buildings/Menu.js

@@ -7,6 +7,9 @@ import UserService from '../../services/UserService';
 
 import Text from '../misc/Text';
 import Button from '../misc/Button';
+
+import SocketService from '../../services/SocketService';
+
 const BlueURL = '/files/assets/cards/frame_blue.png';
 const BlueImage = PIXI.Texture.fromImage(BlueURL);
 
@@ -43,7 +46,10 @@ class Menu extends GuiableContainer{
         this.textSprite.setText(UserService.getUsername() + ':' + UserService.getToken());
             
         let play = new Button({  y:-100 , Text: {text: "Play"}});
-        play.onClick((e) => alert(e));
+        play.onClick((e) => {
+            SocketService.openSocket('randomFree');
+        });
+
         let collection = new Button({  y:50 , Text: {text: "Collection"}});
         collection.onClick((e) => alert(e));
         let logout = new Button({  y:200 , Text: {text: "Logout"}});

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio