Browse Source

feat(AvgRTPStatsReporter): add 'jvb121_' prefix

Will report stats for one to one JVB conference under different prefix.
dev1
paweldomas 8 years ago
parent
commit
3e91477a7d
1 changed files with 42 additions and 24 deletions
  1. 42
    24
      modules/statistics/AvgRTPStatsReporter.js

+ 42
- 24
modules/statistics/AvgRTPStatsReporter.js View File

@@ -44,6 +44,20 @@ const AVG_RTP_STATS_EVENT = 'avg.rtp.stats';
44 44
 
45 45
 const logger = getLogger(__filename);
46 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
+
47 61
 /**
48 62
  * This will calculate an average for one, named stat and submit it to
49 63
  * the analytics module when requested. It automatically counts the samples.
@@ -89,14 +103,15 @@ class AverageStatReport {
89 103
 
90 104
     /**
91 105
      * Appends the report to the analytics "data" object. The object will be
92
-     * added under {@link this.name} key or "p2p_" + {@link this.name} if
93
-     * <tt>isP2P</tt> is <tt>true</tt>.
106
+     * set under <tt>prefix</tt> + {@link this.name} key.
94 107
      * @param {Object} report the analytics "data" object
95
-     * @param {boolean} isP2P <tt>true</tt> if the stats is being report for
96
-     * P2P connection or <tt>false</tt> for the JVB connection.
108
+     * @param {string} prefix the prefix string that will be added at
109
+     * the beginning of the key name.
97 110
      */
98
-    appendReport(report, isP2P) {
99
-        report[`${isP2P ? 'p2p_' : ''}${this.name}`] = {
111
+    appendReport(report, prefix) {
112
+        const keyName = `${prefix}${this.name}`;
113
+
114
+        report[keyName] = {
100 115
             value: this.calculate(),
101 116
             samples: this.samples
102 117
         };
@@ -216,8 +231,10 @@ class ConnectionAvgStats {
216 231
         if (this._sampleIdx >= this._n) {
217 232
             if (RTCBrowserType.supportsRTTStatistics()) {
218 233
                 const batchReport = { };
234
+                const confSize = this._conference.getParticipantCount();
235
+                const prefix = getPrefix(this.isP2P, confSize);
219 236
 
220
-                this._avgRTT.appendReport(batchReport, this.isP2P);
237
+                this._avgRTT.appendReport(batchReport, prefix);
221 238
 
222 239
                 // Report end to end RTT only for JVB
223 240
                 if (!this.isP2P) {
@@ -226,7 +243,7 @@ class ConnectionAvgStats {
226 243
 
227 244
                     if (!isNaN(avgLocalRTT) && !isNaN(avgRemoteRTT)) {
228 245
                         // eslint-disable-next-line camelcase
229
-                        batchReport.stat_avg_end2endrtt
246
+                        batchReport[`${prefix}stat_avg_end2endrtt`]
230 247
                             = { value: avgLocalRTT + avgRemoteRTT };
231 248
                     }
232 249
                 }
@@ -506,9 +523,10 @@ export default class AvgRTPStatsReporter {
506 523
     _calculateAvgStats(data) {
507 524
 
508 525
         const isP2P = this._conference.isP2PActive();
509
-        const peerCount = this._conference.getParticipants().length;
526
+        const confSize = this._conference.getParticipantCount();
527
+        const prefix = getPrefix(isP2P, confSize);
510 528
 
511
-        if (!isP2P && peerCount < 1) {
529
+        if (!isP2P && confSize < 2) {
512 530
 
513 531
             // There's no point in collecting stats for a JVB conference of 1.
514 532
             // That happens for short period of time after everyone leaves
@@ -590,30 +608,30 @@ export default class AvgRTPStatsReporter {
590 608
         if (this._sampleIdx >= this._n) {
591 609
             const batchReport = { };
592 610
 
593
-            this._avgAudioBitrateUp.appendReport(batchReport, isP2P);
594
-            this._avgAudioBitrateDown.appendReport(batchReport, isP2P);
611
+            this._avgAudioBitrateUp.appendReport(batchReport, prefix);
612
+            this._avgAudioBitrateDown.appendReport(batchReport, prefix);
595 613
 
596
-            this._avgVideoBitrateUp.appendReport(batchReport, isP2P);
597
-            this._avgVideoBitrateDown.appendReport(batchReport, isP2P);
614
+            this._avgVideoBitrateUp.appendReport(batchReport, prefix);
615
+            this._avgVideoBitrateDown.appendReport(batchReport, prefix);
598 616
 
599 617
             if (RTCBrowserType.supportsBandwidthStatistics()) {
600
-                this._avgBandwidthUp.appendReport(batchReport, isP2P);
601
-                this._avgBandwidthDown.appendReport(batchReport, isP2P);
618
+                this._avgBandwidthUp.appendReport(batchReport, prefix);
619
+                this._avgBandwidthDown.appendReport(batchReport, prefix);
602 620
             }
603
-            this._avgPacketLossUp.appendReport(batchReport, isP2P);
604
-            this._avgPacketLossDown.appendReport(batchReport, isP2P);
605
-            this._avgPacketLossTotal.appendReport(batchReport, isP2P);
621
+            this._avgPacketLossUp.appendReport(batchReport, prefix);
622
+            this._avgPacketLossDown.appendReport(batchReport, prefix);
623
+            this._avgPacketLossTotal.appendReport(batchReport, prefix);
606 624
 
607
-            this._avgRemoteFPS.appendReport(batchReport, isP2P);
625
+            this._avgRemoteFPS.appendReport(batchReport, prefix);
608 626
             if (!isNaN(this._avgRemoteScreenFPS.calculate())) {
609
-                this._avgRemoteScreenFPS.appendReport(batchReport, isP2P);
627
+                this._avgRemoteScreenFPS.appendReport(batchReport, prefix);
610 628
             }
611
-            this._avgLocalFPS.appendReport(batchReport, isP2P);
629
+            this._avgLocalFPS.appendReport(batchReport, prefix);
612 630
             if (!isNaN(this._avgLocalScreenFPS.calculate())) {
613
-                this._avgLocalScreenFPS.appendReport(batchReport, isP2P);
631
+                this._avgLocalScreenFPS.appendReport(batchReport, prefix);
614 632
             }
615 633
 
616
-            this._avgCQ.appendReport(batchReport, isP2P);
634
+            this._avgCQ.appendReport(batchReport, prefix);
617 635
 
618 636
             Statistics.analytics.sendEvent(AVG_RTP_STATS_EVENT, batchReport);
619 637
 

Loading…
Cancel
Save