Fix attempt - still chat issues when tabs are not reloaded after live game start
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 20 Jan 2020 17:16:01 +0000 (18:16 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 20 Jan 2020 17:16:01 +0000 (18:16 +0100)
client/src/components/Chat.vue
client/src/views/Game.vue
client/src/views/Hall.vue
server/sockets.js

index c7f63cf..2dc6842 100644 (file)
@@ -23,7 +23,9 @@ export default {
     };
   },
   created: function() {
+    const curMsgListener = this.st.conn.onmessage; //from Game or Hall
     const socketMessageListener = msg => {
+      curMsgListener(msg);
       const data = JSON.parse(msg.data);
       if (data.code == "newchat") //only event at this level
       {
index 5939c90..cadda01 100644 (file)
@@ -162,6 +162,10 @@ export default {
         case "identity":
         {
           let player = this.people.find(p => p.sid == data.user.sid);
+          // NOTE: sometimes player.id fails because player is undefined...
+          // Probably because the event was meant for Hall?
+          if (!player)
+            return;
           player.id = data.user.id;
           player.name = data.user.name;
           // Sending last state only for live games: corr games are complete
index 851201f..60f6291 100644 (file)
@@ -284,8 +284,9 @@ export default {
             // Ask identity, challenges and game(s)
             this.st.conn.send(JSON.stringify({code:"askidentity", target:sid}));
             this.st.conn.send(JSON.stringify({code:"askchallenge", target:sid}));
-            this.st.conn.send(JSON.stringify({code:"askgame", target:sid}));
           });
+          // Also ask current games to all playing peers (TODO: some design issue)
+          this.st.conn.send(JSON.stringify({code:"askgames"}));
           break;
         }
         case "askidentity":
index b7689d7..891c516 100644 (file)
@@ -39,9 +39,6 @@ module.exports = function(wss) {
       let obj = JSON.parse(objtxt);
       if (!!obj.target && !clients[obj.target])
         return; //receiver not connected, nothing we can do
-
-console.log(obj.code);
-
       switch (obj.code)
       {
         case "pollclients":
@@ -70,7 +67,7 @@ console.log(obj.code);
           clients[obj.target].sock.send(JSON.stringify(
             {code:"askchallenge",from:sid}));
           break;
-        case "askgame":
+        case "askgames":
           // Check all clients playing, and send them a "askgame" message
           Object.keys(clients).forEach(k => {
             if (k != sid && clients[k].page.indexOf("/game/") >= 0)
@@ -79,8 +76,6 @@ console.log(obj.code);
                 {code:"askgame", from: sid}));
             }
           });
-          clients[obj.target].sock.send(JSON.stringify(
-            {code:"askgame",from:sid}));
           break;
         case "identity":
           clients[obj.target].sock.send(JSON.stringify(