|
@@ -134,8 +134,6 @@ function ConferenceStats() {
|
134
|
134
|
*/
|
135
|
135
|
export default function StatsCollector(peerconnection, audioLevelsInterval, statsInterval, eventEmitter) {
|
136
|
136
|
this.peerconnection = peerconnection;
|
137
|
|
- this.baselineAudioLevelsReport = null;
|
138
|
|
- this.currentAudioLevelsReport = null;
|
139
|
137
|
this.currentStatsReport = null;
|
140
|
138
|
this.previousStatsReport = null;
|
141
|
139
|
this.audioLevelReportHistory = {};
|
|
@@ -196,40 +194,23 @@ StatsCollector.prototype.errorCallback = function(error) {
|
196
|
194
|
* Starts stats updates.
|
197
|
195
|
*/
|
198
|
196
|
StatsCollector.prototype.start = function(startAudioLevelStats) {
|
199
|
|
- if (startAudioLevelStats) {
|
200
|
|
- if (browser.supportsReceiverStats()) {
|
201
|
|
- logger.info('Using RTCRtpSynchronizationSource for remote audio levels');
|
202
|
|
- }
|
|
197
|
+ if (startAudioLevelStats && browser.supportsReceiverStats()) {
|
203
|
198
|
this.audioLevelsIntervalId = setInterval(
|
204
|
199
|
() => {
|
205
|
|
- if (browser.supportsReceiverStats()) {
|
206
|
|
- const audioLevels = this.peerconnection.getAudioLevels(this.speakerList);
|
207
|
|
-
|
208
|
|
- for (const ssrc in audioLevels) {
|
209
|
|
- if (audioLevels.hasOwnProperty(ssrc)) {
|
210
|
|
- // Use a scaling factor of 2.5 to report the same
|
211
|
|
- // audio levels that getStats reports.
|
212
|
|
- const audioLevel = audioLevels[ssrc] * 2.5;
|
213
|
|
-
|
214
|
|
- this.eventEmitter.emit(
|
215
|
|
- StatisticsEvents.AUDIO_LEVEL,
|
216
|
|
- this.peerconnection,
|
217
|
|
- Number.parseInt(ssrc, 10),
|
218
|
|
- audioLevel,
|
219
|
|
- false /* isLocal */);
|
220
|
|
- }
|
|
200
|
+ const audioLevels = this.peerconnection.getAudioLevels(this.speakerList);
|
|
201
|
+
|
|
202
|
+ for (const ssrc in audioLevels) {
|
|
203
|
+ if (audioLevels.hasOwnProperty(ssrc)) {
|
|
204
|
+ // Use a scaling factor of 2.5 to report the same audio levels that getStats reports.
|
|
205
|
+ const audioLevel = audioLevels[ssrc] * 2.5;
|
|
206
|
+
|
|
207
|
+ this.eventEmitter.emit(
|
|
208
|
+ StatisticsEvents.AUDIO_LEVEL,
|
|
209
|
+ this.peerconnection,
|
|
210
|
+ Number.parseInt(ssrc, 10),
|
|
211
|
+ audioLevel,
|
|
212
|
+ false /* isLocal */);
|
221
|
213
|
}
|
222
|
|
- } else {
|
223
|
|
- // Interval updates
|
224
|
|
- this.peerconnection.getStats()
|
225
|
|
- .then(report => {
|
226
|
|
- this.currentAudioLevelsReport = typeof report?.result === 'function'
|
227
|
|
- ? report.result()
|
228
|
|
- : report;
|
229
|
|
- this.processAudioLevelReport();
|
230
|
|
- this.baselineAudioLevelsReport = this.currentAudioLevelsReport;
|
231
|
|
- })
|
232
|
|
- .catch(error => this.errorCallback(error));
|
233
|
214
|
}
|
234
|
215
|
},
|
235
|
216
|
this.audioLevelsIntervalMilis
|
|
@@ -679,41 +660,3 @@ StatsCollector.prototype.processStatsReport = function() {
|
679
|
660
|
|
680
|
661
|
this._processAndEmitReport();
|
681
|
662
|
};
|
682
|
|
-
|
683
|
|
-/**
|
684
|
|
- * Stats processing logic.
|
685
|
|
- */
|
686
|
|
-StatsCollector.prototype.processAudioLevelReport = function() {
|
687
|
|
- if (!this.baselineAudioLevelsReport) {
|
688
|
|
- return;
|
689
|
|
- }
|
690
|
|
-
|
691
|
|
- this.currentAudioLevelsReport.forEach(now => {
|
692
|
|
- if (now.type !== 'track') {
|
693
|
|
- return;
|
694
|
|
- }
|
695
|
|
-
|
696
|
|
- // Audio level
|
697
|
|
- const audioLevel = now.audioLevel;
|
698
|
|
-
|
699
|
|
- if (!audioLevel) {
|
700
|
|
- return;
|
701
|
|
- }
|
702
|
|
-
|
703
|
|
- const trackIdentifier = now.trackIdentifier;
|
704
|
|
- const ssrc = this.peerconnection.getSsrcByTrackId(trackIdentifier);
|
705
|
|
-
|
706
|
|
- if (ssrc) {
|
707
|
|
- const isLocal
|
708
|
|
- = ssrc === this.peerconnection.getLocalSSRC(
|
709
|
|
- this.peerconnection.getLocalTracks(MediaType.AUDIO));
|
710
|
|
-
|
711
|
|
- this.eventEmitter.emit(
|
712
|
|
- StatisticsEvents.AUDIO_LEVEL,
|
713
|
|
- this.peerconnection,
|
714
|
|
- ssrc,
|
715
|
|
- audioLevel,
|
716
|
|
- isLocal);
|
717
|
|
- }
|
718
|
|
- });
|
719
|
|
-};
|