- clients[sid] = socket;
- // Notify room:
- Object.keys(clients).forEach(k => {
- if (k != sid)
- clients[k].send(JSON.stringify({code:"connect",sid:sid}));
- });
+ 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)));
+ }
+ });
+ };
+ notifyRoom(query["page"], "connect"); //Hall or Game