Browse Source

Reformat the source code for consistency

tags/v0.0.2
Lyubomir Marinov 9 years ago
parent
commit
27a7d7da72
2 changed files with 30 additions and 43 deletions
  1. 16
    24
      modules/statistics/RTPStatsCollector.js
  2. 14
    19
      modules/statistics/statistics.js

+ 16
- 24
modules/statistics/RTPStatsCollector.js View File

106
  * Peer statistics data holder.
106
  * Peer statistics data holder.
107
  * @constructor
107
  * @constructor
108
  */
108
  */
109
-function PeerStats()
110
-{
109
+function PeerStats() {
111
     this.ssrc2Loss = {};
110
     this.ssrc2Loss = {};
112
     this.ssrc2AudioLevel = {};
111
     this.ssrc2AudioLevel = {};
113
     this.ssrc2bitrate = {
112
     this.ssrc2bitrate = {
167
 
166
 
168
 function ConferenceStats() {
167
 function ConferenceStats() {
169
 
168
 
170
-
171
     /**
169
     /**
172
      * The bandwidth
170
      * The bandwidth
173
      * @type {{}}
171
      * @type {{}}
186
      */
184
      */
187
     this.packetLoss = null;
185
     this.packetLoss = null;
188
 
186
 
189
-
190
     /**
187
     /**
191
      * Array with the transport information.
188
      * Array with the transport information.
192
      * @type {Array}
189
      * @type {Array}
233
     /**
230
     /**
234
      * Stores the statistics which will be send to the focus to be logged.
231
      * Stores the statistics which will be send to the focus to be logged.
235
      */
232
      */
236
-    this.statsToBeLogged =
237
-    {
233
+    this.statsToBeLogged = {
238
         timestamps: [],
234
         timestamps: [],
239
         stats: {}
235
         stats: {}
240
     };
236
     };
259
         this.audioLevelsIntervalId = null;
255
         this.audioLevelsIntervalId = null;
260
     }
256
     }
261
 
257
 
262
-    if (this.statsIntervalId)
263
-    {
258
+    if (this.statsIntervalId) {
264
         clearInterval(this.statsIntervalId);
259
         clearInterval(this.statsIntervalId);
265
         this.statsIntervalId = null;
260
         this.statsIntervalId = null;
266
     }
261
     }
267
 
262
 
268
-    if(this.gatherStatsIntervalId)
269
-    {
263
+    if (this.gatherStatsIntervalId) {
270
         clearInterval(this.gatherStatsIntervalId);
264
         clearInterval(this.gatherStatsIntervalId);
271
         this.gatherStatsIntervalId = null;
265
         this.gatherStatsIntervalId = null;
272
     }
266
     }
276
  * Callback passed to <tt>getStats</tt> method.
270
  * Callback passed to <tt>getStats</tt> method.
277
  * @param error an error that occurred on <tt>getStats</tt> call.
271
  * @param error an error that occurred on <tt>getStats</tt> call.
278
  */
272
  */
279
-StatsCollector.prototype.errorCallback = function (error)
280
-{
273
+StatsCollector.prototype.errorCallback = function (error) {
281
     logger.error("Get stats error", error);
274
     logger.error("Get stats error", error);
282
     this.stop();
275
     this.stop();
283
 };
276
 };
285
 /**
278
 /**
286
  * Starts stats updates.
279
  * Starts stats updates.
287
  */
280
  */
288
-StatsCollector.prototype.start = function ()
289
-{
281
+StatsCollector.prototype.start = function () {
290
     var self = this;
282
     var self = this;
291
     this.audioLevelsIntervalId = setInterval(
283
     this.audioLevelsIntervalId = setInterval(
292
         function () {
284
         function () {
458
             continue;
450
             continue;
459
         }
451
         }
460
 
452
 
461
-        if(now.type == "candidatepair")
462
-        {
453
+        if(now.type == "candidatepair") {
463
             if(now.state == "succeeded")
454
             if(now.state == "succeeded")
464
                 continue;
455
                 continue;
465
 
456
 
466
             var local = this.currentStatsReport[now.localCandidateId];
457
             var local = this.currentStatsReport[now.localCandidateId];
467
             var remote = this.currentStatsReport[now.remoteCandidateId];
458
             var remote = this.currentStatsReport[now.remoteCandidateId];
468
-            this.conferenceStats.transport.push({localip: local.ipAddress + ":" + local.portNumber,
469
-                ip: remote.ipAddress + ":" + remote.portNumber, type: local.transport});
470
-
459
+            this.conferenceStats.transport.push({
460
+                localip: local.ipAddress + ":" + local.portNumber,
461
+                ip: remote.ipAddress + ":" + remote.portNumber,
462
+                type: local.transport
463
+            });
471
         }
464
         }
472
 
465
 
473
         if (now.type != 'ssrc' && now.type != "outboundrtp" &&
466
         if (now.type != 'ssrc' && now.type != "outboundrtp" &&
619
         this
612
         this
620
     );
613
     );
621
 
614
 
622
-    this.conferenceStats.bitrate = {"upload": bitrateUpload, "download": bitrateDownload};
615
+    this.conferenceStats.bitrate
616
+      = {"upload": bitrateUpload, "download": bitrateDownload};
623
 
617
 
624
     this.conferenceStats.packetLoss = {
618
     this.conferenceStats.packetLoss = {
625
         total:
619
         total:
630
         upload:
624
         upload:
631
             calculatePacketLoss(lostPackets.upload, totalPackets.upload)
625
             calculatePacketLoss(lostPackets.upload, totalPackets.upload)
632
     };
626
     };
633
-    this.eventEmitter.emit(StatisticsEvents.CONNECTION_STATS,
634
-        {
627
+    this.eventEmitter.emit(StatisticsEvents.CONNECTION_STATS, {
635
             "bitrate": this.conferenceStats.bitrate,
628
             "bitrate": this.conferenceStats.bitrate,
636
             "packetLoss": this.conferenceStats.packetLoss,
629
             "packetLoss": this.conferenceStats.packetLoss,
637
             "bandwidth": this.conferenceStats.bandwidth,
630
             "bandwidth": this.conferenceStats.bandwidth,
639
             "transport": this.conferenceStats.transport
632
             "transport": this.conferenceStats.transport
640
         });
633
         });
641
     this.conferenceStats.transport = [];
634
     this.conferenceStats.transport = [];
642
-
643
 };
635
 };
644
 
636
 
645
 /**
637
 /**
666
 
658
 
667
         var ssrc = getStatValue(now, 'ssrc');
659
         var ssrc = getStatValue(now, 'ssrc');
668
         if (!ssrc) {
660
         if (!ssrc) {
669
-            if((Date.now() - now.timestamp) < 3000)
661
+            if ((Date.now() - now.timestamp) < 3000)
670
                 logger.warn("No ssrc: ");
662
                 logger.warn("No ssrc: ");
671
             continue;
663
             continue;
672
         }
664
         }

+ 14
- 19
modules/statistics/statistics.js View File

6
 var CallStats = require("./CallStats");
6
 var CallStats = require("./CallStats");
7
 var ScriptUtil = require('../util/ScriptUtil');
7
 var ScriptUtil = require('../util/ScriptUtil');
8
 
8
 
9
-// Since callstats.io is a third party, we cannot guarantee the quality of
10
-// their service. More specifically, their server may take noticeably long
11
-// time to respond. Consequently, it is in our best interest (in the sense
12
-// that the intergration of callstats.io is pretty important to us but not
13
-// enough to allow it to prevent people from joining a conference) to (1)
14
-// start downloading their API as soon as possible and (2) do the
15
-// downloading asynchronously.
9
+// Since callstats.io is a third party, we cannot guarantee the quality of their
10
+// service. More specifically, their server may take noticeably long time to
11
+// respond. Consequently, it is in our best interest (in the sense that the
12
+// intergration of callstats.io is pretty important to us but not enough to
13
+// allow it to prevent people from joining a conference) to (1) start
14
+// downloading their API as soon as possible and (2) do the downloading
15
+// asynchronously.
16
 function loadCallStatsAPI() {
16
 function loadCallStatsAPI() {
17
     ScriptUtil.loadScript(
17
     ScriptUtil.loadScript(
18
             'https://api.callstats.io/static/callstats.min.js',
18
             'https://api.callstats.io/static/callstats.min.js',
22
     // have loaded by the time we needed it (i.e. CallStats.init is invoked).
22
     // have loaded by the time we needed it (i.e. CallStats.init is invoked).
23
 }
23
 }
24
 
24
 
25
-
26
 /**
25
 /**
27
  * Log stats via the focus once every this many milliseconds.
26
  * Log stats via the focus once every this many milliseconds.
28
  */
27
  */
37
     this.options = options || {};
36
     this.options = options || {};
38
     this.callStatsIntegrationEnabled
37
     this.callStatsIntegrationEnabled
39
         = this.options.callStatsID && this.options.callStatsSecret
38
         = this.options.callStatsID && this.options.callStatsSecret
40
-        // Even though AppID and AppSecret may be specified, the integration of
41
-        // callstats.io may be disabled because of globally-disallowed requests
42
-        // to any third parties.
43
-        && (this.options.disableThirdPartyRequests !== true);
39
+            // Even though AppID and AppSecret may be specified, the integration
40
+            // of callstats.io may be disabled because of globally-disallowed
41
+            // requests to any third parties.
42
+            && (this.options.disableThirdPartyRequests !== true);
44
     if(this.callStatsIntegrationEnabled)
43
     if(this.callStatsIntegrationEnabled)
45
         loadCallStatsAPI();
44
         loadCallStatsAPI();
46
     this.callStats = null;
45
     this.callStats = null;
47
 
46
 
48
     /**
47
     /**
49
-     * Send the stats already saved in rtpStats to be logged via
50
-     * the focus.
48
+     * Send the stats already saved in rtpStats to be logged via the focus.
51
      */
49
      */
52
     this.logStatsIntervalId = null;
50
     this.logStatsIntervalId = null;
53
 }
51
 }
80
     localStats.start();
78
     localStats.start();
81
 };
79
 };
82
 
80
 
83
-Statistics.prototype.addAudioLevelListener = function(listener)
84
-{
81
+Statistics.prototype.addAudioLevelListener = function(listener) {
85
     if(!Statistics.audioLevelsEnabled)
82
     if(!Statistics.audioLevelsEnabled)
86
         return;
83
         return;
87
     this.eventEmitter.on(StatisticsEvents.AUDIO_LEVEL, listener);
84
     this.eventEmitter.on(StatisticsEvents.AUDIO_LEVEL, listener);
88
 };
85
 };
89
 
86
 
90
-Statistics.prototype.removeAudioLevelListener = function(listener)
91
-{
87
+Statistics.prototype.removeAudioLevelListener = function(listener) {
92
     if(!Statistics.audioLevelsEnabled)
88
     if(!Statistics.audioLevelsEnabled)
93
         return;
89
         return;
94
     this.eventEmitter.removeListener(StatisticsEvents.AUDIO_LEVEL, listener);
90
     this.eventEmitter.removeListener(StatisticsEvents.AUDIO_LEVEL, listener);
114
     }
110
     }
115
 };
111
 };
116
 
112
 
117
-
118
 Statistics.stopAllLocalStats = function () {
113
 Statistics.stopAllLocalStats = function () {
119
     if(!Statistics.audioLevelsEnabled)
114
     if(!Statistics.audioLevelsEnabled)
120
         return;
115
         return;

Loading…
Cancel
Save