Websocket: use event + payload

This commit is contained in:
Miroslav Šedivý 2021-09-08 22:03:19 +00:00
parent f0cdd69dcf
commit 96b6d8fa8d
3 changed files with 6 additions and 34 deletions

View File

@ -127,7 +127,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
Vue.set(this._state.connection.webrtc, 'video', video) 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._log.debug('EVENT.SIGNAL_RESTART')
this.emit('connection.webrtc.sdp', 'remote', sdp) this.emit('connection.webrtc.sdp', 'remote', sdp)
@ -139,7 +139,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
this.emit('connection.webrtc.sdp', 'local', localSdp) 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._log.debug('EVENT.SIGNAL_CANDIDATE')
this._connection.webrtc.setCandidate(candidate) this._connection.webrtc.setCandidate(candidate)
this.emit('connection.webrtc.sdp.candidate', 'remote', candidate) this.emit('connection.webrtc.sdp.candidate', 'remote', candidate)
@ -218,7 +218,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
// Broadcast Events // 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') this._log.debug('EVENT.BORADCAST_STATUS')
// TODO: Handle. // TODO: Handle.
this.emit('room.broadcast.status', is_active, url) this.emit('room.broadcast.status', is_active, url)

View File

@ -72,11 +72,11 @@ export class NekoWebSocket extends EventEmitter<NekoWebSocketEvents> {
} }
this._log.debug(`sending event '${event}' ${payload ? `with payload: ` : ''}`, payload) 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) { 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._log.debug(`received websocket event ${event} ${payload ? `with payload: ` : ''}`, payload)
this.emit('message', event, payload) this.emit('message', event, payload)

View File

@ -1,21 +1,14 @@
import { ICEServer } from '../internal/webrtc' import { ICEServer } from '../internal/webrtc'
export interface Message {
event?: string
payload: any
}
///////////////////////////// /////////////////////////////
// System // System
///////////////////////////// /////////////////////////////
export interface SystemWebRTC { export interface SystemWebRTC {
event?: string
videos: string[] videos: string[]
} }
export interface SystemInit { export interface SystemInit {
event?: string
session_id: string session_id: string
control_host: ControlHost control_host: ControlHost
screen_size: ScreenSize screen_size: ScreenSize
@ -26,13 +19,11 @@ export interface SystemInit {
} }
export interface SystemAdmin { export interface SystemAdmin {
event?: string
screen_sizes_list: ScreenSize[] screen_sizes_list: ScreenSize[]
broadcast_status: BroadcastStatus broadcast_status: BroadcastStatus
} }
export interface SystemDisconnect { export interface SystemDisconnect {
event?: string
message: string message: string
} }
@ -41,23 +32,18 @@ export interface SystemDisconnect {
///////////////////////////// /////////////////////////////
export interface SignalProvide { export interface SignalProvide {
event?: string
sdp: string sdp: string
iceservers: ICEServer[] iceservers: ICEServer[]
video: string video: string
} }
export interface SignalCandidate extends RTCIceCandidateInit { export type SignalCandidate = RTCIceCandidateInit
event?: string
}
export interface SignalAnswer { export interface SignalAnswer {
event?: string
sdp: string sdp: string
} }
export interface SignalVideo { export interface SignalVideo {
event?: string
video: string video: string
} }
@ -66,12 +52,10 @@ export interface SignalVideo {
///////////////////////////// /////////////////////////////
export interface SessionID { export interface SessionID {
event?: string
id: string id: string
} }
export interface MemberProfile { export interface MemberProfile {
event?: string
id: string id: string
name: string name: string
is_admin: boolean is_admin: boolean
@ -83,14 +67,12 @@ export interface MemberProfile {
} }
export interface SessionState { export interface SessionState {
event?: string
id: string id: string
is_connected: boolean is_connected: boolean
is_watching: boolean is_watching: boolean
} }
export interface SessionData { export interface SessionData {
event?: string
id: string id: string
profile: MemberProfile profile: MemberProfile
is_connected: boolean is_connected: boolean
@ -102,28 +84,24 @@ export interface SessionData {
///////////////////////////// /////////////////////////////
export interface ControlHost { export interface ControlHost {
event?: string
has_host: boolean has_host: boolean
host_id: string | undefined host_id: string | undefined
} }
// TODO: New. // TODO: New.
export interface ControlMove { export interface ControlMove {
event?: string
x: number x: number
y: number y: number
} }
// TODO: New. // TODO: New.
export interface ControlScroll { export interface ControlScroll {
event?: string
x: number x: number
y: number y: number
} }
// TODO: New. // TODO: New.
export interface ControlKey { export interface ControlKey {
event?: string
key: number key: number
} }
@ -132,7 +110,6 @@ export interface ControlKey {
///////////////////////////// /////////////////////////////
export interface ScreenSize { export interface ScreenSize {
event?: string
width: number width: number
height: number height: number
rate: number rate: number
@ -143,7 +120,6 @@ export interface ScreenSize {
///////////////////////////// /////////////////////////////
export interface ClipboardData { export interface ClipboardData {
event?: string
text: string text: string
} }
@ -152,14 +128,12 @@ export interface ClipboardData {
///////////////////////////// /////////////////////////////
export interface KeyboardModifiers { export interface KeyboardModifiers {
event?: string
caps_lock: boolean caps_lock: boolean
num_lock: boolean num_lock: boolean
scroll_lock: boolean scroll_lock: boolean
} }
export interface KeyboardMap { export interface KeyboardMap {
event?: string
layout: string layout: string
variant: string variant: string
} }
@ -169,7 +143,6 @@ export interface KeyboardMap {
///////////////////////////// /////////////////////////////
export interface BroadcastStatus { export interface BroadcastStatus {
event?: string
is_active: boolean is_active: boolean
url: string | undefined url: string | undefined
} }
@ -179,7 +152,6 @@ export interface BroadcastStatus {
///////////////////////////// /////////////////////////////
export interface SendMessage { export interface SendMessage {
event?: string
sender: string sender: string
subject: string subject: string
body: string body: string