- return socket.send(JSON.stringify({code:"duplicate"}));
- clients[sid] = socket;
- // Notify room:
- Object.keys(clients).forEach(k => {
- if (k != sid)
- clients[k].send(JSON.stringify({code:"connect",sid:sid}));
- });
+ {
+ // Dummy messages listener: just send "duplicate" event on anything
+ // ('connect' events for Hall and Game, 'askfullgame' for observers)
+ return socket.on("message", objtxt => {
+ if (["connect","askfullgame"].includes(JSON.parse(objtxt).code))
+ socket.send(JSON.stringify({code:"duplicate"}));
+ });
+ }
+ clients[sid] = {sock: socket, page: query["page"]};
+ const notifyRoom = (page,code,obj={},excluded=[]) => {
+ Object.keys(clients).forEach(k => {
+ if (k in excluded)
+ return;
+ if (k != sid && clients[k].page == page)
+ {
+ clients[k].sock.send(JSON.stringify(Object.assign(
+ {code:code, from:sid}, obj)));
+ }
+ });
+ };
+ // 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.