settings: {},
lang: "",
},
+ socketCloseListener: null,
initialize() {
ajax("/variants", "GET", res => { this.state.variants = res.variantArray; });
let mysid = localStorage["mysid"];
highlight: !!eval(localStorage["highlight"]),
sqSize: parseInt(localStorage["sqSize"]),
};
- const socketCloseListener = () => {
+ this.socketCloseListener = () => {
this.state.conn = new WebSocket(params.socketUrl + "/?sid=" + mysid);
};
- this.state.conn.onclose = socketCloseListener;
+ this.state.conn.onclose = this.socketCloseListener;
const supportedLangs = ["en","es","fr"];
this.state.lang = localStorage["lang"] ||
supportedLangs.includes(navigator.language)
this.gameRef.rid = this.$route.query["rid"];
this.loadGame();
}
- const socketMessageListener = msg => {
+ // TODO: onopen, ask lastState informations + update observers and players status
+ const socketCloseListener = () => {
+ store.socketCloseListener(); //reinitialize connexion (in store.js)
+ this.st.conn.addEventListener('message', socketMessageListener);
+ this.st.conn.addEventListener('close', socketCloseListener);
+ };
+ this.st.conn.onmessage = this.socketMessageListener;
+ this.st.conn.onclose = socketCloseListener;
+ },
+ methods: {
+ socketMessageListener: function(msg) {
const data = JSON.parse(msg.data);
switch (data.code)
{
}
break;
}
- };
- // TODO: onopen, ask lastState informations + update observers and players status
- const socketCloseListener = () => {
- this.st.conn.addEventListener('message', socketMessageListener);
- this.st.conn.addEventListener('close', socketCloseListener);
- };
- this.st.conn.onmessage = socketMessageListener;
- this.st.conn.onclose = socketCloseListener;
- },
- methods: {
+ },
offerDraw: function() {
// TODO: also for corr games
if (this.drawOffer == "received")
else //socket not ready yet (initial loading)
this.st.conn.onopen = funcPollClients;
this.st.conn.onmessage = this.socketMessageListener;
- const oldOnclose = this.st.conn.onclose;
const socketCloseListener = () => {
- oldOnclose(); //reinitialize connexion (in store.js)
+ store.socketCloseListener(); //reinitialize connexion (in store.js)
this.st.conn.addEventListener('message', this.socketMessageListener);
this.st.conn.addEventListener('close', socketCloseListener);
};