always cleanup old sockets regardless of autoconnect
This commit is contained in:
parent
a6feb49eb0
commit
903ec31b47
1 changed files with 9 additions and 9 deletions
|
@ -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', '<label class="time-label" for="ws-input-send">Send: </label> <input placeholder="Press enter" id="ws-input-send" />');
|
||||
this.insertAdjacentHTML('beforeend', `
|
||||
<label class="time-label" for="ws-input-send">Send: </label>
|
||||
<input placeholder="Press enter" id="ws-input-send" />`
|
||||
);
|
||||
|
||||
this.input = this.querySelector('input');
|
||||
var self = this;
|
||||
this.input.addEventListener('keyup', function(evt) {
|
||||
|
|
Loading…
Reference in a new issue