diff --git a/src/common/ClientConnection.ts b/src/common/ClientConnection.ts index 34174c6..3383fde 100644 --- a/src/common/ClientConnection.ts +++ b/src/common/ClientConnection.ts @@ -35,14 +35,24 @@ export default class ClientConnection { return this._is_login; } + private _destoryWS() { + this._destoryed = true; + if (this.ws) { + this.ws.onclose = null; + this.ws.onerror = null; + this.ws.onopen = null; + this.ws.onmessage = null; + } + this.ws?.close(); + this.ws = null; + } public reconnectTo( url: string, user_name?: string | null, password?: string | null ) { if (this._destoryed) { - this.ws?.close(); - this.ws = null; + this._destoryWS(); return; } this.url = url; @@ -76,8 +86,7 @@ export default class ClientConnection { login() { if (this._destoryed) { - this.ws?.close(); - this.ws = null; + this._destoryWS(); return; } if (this.is_connected) { @@ -102,8 +111,7 @@ export default class ClientConnection { private _reconnect() { if (this._destoryed) { - this.ws?.close(); - this.ws = null; + this._destoryWS(); return; } if ( @@ -123,8 +131,7 @@ export default class ClientConnection { onOpen(ev: Event) { if (this._destoryed) { - this.ws?.close(); - this.ws = null; + this._destoryWS(); return; } @@ -134,8 +141,7 @@ export default class ClientConnection { onMessage(ev: MessageEvent) { if (this._destoryed) { - this.ws?.close(); - this.ws = null; + this._destoryWS(); return; } try { diff --git a/src/pages/LeftToolBar.vue b/src/pages/LeftToolBar.vue index cdeb6da..1091740 100644 --- a/src/pages/LeftToolBar.vue +++ b/src/pages/LeftToolBar.vue @@ -122,7 +122,7 @@