X-Git-Url: https://git.auder.net/assets/icon_infos.svg?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=2a5b57092440a40ae04521c23d5ffe566d989e51;hb=30ff6e040843efa1f283eede84e5995bb0eed09d;hp=c5d858f0d3aa4965a41fc344e6b6aec484989540;hpb=d35f20e4fcfcbadae3dd98ef9cf757e7f88d12a2;p=vchess.git diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index c5d858f0..2a5b5709 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -1,3 +1,5 @@ +// TODO: use indexedDB instead of localStorage: more flexible. + Vue.component('my-game', { data: function() { return { @@ -27,7 +29,17 @@ Vue.component('my-game', { let actionArray = [ h('button', { - on: { click: () => this.newGame("human") }, + on: { + click: () => { + if (localStorage.getItem("newgame") === variant) + delete localStorage["newgame"]; //cancel game seek + else + { + localStorage["newgame"] = variant; + this.newGame("human"); + } + } + }, attrs: { "aria-label": 'New game VS human' }, 'class': { "tooltip":true }, }, @@ -137,7 +149,7 @@ Vue.component('my-game', { ) ); } - const lm = this.vr.lastMove; //TODO: interruptions (FEN local storage..) + const lm = this.vr.lastMove; const highlight = !!lm && _.isMatch(lm.end, {x:ci,y:cj}); //&& _.isMatch(lm.start, {x:ci,y:cj}) return h( 'div', @@ -314,6 +326,11 @@ Vue.component('my-game', { // Send ping to server, which answers pong if opponent is connected this.conn.send(JSON.stringify({code:"ping", oppid:this.oppId})); } + else if (localStorage.getItem("newgame") === variant) + { + // New game request has been cancelled on disconnect + this.newGame("human"); + } }; const socketMessageListener = msg => { const data = JSON.parse(msg.data); @@ -340,7 +357,7 @@ Vue.component('my-game', { } }; const socketCloseListener = () => { - console.log("Lost connection -- reconnect"); //TODO: be more subtle than that, reconnect only when needed! + console.log("Lost connection -- reconnect"); this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant); this.conn.addEventListener('open', socketOpenListener); this.conn.addEventListener('message', socketMessageListener);