});
};
notifyRoom(query["page"], "connect"); //Hall or Game
+ if (query["page"].indexOf("/game/") >= 0)
+ notifyRoom("/", "connect"); //notify main hall
socket.on("message", objtxt => {
let obj = JSON.parse(objtxt);
if (!!obj.target && !clients[obj.target])
return; //receiver not connected, nothing we can do
-
-console.log(obj.code);
-console.log(clients);
-
switch (obj.code)
{
case "pollclients":
break;
case "pagechange":
notifyRoom(clients[sid].page, "disconnect");
+ if (clients[sid].page.indexOf("/game/") >= 0)
+ notifyRoom("/", "disconnect");
clients[sid].page = obj.page;
notifyRoom(obj.page, "connect");
+ if (obj.page.indexOf("/game/") >= 0)
+ notifyRoom("/", "connect");
break;
case "askidentity":
clients[obj.target].sock.send(JSON.stringify(
clients[obj.target].sock.send(JSON.stringify(
{code:"askchallenge",from:sid}));
break;
- case "askgame":
+ case "askgames":
// Check all clients playing, and send them a "askgame" message
Object.keys(clients).forEach(k => {
if (k != sid && clients[k].page.indexOf("/game/") >= 0)
{code:"askgame", from: sid}));
}
});
- clients[obj.target].sock.send(JSON.stringify(
- {code:"askgame",from:sid}));
break;
case "identity":
clients[obj.target].sock.send(JSON.stringify(
const page = clients[sid].page;
delete clients[sid];
notifyRoom(page, "disconnect");
+ if (page.indexOf("/game/") >= 0)
+ notifyRoom("/", "disconnect"); //notify main hall
});
});
}