From 84649330578ab3994fbd3f061f1b9b24874f3c49 Mon Sep 17 00:00:00 2001 From: fangxiang Date: Wed, 11 Aug 2021 10:56:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=80=E7=AA=97=E5=9D=90?= =?UTF-8?q?=E6=A0=87=E9=94=99=E8=AF=AF=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/ClientConnection.ts | 26 ++++++++++++++++---------- src/pages/LeftToolBar.vue | 13 ++++++++++++- src/pages/WallPage.vue | 10 +++++----- src/store/index.ts | 1 - 4 files changed, 33 insertions(+), 17 deletions(-) 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 @@