change ws variable to private property
This commit is contained in:
parent
fc5a5e1cc1
commit
60300ad2c3
1 changed files with 8 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
||||||
class WSElement extends HTMLElement {
|
class WSElement extends HTMLElement {
|
||||||
static #sockets = {};
|
static #sockets = {};
|
||||||
|
#socket;
|
||||||
#delay = 1000;
|
#delay = 1000;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -16,8 +17,6 @@ class WSElement extends HTMLElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
#connect_socket(recreate) {
|
#connect_socket(recreate) {
|
||||||
var ws;
|
|
||||||
|
|
||||||
// `recreate` is used to handle reconnects, removeing the old websocket object
|
// `recreate` is used to handle reconnects, removeing the old websocket object
|
||||||
// and recreating a new one
|
// and recreating a new one
|
||||||
if(recreate && WSElement.#sockets[this.src]) {
|
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
|
// check to see if one exists for this `src` else create
|
||||||
// a new one.
|
// a new one.
|
||||||
if(!(this.src in WSElement.#sockets)) {
|
if(!(this.src in WSElement.#sockets)) {
|
||||||
ws = WSElement.#newSocket(this.src);
|
this.#socket = WSElement.#newSocket(this.src);
|
||||||
WSElement.#sockets[this.src] = ws;
|
WSElement.#sockets[this.src] = this.#socket;
|
||||||
} else {
|
} else {
|
||||||
ws = WSElement.#sockets[this.src];
|
this.#socket = WSElement.#sockets[this.src];
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup event handlers for this WebSocket/Elemnent pair
|
// setup event handlers for this WebSocket/Elemnent pair
|
||||||
ws.addEventListener('error', this.#on_ws_error.bind(this));
|
this.#socket.addEventListener('error', this.#on_ws_error.bind(this));
|
||||||
ws.addEventListener('message', this.#on_ws_message.bind(this));
|
this.#socket.addEventListener('message', this.#on_ws_message.bind(this));
|
||||||
ws.addEventListener('open', this.#on_ws_open.bind(this));
|
this.#socket.addEventListener('open', this.#on_ws_open.bind(this));
|
||||||
ws.addEventListener('close', this.#on_ws_close.bind(this));
|
this.#socket.addEventListener('close', this.#on_ws_close.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
#on_ws_open(sock) {
|
#on_ws_open(sock) {
|
||||||
|
|
Loading…
Reference in a new issue