corr: Number.MAX_SAFE_INTEGER
},
// hasMore == TRUE: a priori there could be more games to load
- hasMore: { live: true, corr: true },
+ hasMore: { live: true, corr: store.state.user.id > 0 },
conn: null,
- connexionString: ""
+ connexionString: "",
+ socketCloseListener: 0
};
},
watch: {
// Initialize connection
this.connexionString =
params.socketUrl +
- "/?sid=" +
- this.st.user.sid +
- "&id=" +
- this.st.user.id +
- "&tmpId=" +
- getRandString() +
+ "/?sid=" + this.st.user.sid +
+ "&id=" + this.st.user.id +
+ "&tmpId=" + getRandString() +
"&page=" +
encodeURIComponent(this.$route.path);
this.conn = new WebSocket(this.connexionString);
this.conn.onmessage = this.socketMessageListener;
- this.conn.onclose = this.socketCloseListener;
+ this.socketCloseListener = setInterval(
+ () => {
+ if (this.conn.readyState == 3) {
+ // Connexion is closed: re-open
+ this.conn.removeEventListener("message", this.socketMessageListener);
+ this.conn = new WebSocket(this.connexionString);
+ this.conn.addEventListener("message", this.socketMessageListener);
+ }
+ },
+ 1000
+ );
},
mounted: function() {
const adjustAndSetDisplay = () => {
}
}
);
- } else {
- this.loadMore(
- "live",
- () => this.loadMore("corr", adjustAndSetDisplay)
- );
- }
+ } else this.loadMore("live", adjustAndSetDisplay);
});
},
beforeDestroy: function() {
},
methods: {
cleanBeforeDestroy: function() {
+ clearInterval(this.socketCloseListener);
window.removeEventListener("beforeunload", this.cleanBeforeDestroy);
this.conn.removeEventListener("message", this.socketMessageListener);
- this.conn.removeEventListener("close", this.socketCloseListener);
this.conn.send(JSON.stringify({code: "disconnect"}));
this.conn = null;
},
}
}
},
- socketCloseListener: function() {
- this.conn = new WebSocket(this.connexionString);
- this.conn.addEventListener("message", this.socketMessageListener);
- this.conn.addEventListener("close", this.socketCloseListener);
- },
showGame: function(game) {
if (game.type == "live" || !game.myTurn) {
this.$router.push("/game/" + game.id);
}
},
loadMore: function(type, cb) {
- if (type == "corr") {
+ if (type == "corr" && this.st.user.id > 0) {
ajax(
"/completedgames",
"GET",