X-Git-Url: https://git.auder.net/js/img/rock_paper_scissors_lizard_spock.gif?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FHall.vue;h=6a57622026cb7c5fc5dbef3c57eb981d9447b3ec;hb=f6f2bef10910ddb3430a40f4ab393b225250234a;hp=636eabc3cca71d147411ed4ef0647b821c0b8888;hpb=2cc10cdbc230f82202bdddb7a244c903c05ab351;p=vchess.git diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 636eabc3..6a576220 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) @@ -199,19 +208,17 @@ export default { {target: sid} ))); }; - if (!!to[0]) + if (!!to) { - to.forEach(pname => { - // Challenge with targeted players - const targetSid = this.getSid(pname); - if (!targetSid) - { - if (!!warnDisconnected) - alert("Warning: " + pname + " is not connected"); - } - else - doSend(code, obj, targetSid); - }); + // Challenge with targeted players + const targetSid = this.getSid(to); + if (!targetSid) + { + if (!!warnDisconnected) + alert("Warning: " + pname + " is not connected"); + } + else + doSend(code, obj, targetSid); } else { @@ -403,12 +410,13 @@ export default { const finishAddChallenge = (cid,warnDisconnected) => { chall.id = cid || "c" + getRandString(); // Send challenge to peers (if connected) - this.sendSomethingTo(cto, "challenge", {chall:chall}, !!warnDisconnected); + this.sendSomethingTo(chall.to, "challenge", {chall:chall}, !!warnDisconnected); chall.added = Date.now(); chall.type = ctype; 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(