Fix disconnect event by closing tab
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 12 Feb 2020 19:33:03 +0000 (20:33 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 12 Feb 2020 19:33:03 +0000 (20:33 +0100)
client/src/views/Hall.vue
server/sockets.js

index ae04b7d..34cd63b 100644 (file)
@@ -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
index da748f0..ba14df9 100644 (file)
@@ -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])