- case "pollclients":
- const curPage = clients[sid].page;
- socket.send(JSON.stringify({code:"pollclients",
- sockIds: Object.keys(clients).filter(k => k != sid &&
- (clients[k].page == curPage ||
- // Consider that people playing are in Hall too:
- (curPage == "/" && clients[k].page.indexOf("/game/") >= 0))
- )}));
- 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(
- {code:"askidentity",from:sid}));
+ // 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});