X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=sockets.js;h=6dbb24a27b01456c0536939663f44133cdd25254;hb=0cb758e078f4981d1e5b5209e66ca02f544ec9d5;hp=2a43e323d6cdf58616918d1323486862af8f823d;hpb=3066bb47f49d374fca4c1c1cc047d9be8257ad35;p=vchess.git diff --git a/sockets.js b/sockets.js index 2a43e323..6dbb24a2 100644 --- a/sockets.js +++ b/sockets.js @@ -47,7 +47,10 @@ module.exports = function(wss) { switch (obj.code) { case "newmove": - clients[page][obj.oppid].send(JSON.stringify({code:"newmove",move:obj.move})); + // TODO: adjust with readyState? (+ setTimeout()?) + send opponent (re)disconnect + // https://github.com/websockets/ws/blob/master/lib/websocket.js line 313 + if (!!clients[page][obj.oppid]) + clients[page][obj.oppid].send(JSON.stringify({code:"newmove",move:obj.move})); break; case "ping": if (!!clients[page][obj.oppid]) @@ -62,6 +65,7 @@ module.exports = function(wss) { delete games[page]; const mycolor = Math.random() < 0.5 ? 'w' : 'b'; socket.send(JSON.stringify({code:"newgame",fen:fen,oppid:oppId,color:mycolor})); + // TODO: check readyState, potential setTimeout()? + send opponent (re)disconnect clients[page][oppId].send(JSON.stringify({code:"newgame",fen:fen,oppid:sid,color:mycolor=="w"?"b":"w"})); } else