X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FHall.vue;h=5c5dc33ef0d3a0ac1d6019ed8547ef486edabe55;hb=0d5335de5c94d780e03ac0aa3279b731c69455cc;hp=e60d982fe916cc04c61913e890c9b0b08d7ab7fb;hpb=7ebc0408a76b4a966273190a2ade49e0f97099be;p=vchess.git diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index e60d982f..5c5dc33e 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -253,6 +253,7 @@ export default { presetChalls: JSON.parse(localStorage.getItem("presetChalls") || "[]"), conn: null, connexionString: "", + socketCloseListener: 0, // Related to (killing of) self multi-connects: newConnect: {}, killed: {} @@ -306,7 +307,16 @@ export default { 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 => { @@ -396,10 +406,10 @@ export default { }, 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; }, @@ -578,7 +588,6 @@ export default { // TODO: shuffling and random filtering on server, // if the room is really crowded. Object.keys(data.sockIds).forEach(sid => { - // TODO: test sid != user.sid was already done on server if (sid != this.st.user.sid) { // Pick a target tmpId (+page) at random: const pt = Object.values(data.sockIds[sid]); @@ -595,7 +604,7 @@ export default { // 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 }); @@ -838,12 +847,6 @@ export default { 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",