From 96b6d8fa8d598e9019a614a23782aaf54ff59baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= <7365062-m1k1o@users.noreply.gitlab.com> Date: Wed, 8 Sep 2021 22:03:19 +0000 Subject: [PATCH] Websocket: use event + payload --- src/component/internal/messages.ts | 6 +++--- src/component/internal/websocket.ts | 4 ++-- src/component/types/messages.ts | 30 +---------------------------- 3 files changed, 6 insertions(+), 34 deletions(-) diff --git a/src/component/internal/messages.ts b/src/component/internal/messages.ts index f96114ef..6d6ea193 100644 --- a/src/component/internal/messages.ts +++ b/src/component/internal/messages.ts @@ -127,7 +127,7 @@ export class NekoMessages extends EventEmitter { Vue.set(this._state.connection.webrtc, 'video', video) } - protected async [EVENT.SIGNAL_RESTART]({ event, sdp }: message.SignalAnswer) { + protected async [EVENT.SIGNAL_RESTART]({ sdp }: message.SignalAnswer) { this._log.debug('EVENT.SIGNAL_RESTART') this.emit('connection.webrtc.sdp', 'remote', sdp) @@ -139,7 +139,7 @@ export class NekoMessages extends EventEmitter { this.emit('connection.webrtc.sdp', 'local', localSdp) } - protected [EVENT.SIGNAL_CANDIDATE]({ event, ...candidate }: message.SignalCandidate) { + protected [EVENT.SIGNAL_CANDIDATE](candidate: message.SignalCandidate) { this._log.debug('EVENT.SIGNAL_CANDIDATE') this._connection.webrtc.setCandidate(candidate) this.emit('connection.webrtc.sdp.candidate', 'remote', candidate) @@ -218,7 +218,7 @@ export class NekoMessages extends EventEmitter { // Broadcast Events ///////////////////////////// - protected [EVENT.BORADCAST_STATUS]({ event, url, is_active }: message.BroadcastStatus) { + protected [EVENT.BORADCAST_STATUS]({ url, is_active }: message.BroadcastStatus) { this._log.debug('EVENT.BORADCAST_STATUS') // TODO: Handle. this.emit('room.broadcast.status', is_active, url) diff --git a/src/component/internal/websocket.ts b/src/component/internal/websocket.ts index c7f7f065..e17b22c8 100644 --- a/src/component/internal/websocket.ts +++ b/src/component/internal/websocket.ts @@ -72,11 +72,11 @@ export class NekoWebSocket extends EventEmitter { } this._log.debug(`sending event '${event}' ${payload ? `with payload: ` : ''}`, payload) - this._ws!.send(JSON.stringify({ event, ...payload })) + this._ws!.send(JSON.stringify({ event, payload })) } private onMessage(e: MessageEvent) { - const { event, ...payload } = JSON.parse(e.data) + const { event, payload } = JSON.parse(e.data) this._log.debug(`received websocket event ${event} ${payload ? `with payload: ` : ''}`, payload) this.emit('message', event, payload) diff --git a/src/component/types/messages.ts b/src/component/types/messages.ts index c8523682..11940572 100644 --- a/src/component/types/messages.ts +++ b/src/component/types/messages.ts @@ -1,21 +1,14 @@ import { ICEServer } from '../internal/webrtc' -export interface Message { - event?: string - payload: any -} - ///////////////////////////// // System ///////////////////////////// export interface SystemWebRTC { - event?: string videos: string[] } export interface SystemInit { - event?: string session_id: string control_host: ControlHost screen_size: ScreenSize @@ -26,13 +19,11 @@ export interface SystemInit { } export interface SystemAdmin { - event?: string screen_sizes_list: ScreenSize[] broadcast_status: BroadcastStatus } export interface SystemDisconnect { - event?: string message: string } @@ -41,23 +32,18 @@ export interface SystemDisconnect { ///////////////////////////// export interface SignalProvide { - event?: string sdp: string iceservers: ICEServer[] video: string } -export interface SignalCandidate extends RTCIceCandidateInit { - event?: string -} +export type SignalCandidate = RTCIceCandidateInit export interface SignalAnswer { - event?: string sdp: string } export interface SignalVideo { - event?: string video: string } @@ -66,12 +52,10 @@ export interface SignalVideo { ///////////////////////////// export interface SessionID { - event?: string id: string } export interface MemberProfile { - event?: string id: string name: string is_admin: boolean @@ -83,14 +67,12 @@ export interface MemberProfile { } export interface SessionState { - event?: string id: string is_connected: boolean is_watching: boolean } export interface SessionData { - event?: string id: string profile: MemberProfile is_connected: boolean @@ -102,28 +84,24 @@ export interface SessionData { ///////////////////////////// export interface ControlHost { - event?: string has_host: boolean host_id: string | undefined } // TODO: New. export interface ControlMove { - event?: string x: number y: number } // TODO: New. export interface ControlScroll { - event?: string x: number y: number } // TODO: New. export interface ControlKey { - event?: string key: number } @@ -132,7 +110,6 @@ export interface ControlKey { ///////////////////////////// export interface ScreenSize { - event?: string width: number height: number rate: number @@ -143,7 +120,6 @@ export interface ScreenSize { ///////////////////////////// export interface ClipboardData { - event?: string text: string } @@ -152,14 +128,12 @@ export interface ClipboardData { ///////////////////////////// export interface KeyboardModifiers { - event?: string caps_lock: boolean num_lock: boolean scroll_lock: boolean } export interface KeyboardMap { - event?: string layout: string variant: string } @@ -169,7 +143,6 @@ export interface KeyboardMap { ///////////////////////////// export interface BroadcastStatus { - event?: string is_active: boolean url: string | undefined } @@ -179,7 +152,6 @@ export interface BroadcastStatus { ///////////////////////////// export interface SendMessage { - event?: string sender: string subject: string body: string