+ // Wait for "connect" message to notify connection to the room,
+ // because if game loading is slow the message listener might
+ // not be ready too early.
+ case "connect":
+ {
+ notifyRoom(page, "connect");
+ if (page.indexOf("/game/") >= 0)
+ notifyRoom("/", "gconnect", {page:page});
+ break;
+ }
+ case "disconnect":
+ // When page changes:
+ deleteConnexion();
+ if (!clients[page][sid])
+ {
+ // I effectively disconnected from this page:
+ notifyRoom(page, "disconnect");
+ if (page.indexOf("/game/") >= 0)
+ notifyRoom("/", "gdisconnect", {page:page});
+ }
+ break;
+ case "pollclients": //from Hall or Game
+ {
+ let sockIds = [];
+ Object.keys(clients[page]).forEach(k => {
+ // Poll myself if I'm on at least another tab (same page)
+ if (k != sid || Object.keys(clients["/"][k]).length >= 2)
+ sockIds.push(k);
+ });
+ socket.send(JSON.stringify({code:"pollclients", sockIds:sockIds}));
+ break;
+ }
+ case "pollclientsandgamers": //from Hall
+ {
+ let sockIds = [];
+ Object.keys(clients["/"]).forEach(k => {
+ // Poll myself if I'm on at least another tab (same page)
+ if (k != sid || Object.keys(clients["/"][k]).length >= 2)
+ sockIds.push({sid:k});
+ });
+ // NOTE: a "gamer" could also just be an observer
+ Object.keys(clients).forEach(p => {
+ if (p != "/")
+ {
+ Object.keys(clients[p]).forEach(k => {
+ if (k != sid)
+ sockIds.push({sid:k, page:p}); //page needed for gamers
+ });
+ }
+ });
+ socket.send(JSON.stringify({code:"pollclientsandgamers", sockIds:sockIds}));
+ break;
+ }
+
+ // Asking something: from is fully identified,
+ // but the requested resource can be from any tmpId (except current!)