From 80ee5d5a70f17f78900a8a3ae2d803ed1f2f14c9 Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Sat, 18 Jan 2020 18:22:31 +0100 Subject: [PATCH] Some fixes --- client/src/main.js | 4 +++- client/src/store.js | 3 ++- server/sockets.js | 11 +++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/client/src/main.js b/client/src/main.js index 6714939b..674852db 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -12,7 +12,9 @@ new Vue({ }, created: function() { window.doClick = (elemId) => { document.getElementById(elemId).click() }; - store.initialize(this.$route.path); + // TODO: why is this wrong? + //store.initialize(this.$route.path); + store.initialize(window.location.href.split("#")[1]); // 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 2728aaf0..1cfb7c5a 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -49,7 +49,8 @@ export const store = }; this.socketCloseListener = () => { // Next line may fail at first, but should retry and eventually success (TODO?) - this.state.conn = new WebSocket(params.socketUrl + "/?sid=" + mysid); + this.state.conn = new WebSocket(params.socketUrl + "/?sid=" + mysid + + "&page=" + encodeURIComponent(page)); }; this.state.conn.onclose = this.socketCloseListener; const supportedLangs = ["en","es","fr"]; diff --git a/server/sockets.js b/server/sockets.js index b3c3a1d6..b547c6a1 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -3,10 +3,9 @@ const url = require('url'); // Node version in Ubuntu 16.04 does not know about URL class function getJsonFromUrl(url) { - // url: /game/XYZ/?sid=XYZ - const queryParts = url.split("?"); - let result = {page: queryParts[0]}; - queryParts[1].split("&").forEach((part) => { + const query = url.substr(2); //starts with "/?" + let result = {}; + query.split("&").forEach((part) => { const item = part.split("="); result[item[0]] = decodeURIComponent(item[1]); }); @@ -102,12 +101,12 @@ console.log(clients); if (!!obj.target) { clients[obj.target].sock.send(JSON.stringify( - {code:"game", game:data.game, from:sid})); + {code:"game", game:obj.game, from:sid})); } else { // Notify all room except opponent and me: - notifyRoom("/", "game", {game:data.game}, [data.oppsid]); + notifyRoom("/", "game", {game:obj.game}, [obj.oppsid]); } break; case "newchat": -- 2.44.0