Improvements - untested
[vchess.git] / server / sockets.js
index 42a8840..cf5ea1b 100644 (file)
@@ -190,8 +190,30 @@ module.exports = function(wss) {
         case "abort":
         case "drawoffer":
         case "draw":
+        {
           notifyRoom(page, obj.code, {data:obj.data});
+          const mygamesPg = "/mygames";
+          if (obj.code == "newmove" && clients[mygamesPg])
+          {
+            // Relay newmove info to myGames page
+            // NOTE: the move itself is not needed (for now at least)
+            const newmoveForMygames = {
+              gid: page.split("/")[2] //format is "/game/gid"
+            };
+            obj.data.players.forEach(pSid => {
+              if (clients[mygamesPg][pSid])
+              {
+                Object.keys(clients[mygamesPg][pSid]).forEach(x => {
+                  send(
+                    clients[mygamesPg][pSid][x],
+                    {code:"newmove", data:newmoveForMygames}
+                  );
+                });
+              }
+            });
+          }
           break;
+        }
 
         case "result":
           // Special case: notify all, 'transroom': Game --> Hall