X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FHall.vue;h=95a9e9548e27b8a74bebd2b71f1584083e2979b7;hb=42c15a75118bfeb3251cea1f65acb01fcd023f01;hp=c7dc588b09fa3cc7789c230fe6abd8734a2535f9;hpb=c9695cb1ffd02c472dd24a2d336c9f3b98bd89da;p=vchess.git diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index c7dc588b..95a9e954 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -113,6 +113,15 @@ export default { created: function() { // Always add myself to players' list this.people.push(this.st.user); + // Retrieve live challenge (not older than 30 minute) if any: + const chall = JSON.parse(localStorage.getItem("challenge") || "false"); + if (!!chall) + { + if ((Date.now() - chall.added)/1000 <= 30*60) + this.challenges.push(chall); + else + localStorage.removeItem("challenge"); + } if (this.st.user.id > 0) { // Ask server for current corr games (all but mines) @@ -268,27 +277,28 @@ export default { timeControl: c.timeControl }; this.st.conn.send(JSON.stringify({code:"challenge", - challenge:myChallenge, target:data.from})); + chall:myChallenge, target:data.from})); } break; } case "askgame": { - // Send my current live games (if any) - // TODO: from indexedDB, through GameStorage. -// if (!!localStorage["gid"]) -// { -// const myGame = -// { -// // Minimal game informations: (fen+clock not required) -// id: localStorage["gid"], -// players: JSON.parse(localStorage["players"]), //array sid+id+name -// vname: localStorage["vname"], -// timeControl: localStorage["timeControl"], -// }; -// this.st.conn.send(JSON.stringify({code:"game", -// game:myGame, target:data.from})); -// } + // Send my current live game (if any) + GameStorage.getCurrent((game) => { + if (!!game) + { + const myGame = + { + // Minimal game informations: + id: game.id, + players: game.players.map(p => p.name), + vname: game.vname, + timeControl: game.timeControl, + }; + this.st.conn.send(JSON.stringify({code:"game", + game:myGame, target:data.from})); + } + }); break; } case "identity": @@ -305,8 +315,8 @@ export default { newChall.type = this.classifyObject(data.chall); const pIdx = this.people.findIndex(p => p.sid == data.from); newChall.from = this.people[pIdx]; //may be anonymous - newChall.added = Date.now(); - newChall.vname = this.getVname(newChall.vid); + newChall.added = Date.now(); //TODO: this is reception timestamp, not creation + newChall.vname = this.getVname(newChall.vid); //TODO: just send vname? this.challenges.push(newChall); break; } @@ -314,10 +324,10 @@ export default { { // Receive game from some player (+sid) // NOTE: it may be correspondance (if newgame while we are connected) - // TODO: ambiguous naming "newGame" ==> rename function ? let newGame = data.game; newGame.type = this.classifyObject(data.game); - newGame.vname = newGame.vname; + newGame.rid = data.from; + newGame.score = "*"; this.games.push(newGame); break; } @@ -328,7 +338,7 @@ export default { // Delete corresponding challenge: ArrayFun.remove(this.challenges, c => c.id == data.cid); // New game just started: data contain all informations - this.newGame(data.gameInfo); + this.startNewGame(data.gameInfo); break; } // * - receive "accept/cancel challenge": apply action to challenges list @@ -407,6 +417,7 @@ export default { chall.vname = vname; chall.from = this.st.user; this.challenges.push(chall); + localStorage.setItem("challenge", JSON.stringify(chall)); document.getElementById("modalNewgame").checked = false; }; const cIdx = this.challenges.findIndex( @@ -524,10 +535,10 @@ export default { gameInfo:gameInfo, cid:c.id, target:c.seat.sid})); // Delete corresponding challenge: ArrayFun.remove(this.challenges, ch => ch.id == c.id); - this.newGame(gameInfo); //also! + this.startNewGame(gameInfo); //also! }, // NOTE: for live games only (corr games are launched on server) - newGame: function(gameInfo) { + startNewGame: function(gameInfo) { // Extract times (in [milli]seconds), set clocks const tc = extractTime(gameInfo.timeControl); let initime = [...Array(gameInfo.players.length)];