From: Benjamin Auder Date: Sun, 9 Feb 2020 13:27:09 +0000 (+0100) Subject: Fixes X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/images/assets/doc/html/left.jpg?a=commitdiff_plain;h=d641bec1b3b299e16b7da93f966dad0b0bd35088;p=vchess.git Fixes --- diff --git a/client/src/main.js b/client/src/main.js index 9d2e73d1..2d855b8a 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -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"); diff --git a/client/src/store.js b/client/src/store.js index 798251f9..a1e432f3 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -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; diff --git a/client/src/views/Analyze.vue b/client/src/views/Analyze.vue index 96ecdad9..59d2f3a8 100644 --- a/client/src/views/Analyze.vue +++ b/client/src/views/Analyze.vue @@ -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() { diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index e3a9408b..8f571538 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -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) diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 5fcbb31a..b3645684 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -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; diff --git a/server/sockets.js b/server/sockets.js index df44520d..45e003f8 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -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;