Skip to content

Commit

Permalink
feat(RTCStats): Suppress unnecessary error message when rtcstatsEnabl…
Browse files Browse the repository at this point in the history
…ed === false (jitsi#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
  • Loading branch information
andy-leezard authored and subhamcyara committed Jul 19, 2024
1 parent edde1f4 commit 5fe70f0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
62 changes: 31 additions & 31 deletions modules/RTCStats/RTCStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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: {
Expand All @@ -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,
Expand All @@ -142,7 +142,7 @@ class RTCStats {
meetingUniqueId,
isBreakoutRoom
}

this.sendIdentity(identityData);
});

Expand All @@ -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
Expand All @@ -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}
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/RTCStats/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export interface IRTCStatsConfiguration {
rtcstatsStoreLogs?: boolean;
rtcstatsUseLegacy?: boolean;
};
}
}

0 comments on commit 5fe70f0

Please sign in to comment.