presetChalls: JSON.parse(localStorage.getItem("presetChalls") || "[]"),
conn: null,
connexionString: "",
+ socketCloseListener: 0,
// Related to (killing of) self multi-connects:
newConnect: {},
killed: {}
this.conn = new WebSocket(this.connexionString);
this.conn.onopen = connectAndPoll;
this.conn.addEventListener("message", this.socketMessageListener);
- this.conn.addEventListener("close", this.socketCloseListener);
+ this.socketCloseListener = setInterval(
+ () => {
+ if (this.conn.readyState == 3) {
+ this.conn.removeEventListener("message", this.socketMessageListener);
+ this.conn = new WebSocket(this.connexionString);
+ this.conn.addEventListener("message", this.socketMessageListener);
+ }
+ },
+ 1000
+ );
},
mounted: function() {
["peopleWrap", "infoDiv", "newgameDiv"].forEach(eltName => {
},
methods: {
cleanBeforeDestroy: function() {
+ clearInterval(this.socketCloseListener);
document.removeEventListener('visibilitychange', this.visibilityChange);
window.removeEventListener("beforeunload", this.cleanBeforeDestroy);
this.conn.removeEventListener("message", this.socketMessageListener);
- this.conn.removeEventListener("close", this.socketCloseListener);
this.send("disconnect");
this.conn = null;
},
// Do not set name or id: identity unknown yet
this.people[sid] = { tmpIds: data.sockIds[sid] };
else
- Object.assign(this.people[s.sid].tmpIds, data.sockIds[sid]);
+ Object.assign(this.people[sid].tmpIds, data.sockIds[sid]);
if (Object.values(data.sockIds[sid]).some(v => v.page == "/"))
// Peer is in Hall
this.send("askchallenges", { target: sid });
break;
}
},
- socketCloseListener: function() {
- if (!this.conn) return;
- this.conn = new WebSocket(this.connexionString);
- this.conn.addEventListener("message", this.socketMessageListener);
- this.conn.addEventListener("close", this.socketCloseListener);
- },
loadMoreCorr: function() {
ajax(
"/observedgames",