From 903ec31b477ffd600dbeb1bb1df4eb1bedb91f49 Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Fri, 20 Oct 2023 11:50:56 -0700 Subject: [PATCH] always cleanup old sockets regardless of autoconnect --- static/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/static/index.js b/static/index.js index 36d7e55..cc43dd0 100644 --- a/static/index.js +++ b/static/index.js @@ -16,13 +16,7 @@ class WSElement extends HTMLElement { this.#connect_socket(false); } - #connect_socket(recreate) { - // `recreate` is used to handle reconnects, removeing the old websocket object - // and recreating a new one - if(recreate && WSElement.#sockets[this.src]) { - delete WSElement.#sockets[this.src]; - } - + #connect_socket() { // a single WebSocket can be reused for multiple elements // check to see if one exists for this `src` else create // a new one. @@ -77,9 +71,11 @@ class WSElement extends HTMLElement { this.close(sock); } + delete WSElement.#sockets[this.src]; + // handle autoreconnect and delay throttling if(this.autoreconnect) { - setTimeout(this.#connect_socket.call(this, true), this.#delay); + setTimeout(this.#connect_socket.bind(this), this.#delay); if(this.#delay < 10000) { this.#delay += 1000; } @@ -131,7 +127,11 @@ class WSInput extends WSSenderElement { connectedCallback() { super.connectedCallback(); - this.insertAdjacentHTML('beforeend', ' '); + this.insertAdjacentHTML('beforeend', ` + + ` + ); + this.input = this.querySelector('input'); var self = this; this.input.addEventListener('keyup', function(evt) {