From: Benjamin Auder Date: Mon, 20 Jan 2020 10:19:56 +0000 (+0100) Subject: Fix online indicators between Hall and Game pages X-Git-Url: https://git.auder.net/doc/html/index.html?a=commitdiff_plain;h=bcaa8c0061b67fa95691a951d415bafef33265a2;p=vchess.git Fix online indicators between Hall and Game pages --- diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index e11e8e13..851201f8 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -117,17 +117,21 @@ export default { computed: { uniquePlayers: function() { // Show e.g. "@nonymous (5)", and do nothing on click on anonymous - let anonymous = {id:0, name:"@nonymous", count:0}; - let playerList = []; + let anonymous = {name:"@nonymous", count:0}; + let playerList = {}; this.people.forEach(p => { if (p.id > 0) - playerList.push(p); + { + // We don't count registered users connections: either they are here or not. + if (!playerList[p.id]) + playerList[p.id] = {name: p.name, count: 0}; + } else anonymous.count++; }); if (anonymous.count > 0) - playerList.push(anonymous); - return playerList; + playerList[0] = anonymous; + return Object.values(playerList); }, }, created: function() { diff --git a/server/sockets.js b/server/sockets.js index b547c6a1..b7689d7a 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -33,13 +33,14 @@ module.exports = function(wss) { }); }; notifyRoom(query["page"], "connect"); //Hall or Game + if (query["page"].indexOf("/game/") >= 0) + notifyRoom("/", "connect"); //notify main hall socket.on("message", objtxt => { let obj = JSON.parse(objtxt); if (!!obj.target && !clients[obj.target]) return; //receiver not connected, nothing we can do console.log(obj.code); -console.log(clients); switch (obj.code) { @@ -54,8 +55,12 @@ console.log(clients); break; case "pagechange": notifyRoom(clients[sid].page, "disconnect"); + if (clients[sid].page.indexOf("/game/") >= 0) + notifyRoom("/", "disconnect"); clients[sid].page = obj.page; notifyRoom(obj.page, "connect"); + if (obj.page.indexOf("/game/") >= 0) + notifyRoom("/", "connect"); break; case "askidentity": clients[obj.target].sock.send(JSON.stringify( @@ -143,6 +148,8 @@ console.log(clients); const page = clients[sid].page; delete clients[sid]; notifyRoom(page, "disconnect"); + if (page.indexOf("/game/") >= 0) + notifyRoom("/", "disconnect"); //notify main hall }); }); }