From 962b84d89e27e2880e82eba75c737282fb9f48d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 28 Jan 2021 16:08:17 +0100 Subject: [PATCH] send / receive message. --- src/component/internal/messages.ts | 16 ++++++++++++++++ src/component/main.vue | 8 ++++++++ src/component/types/events.ts | 3 +++ src/component/types/messages.ts | 11 +++++++++++ 4 files changed, 38 insertions(+) diff --git a/src/component/internal/messages.ts b/src/component/internal/messages.ts index 7200fe10..c5bfaaa0 100644 --- a/src/component/internal/messages.ts +++ b/src/component/internal/messages.ts @@ -22,6 +22,8 @@ export interface NekoEvents { ['screen.updated']: (width: number, height: number, rate: number) => void ['clipboard.updated']: (text: string) => void ['broadcast.status']: (isActive: boolean, url: string | undefined) => void + ['receive.unicast']: (sender: string, subject: string, body: string) => void + ['receive.broadcast']: (sender: string, subject: string, body: string) => void ['file_chooser_dialog.requested']: () => void ['file_chooser_dialog.overlay']: (id: string) => void ['file_chooser_dialog.closed']: () => void @@ -177,6 +179,20 @@ export class NekoMessages extends EventEmitter { this.emit('broadcast.status', is_active, url) } + ///////////////////////////// + // Send Events + ///////////////////////////// + + protected [EVENT.SEND_UNICAST]({ sender, subject, body }: message.SendMessage) { + this._log.debug('EVENT.SEND_UNICAST') + this.emit('receive.unicast', sender, subject, body) + } + + protected [EVENT.SEND_BROADCAST]({ sender, subject, body }: message.SendMessage) { + this._log.debug('EVENT.BORADCAST_STATUS') + this.emit('receive.broadcast', sender, subject, body) + } + ///////////////////////////// // FileChooserDialog Events ///////////////////////////// diff --git a/src/component/main.vue b/src/component/main.vue index 01f65a29..8d2b3f99 100644 --- a/src/component/main.vue +++ b/src/component/main.vue @@ -230,6 +230,14 @@ this.websocket.send('screen/set', { width, height, rate }) } + public sendUnicast(receiver: string, subject: string, body: string) { + this.websocket.send('send/unicast', { receiver, subject, body }) + } + + public sendBroadcast(subject: string, body: string) { + this.websocket.send('send/broadcast', { subject, body }) + } + public get room(): RoomApi { return this.api.room } diff --git a/src/component/types/events.ts b/src/component/types/events.ts index 098a6210..09cb02c8 100644 --- a/src/component/types/events.ts +++ b/src/component/types/events.ts @@ -32,5 +32,8 @@ export const CURSOR_IMAGE = 'cursor/image' export const BORADCAST_STATUS = 'broadcast/status' +export const SEND_UNICAST = 'send/unicast' +export const SEND_BROADCAST = 'send/broadcast' + export const FILE_CHOOSER_DIALOG_OPENED = 'file_chooser_dialog/opened' export const FILE_CHOOSER_DIALOG_CLOSED = 'file_chooser_dialog/closed' diff --git a/src/component/types/messages.ts b/src/component/types/messages.ts index 23faffe5..55d28f01 100644 --- a/src/component/types/messages.ts +++ b/src/component/types/messages.ts @@ -170,3 +170,14 @@ export interface BroadcastStatus { is_active: boolean url: string | undefined } + +///////////////////////////// +// Send +///////////////////////////// + +export interface SendMessage { + event: string | undefined + sender: string + subject: string + body: string +}