Various fixes
[vchess.git] / client / src / store.js
index 12c756c..94dcb06 100644 (file)
@@ -14,7 +14,7 @@ export const store =
     lang: "",
   },
   socketCloseListener: null,
-  initialize() {
+  initialize(page) {
     ajax("/variants", "GET", res => { this.state.variants = res.variantArray; });
     let mysid = localStorage["mysid"];
     if (!mysid)
@@ -35,18 +35,9 @@ export const store =
         this.state.user.email = res.email;
         this.state.user.notify = res.notify;
       });
-      // TODO: fetch is simpler, but does not set req.xhr (for security check)
-//      fetch(params.serverUrl + "/whoami", {
-//        method: "GET",
-//        credentials: params.cors ? "include" : "omit",
-//      }).then((res) => {
-//        return res.json()
-//      }).then((user) => {
-//        this.state.user.email = user.email;
-//        this.state.user.notify = user.notify;
-//      });
     }
-    this.state.conn = new WebSocket(params.socketUrl + "/?sid=" + mysid);
+    this.state.conn = new WebSocket(params.socketUrl + "/?sid=" + mysid +
+      "&page=" + encodeURIComponent(page));
     // Settings initialized with values from localStorage
     this.state.settings = {
       bcolor: localStorage["bcolor"] || "lichess",
@@ -58,14 +49,15 @@ 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"];
     this.state.lang = localStorage["lang"] ||
-      supportedLangs.includes(navigator.language)
+      (supportedLangs.includes(navigator.language)
         ? navigator.language
-        : "en";
+        : "en");
     this.setTranslations();
   },
   setTranslations: async function() {