Skip to content

Commit

Permalink
fix(statistics) initialize LocalStatsCollector on Statistics.init
Browse files Browse the repository at this point in the history
Creating the AudioContext at import time means a warning line is printed
in the JS console even before the user has a chance of initializing the
library, which is weird.

There is no harm in initializing it in init since it's the first thing
the user needs to do in order to use the library.
  • Loading branch information
saghul committed Mar 28, 2024
1 parent 5237dbf commit b564cbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions modules/statistics/LocalStatsCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ LocalStatsCollector.prototype.stop = function() {
this.source = null;
};

/**
* Initialize collector.
*/
LocalStatsCollector.init = function() {
LocalStatsCollector.connectAudioContext();
};

/**
* Checks if the environment has the necessary conditions to support
* collecting stats from local streams.
Expand Down Expand Up @@ -170,8 +177,3 @@ LocalStatsCollector.connectAudioContext = function() {

context.suspend();
};

/**
* Initialize the audio context on startup.
*/
LocalStatsCollector.connectAudioContext();
2 changes: 2 additions & 0 deletions modules/statistics/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Statistics.init = function(options) {

Statistics.disableThirdPartyRequests = options.disableThirdPartyRequests;

LocalStats.init();

// WatchRTC is not required to work for react native
browser.isReactNative()
? logger.warn('Cannot initialize WatchRTC in a react native environment!')
Expand Down

0 comments on commit b564cbf

Please sign in to comment.