Some fixes
authorBenjamin Auder <benjamin.auder@somewhere>
Sat, 18 Jan 2020 17:22:31 +0000 (18:22 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sat, 18 Jan 2020 17:22:31 +0000 (18:22 +0100)
client/src/main.js
client/src/store.js
server/sockets.js

index 6714939..674852d 100644 (file)
@@ -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");
index 2728aaf..1cfb7c5 100644 (file)
@@ -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"];
index b3c3a1d..b547c6a 100644 (file)
@@ -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":