Fixes
authorBenjamin Auder <benjamin.auder@somewhere>
Sun, 9 Feb 2020 13:27:09 +0000 (14:27 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sun, 9 Feb 2020 13:27:09 +0000 (14:27 +0100)
client/src/main.js
client/src/store.js
client/src/views/Analyze.vue
client/src/views/Game.vue
client/src/views/Hall.vue
server/sockets.js

index 9d2e73d..2d855b8 100644 (file)
@@ -22,9 +22,7 @@ new Vue({
         });
       }
     });
-    // TODO: why is this wrong? (Maybe because $route still uninitialized?)
-    //store.initialize(this.$route.path);
+    // NOTE: store.initialize(this.$route.path); doesn't work
     store.initialize(window.location.href.split("#")[1].split("?")[0]);
-    // NOTE: at this point, variants and tr(anslations) might be uninitialized
   },
 }).$mount("#app");
index 798251f..a1e432f 100644 (file)
@@ -38,6 +38,13 @@ export const store =
       this.state.user.email = res.email;
       this.state.user.notify = res.notify;
     });
+    const supportedLangs = ["en","es","fr"];
+    this.state.lang = localStorage["lang"] ||
+      (supportedLangs.includes(navigator.language)
+        ? navigator.language
+        : "en");
+    this.setTranslations();
+    // Initialize connection (even if the current page doesn't need it)
     this.state.conn = new WebSocket(params.socketUrl + "/?sid=" + mysid +
       "&page=" + encodeURIComponent(page));
     // Settings initialized with values from localStorage
@@ -53,12 +60,6 @@ export const store =
         "&page=" + encodeURIComponent(page));
     };
     this.state.conn.onclose = this.socketCloseListener;
-    const supportedLangs = ["en","es","fr"];
-    this.state.lang = localStorage["lang"] ||
-      (supportedLangs.includes(navigator.language)
-        ? navigator.language
-        : "en");
-    this.setTranslations();
   },
   updateSetting: function(propName, value) {
     this.state.settings[propName] = value;
index 96ecdad..59d2f3a 100644 (file)
@@ -70,6 +70,7 @@ export default {
       this.curFen = this.game.fen;
       this.adjustFenSize();
       this.vr = new V(this.game.fen);
+      this.game.mycolor = this.vr.turn;
       this.$set(this.game, "fenStart", this.gameRef.fen);
     },
     adjustFenSize: function() {
index e3a9408..8f57153 100644 (file)
@@ -165,7 +165,8 @@ export default {
       switch (data.code)
       {
         case "duplicate":
-          this.st.conn.send(JSON.stringify({code:"duplicate"}));
+          this.st.conn.send(JSON.stringify({code:"duplicate",
+            page:"/game/" + this.game.id}));
           alert(this.st.tr["Warning: multi-tabs not supported"]);
           break;
         // 0.2] Receive clients list (just socket IDs)
index 5fcbb31..b364568 100644 (file)
@@ -307,7 +307,7 @@ export default {
       switch (data.code)
       {
         case "duplicate":
-          this.st.conn.send(JSON.stringify({code:"duplicate"}));
+          this.st.conn.send(JSON.stringify({code:"duplicate", page:"/"}));
           this.st.conn.send = () => {};
           alert(this.st.tr["Warning: multi-tabs not supported"]);
           break;
index df44520..45e003f 100644 (file)
@@ -39,10 +39,11 @@ module.exports = function(wss) {
           // Turn off message listening, and send disconnect if needed:
           socket.removeListener("message", messageListener);
           socket.removeListener("close", closeListener);
+          // From obj.page to clients[sid].page (TODO: unclear)
           if (clients[sid].page != obj.page)
           {
-            notifyRoom(clients[sid].page, "disconnect");
-            if (clients[sid].page.indexOf("/game/") >= 0)
+            notifyRoom(obj.page, "disconnect");
+            if (obj.page.indexOf("/game/") >= 0)
               notifyRoom("/", "gdisconnect");
           }
           break;