X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=server%2Fsockets.js;h=ef2f07b4d1e57b146c58c140e6a8366f3a3db1a7;hp=b31334c185382e65d799cc3bfd72f605a17fbca9;hb=41c80bb63b85b2696d3925c10784c3d7bb5d2aa3;hpb=dcd68c4108412f45b8ce119ae80ce8f6e296800b diff --git a/server/sockets.js b/server/sockets.js index b31334c1..ef2f07b4 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -31,15 +31,20 @@ module.exports = function(wss) { } }); }; - notifyRoom(query["page"], "connect"); //Hall or Game - if (query["page"].indexOf("/game/") >= 0) - notifyRoom("/", "connect"); //notify main hall + // Wait for "connect" message to notify connection to the room, + // because if game loading is slow the message listener might + // not be ready too early. socket.on("message", objtxt => { let obj = JSON.parse(objtxt); if (!!obj.target && !clients[obj.target]) return; //receiver not connected, nothing we can do switch (obj.code) { + case "connect": + notifyRoom(query["page"], "connect"); //Hall or Game + if (query["page"].indexOf("/game/") >= 0) + notifyRoom("/", "connect"); //notify main hall + break; case "pollclients": const curPage = clients[sid].page; socket.send(JSON.stringify({code:"pollclients",