X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fsockets.js;h=3fb7ea2a8c3fe69f9b1bb12516073f826d31670b;hb=89021f181ac0689bbc785ce0ebd9a910e66352b0;hp=da748f0642fd12b60a94cb48ad03f83fb30effeb;hpb=8b152adaed809e759bb2507ade9d2273783c4a39;p=vchess.git diff --git a/server/sockets.js b/server/sockets.js index da748f06..3fb7ea2a 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 @@ -186,6 +186,11 @@ module.exports = function(wss) { notifyRoom(page, obj.code, {data:obj.data}); break; + case "result": + // Special case: notify all, 'transroom': Game --> Hall + notifyRoom("/", "result", {gid:obj.gid, score:obj.score}); + break; + // Passing, relaying something: from isn't needed, // but target is fully identified (sid + tmpId) case "challenge": @@ -201,8 +206,8 @@ module.exports = function(wss) { } }; const closeListener = () => { - // For tab or browser closing: - deleteConnexion(); + // For browser or tab closing (including page reload): + doDisconnect(); }; // Update clients object: add new connexion if (!clients[page])