mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
messages add remote log.
This commit is contained in:
parent
b7ebbcbdf5
commit
a4d05c6bce
@ -44,14 +44,16 @@ export interface NekoEvents {
|
|||||||
export class NekoMessages extends EventEmitter<NekoEvents> {
|
export class NekoMessages extends EventEmitter<NekoEvents> {
|
||||||
private _connection: NekoConnection
|
private _connection: NekoConnection
|
||||||
private _state: NekoState
|
private _state: NekoState
|
||||||
private _log: Logger
|
private _localLog: Logger
|
||||||
|
private _remoteLog: Logger
|
||||||
|
|
||||||
constructor(connection: NekoConnection, state: NekoState, logger?: Logger) {
|
constructor(connection: NekoConnection, state: NekoState) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this._log = logger || new Logger('messages')
|
|
||||||
this._state = state
|
|
||||||
this._connection = connection
|
this._connection = connection
|
||||||
|
this._state = state
|
||||||
|
this._localLog = new Logger('messages')
|
||||||
|
this._remoteLog = connection.getLogger('messages')
|
||||||
|
|
||||||
this._connection.websocket.on('message', async (event: string, payload: any) => {
|
this._connection.websocket.on('message', async (event: string, payload: any) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -60,10 +62,10 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this[event](payload)
|
this[event](payload)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this._log.error(`error while processing websocket event`, { event, error })
|
this._remoteLog.error(`error while processing websocket event`, { event, error })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this._log.warn(`unhandled websocket event`, { event, payload })
|
this._remoteLog.warn(`unhandled websocket event`, { event, payload })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -78,7 +80,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
protected [EVENT.SYSTEM_INIT](conf: message.SystemInit) {
|
protected [EVENT.SYSTEM_INIT](conf: message.SystemInit) {
|
||||||
this._log.debug(`EVENT.SYSTEM_INIT`)
|
this._localLog.debug(`EVENT.SYSTEM_INIT`)
|
||||||
Vue.set(this._state, 'session_id', conf.session_id)
|
Vue.set(this._state, 'session_id', conf.session_id)
|
||||||
Vue.set(this._state.control, 'implicit_hosting', conf.implicit_hosting)
|
Vue.set(this._state.control, 'implicit_hosting', conf.implicit_hosting)
|
||||||
Vue.set(this._state.connection, 'screencast', conf.screencast_enabled)
|
Vue.set(this._state.connection, 'screencast', conf.screencast_enabled)
|
||||||
@ -93,7 +95,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected [EVENT.SYSTEM_ADMIN]({ screen_sizes_list, broadcast_status }: message.SystemAdmin) {
|
protected [EVENT.SYSTEM_ADMIN]({ screen_sizes_list, broadcast_status }: message.SystemAdmin) {
|
||||||
this._log.debug(`EVENT.SYSTEM_ADMIN`)
|
this._localLog.debug(`EVENT.SYSTEM_ADMIN`)
|
||||||
|
|
||||||
const list = screen_sizes_list.sort((a, b) => {
|
const list = screen_sizes_list.sort((a, b) => {
|
||||||
if (b.width === a.width && b.height == a.height) {
|
if (b.width === a.width && b.height == a.height) {
|
||||||
@ -110,7 +112,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected [EVENT.SYSTEM_DISCONNECT]({ message }: message.SystemDisconnect) {
|
protected [EVENT.SYSTEM_DISCONNECT]({ message }: message.SystemDisconnect) {
|
||||||
this._log.debug(`EVENT.SYSTEM_DISCONNECT`)
|
this._localLog.debug(`EVENT.SYSTEM_DISCONNECT`)
|
||||||
this._connection.close(new Error(message))
|
this._connection.close(new Error(message))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +121,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
protected async [EVENT.SIGNAL_PROVIDE]({ sdp: remoteSdp, video, iceservers }: message.SignalProvide) {
|
protected async [EVENT.SIGNAL_PROVIDE]({ sdp: remoteSdp, video, iceservers }: message.SignalProvide) {
|
||||||
this._log.debug(`EVENT.SIGNAL_PROVIDE`)
|
this._localLog.debug(`EVENT.SIGNAL_PROVIDE`)
|
||||||
this.emit('connection.webrtc.sdp', 'remote', remoteSdp)
|
this.emit('connection.webrtc.sdp', 'remote', remoteSdp)
|
||||||
|
|
||||||
const localSdp = await this._connection.webrtc.connect(remoteSdp, iceservers)
|
const localSdp = await this._connection.webrtc.connect(remoteSdp, iceservers)
|
||||||
@ -132,7 +134,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async [EVENT.SIGNAL_RESTART]({ sdp }: message.SignalAnswer) {
|
protected async [EVENT.SIGNAL_RESTART]({ sdp }: message.SignalAnswer) {
|
||||||
this._log.debug(`EVENT.SIGNAL_RESTART`)
|
this._localLog.debug(`EVENT.SIGNAL_RESTART`)
|
||||||
this.emit('connection.webrtc.sdp', 'remote', sdp)
|
this.emit('connection.webrtc.sdp', 'remote', sdp)
|
||||||
|
|
||||||
const localSdp = await this._connection.webrtc.offer(sdp)
|
const localSdp = await this._connection.webrtc.offer(sdp)
|
||||||
@ -144,13 +146,13 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected [EVENT.SIGNAL_CANDIDATE](candidate: message.SignalCandidate) {
|
protected [EVENT.SIGNAL_CANDIDATE](candidate: message.SignalCandidate) {
|
||||||
this._log.debug(`EVENT.SIGNAL_CANDIDATE`)
|
this._localLog.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)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected [EVENT.SIGNAL_VIDEO]({ video }: message.SignalVideo) {
|
protected [EVENT.SIGNAL_VIDEO]({ video }: message.SignalVideo) {
|
||||||
this._log.debug(`EVENT.SIGNAL_VIDEO`, { video })
|
this._localLog.debug(`EVENT.SIGNAL_VIDEO`, { video })
|
||||||
Vue.set(this._state.connection.webrtc, 'video', video)
|
Vue.set(this._state.connection.webrtc, 'video', video)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,25 +161,25 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
protected [EVENT.SESSION_CREATED]({ id, ...data }: message.SessionData) {
|
protected [EVENT.SESSION_CREATED]({ id, ...data }: message.SessionData) {
|
||||||
this._log.debug(`EVENT.SESSION_CREATED`, { id })
|
this._localLog.debug(`EVENT.SESSION_CREATED`, { id })
|
||||||
Vue.set(this._state.sessions, id, data)
|
Vue.set(this._state.sessions, id, data)
|
||||||
this.emit('session.created', id)
|
this.emit('session.created', id)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected [EVENT.SESSION_DELETED]({ id }: message.SessionID) {
|
protected [EVENT.SESSION_DELETED]({ id }: message.SessionID) {
|
||||||
this._log.debug(`EVENT.SESSION_DELETED`, { id })
|
this._localLog.debug(`EVENT.SESSION_DELETED`, { id })
|
||||||
Vue.delete(this._state.sessions, id)
|
Vue.delete(this._state.sessions, id)
|
||||||
this.emit('session.deleted', id)
|
this.emit('session.deleted', id)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected [EVENT.SESSION_PROFILE]({ id, ...profile }: message.MemberProfile) {
|
protected [EVENT.SESSION_PROFILE]({ id, ...profile }: message.MemberProfile) {
|
||||||
this._log.debug(`EVENT.SESSION_PROFILE`, { id })
|
this._localLog.debug(`EVENT.SESSION_PROFILE`, { id })
|
||||||
Vue.set(this._state.sessions[id], 'profile', profile)
|
Vue.set(this._state.sessions[id], 'profile', profile)
|
||||||
this.emit('session.updated', id)
|
this.emit('session.updated', id)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected [EVENT.SESSION_STATE]({ id, ...state }: message.SessionState) {
|
protected [EVENT.SESSION_STATE]({ id, ...state }: message.SessionState) {
|
||||||
this._log.debug(`EVENT.SESSION_STATE`, { id })
|
this._localLog.debug(`EVENT.SESSION_STATE`, { id })
|
||||||
Vue.set(this._state.sessions[id], 'state', state)
|
Vue.set(this._state.sessions[id], 'state', state)
|
||||||
this.emit('session.updated', id)
|
this.emit('session.updated', id)
|
||||||
}
|
}
|
||||||
@ -187,7 +189,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
protected [EVENT.CONTROL_HOST]({ has_host, host_id }: message.ControlHost) {
|
protected [EVENT.CONTROL_HOST]({ has_host, host_id }: message.ControlHost) {
|
||||||
this._log.debug(`EVENT.CONTROL_HOST`)
|
this._localLog.debug(`EVENT.CONTROL_HOST`)
|
||||||
|
|
||||||
if (has_host && host_id) {
|
if (has_host && host_id) {
|
||||||
Vue.set(this._state.control, 'host_id', host_id)
|
Vue.set(this._state.control, 'host_id', host_id)
|
||||||
@ -203,7 +205,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
protected [EVENT.SCREEN_UPDATED]({ width, height, rate }: message.ScreenSize) {
|
protected [EVENT.SCREEN_UPDATED]({ width, height, rate }: message.ScreenSize) {
|
||||||
this._log.debug(`EVENT.SCREEN_UPDATED`)
|
this._localLog.debug(`EVENT.SCREEN_UPDATED`)
|
||||||
Vue.set(this._state.screen, 'size', { width, height, rate })
|
Vue.set(this._state.screen, 'size', { width, height, rate })
|
||||||
this.emit('room.screen.updated', width, height, rate)
|
this.emit('room.screen.updated', width, height, rate)
|
||||||
}
|
}
|
||||||
@ -213,7 +215,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
protected [EVENT.CLIPBOARD_UPDATED]({ text }: message.ClipboardData) {
|
protected [EVENT.CLIPBOARD_UPDATED]({ text }: message.ClipboardData) {
|
||||||
this._log.debug(`EVENT.CLIPBOARD_UPDATED`)
|
this._localLog.debug(`EVENT.CLIPBOARD_UPDATED`)
|
||||||
Vue.set(this._state.control, 'clipboard', { text })
|
Vue.set(this._state.control, 'clipboard', { text })
|
||||||
this.emit('room.clipboard.updated', text)
|
this.emit('room.clipboard.updated', text)
|
||||||
}
|
}
|
||||||
@ -223,7 +225,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
protected [EVENT.BORADCAST_STATUS]({ url, is_active }: message.BroadcastStatus) {
|
protected [EVENT.BORADCAST_STATUS]({ url, is_active }: message.BroadcastStatus) {
|
||||||
this._log.debug(`EVENT.BORADCAST_STATUS`)
|
this._localLog.debug(`EVENT.BORADCAST_STATUS`)
|
||||||
// TODO: Handle.
|
// TODO: Handle.
|
||||||
this.emit('room.broadcast.status', is_active, url)
|
this.emit('room.broadcast.status', is_active, url)
|
||||||
}
|
}
|
||||||
@ -233,12 +235,12 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
protected [EVENT.SEND_UNICAST]({ sender, subject, body }: message.SendMessage) {
|
protected [EVENT.SEND_UNICAST]({ sender, subject, body }: message.SendMessage) {
|
||||||
this._log.debug(`EVENT.SEND_UNICAST`)
|
this._localLog.debug(`EVENT.SEND_UNICAST`)
|
||||||
this.emit('receive.unicast', sender, subject, body)
|
this.emit('receive.unicast', sender, subject, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected [EVENT.SEND_BROADCAST]({ sender, subject, body }: message.SendMessage) {
|
protected [EVENT.SEND_BROADCAST]({ sender, subject, body }: message.SendMessage) {
|
||||||
this._log.debug(`EVENT.BORADCAST_STATUS`)
|
this._localLog.debug(`EVENT.BORADCAST_STATUS`)
|
||||||
this.emit('receive.broadcast', sender, subject, body)
|
this.emit('receive.broadcast', sender, subject, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +249,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
protected [EVENT.FILE_CHOOSER_DIALOG_OPENED]({ id }: message.SessionID) {
|
protected [EVENT.FILE_CHOOSER_DIALOG_OPENED]({ id }: message.SessionID) {
|
||||||
this._log.debug(`EVENT.FILE_CHOOSER_DIALOG_OPENED`)
|
this._localLog.debug(`EVENT.FILE_CHOOSER_DIALOG_OPENED`)
|
||||||
|
|
||||||
if (id == this._state.session_id) {
|
if (id == this._state.session_id) {
|
||||||
this.emit('upload.dialog.requested')
|
this.emit('upload.dialog.requested')
|
||||||
@ -257,7 +259,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected [EVENT.FILE_CHOOSER_DIALOG_CLOSED]({ id }: message.SessionID) {
|
protected [EVENT.FILE_CHOOSER_DIALOG_CLOSED]({ id }: message.SessionID) {
|
||||||
this._log.debug(`EVENT.FILE_CHOOSER_DIALOG_CLOSED`)
|
this._localLog.debug(`EVENT.FILE_CHOOSER_DIALOG_CLOSED`)
|
||||||
this.emit('upload.dialog.closed')
|
this.emit('upload.dialog.closed')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user