X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=server%2Fsockets.js;h=ef2f07b4d1e57b146c58c140e6a8366f3a3db1a7;hp=e4aa4493c15bad223613509d12a4bbf1de37127b;hb=5fd5fb22de02ed6c585e86a1c3dda50ff6071d2f;hpb=6d9f43154dc2374edf5b7b802910783869d66de1 diff --git a/server/sockets.js b/server/sockets.js index e4aa4493..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", @@ -150,11 +155,11 @@ module.exports = function(wss) { break; case "resign": clients[obj.target].sock.send(JSON.stringify( - {code:"resign"})); + {code:"resign", side:obj.side})); break; case "abort": clients[obj.target].sock.send(JSON.stringify( - {code:"abort",msg:obj.msg})); + {code:"abort"})); break; case "drawoffer": clients[obj.target].sock.send(JSON.stringify( @@ -162,7 +167,7 @@ module.exports = function(wss) { break; case "draw": clients[obj.target].sock.send(JSON.stringify( - {code:"draw"})); + {code:"draw", message:obj.message})); break; } });