X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fsockets.js;h=75aeadd33da5910c05a72bdd17b3bb926d422dd7;hb=120fe373ca3b9e83e33bd59979af10fe09350fc5;hp=ef2f07b4d1e57b146c58c140e6a8366f3a3db1a7;hpb=41c80bb63b85b2696d3925c10784c3d7bb5d2aa3;p=vchess.git diff --git a/server/sockets.js b/server/sockets.js index ef2f07b4..75aeadd3 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -41,27 +41,37 @@ module.exports = function(wss) { switch (obj.code) { case "connect": - notifyRoom(query["page"], "connect"); //Hall or Game - if (query["page"].indexOf("/game/") >= 0) - notifyRoom("/", "connect"); //notify main hall + { + const curPage = clients[sid].page; + notifyRoom(curPage, "connect"); //Hall or Game + if (curPage.indexOf("/game/") >= 0) + notifyRoom("/", "gconnect"); //notify main hall break; + } case "pollclients": + { const curPage = clients[sid].page; socket.send(JSON.stringify({code:"pollclients", - sockIds: Object.keys(clients).filter(k => k != sid && - (clients[k].page == curPage || - // Consider that people playing are in Hall too: - (curPage == "/" && clients[k].page.indexOf("/game/") >= 0)) + sockIds: Object.keys(clients).filter(k => + k != sid && clients[k].page == curPage + )})); + break; + } + case "pollgamers": + socket.send(JSON.stringify({code:"pollgamers", + sockIds: Object.keys(clients).filter(k => + k != sid && clients[k].page.indexOf("/game/") >= 0 )})); break; case "pagechange": + // page change clients[sid].page --> obj.page notifyRoom(clients[sid].page, "disconnect"); if (clients[sid].page.indexOf("/game/") >= 0) - notifyRoom("/", "disconnect"); + notifyRoom("/", "gdisconnect"); clients[sid].page = obj.page; notifyRoom(obj.page, "connect"); if (obj.page.indexOf("/game/") >= 0) - notifyRoom("/", "connect"); + notifyRoom("/", "gconnect"); break; case "askidentity": clients[obj.target].sock.send(JSON.stringify( @@ -140,11 +150,10 @@ module.exports = function(wss) { } break; case "newchat": - // WARNING: do not use query["page"], because the page may change - notifyRoom(clients[sid].page, "newchat", - {msg: obj.msg, name: obj.name}); + notifyRoom(clients[sid].page, "newchat", {chat:obj.chat}); break; // TODO: WebRTC instead in this case (most demanding?) + // --> At least do a "notifyRoom" case "newmove": clients[obj.target].sock.send(JSON.stringify( {code:"newmove", move:obj.move})); @@ -176,7 +185,7 @@ module.exports = function(wss) { delete clients[sid]; notifyRoom(page, "disconnect"); if (page.indexOf("/game/") >= 0) - notifyRoom("/", "disconnect"); //notify main hall + notifyRoom("/", "gdisconnect"); //notify main hall }); }); }