+ // Always add myself to players' list
+ const my = this.st.user;
+ this.people.push({sid:my.sid, id:my.id, name:my.name});
+ this.gameRef.id = this.$route.params["id"];
+ this.gameRef.rid = this.$route.query["rid"]; //may be undefined
+ if (!this.gameRef.rid)
+ this.loadGame(); //local or corr: can load from now
+ // TODO: mode analyse (/analyze/Atomic/rn
+ // ... fen = query[], vname=params[] ...
+ // 0.1] Ask server for room composition:
+ const initialize = () => {
+ // Poll clients + load game if stored remotely
+ this.st.conn.send(JSON.stringify({code:"pollclients"}));
+ if (!!this.gameRef.rid)
+ this.loadGame();
+ };
+ if (!!this.st.conn && this.st.conn.readyState == 1) //1 == OPEN state
+ initialize();
+ else //socket not ready yet (initial loading)
+ this.st.conn.onopen = initialize;
+ this.st.conn.onmessage = this.socketMessageListener;
+ const socketCloseListener = () => {
+ store.socketCloseListener(); //reinitialize connexion (in store.js)
+ this.st.conn.addEventListener('message', this.socketMessageListener);
+ this.st.conn.addEventListener('close', socketCloseListener);
+ };
+ this.st.conn.onclose = socketCloseListener;
+ },
+ methods: {
+ getOppSid: function() {
+ if (!!this.game.oppsid)
+ return this.game.oppsid;
+ const opponent = this.people.find(p => p.id == this.game.oppid);
+ return (!!opponent ? opponent.sid : null);
+ },
+ socketMessageListener: function(msg) {