X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fsockets.js;h=d00b3c898c1d5f3ce41edb5740e847c96b04896b;hb=e45c98ec2e15626db02c98997ae9725635715990;hp=65e41635d1734ec76aa4182ef5b6656cb5277673;hpb=7ebc0408a76b4a966273190a2ade49e0f97099be;p=vchess.git diff --git a/server/sockets.js b/server/sockets.js index 65e41635..d00b3c89 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -124,13 +124,12 @@ module.exports = function(wss) { // From Game let sockIds = {}; Object.keys(clients[page]).forEach(k => { - // Avoid polling myself: no new information to get - if (k != sid) { - sockIds[k] = {}; - Object.keys(clients[page][k]).forEach(x => { + sockIds[k] = {}; + Object.keys(clients[page][k]).forEach(x => { + // Avoid polling my tmpId: no information to get + if (k != sid || x != tmpId) sockIds[k][x] = { focus: clients[page][k][x].focus }; - }); - } + }); }); send(socket, { code: "pollclients", sockIds: sockIds }); break; @@ -139,30 +138,30 @@ module.exports = function(wss) { // From Hall let sockIds = {}; Object.keys(clients["/"]).forEach(k => { - // Avoid polling myself: no new information to get - if (k != sid) { - sockIds[k] = {}; - Object.keys(clients[page][k]).forEach(x => { + sockIds[k] = {}; + Object.keys(clients[page][k]).forEach(x => { + // Avoid polling my tmpId: no information to get + if (k != sid || x != tmpId) { sockIds[k][x] = { page: "/", focus: clients[page][k][x].focus }; - }); - } + } + }); }); // NOTE: a "gamer" could also just be an observer Object.keys(clients).forEach(p => { if (p.indexOf("/game/") >= 0) { Object.keys(clients[p]).forEach(k => { - if (k != sid) { - if (!sockIds[k]) sockIds[k] = {}; - Object.keys(clients[p][k]).forEach(x => { + if (!sockIds[k]) sockIds[k] = {}; + Object.keys(clients[p][k]).forEach(x => { + if (k != sid || x != tmpId) { sockIds[k][x] = { page: p, focus: clients[p][k][x].focus }; - }); - } + } + }); }); } }); @@ -210,6 +209,9 @@ module.exports = function(wss) { clients[page][rid][rtmpId].socket, { code: "askfullgame", from: [sid,tmpId] } ); + } else { + // I'm the only person who have the game for the moment: + send(socket, { code: "fullgame", data: { empty: true } }); } } break;