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