diff --git a/chat-signaling-server/templates/index.html b/chat-signaling-server/templates/index.html index 49dc15d..16d581f 100644 --- a/chat-signaling-server/templates/index.html +++ b/chat-signaling-server/templates/index.html @@ -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) {