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 @@