});
};
// For focus events: no need to target self
- const notifyAllButMe = (page,code,obj={}) => {
+ const notifyAllBut = (page,code,obj={},except) => {
if (!clients[page]) return;
Object.keys(clients[page]).forEach(k => {
- if (k == sid) return;
+ if (except.includes(k)) return;
Object.keys(clients[page][k]).forEach(x => {
send(
clients[page][k][x].socket,
// Notify all room: mostly game events
case "newchat":
case "newchallenge":
- case "newgame":
case "deletechallenge":
+ case "newgame":
case "resign":
case "abort":
case "drawoffer":
+ case "rematchoffer":
case "draw":
- notifyRoom(page, obj.code, {data: obj.data});
+ if (!!obj.oppsid)
+ // "newgame" message from Hall: do not target players
+ notifyAllBut(page, "newgame", {data: obj.data}, [sid, obj.oppsid]);
+ else notifyRoom(page, obj.code, {data: obj.data});
+ break;
+
+ case "rnewgame":
+ // A rematch game started: players are already informed
+ notifyAllBut(page, "newgame", {data: obj.data}, [sid]);
+ notifyAllBut("/", "newgame", {data: obj.data}, [sid, obj.oppsid]);
+ notifyRoom("/mygames", "newgame", {data: obj.data});
break;
case "newmove": {
case "getfocus":
case "losefocus":
- if (page == "/") notifyAllButMe("/", obj.code, { page: "/" });
+ if (page == "/") notifyAllBut("/", obj.code, { page: "/" }, [sid]);
else {
// Notify game room + Hall:
- notifyAllButMe(page, obj.code);
- notifyAllButMe("/", obj.code, { page: page });
+ notifyAllBut(page, obj.code, {}, [sid]);
+ notifyAllBut("/", obj.code, { page: page }, [sid]);
}
break;