From a4d05c6bce27e0f30dcb4bb13393117a103017c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 12 Sep 2021 18:05:16 +0200 Subject: [PATCH] messages add remote log. --- src/component/internal/messages.ts | 52 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/component/internal/messages.ts b/src/component/internal/messages.ts index 91360c8e..958deb85 100644 --- a/src/component/internal/messages.ts +++ b/src/component/internal/messages.ts @@ -44,14 +44,16 @@ export interface NekoEvents { export class NekoMessages extends EventEmitter { private _connection: NekoConnection 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() - this._log = logger || new Logger('messages') - this._state = state 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) => { // @ts-ignore @@ -60,10 +62,10 @@ export class NekoMessages extends EventEmitter { // @ts-ignore this[event](payload) } catch (error: any) { - this._log.error(`error while processing websocket event`, { event, error }) + this._remoteLog.error(`error while processing websocket event`, { event, error }) } } 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 { ///////////////////////////// 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.control, 'implicit_hosting', conf.implicit_hosting) Vue.set(this._state.connection, 'screencast', conf.screencast_enabled) @@ -93,7 +95,7 @@ export class NekoMessages extends EventEmitter { } 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) => { if (b.width === a.width && b.height == a.height) { @@ -110,7 +112,7 @@ export class NekoMessages extends EventEmitter { } 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)) } @@ -119,7 +121,7 @@ export class NekoMessages extends EventEmitter { ///////////////////////////// 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) const localSdp = await this._connection.webrtc.connect(remoteSdp, iceservers) @@ -132,7 +134,7 @@ export class NekoMessages extends EventEmitter { } 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) const localSdp = await this._connection.webrtc.offer(sdp) @@ -144,13 +146,13 @@ export class NekoMessages extends EventEmitter { } 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.emit('connection.webrtc.sdp.candidate', 'remote', candidate) } 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) } @@ -159,25 +161,25 @@ export class NekoMessages extends EventEmitter { ///////////////////////////// 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) this.emit('session.created', id) } 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) this.emit('session.deleted', id) } 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) this.emit('session.updated', id) } 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) this.emit('session.updated', id) } @@ -187,7 +189,7 @@ export class NekoMessages extends EventEmitter { ///////////////////////////// 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) { Vue.set(this._state.control, 'host_id', host_id) @@ -203,7 +205,7 @@ export class NekoMessages extends EventEmitter { ///////////////////////////// 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 }) this.emit('room.screen.updated', width, height, rate) } @@ -213,7 +215,7 @@ export class NekoMessages extends EventEmitter { ///////////////////////////// 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 }) this.emit('room.clipboard.updated', text) } @@ -223,7 +225,7 @@ export class NekoMessages extends EventEmitter { ///////////////////////////// protected [EVENT.BORADCAST_STATUS]({ url, is_active }: message.BroadcastStatus) { - this._log.debug(`EVENT.BORADCAST_STATUS`) + this._localLog.debug(`EVENT.BORADCAST_STATUS`) // TODO: Handle. this.emit('room.broadcast.status', is_active, url) } @@ -233,12 +235,12 @@ export class NekoMessages extends EventEmitter { ///////////////////////////// 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) } 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) } @@ -247,7 +249,7 @@ export class NekoMessages extends EventEmitter { ///////////////////////////// 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) { this.emit('upload.dialog.requested') @@ -257,7 +259,7 @@ export class NekoMessages extends EventEmitter { } 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') } }