X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FMyGames.vue;h=d1079ee49cbb536b3746d8445901c447eec6ab96;hb=882ec6fe88ac4a536dd25eca5fd50ff3d27f7994;hp=94035287c16807b30a3ad7ca6e66886ee90e01f1;hpb=c0250d0a78682d9d6eee3193a4573c7aeaf7b32f;p=vchess.git diff --git a/client/src/views/MyGames.vue b/client/src/views/MyGames.vue index 94035287..d1079ee4 100644 --- a/client/src/views/MyGames.vue +++ b/client/src/views/MyGames.vue @@ -55,7 +55,8 @@ export default { // hasMore == TRUE: a priori there could be more games to load hasMore: { live: true, corr: store.state.user.id > 0 }, conn: null, - connexionString: "" + connexionString: "", + socketCloseListener: 0 }; }, watch: { @@ -75,7 +76,17 @@ export default { encodeURIComponent(this.$route.path); this.conn = new WebSocket(this.connexionString); this.conn.onmessage = this.socketMessageListener; - this.conn.onclose = this.socketCloseListener; + this.socketCloseListener = setInterval( + () => { + if (this.conn.readyState == 3) { + // Connexion is closed: re-open + this.conn.removeEventListener("message", this.socketMessageListener); + this.conn = new WebSocket(this.connexionString); + this.conn.addEventListener("message", this.socketMessageListener); + } + }, + 1000 + ); }, mounted: function() { const adjustAndSetDisplay = () => { @@ -134,9 +145,9 @@ export default { }, methods: { cleanBeforeDestroy: function() { + clearInterval(this.socketCloseListener); window.removeEventListener("beforeunload", this.cleanBeforeDestroy); this.conn.removeEventListener("message", this.socketMessageListener); - this.conn.removeEventListener("close", this.socketCloseListener); this.conn.send(JSON.stringify({code: "disconnect"})); this.conn = null; }, @@ -228,11 +239,6 @@ export default { } } }, - socketCloseListener: function() { - this.conn = new WebSocket(this.connexionString); - this.conn.addEventListener("message", this.socketMessageListener); - this.conn.addEventListener("close", this.socketCloseListener); - }, showGame: function(game) { if (game.type == "live" || !game.myTurn) { this.$router.push("/game/" + game.id);