From 9ab6d4c6eef6ed2f42112a15bad5b219d07088b5 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Thu, 30 Nov 2023 15:14:37 -0500 Subject: [PATCH 1/2] Add enable logger in webRtcClient --- src/simple/Phone.ts | 37 +++++++++++++++++++++---------------- src/web-rtc-client.ts | 20 +++++++++++++++++++- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/simple/Phone.ts b/src/simple/Phone.ts index acd8ecc0..2e210cdc 100644 --- a/src/simple/Phone.ts +++ b/src/simple/Phone.ts @@ -290,22 +290,7 @@ class Phone extends Emitter implements IPhone { options.log.builtinEnabled = false; options.log.logLevel = 'debug'; - options.log.connector = (level: any, className: string, label: any, content: string) => { - const protocolIndex = content && content.indexOf ? protocolDebugMessages.findIndex(prefix => content.indexOf(prefix) !== -1) : -1; - - if (className === 'sip.Transport' && protocolIndex !== -1) { - const direction = protocolIndex === 0 ? 'receiving' : 'sending'; - const message = content.replace(`${protocolDebugMessages[protocolIndex]}\n\n`, '').replace('\r\n', '\n'); - protocolLogger.trace(message, { - className, - direction, - }); - } else { - sipLogger.trace(content, { - className, - }); - } - }; + options.log.connector = this._logConnector; } this.client = new WazoWebRTCClient({ @@ -609,6 +594,10 @@ class Phone extends Emitter implements IPhone { } } + enableLogger(): void { + this.client.enableLogger(this._logConnector); + } + _transferEvents() { this.unbind(); [...clientEvents, ...transportEvents].forEach(event => { @@ -623,6 +612,22 @@ class Phone extends Emitter implements IPhone { }); } + _logConnector(level: any, className: string, label: any, content: string): void { + const protocolIndex = content && content.indexOf ? protocolDebugMessages.findIndex(prefix => content.indexOf(prefix) !== -1) : -1; + + if (className === 'sip.Transport' && protocolIndex !== -1) { + const direction = protocolIndex === 0 ? 'receiving' : 'sending'; + const message = content.replace(`${protocolDebugMessages[protocolIndex]}\n\n`, '').replace('\r\n', '\n'); + protocolLogger.trace(message, { + className, + direction, + }); + } else { + sipLogger.trace(content, { + className, + }); + } + } } if (!global.wazoTelephonyInstance) { diff --git a/src/web-rtc-client.ts b/src/web-rtc-client.ts index 24891378..ffb8d84d 100644 --- a/src/web-rtc-client.ts +++ b/src/web-rtc-client.ts @@ -416,7 +416,7 @@ export default class WebRTCClient extends Emitter { return this._connectIfNeeded().then(() => { // Avoid race condition with the close method called just before register and setting userAgent to null - // during the resolution of the primise. + // during the resolution of the promise. if (!this.userAgent) { logger.info('sdk webrtc recreating User Agent after connection'); this.userAgent = this.createUserAgent(this.uaConfigOverrides); @@ -1878,6 +1878,24 @@ export default class WebRTCClient extends Emitter { this.attemptReconnection(); } + enableLogger(logConnector: Function): void { + if (!this.userAgent) { + return; + } + + if (this.userAgent?.transport) { + // @ts-ignore + this.userAgent.transport.configuration.traceSip = true; + } + + // @ts-ignore + this.userAgent.loggerFactory.builtinEnabled = true; + // @ts-ignore + this.userAgent.loggerFactory.level = 3; // debug + // @ts-ignore + this.userAgent.loggerFactory.connector = logConnector; + } + _onHeartbeat(message: string | Record): void { const body = message && typeof message === 'object' ? message.data : message; From ca8ce8056bab32a314846c4ad6777ddeb6fcca10 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Fri, 8 Dec 2023 14:23:56 -0500 Subject: [PATCH 2/2] Fix linting --- .eslintrc | 3 ++- src/web-rtc-client.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index dbd67a66..dd2169e3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -74,7 +74,8 @@ } ], "@typescript-eslint/ban-ts-comment": 0, - "@typescript-eslint/return-await": 0 + "@typescript-eslint/return-await": 0, + "@typescript-eslint/no-non-null-assertion": 0 }, "settings": { "import/resolver": { diff --git a/src/web-rtc-client.ts b/src/web-rtc-client.ts index ffb8d84d..6876baf4 100644 --- a/src/web-rtc-client.ts +++ b/src/web-rtc-client.ts @@ -1878,7 +1878,7 @@ export default class WebRTCClient extends Emitter { this.attemptReconnection(); } - enableLogger(logConnector: Function): void { + enableLogger(logConnector: (level: any, className: string, label: any, content: string) => void): void { if (!this.userAgent) { return; }