From: Benjamin Auder Date: Wed, 12 Feb 2020 19:33:03 +0000 (+0100) Subject: Fix disconnect event by closing tab X-Git-Url: https://git.auder.net/variants/%24%7Bvname%7D/app_dev.php/_configurator?a=commitdiff_plain;h=f5f51daf4515c43d11bc5d739660ac213abec613;p=vchess.git Fix disconnect event by closing tab --- diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index ae04b7d1..34cd63b7 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -488,6 +488,8 @@ export default { newGame.vname = this.getVname(game.vid); if (!game.score) //if new game from Hall newGame.score = "*"; + newGame.rids = [game.rid]; + delete newGame["rid"]; this.games.push(newGame); } else diff --git a/server/sockets.js b/server/sockets.js index da748f06..ba14df95 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -52,6 +52,16 @@ module.exports = function(wss) { delete clients[page]; } }; + const doDisconnect = () => { + deleteConnexion(); + if (!clients[page] || !clients[page][sid]) + { + // I effectively disconnected from this page: + notifyRoom(page, "disconnect"); + if (page.indexOf("/game/") >= 0) + notifyRoom("/", "gdisconnect", {page:page}); + } + }; const messageListener = (objtxt) => { let obj = JSON.parse(objtxt); switch (obj.code) @@ -68,14 +78,7 @@ module.exports = function(wss) { } case "disconnect": // When page changes: - deleteConnexion(); - if (!clients[page] || !clients[page][sid]) - { - // I effectively disconnected from this page: - notifyRoom(page, "disconnect"); - if (page.indexOf("/game/") >= 0) - notifyRoom("/", "gdisconnect", {page:page}); - } + doDisconnect(); break; case "killme": { @@ -148,9 +151,6 @@ module.exports = function(wss) { case "askgame": case "askfullgame": { - // DEBUG: - //console.log(sid + " " + page + " " + obj.code + " " + obj.target + " " + obj.page); - //console.log(clients); const pg = obj.page || page; //required for askidentity and askgame const tmpIds = Object.keys(clients[pg][obj.target]); if (obj.target == sid) //targetting myself @@ -202,7 +202,7 @@ module.exports = function(wss) { }; const closeListener = () => { // For tab or browser closing: - deleteConnexion(); + doDisconnect(); }; // Update clients object: add new connexion if (!clients[page])