From: Benjamin Auder Date: Sun, 22 Mar 2020 14:18:39 +0000 (+0100) Subject: Attempt to get rid of unwanted trans-rooms socket listen/message... X-Git-Url: https://git.auder.net/game/current/app_dev.php/rpsls.js?a=commitdiff_plain;h=68e3aa8c7a92efe3461bfc5c904f9763bca5d2da;p=vchess.git Attempt to get rid of unwanted trans-rooms socket listen/message... --- diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 0662fe84..89edb96d 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -236,7 +236,10 @@ export default { clearInterval(this.retrySendmove); if (!!this.clockUpdate) clearInterval(this.clockUpdate); + this.conn.removeEventListener("message", this.socketMessageListener); + this.conn.removeEventListener("close", this.socketCloseListener); this.send("disconnect"); + this.conn = null; }, visibilityChange: function() { // TODO: Use document.hidden? https://webplatform.news/issues/2019-03-27 diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index d113da7a..24c3ac6a 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -398,7 +398,10 @@ export default { cleanBeforeDestroy: function() { document.removeEventListener('visibilitychange', this.visibilityChange); window.removeEventListener("beforeunload", this.cleanBeforeDestroy); + this.conn.removeEventListener("message", this.socketMessageListener); + this.conn.removeEventListener("close", this.socketCloseListener); this.send("disconnect"); + this.conn = null; }, getRandomnessClass: function(pc) { return { diff --git a/client/src/views/MyGames.vue b/client/src/views/MyGames.vue index 3c2f460b..7615308b 100644 --- a/client/src/views/MyGames.vue +++ b/client/src/views/MyGames.vue @@ -143,7 +143,10 @@ export default { methods: { cleanBeforeDestroy: function() { 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; }, setDisplay: function(type, e) { this.display = type; @@ -182,6 +185,7 @@ export default { }); }, socketMessageListener: function(msg) { + if (!this.conn) return; const data = JSON.parse(msg.data); let gamesArrays = { "corr": this.corrGames, @@ -262,16 +266,18 @@ export default { game.players[0].sid == this.st.user.sid ? game.players[1].sid : game.players[0].sid; - this.conn.send( - JSON.stringify( - { - code: "mabort", - gid: game.id, - // NOTE: target might not be online - target: oppsid - } - ) - ); + if (!!this.conn) { + this.conn.send( + JSON.stringify( + { + code: "mabort", + gid: game.id, + // NOTE: target might not be online + target: oppsid + } + ) + ); + } } else if (!game.deletedByWhite || !game.deletedByBlack) { // Set score if game isn't deleted on server: