|
@@ -9,8 +9,55 @@ import RTCBrowserType from '../RTC/RTCBrowserType';
|
9
|
9
|
import Statistics from './statistics';
|
10
|
10
|
import * as VideoType from '../../service/RTC/VideoType';
|
11
|
11
|
|
|
12
|
+/**
|
|
13
|
+ * All avg RTP stats are currently reported under 1 event name, but under
|
|
14
|
+ * different keys. This constant stores the name of this event.
|
|
15
|
+ * Example structure of "avg.rtp.stats" analytics event:
|
|
16
|
+ *
|
|
17
|
+ * {
|
|
18
|
+ * "stat_avg_rtt": {
|
|
19
|
+ * value: 200,
|
|
20
|
+ * samples: [ 100, 200, 300 ]
|
|
21
|
+ * },
|
|
22
|
+ * "stat_avg_packetloss_total": {
|
|
23
|
+ * value: 10,
|
|
24
|
+ * samples: [ 5, 10, 15]
|
|
25
|
+ * },
|
|
26
|
+ * "p2p_stat_avg_packetloss_total": {
|
|
27
|
+ * value: 15,
|
|
28
|
+ * samples: [ 10, 15, 20]
|
|
29
|
+ * }
|
|
30
|
+ * }
|
|
31
|
+ *
|
|
32
|
+ * Note that the samples array is currently emitted for debug purposes only and
|
|
33
|
+ * can be removed anytime soon from the structure.
|
|
34
|
+ *
|
|
35
|
+ * Also not all values are always present in "avg.rtp.stats", some of the values
|
|
36
|
+ * are obtained and calculated as part of different process/event pipe. For
|
|
37
|
+ * example {@link ConnectionAvgStats} instances are doing the reports for each
|
|
38
|
+ * {@link TraceablePeerConnection} and work independently from the main stats
|
|
39
|
+ * pipe.
|
|
40
|
+ *
|
|
41
|
+ * @type {string}
|
|
42
|
+ */
|
|
43
|
+const AVG_RTP_STATS_EVENT = 'avg.rtp.stats';
|
|
44
|
+
|
12
|
45
|
const logger = getLogger(__filename);
|
13
|
46
|
|
|
47
|
+/**
|
|
48
|
+ * Figures out what prefix should be added to the stat name.
|
|
49
|
+ * @param {boolean} isP2P is it P2P or JVB conference ?
|
|
50
|
+ * @param {number} conferenceSize how many participants are there in
|
|
51
|
+ * the conference (including us)
|
|
52
|
+ * @return {string} "" (for JVB conference) or "p2p_" (for P2P) or "jvb121_"
|
|
53
|
+ * (for JVB 2 participant conference).
|
|
54
|
+ */
|
|
55
|
+function getPrefix(isP2P, conferenceSize) {
|
|
56
|
+ return isP2P
|
|
57
|
+ ? 'p2p_'
|
|
58
|
+ : conferenceSize === 2 ? 'jvb121_' : '';
|
|
59
|
+}
|
|
60
|
+
|
14
|
61
|
/**
|
15
|
62
|
* This will calculate an average for one, named stat and submit it to
|
16
|
63
|
* the analytics module when requested. It automatically counts the samples.
|
|
@@ -25,6 +72,7 @@ class AverageStatReport {
|
25
|
72
|
this.name = name;
|
26
|
73
|
this.count = 0;
|
27
|
74
|
this.sum = 0;
|
|
75
|
+ this.samples = [];
|
28
|
76
|
}
|
29
|
77
|
|
30
|
78
|
/**
|
|
@@ -39,6 +87,7 @@ class AverageStatReport {
|
39
|
87
|
nextValue);
|
40
|
88
|
} else if (!isNaN(nextValue)) {
|
41
|
89
|
this.sum += nextValue;
|
|
90
|
+ this.samples.push(nextValue);
|
42
|
91
|
this.count += 1;
|
43
|
92
|
}
|
44
|
93
|
}
|
|
@@ -53,16 +102,19 @@ class AverageStatReport {
|
53
|
102
|
}
|
54
|
103
|
|
55
|
104
|
/**
|
56
|
|
- * Calculates an average and submit the report to the analytics module.
|
57
|
|
- * @param {boolean} isP2P indicates if the report is to be submitted for
|
58
|
|
- * the P2P connection (when conference is currently in the P2P mode). This
|
59
|
|
- * will add 'p2p.' prefix to the name of the event. All averages should be
|
60
|
|
- * cleared when the conference switches, between P2P and JVB modes.
|
|
105
|
+ * Appends the report to the analytics "data" object. The object will be
|
|
106
|
+ * set under <tt>prefix</tt> + {@link this.name} key.
|
|
107
|
+ * @param {Object} report the analytics "data" object
|
|
108
|
+ * @param {string} prefix the prefix string that will be added at
|
|
109
|
+ * the beginning of the key name.
|
61
|
110
|
*/
|
62
|
|
- report(isP2P) {
|
63
|
|
- Statistics.analytics.sendEvent(
|
64
|
|
- `${isP2P ? 'p2p.' : ''}${this.name}`,
|
65
|
|
- { value: this.calculate() });
|
|
111
|
+ appendReport(report, prefix) {
|
|
112
|
+ const keyName = `${prefix}${this.name}`;
|
|
113
|
+
|
|
114
|
+ report[keyName] = {
|
|
115
|
+ value: this.calculate(),
|
|
116
|
+ samples: this.samples
|
|
117
|
+ };
|
66
|
118
|
}
|
67
|
119
|
|
68
|
120
|
/**
|
|
@@ -70,6 +122,7 @@ class AverageStatReport {
|
70
|
122
|
* calculated using this instance.
|
71
|
123
|
*/
|
72
|
124
|
reset() {
|
|
125
|
+ this.samples = [];
|
73
|
126
|
this.sum = 0;
|
74
|
127
|
this.count = 0;
|
75
|
128
|
}
|
|
@@ -114,7 +167,7 @@ class ConnectionAvgStats {
|
114
|
167
|
* Average round trip time reported by the ICE candidate pair.
|
115
|
168
|
* @type {AverageStatReport}
|
116
|
169
|
*/
|
117
|
|
- this._avgRTT = new AverageStatReport('stat.avg.rtt');
|
|
170
|
+ this._avgRTT = new AverageStatReport('stat_avg_rtt');
|
118
|
171
|
|
119
|
172
|
/**
|
120
|
173
|
* Map stores average RTT to the JVB reported by remote participants.
|
|
@@ -177,7 +230,11 @@ class ConnectionAvgStats {
|
177
|
230
|
|
178
|
231
|
if (this._sampleIdx >= this._n) {
|
179
|
232
|
if (RTCBrowserType.supportsRTTStatistics()) {
|
180
|
|
- this._avgRTT.report(this.isP2P);
|
|
233
|
+ const batchReport = { };
|
|
234
|
+ const confSize = this._conference.getParticipantCount();
|
|
235
|
+ const prefix = getPrefix(this.isP2P, confSize);
|
|
236
|
+
|
|
237
|
+ this._avgRTT.appendReport(batchReport, prefix);
|
181
|
238
|
|
182
|
239
|
// Report end to end RTT only for JVB
|
183
|
240
|
if (!this.isP2P) {
|
|
@@ -185,11 +242,14 @@ class ConnectionAvgStats {
|
185
|
242
|
const avgLocalRTT = this._avgRTT.calculate();
|
186
|
243
|
|
187
|
244
|
if (!isNaN(avgLocalRTT) && !isNaN(avgRemoteRTT)) {
|
188
|
|
- Statistics.analytics.sendEvent(
|
189
|
|
- 'stat.avg.end2endrtt',
|
190
|
|
- { value: avgLocalRTT + avgRemoteRTT });
|
|
245
|
+ // eslint-disable-next-line camelcase
|
|
246
|
+ batchReport[`${prefix}stat_avg_end2endrtt`]
|
|
247
|
+ = { value: avgLocalRTT + avgRemoteRTT };
|
191
|
248
|
}
|
192
|
249
|
}
|
|
250
|
+
|
|
251
|
+ Statistics.analytics.sendEvent(
|
|
252
|
+ AVG_RTP_STATS_EVENT, batchReport);
|
193
|
253
|
}
|
194
|
254
|
|
195
|
255
|
this._resetAvgStats();
|
|
@@ -232,7 +292,7 @@ class ConnectionAvgStats {
|
232
|
292
|
let rttAvg = this._avgRemoteRTTMap.get(id);
|
233
|
293
|
|
234
|
294
|
if (!rttAvg && validData) {
|
235
|
|
- rttAvg = new AverageStatReport(`${id}.stat.rtt`);
|
|
295
|
+ rttAvg = new AverageStatReport(`${id}_stat_rtt`);
|
236
|
296
|
this._avgRemoteRTTMap.set(id, rttAvg);
|
237
|
297
|
}
|
238
|
298
|
|
|
@@ -326,7 +386,7 @@ export default class AvgRTPStatsReporter {
|
326
|
386
|
* @private
|
327
|
387
|
*/
|
328
|
388
|
this._avgAudioBitrateUp
|
329
|
|
- = new AverageStatReport('stat.avg.bitrate.audio.upload');
|
|
389
|
+ = new AverageStatReport('stat_avg_bitrate_audio_upload');
|
330
|
390
|
|
331
|
391
|
/**
|
332
|
392
|
* Average audio download bitrate
|
|
@@ -334,7 +394,7 @@ export default class AvgRTPStatsReporter {
|
334
|
394
|
* @private
|
335
|
395
|
*/
|
336
|
396
|
this._avgAudioBitrateDown
|
337
|
|
- = new AverageStatReport('stat.avg.bitrate.audio.download');
|
|
397
|
+ = new AverageStatReport('stat_avg_bitrate_audio_download');
|
338
|
398
|
|
339
|
399
|
/**
|
340
|
400
|
* Average video upload bitrate
|
|
@@ -342,7 +402,7 @@ export default class AvgRTPStatsReporter {
|
342
|
402
|
* @private
|
343
|
403
|
*/
|
344
|
404
|
this._avgVideoBitrateUp
|
345
|
|
- = new AverageStatReport('stat.avg.bitrate.video.upload');
|
|
405
|
+ = new AverageStatReport('stat_avg_bitrate_video_upload');
|
346
|
406
|
|
347
|
407
|
/**
|
348
|
408
|
* Average video download bitrate
|
|
@@ -350,7 +410,7 @@ export default class AvgRTPStatsReporter {
|
350
|
410
|
* @private
|
351
|
411
|
*/
|
352
|
412
|
this._avgVideoBitrateDown
|
353
|
|
- = new AverageStatReport('stat.avg.bitrate.video.download');
|
|
413
|
+ = new AverageStatReport('stat_avg_bitrate_video_download');
|
354
|
414
|
|
355
|
415
|
/**
|
356
|
416
|
* Average upload bandwidth
|
|
@@ -358,7 +418,7 @@ export default class AvgRTPStatsReporter {
|
358
|
418
|
* @private
|
359
|
419
|
*/
|
360
|
420
|
this._avgBandwidthUp
|
361
|
|
- = new AverageStatReport('stat.avg.bandwidth.upload');
|
|
421
|
+ = new AverageStatReport('stat_avg_bandwidth_upload');
|
362
|
422
|
|
363
|
423
|
/**
|
364
|
424
|
* Average download bandwidth
|
|
@@ -366,7 +426,7 @@ export default class AvgRTPStatsReporter {
|
366
|
426
|
* @private
|
367
|
427
|
*/
|
368
|
428
|
this._avgBandwidthDown
|
369
|
|
- = new AverageStatReport('stat.avg.bandwidth.download');
|
|
429
|
+ = new AverageStatReport('stat_avg_bandwidth_download');
|
370
|
430
|
|
371
|
431
|
/**
|
372
|
432
|
* Average total packet loss
|
|
@@ -374,7 +434,7 @@ export default class AvgRTPStatsReporter {
|
374
|
434
|
* @private
|
375
|
435
|
*/
|
376
|
436
|
this._avgPacketLossTotal
|
377
|
|
- = new AverageStatReport('stat.avg.packetloss.total');
|
|
437
|
+ = new AverageStatReport('stat_avg_packetloss_total');
|
378
|
438
|
|
379
|
439
|
/**
|
380
|
440
|
* Average upload packet loss
|
|
@@ -382,7 +442,7 @@ export default class AvgRTPStatsReporter {
|
382
|
442
|
* @private
|
383
|
443
|
*/
|
384
|
444
|
this._avgPacketLossUp
|
385
|
|
- = new AverageStatReport('stat.avg.packetloss.upload');
|
|
445
|
+ = new AverageStatReport('stat_avg_packetloss_upload');
|
386
|
446
|
|
387
|
447
|
/**
|
388
|
448
|
* Average download packet loss
|
|
@@ -390,14 +450,14 @@ export default class AvgRTPStatsReporter {
|
390
|
450
|
* @private
|
391
|
451
|
*/
|
392
|
452
|
this._avgPacketLossDown
|
393
|
|
- = new AverageStatReport('stat.avg.packetloss.download');
|
|
453
|
+ = new AverageStatReport('stat_avg_packetloss_download');
|
394
|
454
|
|
395
|
455
|
/**
|
396
|
456
|
* Average FPS for remote videos
|
397
|
457
|
* @type {AverageStatReport}
|
398
|
458
|
* @private
|
399
|
459
|
*/
|
400
|
|
- this._avgRemoteFPS = new AverageStatReport('stat.avg.framerate.remote');
|
|
460
|
+ this._avgRemoteFPS = new AverageStatReport('stat_avg_framerate_remote');
|
401
|
461
|
|
402
|
462
|
/**
|
403
|
463
|
* Average FPS for remote screen streaming videos (reported only if not
|
|
@@ -406,14 +466,14 @@ export default class AvgRTPStatsReporter {
|
406
|
466
|
* @private
|
407
|
467
|
*/
|
408
|
468
|
this._avgRemoteScreenFPS
|
409
|
|
- = new AverageStatReport('stat.avg.framerate.screen.remote');
|
|
469
|
+ = new AverageStatReport('stat_avg_framerate_screen_remote');
|
410
|
470
|
|
411
|
471
|
/**
|
412
|
472
|
* Average FPS for local video (camera)
|
413
|
473
|
* @type {AverageStatReport}
|
414
|
474
|
* @private
|
415
|
475
|
*/
|
416
|
|
- this._avgLocalFPS = new AverageStatReport('stat.avg.framerate.local');
|
|
476
|
+ this._avgLocalFPS = new AverageStatReport('stat_avg_framerate_local');
|
417
|
477
|
|
418
|
478
|
/**
|
419
|
479
|
* Average FPS for local screen streaming video (reported only if not
|
|
@@ -422,7 +482,7 @@ export default class AvgRTPStatsReporter {
|
422
|
482
|
* @private
|
423
|
483
|
*/
|
424
|
484
|
this._avgLocalScreenFPS
|
425
|
|
- = new AverageStatReport('stat.avg.framerate.screen.local');
|
|
485
|
+ = new AverageStatReport('stat_avg_framerate_screen_local');
|
426
|
486
|
|
427
|
487
|
/**
|
428
|
488
|
* Average connection quality as defined by
|
|
@@ -430,7 +490,7 @@ export default class AvgRTPStatsReporter {
|
430
|
490
|
* @type {AverageStatReport}
|
431
|
491
|
* @private
|
432
|
492
|
*/
|
433
|
|
- this._avgCQ = new AverageStatReport('stat.avg.cq');
|
|
493
|
+ this._avgCQ = new AverageStatReport('stat_avg_cq');
|
434
|
494
|
|
435
|
495
|
this._onLocalStatsUpdated = data => this._calculateAvgStats(data);
|
436
|
496
|
conference.on(
|
|
@@ -447,6 +507,19 @@ export default class AvgRTPStatsReporter {
|
447
|
507
|
ConferenceEvents.P2P_STATUS,
|
448
|
508
|
this._onP2PStatusChanged);
|
449
|
509
|
|
|
510
|
+ this._onJvb121StatusChanged = (oldStatus, newStatus) => {
|
|
511
|
+ // We want to reset only on the transition from false => true,
|
|
512
|
+ // because otherwise those stats are resetted on JVB <=> P2P
|
|
513
|
+ // transition.
|
|
514
|
+ if (newStatus === true) {
|
|
515
|
+ logger.info('Resetting JVB avg RTP stats');
|
|
516
|
+ this._resetAvgJvbStats();
|
|
517
|
+ }
|
|
518
|
+ };
|
|
519
|
+ conference.on(
|
|
520
|
+ ConferenceEvents.JVB121_STATUS,
|
|
521
|
+ this._onJvb121StatusChanged);
|
|
522
|
+
|
450
|
523
|
this.jvbStatsMonitor
|
451
|
524
|
= new ConnectionAvgStats(conference, false /* JVB */, n);
|
452
|
525
|
|
|
@@ -463,9 +536,10 @@ export default class AvgRTPStatsReporter {
|
463
|
536
|
_calculateAvgStats(data) {
|
464
|
537
|
|
465
|
538
|
const isP2P = this._conference.isP2PActive();
|
466
|
|
- const peerCount = this._conference.getParticipants().length;
|
|
539
|
+ const confSize = this._conference.getParticipantCount();
|
|
540
|
+ const prefix = getPrefix(isP2P, confSize);
|
467
|
541
|
|
468
|
|
- if (!isP2P && peerCount < 1) {
|
|
542
|
+ if (!isP2P && confSize < 2) {
|
469
|
543
|
|
470
|
544
|
// There's no point in collecting stats for a JVB conference of 1.
|
471
|
545
|
// That happens for short period of time after everyone leaves
|
|
@@ -545,30 +619,34 @@ export default class AvgRTPStatsReporter {
|
545
|
619
|
this._sampleIdx += 1;
|
546
|
620
|
|
547
|
621
|
if (this._sampleIdx >= this._n) {
|
548
|
|
- this._avgAudioBitrateUp.report(isP2P);
|
549
|
|
- this._avgAudioBitrateDown.report(isP2P);
|
|
622
|
+ const batchReport = { };
|
550
|
623
|
|
551
|
|
- this._avgVideoBitrateUp.report(isP2P);
|
552
|
|
- this._avgVideoBitrateDown.report(isP2P);
|
|
624
|
+ this._avgAudioBitrateUp.appendReport(batchReport, prefix);
|
|
625
|
+ this._avgAudioBitrateDown.appendReport(batchReport, prefix);
|
|
626
|
+
|
|
627
|
+ this._avgVideoBitrateUp.appendReport(batchReport, prefix);
|
|
628
|
+ this._avgVideoBitrateDown.appendReport(batchReport, prefix);
|
553
|
629
|
|
554
|
630
|
if (RTCBrowserType.supportsBandwidthStatistics()) {
|
555
|
|
- this._avgBandwidthUp.report(isP2P);
|
556
|
|
- this._avgBandwidthDown.report(isP2P);
|
|
631
|
+ this._avgBandwidthUp.appendReport(batchReport, prefix);
|
|
632
|
+ this._avgBandwidthDown.appendReport(batchReport, prefix);
|
557
|
633
|
}
|
558
|
|
- this._avgPacketLossUp.report(isP2P);
|
559
|
|
- this._avgPacketLossDown.report(isP2P);
|
560
|
|
- this._avgPacketLossTotal.report(isP2P);
|
|
634
|
+ this._avgPacketLossUp.appendReport(batchReport, prefix);
|
|
635
|
+ this._avgPacketLossDown.appendReport(batchReport, prefix);
|
|
636
|
+ this._avgPacketLossTotal.appendReport(batchReport, prefix);
|
561
|
637
|
|
562
|
|
- this._avgRemoteFPS.report(isP2P);
|
|
638
|
+ this._avgRemoteFPS.appendReport(batchReport, prefix);
|
563
|
639
|
if (!isNaN(this._avgRemoteScreenFPS.calculate())) {
|
564
|
|
- this._avgRemoteScreenFPS.report(isP2P);
|
|
640
|
+ this._avgRemoteScreenFPS.appendReport(batchReport, prefix);
|
565
|
641
|
}
|
566
|
|
- this._avgLocalFPS.report(isP2P);
|
|
642
|
+ this._avgLocalFPS.appendReport(batchReport, prefix);
|
567
|
643
|
if (!isNaN(this._avgLocalScreenFPS.calculate())) {
|
568
|
|
- this._avgLocalScreenFPS.report(isP2P);
|
|
644
|
+ this._avgLocalScreenFPS.appendReport(batchReport, prefix);
|
569
|
645
|
}
|
570
|
646
|
|
571
|
|
- this._avgCQ.report(isP2P);
|
|
647
|
+ this._avgCQ.appendReport(batchReport, prefix);
|
|
648
|
+
|
|
649
|
+ Statistics.analytics.sendEvent(AVG_RTP_STATS_EVENT, batchReport);
|
572
|
650
|
|
573
|
651
|
this._resetAvgStats();
|
574
|
652
|
}
|
|
@@ -667,6 +745,18 @@ export default class AvgRTPStatsReporter {
|
667
|
745
|
return peerFpsSum / peerSsrcCount;
|
668
|
746
|
}
|
669
|
747
|
|
|
748
|
+ /**
|
|
749
|
+ * Resets the stats related to JVB connection. Must not be called when in
|
|
750
|
+ * P2P mode, because then the {@link AverageStatReport} instances are
|
|
751
|
+ * tracking P2P stats. Note that this should never happen unless something
|
|
752
|
+ * is wrong with the P2P and JVB121 events.
|
|
753
|
+ * @private
|
|
754
|
+ */
|
|
755
|
+ _resetAvgJvbStats() {
|
|
756
|
+ this._resetAvgStats();
|
|
757
|
+ this.jvbStatsMonitor._resetAvgStats();
|
|
758
|
+ }
|
|
759
|
+
|
670
|
760
|
/**
|
671
|
761
|
* Reset cache of all averages and {@link _sampleIdx}.
|
672
|
762
|
* @private
|
|
@@ -705,6 +795,9 @@ export default class AvgRTPStatsReporter {
|
705
|
795
|
this._conference.off(
|
706
|
796
|
ConnectionQualityEvents.LOCAL_STATS_UPDATED,
|
707
|
797
|
this._onLocalStatsUpdated);
|
|
798
|
+ this._conference.off(
|
|
799
|
+ ConferenceEvents.JVB121_STATUS,
|
|
800
|
+ this._onJvb121StatusChanged);
|
708
|
801
|
this.jvbStatsMonitor.dispose();
|
709
|
802
|
this.p2pStatsMonitor.dispose();
|
710
|
803
|
}
|