X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=sockets.js;h=a1818e09803ab50542f6599d2072b9553d242c98;hb=4b5fe3061829e184f9ad86a13d831eda22d95343;hp=6dbb24a27b01456c0536939663f44133cdd25254;hpb=0cb758e078f4981d1e5b5209e66ca02f544ec9d5;p=vchess.git diff --git a/sockets.js b/sockets.js index 6dbb24a2..a1818e09 100644 --- a/sockets.js +++ b/sockets.js @@ -18,6 +18,10 @@ module.exports = function(wss) { for (const v of Variants) clients[v.name] = {}; + // TODO: when relaying to opponent, check readyState, potential setTimeout()? + send opponent (re)disconnect + // (resign, newgame, newmove). See https://github.com/websockets/ws/blob/master/lib/websocket.js around line 313 + // TODO: awaiting newmove, resign, newgame :: in memory structure + wss.on("connection", (socket, req) => { //const params = new URL("http://localhost" + req.url).searchParams; var query = getJsonFromUrl(req.url); @@ -47,10 +51,7 @@ module.exports = function(wss) { switch (obj.code) { case "newmove": - // 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})); + clients[page][obj.oppid].send(JSON.stringify({code:"newmove",move:obj.move})); break; case "ping": if (!!clients[page][obj.oppid]) @@ -65,7 +66,6 @@ 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