Pārlūkot izejas kodu

Client Open Socket on play

Nikatlas 6 gadi atpakaļ
vecāks
revīzija
4751ccc9ab
4 mainītis faili ar 367 papildinājumiem un 235 dzēšanām
  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

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 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"}});

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels