- notifyRoom(query["page"],"connect");
- socket.on("message", objtxt => {
+ const deleteConnexion = () => {
+ if (!clients[page] || !clients[page][sid] || !clients[page][sid][tmpId])
+ return; //job already done
+ delete clients[page][sid][tmpId];
+ if (Object.keys(clients[page][sid]).length == 0) {
+ delete clients[page][sid];
+ const pgIndex = sidToPages[sid].findIndex(pg => pg == page);
+ sidToPages[sid].splice(pgIndex, 1);
+ if (Object.keys(clients[page]).length == 0)
+ delete clients[page];
+ // Am I totally offline?
+ if (sidToPages[sid].length == 0) {
+ delete sidToPages[sid];
+ delete idToSid[id];
+ }
+ }
+ };
+
+ const doDisconnect = () => {
+ deleteConnexion();
+ // Nothing to notify when disconnecting from MyGames page:
+ if (page != "/mygames") {
+ notifyRoom(page, "disconnect");
+ if (page.indexOf("/game/") >= 0)
+ notifyRoom("/", "gdisconnect", { page: page });
+ }
+ };
+ const messageListener = (objtxt) => {