Attempt to get rid of unwanted trans-rooms socket listen/message...
authorBenjamin Auder <benjamin.auder@somewhere>
Sun, 22 Mar 2020 14:18:39 +0000 (15:18 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sun, 22 Mar 2020 14:18:39 +0000 (15:18 +0100)
client/src/views/Game.vue
client/src/views/Hall.vue
client/src/views/MyGames.vue

index 0662fe8..89edb96 100644 (file)
@@ -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
index d113da7..24c3ac6 100644 (file)
@@ -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 {
index 3c2f460..7615308 100644 (file)
@@ -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: