From d573ae8058087fa6b47837a23dd69b3b0f1c111e Mon Sep 17 00:00:00 2001 From: fangxiang Date: Fri, 6 Aug 2021 17:24:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=AA=97=E5=8F=A3=E7=9A=84?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E7=A7=BB=E5=8A=A8=E4=BF=AE=E6=94=B9=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=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 | 41 +++- src/common/EventBus.ts | 1 + src/components/Window.vue | 292 +++++++++++++++++++++++-- src/entities/MultimediaWindowEntity.ts | 28 ++- src/entities/WSProtocol.ts | 116 +++++++++- src/pages/Login.vue | 51 ++--- src/pages/WallPage.vue | 183 +++++++++++++--- src/store/index.ts | 57 ++--- 8 files changed, 654 insertions(+), 115 deletions(-) diff --git a/src/common/ClientConnection.ts b/src/common/ClientConnection.ts index 2665f6f..d158aab 100644 --- a/src/common/ClientConnection.ts +++ b/src/common/ClientConnection.ts @@ -1,4 +1,5 @@ import { Protocol } from "src/entities/WSProtocol"; +import EventBus, { EventNamesDefine } from "./EventBus"; export default class ClientConnection { ws: WebSocket | null = null; @@ -16,15 +17,6 @@ export default class ClientConnection { | ((this: ClientConnection, logined: boolean) => void) | null = null; - public message_callback: - | (( - this: ClientConnection, - command: string, - packet: Protocol.Commands, - data: string - ) => void) - | null = null; - constructor( url: string, user_name?: string | null, @@ -102,6 +94,7 @@ export default class ClientConnection { onMessage(ev: MessageEvent) { try { const packet = JSON.parse(ev.data) as Protocol.PacketEntity; + if (packet) { if (packet.has_exception) { console.error(ev.data); @@ -132,11 +125,15 @@ export default class ClientConnection { f(false, packet, ev.data); this.rpc_map.delete(packet.rpc_id); } - } - if (this.message_callback) { - this.message_callback(packet.command, packet, ev.data); + } else { + EventBus.getInstance().emit(EventNamesDefine.ResponseMessage, { + packet: packet, + data: ev.data, + }); } } + } else { + console.error("unknow command: " + packet.command, packet); } } } catch (e) { @@ -215,4 +212,24 @@ export default class ClientConnection { console.error(e); } } + + public moveWindow(window_id: number, x: number, y: number) { + this.ws?.send( + JSON.stringify(new Protocol.MoveWindowRequestEntity(window_id, x, y)) + ); + } + + public resizeWindow(window_id: number, width: number, height: number) { + this.ws?.send( + JSON.stringify( + new Protocol.ResizeWindowRequestEntity(window_id, width, height) + ) + ); + } + + public closeWindow(window_id: number) { + this.ws?.send( + JSON.stringify(new Protocol.CloseWindowRequestEntity(window_id)) + ); + } } diff --git a/src/common/EventBus.ts b/src/common/EventBus.ts index c33b3df..c24651d 100644 --- a/src/common/EventBus.ts +++ b/src/common/EventBus.ts @@ -14,4 +14,5 @@ export default class EventBus extends EventEmitter { export namespace EventNamesDefine { export const UnSelectAllWindows = "unselect_all_windows"; export const WindowResize = "windowResize"; + export const ResponseMessage = "onResponseData"; } diff --git a/src/components/Window.vue b/src/components/Window.vue index e8ba64d..73047e7 100644 --- a/src/components/Window.vue +++ b/src/components/Window.vue @@ -1,20 +1,133 @@