- case "askidentity":
- clients[obj.target].sock.send(JSON.stringify(
- {code:"askidentity",from:sid}));
- break;
- case "askchallenge":
- clients[obj.target].sock.send(JSON.stringify(
- {code:"askchallenge",from:sid}));
- break;
- case "askgame":
- // Check all clients playing, and send them a "askgame" message
- Object.keys(clients).forEach(k => {
- if (k != sid && clients[k].page.indexOf("/game/") >= 0)
- {
- clients[k].sock.send(JSON.stringify(
- {code:"askgame", from: sid}));
+ }
+ case "disconnect":
+ // When page changes:
+ doDisconnect();
+ break;
+ case "pollclients": {
+ // From Game
+ let sockIds = {};
+ Object.keys(clients[page]).forEach(k => {
+ sockIds[k] = {};
+ Object.keys(clients[page][k]).forEach(x => {
+ // Avoid polling my tmpId: no information to get
+ if (k != sid || x != tmpId)
+ sockIds[k][x] = { focus: clients[page][k][x].focus };
+ });
+ });
+ send(socket, { code: "pollclients", sockIds: sockIds });
+ break;
+ }
+ case "pollclientsandgamers": {
+ // From Hall
+ let sockIds = {};
+ Object.keys(clients["/"]).forEach(k => {
+ sockIds[k] = {};
+ Object.keys(clients[page][k]).forEach(x => {
+ // Avoid polling my tmpId: no information to get
+ if (k != sid || x != tmpId) {
+ sockIds[k][x] = {
+ page: "/",
+ focus: clients[page][k][x].focus
+ };
+ }
+ });
+ });
+ // NOTE: a "gamer" could also just be an observer
+ Object.keys(clients).forEach(p => {
+ if (p.indexOf("/game/") >= 0) {
+ Object.keys(clients[p]).forEach(k => {
+ if (!sockIds[k]) sockIds[k] = {};
+ Object.keys(clients[p][k]).forEach(x => {
+ if (k != sid || x != tmpId) {
+ sockIds[k][x] = {
+ page: p,
+ focus: clients[p][k][x].focus
+ };
+ }
+ });
+ });