From: Benjamin Auder Date: Mon, 20 Jan 2020 17:16:01 +0000 (+0100) Subject: Fix attempt - still chat issues when tabs are not reloaded after live game start X-Git-Url: https://git.auder.net/game/doc/html/current/git-favicon.png?a=commitdiff_plain;h=cd0d7743323309fcfd241ccba959df81a77970c7;p=vchess.git Fix attempt - still chat issues when tabs are not reloaded after live game start --- diff --git a/client/src/components/Chat.vue b/client/src/components/Chat.vue index c7f63cfa..2dc68428 100644 --- a/client/src/components/Chat.vue +++ b/client/src/components/Chat.vue @@ -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 { diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 5939c905..cadda013 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -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 diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 851201f8..60f62917 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -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": diff --git a/server/sockets.js b/server/sockets.js index b7689d7a..891c516d 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -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(