From 68e3aa8c7a92efe3461bfc5c904f9763bca5d2da Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Sun, 22 Mar 2020 15:18:39 +0100 Subject: [PATCH] Attempt to get rid of unwanted trans-rooms socket listen/message... --- client/src/views/Game.vue | 3 +++ client/src/views/Hall.vue | 3 +++ client/src/views/MyGames.vue | 26 ++++++++++++++++---------- 3 files changed, 22 insertions(+), 10 deletions(-) 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: -- 2.44.0