From f4a4bf8e8df06e5e71c5546dbd3c98471b240acf Mon Sep 17 00:00:00 2001 From: fangxiang Date: Mon, 9 Aug 2021 10:59:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=84=A6=E7=82=B9=E7=BD=AE?= =?UTF-8?q?=E9=A1=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/ClientConnection.ts | 36 ++++- src/common/EventBus.ts | 5 + src/components/Window.vue | 45 +++++- src/entities/MultimediaWindowEntity.ts | 15 +- src/entities/NormalWindowRequestEntity.ts | 12 ++ src/entities/WSProtocol.ts | 9 ++ .../WindowOtherStateChangeNotifyEntity.ts | 8 + src/layouts/MainLayout.vue | 7 +- src/pages/RightToolBar.vue | 17 --- src/pages/WallPage.vue | 137 +++++++++++++++--- 10 files changed, 234 insertions(+), 57 deletions(-) create mode 100644 src/entities/NormalWindowRequestEntity.ts create mode 100644 src/entities/WindowOtherStateChangeNotifyEntity.ts delete mode 100644 src/pages/RightToolBar.vue diff --git a/src/common/ClientConnection.ts b/src/common/ClientConnection.ts index 762964f..8ae5169 100644 --- a/src/common/ClientConnection.ts +++ b/src/common/ClientConnection.ts @@ -1,3 +1,4 @@ +import NormalWindowRequestEntity from "src/entities/NormalWindowRequestEntity"; import { Protocol } from "src/entities/WSProtocol"; import EventBus, { EventNamesDefine } from "./EventBus"; @@ -39,6 +40,8 @@ export default class ClientConnection { password?: string | null ) { if (this._destoryed) { + this.ws?.close(); + this.ws = null; return; } this.url = url; @@ -71,6 +74,11 @@ export default class ClientConnection { } login() { + if (this._destoryed) { + this.ws?.close(); + this.ws = null; + return; + } if (this.is_connected) { const request = new Protocol.LoginRequest(this.user_name, this.password); this.ws?.send(JSON.stringify(request)); @@ -79,7 +87,6 @@ export default class ClientConnection { onClose(ev: CloseEvent) { this._is_login = false; - console.log("onClose"); this._reconnect(); EventBus.getInstance().emit(EventNamesDefine.WebSocketClose, this); } @@ -94,6 +101,8 @@ export default class ClientConnection { private _reconnect() { if (this._destoryed) { + this.ws?.close(); + this.ws = null; return; } if ( @@ -106,18 +115,28 @@ export default class ClientConnection { this._reconnectTimer = null; } this._reconnectTimer = setTimeout(() => { - console.log("reconnection...", new Date().getSeconds()); this.reconnectTo(this.url, this.user_name, this.password); }, 3000); } } onOpen(ev: Event) { + if (this._destoryed) { + this.ws?.close(); + this.ws = null; + return; + } + this._is_login = false; this.login(); } onMessage(ev: MessageEvent) { + if (this._destoryed) { + this.ws?.close(); + this.ws = null; + return; + } try { const packet = JSON.parse(ev.data) as Protocol.PacketEntity; @@ -199,11 +218,9 @@ export default class ClientConnection { resolve(response); } else { reject(); - console.log("reject"); } } catch { reject(); - console.log("reject"); } } } @@ -268,6 +285,17 @@ export default class ClientConnection { this.ws?.send(JSON.stringify(data)); } + public focusIn(window_id: number) { + this.ws?.send( + JSON.stringify( + new NormalWindowRequestEntity( + Protocol.Commands.kFocuseWindow, + window_id + ) + ) + ); + } + private _destoryed = false; public destory() { this._destoryed = true; diff --git a/src/common/EventBus.ts b/src/common/EventBus.ts index beacb8e..90668a2 100644 --- a/src/common/EventBus.ts +++ b/src/common/EventBus.ts @@ -9,6 +9,11 @@ export default class EventBus extends EventEmitter { } return EventBus._instance; } + + private constructor() { + super(); + this.setMaxListeners(64); + } } export namespace EventNamesDefine { diff --git a/src/components/Window.vue b/src/components/Window.vue index 73047e7..b03f9ff 100644 --- a/src/components/Window.vue +++ b/src/components/Window.vue @@ -1,6 +1,6 @@