From d5125ea8e18f7c8922a87c5e63097d4e3675b830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 30 Jan 2022 19:44:27 +0100 Subject: [PATCH] add control. --- src/component/internal/control.ts | 39 +++++++++++++++++++++++++++++++ src/component/main.vue | 3 +++ src/component/types/events.ts | 12 ++++++++-- src/component/types/messages.ts | 3 +-- 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/component/internal/control.ts diff --git a/src/component/internal/control.ts b/src/component/internal/control.ts new file mode 100644 index 00000000..4efc41d2 --- /dev/null +++ b/src/component/internal/control.ts @@ -0,0 +1,39 @@ +import * as EVENT from '../types/events' +import * as message from '../types/messages' + +import { NekoConnection } from './connection' + +export class NekoControl { + // eslint-disable-next-line + constructor( + private readonly _connection: NekoConnection, + ) {} + + public keypress(keysym: number) { + this._connection.websocket.send(EVENT.CONTROL_KEYPRESS, { keysym } as message.ControlKey) + } + + public keydown(keysym: number) { + this._connection.websocket.send(EVENT.CONTROL_KEYDOWN, { keysym } as message.ControlKey) + } + + public keyup(keysym: number) { + this._connection.websocket.send(EVENT.CONTROL_KEYUP, { keysym } as message.ControlKey) + } + + public cut() { + this._connection.websocket.send(EVENT.CONTROL_CUT) + } + + public copy() { + this._connection.websocket.send(EVENT.CONTROL_COPY) + } + + public paste() { + this._connection.websocket.send(EVENT.CONTROL_PASTE) + } + + public selectAll() { + this._connection.websocket.send(EVENT.CONTROL_SELECT_ALL) + } +} diff --git a/src/component/main.vue b/src/component/main.vue index 893bb26b..148bfa2a 100644 --- a/src/component/main.vue +++ b/src/component/main.vue @@ -71,6 +71,7 @@ import { NekoApi, MembersApi, RoomApi } from './internal/api' import { NekoConnection } from './internal/connection' import { NekoMessages } from './internal/messages' + import { NekoControl } from './internal/control' import { register as VideoRegister } from './internal/video' import { ReconnectorConfig } from './types/reconnector' @@ -390,6 +391,8 @@ this.connection.websocket.send(EVENT.SEND_BROADCAST, { subject, body }) } + public control = new NekoControl(this.connection) + public get room(): RoomApi { return this.api.room } diff --git a/src/component/types/events.ts b/src/component/types/events.ts index 9311cabe..f94abde2 100644 --- a/src/component/types/events.ts +++ b/src/component/types/events.ts @@ -20,10 +20,18 @@ export const SESSION_CURSORS = 'session/cursors' export const CONTROL_HOST = 'control/host' export const CONTROL_RELEASE = 'control/release' export const CONTROL_REQUEST = 'control/request' +// mouse export const CONTROL_MOVE = 'control/move' // TODO: New. (fallback) export const CONTROL_SCROLL = 'control/scroll' // TODO: New. (fallback) -export const CONTROL_KEYDOWN = 'control/keydown' // TODO: New. (fallback) -export const CONTROL_KEYUP = 'control/keyup' // TODO: New. (fallback) +// keyboard +export const CONTROL_KEYPRESS = 'control/keypress' +export const CONTROL_KEYDOWN = 'control/keydown' +export const CONTROL_KEYUP = 'control/keyup' +// actions +export const CONTROL_CUT = 'control/cut' +export const CONTROL_COPY = 'control/copy' +export const CONTROL_PASTE = 'control/paste' +export const CONTROL_SELECT_ALL = 'control/select_all' export const SCREEN_UPDATED = 'screen/updated' export const SCREEN_SET = 'screen/set' diff --git a/src/component/types/messages.ts b/src/component/types/messages.ts index c6ad4717..e655dc91 100644 --- a/src/component/types/messages.ts +++ b/src/component/types/messages.ts @@ -118,9 +118,8 @@ export interface ControlScroll { y: number } -// TODO: New. export interface ControlKey { - key: number + keysym: number } /////////////////////////////