32347119caedfef7dec35c302402422c2b82925f
1 import { ajax
} from "./utils/ajax";
2 import { getRandString
} from "./utils/alea";
3 import params
from "./parameters"; //for socket connection
16 ajax("/variants", "GET", res
=> { this.state
.variants
= res
.variantArray
; });
18 // id and name could be undefined
19 id: localStorage
["myuid"],
20 name: localStorage
["myname"],
22 // TODO: if there is a socket ID in localStorage, it means a live game was interrupted (and should resume)
23 const mysid
= localStorage
["mysid"] || getRandString();
24 this.state
.conn
= new WebSocket(params
.socketUrl
+ "/?sid=" + mysid
);
25 // Settings initialized with values from localStorage
26 this.state
.settings
= {
27 bcolor: localStorage
["bcolor"] || "lichess",
28 sound: parseInt(localStorage
["sound"]) || 2,
29 hints: parseInt(localStorage
["hints"]) || 1,
30 coords: !!eval(localStorage
["coords"]),
31 highlight: !!eval(localStorage
["highlight"]),
32 sqSize: parseInt(localStorage
["sqSize"]),
34 const socketCloseListener
= () => {
35 this.state
.conn
= new WebSocket(params
.socketUrl
+ "/?sid=" + mysid
);
37 this.state
.conn
.onclose
= socketCloseListener
;
38 const supportedLangs
= ["en","es","fr"];
39 this.state
.lang
= localStorage
["lang"] ||
40 supportedLangs
.includes(navigator
.language
)
43 this.setTranslations();
45 setTranslations: async
function() {
46 // Import translations from "./translations/$lang.js"
47 const tModule
= await
import("@/translations/" + this.state
.lang
+ ".js");
48 this.state
.tr
= tModule
.translations
;
51 this.state
.lang
= lang
;
52 this.setTranslations();