|
@@ -202,16 +202,13 @@ function ConferenceStats() {
|
202
|
202
|
* @param audioLevelsInterval
|
203
|
203
|
* @param statsInterval stats refresh interval given in ms.
|
204
|
204
|
* @param eventEmitter
|
205
|
|
- * @param config {object} supports the following properties: disableAudioLevels,
|
206
|
|
- * disableStats, logStats
|
207
|
205
|
* @constructor
|
208
|
206
|
*/
|
209
|
207
|
function StatsCollector(
|
210
|
208
|
peerconnection,
|
211
|
209
|
audioLevelsInterval,
|
212
|
210
|
statsInterval,
|
213
|
|
- eventEmitter,
|
214
|
|
- config) {
|
|
211
|
+ eventEmitter) {
|
215
|
212
|
// StatsCollector depends entirely on the format of the reports returned by
|
216
|
213
|
// RTCPeerConnection#getStats. Given that the value of
|
217
|
214
|
// RTCBrowserType#getBrowserType() is very unlikely to change at runtime, it
|
|
@@ -247,7 +244,6 @@ function StatsCollector(
|
247
|
244
|
this.baselineStatsReport = null;
|
248
|
245
|
this.audioLevelsIntervalId = null;
|
249
|
246
|
this.eventEmitter = eventEmitter;
|
250
|
|
- this.config = config || {};
|
251
|
247
|
this.conferenceStats = new ConferenceStats();
|
252
|
248
|
|
253
|
249
|
/**
|
|
@@ -312,33 +308,35 @@ StatsCollector.prototype.errorCallback = function (error) {
|
312
|
308
|
/**
|
313
|
309
|
* Starts stats updates.
|
314
|
310
|
*/
|
315
|
|
-StatsCollector.prototype.start = function () {
|
|
311
|
+StatsCollector.prototype.start = function (startAudioLevelStats) {
|
316
|
312
|
var self = this;
|
317
|
|
- this.audioLevelsIntervalId = setInterval(
|
318
|
|
- function () {
|
319
|
|
- // Interval updates
|
320
|
|
- self.peerconnection.getStats(
|
321
|
|
- function (report) {
|
322
|
|
- var results = null;
|
323
|
|
- if (!report || !report.result ||
|
324
|
|
- typeof report.result != 'function') {
|
325
|
|
- results = report;
|
326
|
|
- }
|
327
|
|
- else {
|
328
|
|
- results = report.result();
|
329
|
|
- }
|
330
|
|
- self.currentAudioLevelsReport = results;
|
331
|
|
- self.processAudioLevelReport();
|
332
|
|
- self.baselineAudioLevelsReport =
|
333
|
|
- self.currentAudioLevelsReport;
|
334
|
|
- },
|
335
|
|
- self.errorCallback
|
336
|
|
- );
|
337
|
|
- },
|
338
|
|
- self.audioLevelsIntervalMilis
|
339
|
|
- );
|
|
313
|
+ if(startAudioLevelStats) {
|
|
314
|
+ this.audioLevelsIntervalId = setInterval(
|
|
315
|
+ function () {
|
|
316
|
+ // Interval updates
|
|
317
|
+ self.peerconnection.getStats(
|
|
318
|
+ function (report) {
|
|
319
|
+ var results = null;
|
|
320
|
+ if (!report || !report.result ||
|
|
321
|
+ typeof report.result != 'function') {
|
|
322
|
+ results = report;
|
|
323
|
+ }
|
|
324
|
+ else {
|
|
325
|
+ results = report.result();
|
|
326
|
+ }
|
|
327
|
+ self.currentAudioLevelsReport = results;
|
|
328
|
+ self.processAudioLevelReport();
|
|
329
|
+ self.baselineAudioLevelsReport =
|
|
330
|
+ self.currentAudioLevelsReport;
|
|
331
|
+ },
|
|
332
|
+ self.errorCallback
|
|
333
|
+ );
|
|
334
|
+ },
|
|
335
|
+ self.audioLevelsIntervalMilis
|
|
336
|
+ );
|
|
337
|
+ }
|
340
|
338
|
|
341
|
|
- if (!this.config.disableStats && browserSupported) {
|
|
339
|
+ if (browserSupported) {
|
342
|
340
|
this.statsIntervalId = setInterval(
|
343
|
341
|
function () {
|
344
|
342
|
// Interval updates
|
|
@@ -372,8 +370,7 @@ StatsCollector.prototype.start = function () {
|
372
|
370
|
);
|
373
|
371
|
}
|
374
|
372
|
|
375
|
|
- if (this.config.logStats
|
376
|
|
- && browserSupported
|
|
373
|
+ if (browserSupported
|
377
|
374
|
// logging statistics does not support firefox
|
378
|
375
|
&& this._browserType !== RTCBrowserType.RTC_BROWSER_FIREFOX) {
|
379
|
376
|
this.gatherStatsIntervalId = setInterval(
|
|
@@ -507,6 +504,7 @@ StatsCollector.prototype.processStatsReport = function () {
|
507
|
504
|
}
|
508
|
505
|
|
509
|
506
|
var getStatValue = this._getStatValue;
|
|
507
|
+ byteSentStats = {};
|
510
|
508
|
|
511
|
509
|
for (var idx in this.currentStatsReport) {
|
512
|
510
|
var now = this.currentStatsReport[idx];
|
|
@@ -622,8 +620,16 @@ StatsCollector.prototype.processStatsReport = function () {
|
622
|
620
|
= nowBytesTransmitted - getStatValue(before, "bytesReceived");
|
623
|
621
|
}
|
624
|
622
|
nowBytesTransmitted = getStatValue(now, "bytesSent");
|
625
|
|
- if (nowBytesTransmitted) {
|
626
|
|
- bytesSent = nowBytesTransmitted - getStatValue(before, "bytesSent");
|
|
623
|
+ if(typeof(nowBytesTransmitted) === "number" ||
|
|
624
|
+ typeof(nowBytesTransmitted) === "string") {
|
|
625
|
+ nowBytesTransmitted = Number(nowBytesTransmitted);
|
|
626
|
+ if(!isNaN(nowBytesTransmitted)){
|
|
627
|
+ byteSentStats[ssrc] = nowBytesTransmitted;
|
|
628
|
+ if (nowBytesTransmitted > 0) {
|
|
629
|
+ bytesSent = nowBytesTransmitted -
|
|
630
|
+ getStatValue(before, "bytesSent");
|
|
631
|
+ }
|
|
632
|
+ }
|
627
|
633
|
}
|
628
|
634
|
|
629
|
635
|
var time = Math.round((now.timestamp - before.timestamp) / 1000);
|
|
@@ -687,7 +693,6 @@ StatsCollector.prototype.processStatsReport = function () {
|
687
|
693
|
Object.keys(this.ssrc2stats).forEach(
|
688
|
694
|
function (ssrc) {
|
689
|
695
|
var ssrcStats = this.ssrc2stats[ssrc];
|
690
|
|
-
|
691
|
696
|
// process package loss stats
|
692
|
697
|
var ssrc2Loss = ssrcStats.ssrc2Loss;
|
693
|
698
|
var type = ssrc2Loss.isDownloadStream ? "download" : "upload";
|
|
@@ -707,6 +712,8 @@ StatsCollector.prototype.processStatsReport = function () {
|
707
|
712
|
this
|
708
|
713
|
);
|
709
|
714
|
|
|
715
|
+ this.eventEmitter.emit(StatisticsEvents.BYTE_SENT_STATS, byteSentStats);
|
|
716
|
+
|
710
|
717
|
this.conferenceStats.bitrate
|
711
|
718
|
= {"upload": bitrateUpload, "download": bitrateDownload};
|
712
|
719
|
|