- // TODO: later, allow duplicate connections (shouldn't be much more complicated)
- if (!!clients[sid])
- return 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)));
- }
+ const id = query["id"];
+ const tmpId = query["tmpId"];
+ const page = query["page"];
+ const notifyRoom = (page,code,obj={}) => {
+ if (!clients[page]) return;
+ Object.keys(clients[page]).forEach(k => {
+ Object.keys(clients[page][k]).forEach(x => {
+ if (k == sid && x == tmpId) return;
+ send(
+ clients[page][k][x].socket,
+ Object.assign({ code: code, from: sid }, obj)
+ );
+ });
+ });
+ };
+ // For focus events: no need to target self
+ const notifyAllBut = (page,code,obj={},except) => {
+ if (!clients[page]) return;
+ Object.keys(clients[page]).forEach(k => {
+ if (except.includes(k)) return;
+ Object.keys(clients[page][k]).forEach(x => {
+ send(
+ clients[page][k][x].socket,
+ Object.assign({ code: code, from: sid }, obj)
+ );
+ });