throttle reconnect
This commit is contained in:
parent
ee339c82b3
commit
79b34139b5
@ -42,6 +42,8 @@
|
|||||||
|
|
||||||
this.ws = null;
|
this.ws = null;
|
||||||
|
|
||||||
|
this.reconnectTimeout = null;
|
||||||
|
|
||||||
this.event = new EventTarget();
|
this.event = new EventTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,11 +159,21 @@
|
|||||||
let ws = new WebSocket(protocol + location.host + "/ws");
|
let ws = new WebSocket(protocol + location.host + "/ws");
|
||||||
ws.addEventListener("error", (ev) => {
|
ws.addEventListener("error", (ev) => {
|
||||||
console.error("ws error", ev)
|
console.error("ws error", ev)
|
||||||
|
if(this.reconnectTimeout) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.reconnectTimeout = setTimeout(() => {
|
||||||
this.reconnect()
|
this.reconnect()
|
||||||
|
}, 3000)
|
||||||
})
|
})
|
||||||
ws.addEventListener("close", () => {
|
ws.addEventListener("close", () => {
|
||||||
console.warn("ws closed")
|
console.warn("ws closed")
|
||||||
|
if (this.reconnectTimeout) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.reconnectTimeout = setTimeout(() => {
|
||||||
this.reconnect()
|
this.reconnect()
|
||||||
|
}, 3000)
|
||||||
})
|
})
|
||||||
|
|
||||||
ws.addEventListener("message", ({ data }) => {
|
ws.addEventListener("message", ({ data }) => {
|
||||||
@ -172,6 +184,8 @@
|
|||||||
this.kickoff()
|
this.kickoff()
|
||||||
})
|
})
|
||||||
this.ws = ws;
|
this.ws = ws;
|
||||||
|
|
||||||
|
this.reconnectTimeout = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatRoom.prototype.send_message = function (message) {
|
ChatRoom.prototype.send_message = function (message) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user