- case "enter":
- if (clients[sid].path.length > 0)
- remInArray(pages[clients[sid].path], sid);
- clients[sid].path = obj.path;
- pages[obj.path].push(sid);
- // TODO also: notify "old" sub-room that I left (if it was not index)
- if (obj.path == "/")
- {
- // Send counting info
- let countings = {};
- Object.keys(pages).forEach(
- path => { countings[path] = pages[path].length; });
- socket.send(JSON.stringify({code:"counts",counts:countings}));
- }
- else
- {
- // Send to every client connected on index an update message for counts
- pages["/"].forEach((id) => {
- clients[id].socket.send(
- JSON.stringify({code:"increase",path:obj.path}), noop);
- });
- // TODO: do not notify anything in rules and problems sections (no socket required)
- // --> in fact only /Atomic (main hall) and inside a game: /Atomic/392f3ju
- // Also notify the (sub-)room (including potential opponents):
- Object.keys(clients[page]).forEach( k => {
- clients[page][k].send(JSON.stringify({code:"connect",id:sid}), noop);
- });
- // Finally, receive (sub-)room composition
- // TODO.
- }
-// NOTE: no "leave" counterpart (because it's always to enter somewhere else)
-// case "leave":
-// break;
- // Transmit chats and moves to current room
- // TODO: WebRTC instead in this case (most demanding?)
+ case "pollclients":
+ socket.send(JSON.stringify({code:"pollclients",
+ sockIds:Object.keys(clients).filter(k => k != sid)}));
+ break;
+ case "askidentity":
+ clients[obj.target].send(
+ JSON.stringify({code:"askidentity",from:sid}));
+ break;
+ case "askchallenge":
+ clients[obj.target].send(
+ JSON.stringify({code:"askchallenge",from:sid}));
+ break;
+ case "askgame":
+ clients[obj.target].send(
+ JSON.stringify({code:"askgame",from:sid}));
+ break;
+ case "identity":
+ clients[obj.target].send(
+ JSON.stringify({code:"identity",user:obj.user}));
+ break;
+ case "challenge":
+ // Relay challenge to other player
+ clients[obj.target].send(
+ JSON.stringify({code:"challenge", chall:obj.chall, from:sid}));
+ break;
+ case "acceptchallenge":
+ clients[obj.target].send(
+ JSON.stringify({code:"acceptchallenge", cid:obj.cid, from:sid}));
+ break;
+ case "game":
+ // TODO: relay (live) game to other player
+ break;