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