- notifyRoom(query["page"], "connect"); //Hall or Game
- if (query["page"].indexOf("/game/") >= 0)
- notifyRoom("/", "connect"); //notify main hall
- socket.on("message", objtxt => {
+ // For focus events: no need to target self
+ const notifyAllButMe = (page,code,obj={}) => {
+ if (!clients[page]) return;
+ Object.keys(clients[page]).forEach(k => {
+ if (k == sid) return;
+ Object.keys(clients[page][k]).forEach(x => {
+ send(
+ clients[page][k][x].socket,
+ Object.assign({ code: code, from: sid }, obj)
+ );
+ });
+ });
+ };
+ 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];
+ if (Object.keys(clients[page]).length == 0)
+ 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) => {