From 5fe70f035ac64410acacf2b35e8affd6a8ae676b Mon Sep 17 00:00:00 2001 From: Andy Lee Date: Fri, 20 Oct 2023 10:33:36 +0200 Subject: [PATCH] feat(RTCStats): Suppress unnecessary error message when rtcstatsEnabled === false (#2374) * feat(RTCStats) Allow initializing without enabling * feat(RTCStats) Simpler use of config properties * feat(RTCStats) rollback property access level * feat(RTCStats)revert to private and assert type --- modules/RTCStats/RTCStats.ts | 62 +++++++++++++++++----------------- modules/RTCStats/interfaces.ts | 2 +- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/modules/RTCStats/RTCStats.ts b/modules/RTCStats/RTCStats.ts index 7ea1a26985..7449a7e0e1 100644 --- a/modules/RTCStats/RTCStats.ts +++ b/modules/RTCStats/RTCStats.ts @@ -4,10 +4,10 @@ import rtcstatsInit from '@jitsi/rtcstats/rtcstats'; import traceInit from '@jitsi/rtcstats/trace-ws'; import EventEmitter from 'events'; -import { - CONFERENCE_JOINED, - CONFERENCE_LEFT, - CONFERENCE_UNIQUE_ID_SET +import { + CONFERENCE_JOINED, + CONFERENCE_LEFT, + CONFERENCE_UNIQUE_ID_SET } from '../../JitsiConferenceEvents'; import JitsiConference from '../../JitsiConference'; import { IRTCStatsConfiguration } from './interfaces'; @@ -42,11 +42,11 @@ class RTCStats { * RTCStats "proxies" WebRTC functions such as GUM and RTCPeerConnection by rewriting the global objects. * The proxies will then send data to the rtcstats server via the trace object. * The initialization procedure must be called once when lib-jitsi-meet is loaded. - * + * * @param {IRTCStatsConfiguration} initConfig initial config for rtcstats. * @returns {void} */ - init(initConfig: IRTCStatsConfiguration) { + init(initConfig: IRTCStatsConfiguration) { const { analytics: { rtcstatsUseLegacy: useLegacy = false, @@ -60,9 +60,9 @@ class RTCStats { // Calling rtcsatsInit multiple times will cause the global objects to be rewritten multiple times, // with unforeseen consequences. if (!rtcstatsEnabled || this._initialized) return; - - rtcstatsInit( - { statsEntry: this.sendStatsEntry.bind(this) }, + + rtcstatsInit( + { statsEntry: this.sendStatsEntry.bind(this) }, { connectionFilter, pollInterval, useLegacy, @@ -78,29 +78,18 @@ class RTCStats { * new conference's config. On a normal conference flow this wouldn't be necessary, as the whole page is * reloaded, but in the case of breakout rooms or react native the js context doesn't reload, hence the * RTCStats singleton and its config persists between conferences. - * + * * @param conference - JitsiConference instance that's about to start. * @returns {void} */ start(conference: JitsiConference) { - // If rtcstats proxy module is not initialized, do nothing. - if (!this._initialized) { - logger.error('Calling start before RTCStats proxy module is initialized.'); - - return; - } - - // Reset the trace module in case it wasn't during the previous conference. - // Closing the underlying websocket connection and deleting the trace obj. - this.reset(); - - const { - options: { + const { + options: { config : confConfig = {}, name: confName = '' } = {}, _statsCurrentId : displayName = '' - } = conference; + } = conference; const { analytics: { @@ -110,12 +99,23 @@ class RTCStats { } = {} } = confConfig; + // Reset the trace module in case it wasn't during the previous conference. + // Closing the underlying websocket connection and deleting the trace obj. + this.reset(); + // The new conference config might have rtcstats disabled, so we need to check again. if (!rtcstatsEnabled) return; + // If rtcstats proxy module is not initialized, do nothing. + if (!this._initialized) { + logger.error('Calling start before RTCStats proxy module is initialized.'); + + return; + } + // When the conference is joined, we need to initialize the trace module with the new conference's config. // The trace module will then connect to the rtcstats server and send the identity data. - conference.once(CONFERENCE_JOINED, () => { + conference.once(CONFERENCE_JOINED, () => { const traceOptions = { endpoint, meetingFqn: confName, @@ -142,7 +142,7 @@ class RTCStats { meetingUniqueId, isBreakoutRoom } - + this.sendIdentity(identityData); }); @@ -158,14 +158,14 @@ class RTCStats { /** * Sends the identity data to the rtcstats server. - * + * * @param identityData - Identity data to send. * @returns {void} - */ + */ sendIdentity(identityData) { - this._trace?.identity('identity', null, identityData); + this._trace?.identity('identity', null, identityData); } - + /** * Resets the trace module by closing the websocket and deleting the object. * After reset, the rtcstats proxy module that tries to send data via `sendStatsEntry`, will no longer @@ -182,7 +182,7 @@ class RTCStats { /** * Sends a stats entry to the rtcstats server. This is called by the rtcstats proxy module, * or any other app that wants to send custom stats. - * + * * @param entry - Stats entry to send. * @returns {void} */ diff --git a/modules/RTCStats/interfaces.ts b/modules/RTCStats/interfaces.ts index 518b9b8ad3..b2be1110da 100644 --- a/modules/RTCStats/interfaces.ts +++ b/modules/RTCStats/interfaces.ts @@ -8,4 +8,4 @@ export interface IRTCStatsConfiguration { rtcstatsStoreLogs?: boolean; rtcstatsUseLegacy?: boolean; }; -} \ No newline at end of file +}