From 60300ad2c3bcc3afafa6dad3eb2ee938a7a72ebb Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Thu, 19 Oct 2023 11:51:58 -0700 Subject: [PATCH] change ws variable to private property --- static/index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/static/index.js b/static/index.js index 699bc11..88c2f13 100644 --- a/static/index.js +++ b/static/index.js @@ -1,5 +1,6 @@ class WSElement extends HTMLElement { static #sockets = {}; + #socket; #delay = 1000; constructor() { @@ -16,8 +17,6 @@ class WSElement extends HTMLElement { } #connect_socket(recreate) { - var ws; - // `recreate` is used to handle reconnects, removeing the old websocket object // and recreating a new one if(recreate && WSElement.#sockets[this.src]) { @@ -28,17 +27,17 @@ class WSElement extends HTMLElement { // check to see if one exists for this `src` else create // a new one. if(!(this.src in WSElement.#sockets)) { - ws = WSElement.#newSocket(this.src); - WSElement.#sockets[this.src] = ws; + this.#socket = WSElement.#newSocket(this.src); + WSElement.#sockets[this.src] = this.#socket; } else { - ws = WSElement.#sockets[this.src]; + this.#socket = WSElement.#sockets[this.src]; } // setup event handlers for this WebSocket/Elemnent pair - ws.addEventListener('error', this.#on_ws_error.bind(this)); - ws.addEventListener('message', this.#on_ws_message.bind(this)); - ws.addEventListener('open', this.#on_ws_open.bind(this)); - ws.addEventListener('close', this.#on_ws_close.bind(this)); + this.#socket.addEventListener('error', this.#on_ws_error.bind(this)); + this.#socket.addEventListener('message', this.#on_ws_message.bind(this)); + this.#socket.addEventListener('open', this.#on_ws_open.bind(this)); + this.#socket.addEventListener('close', this.#on_ws_close.bind(this)); } #on_ws_open(sock) {