Cosmetics: 'type first letters' inlined in input text field on Variants page
[vchess.git] / server / sockets.js
index df44520..64b180d 100644 (file)
@@ -17,6 +17,8 @@ module.exports = function(wss) {
   let clients = {}; //associative array sid --> socket
   wss.on("connection", (socket, req) => {
     const query = getJsonFromUrl(req.url);
+    if (query["page"] != "/" && query["page"].indexOf("/game/") < 0)
+      return; //other tabs don't need to be connected
     const sid = query["sid"];
     const notifyRoom = (page,code,obj={},excluded=[]) => {
       Object.keys(clients).forEach(k => {
@@ -39,10 +41,11 @@ module.exports = function(wss) {
           // Turn off message listening, and send disconnect if needed:
           socket.removeListener("message", messageListener);
           socket.removeListener("close", closeListener);
+          // From obj.page to clients[sid].page (TODO: unclear)
           if (clients[sid].page != obj.page)
           {
-            notifyRoom(clients[sid].page, "disconnect");
-            if (clients[sid].page.indexOf("/game/") >= 0)
+            notifyRoom(obj.page, "disconnect");
+            if (obj.page.indexOf("/game/") >= 0)
               notifyRoom("/", "gdisconnect");
           }
           break;