浏览代码

Fixes the wrong values (NaN) in the connection tooltips.

master
hristoterezov 11 年前
父节点
当前提交
f3ac51ae66
共有 2 个文件被更改,包括 68 次插入35 次删除
  1. 1
    1
      index.html
  2. 67
    34
      rtp_sts.js

+ 1
- 1
index.html 查看文件

45
     <script src="replacement.js?v=7"></script><!-- link and smiley replacement -->
45
     <script src="replacement.js?v=7"></script><!-- link and smiley replacement -->
46
     <script src="moderatemuc.js?v=4"></script><!-- moderator plugin -->
46
     <script src="moderatemuc.js?v=4"></script><!-- moderator plugin -->
47
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
47
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
48
-    <script src="rtp_sts.js?v=4"></script><!-- RTP stats processing -->
48
+    <script src="rtp_sts.js?v=5"></script><!-- RTP stats processing -->
49
     <script src="local_sts.js?v=2"></script><!-- Local stats processing -->
49
     <script src="local_sts.js?v=2"></script><!-- Local stats processing -->
50
     <script src="videolayout.js?v=23"></script><!-- video ui -->
50
     <script src="videolayout.js?v=23"></script><!-- video ui -->
51
     <script src="connectionquality.js?v=1"></script>
51
     <script src="connectionquality.js?v=1"></script>

+ 67
- 34
rtp_sts.js 查看文件

1
 /* global ssrc2jid */
1
 /* global ssrc2jid */
2
 /**
2
 /**
3
- * Calculates packet lost percent using the number of lost packets and the number of all packet.
3
+ * Calculates packet lost percent using the number of lost packets and the
4
+ * number of all packet.
4
  * @param lostPackets the number of lost packets
5
  * @param lostPackets the number of lost packets
5
  * @param totalPackets the number of all packets.
6
  * @param totalPackets the number of all packets.
6
  * @returns {number} packet loss percent
7
  * @returns {number} packet loss percent
7
  */
8
  */
8
 function calculatePacketLoss(lostPackets, totalPackets) {
9
 function calculatePacketLoss(lostPackets, totalPackets) {
10
+    if(!totalPackets || totalPackets <= 0 || !lostPackets || lostPackets <= 0)
11
+        return 0;
9
     return Math.round((lostPackets/totalPackets)*100);
12
     return Math.round((lostPackets/totalPackets)*100);
10
 }
13
 }
11
 
14
 
60
  */
63
  */
61
 PeerStats.prototype.setSsrcResolution = function (ssrc, resolution)
64
 PeerStats.prototype.setSsrcResolution = function (ssrc, resolution)
62
 {
65
 {
63
-    if(resolution == null && this.ssrc2resolution[ssrc])
66
+    if(resolution === null && this.ssrc2resolution[ssrc])
64
     {
67
     {
65
         delete this.ssrc2resolution[ssrc];
68
         delete this.ssrc2resolution[ssrc];
66
     }
69
     }
67
-    else if(resolution != null)
70
+    else if(resolution !== null)
68
         this.ssrc2resolution[ssrc] = resolution;
71
         this.ssrc2resolution[ssrc] = resolution;
69
 };
72
 };
70
 
73
 
103
  * <tt>StatsCollector</tt> registers for stats updates of given
106
  * <tt>StatsCollector</tt> registers for stats updates of given
104
  * <tt>peerconnection</tt> in given <tt>interval</tt>. On each update particular
107
  * <tt>peerconnection</tt> in given <tt>interval</tt>. On each update particular
105
  * stats are extracted and put in {@link PeerStats} objects. Once the processing
108
  * stats are extracted and put in {@link PeerStats} objects. Once the processing
106
- * is done <tt>audioLevelsUpdateCallback</tt> is called with <tt>this</tt> instance as
107
- * an event source.
109
+ * is done <tt>audioLevelsUpdateCallback</tt> is called with <tt>this</tt>
110
+ * instance as an event source.
108
  *
111
  *
109
  * @param peerconnection webRTC peer connection object.
112
  * @param peerconnection webRTC peer connection object.
110
  * @param interval stats refresh interval given in ms.
113
  * @param interval stats refresh interval given in ms.
111
- * @param {function(StatsCollector)} audioLevelsUpdateCallback the callback called on stats
112
- *                                   update.
114
+ * @param {function(StatsCollector)} audioLevelsUpdateCallback the callback
115
+ * called on stats update.
113
  * @constructor
116
  * @constructor
114
  */
117
  */
115
-function StatsCollector(peerconnection, audioLevelsInterval, audioLevelsUpdateCallback, statsInterval, statsUpdateCallback)
118
+function StatsCollector(peerconnection, audioLevelsInterval,
119
+                        audioLevelsUpdateCallback, statsInterval,
120
+                        statsUpdateCallback)
116
 {
121
 {
117
     this.peerconnection = peerconnection;
122
     this.peerconnection = peerconnection;
118
     this.baselineAudioLevelsReport = null;
123
     this.baselineAudioLevelsReport = null;
173
                     //console.error("Got interval report", results);
178
                     //console.error("Got interval report", results);
174
                     self.currentAudioLevelsReport = results;
179
                     self.currentAudioLevelsReport = results;
175
                     self.processAudioLevelReport();
180
                     self.processAudioLevelReport();
176
-                    self.baselineAudioLevelsReport = self.currentAudioLevelsReport;
181
+                    self.baselineAudioLevelsReport =
182
+                        self.currentAudioLevelsReport;
177
                 },
183
                 },
178
                 self.errorCallback
184
                 self.errorCallback
179
             );
185
             );
211
 
217
 
212
     for (var idx in this.currentStatsReport) {
218
     for (var idx in this.currentStatsReport) {
213
         var now = this.currentStatsReport[idx];
219
         var now = this.currentStatsReport[idx];
214
-        if (now.stat('googAvailableReceiveBandwidth') || now.stat('googAvailableSendBandwidth')) {
220
+        if (now.stat('googAvailableReceiveBandwidth') ||
221
+            now.stat('googAvailableSendBandwidth'))
222
+        {
215
             PeerStats.bandwidth = {
223
             PeerStats.bandwidth = {
216
-                "download": Math.round((now.stat('googAvailableReceiveBandwidth')) / 1000),
217
-                "upload": Math.round((now.stat('googAvailableSendBandwidth')) / 1000)
224
+                "download": Math.round(
225
+                        (now.stat('googAvailableReceiveBandwidth')) / 1000),
226
+                "upload": Math.round(
227
+                        (now.stat('googAvailableSendBandwidth')) / 1000)
218
             };
228
             };
219
         }
229
         }
220
 
230
 
229
             var addressSaved = false;
239
             var addressSaved = false;
230
             for(var i = 0; i < PeerStats.transport.length; i++)
240
             for(var i = 0; i < PeerStats.transport.length; i++)
231
             {
241
             {
232
-                if(PeerStats.transport[i].ip == ip && PeerStats.transport[i].type == type &&
242
+                if(PeerStats.transport[i].ip == ip &&
243
+                    PeerStats.transport[i].type == type &&
233
                     PeerStats.transport[i].localip == localIP)
244
                     PeerStats.transport[i].localip == localIP)
234
                 {
245
                 {
235
                     addressSaved = true;
246
                     addressSaved = true;
241
             continue;
252
             continue;
242
         }
253
         }
243
 
254
 
244
-//            console.log("bandwidth: " + now.stat('googAvailableReceiveBandwidth') + " - " + now.stat('googAvailableSendBandwidth'));
245
         if (now.type != 'ssrc') {
255
         if (now.type != 'ssrc') {
246
             continue;
256
             continue;
247
         }
257
         }
287
         if(!packetsBefore || packetsBefore < 0)
297
         if(!packetsBefore || packetsBefore < 0)
288
             packetsBefore = 0;
298
             packetsBefore = 0;
289
         var packetRate = packetsNow - packetsBefore;
299
         var packetRate = packetsNow - packetsBefore;
290
-
300
+        if(!packetRate || packetRate < 0)
301
+            packetRate = 0;
291
         var currentLoss = now.stat('packetsLost');
302
         var currentLoss = now.stat('packetsLost');
292
         if(!currentLoss || currentLoss < 0)
303
         if(!currentLoss || currentLoss < 0)
293
             currentLoss = 0;
304
             currentLoss = 0;
295
         if(!previousLoss || previousLoss < 0)
306
         if(!previousLoss || previousLoss < 0)
296
             previousLoss = 0;
307
             previousLoss = 0;
297
         var lossRate = currentLoss - previousLoss;
308
         var lossRate = currentLoss - previousLoss;
298
-        if(lossRate < 0)
309
+        if(!lossRate || lossRate < 0)
299
             lossRate = 0;
310
             lossRate = 0;
300
         var packetsTotal = (packetRate + lossRate);
311
         var packetsTotal = (packetRate + lossRate);
301
 
312
 
302
-        jidStats.setSsrcLoss(ssrc, {"packetsTotal": packetsTotal, "packetsLost": lossRate,
303
-            "isDownloadStream": isDownloadStream});
313
+        jidStats.setSsrcLoss(ssrc,
314
+            {"packetsTotal": packetsTotal,
315
+                "packetsLost": lossRate,
316
+                "isDownloadStream": isDownloadStream});
304
 
317
 
305
         var bytesReceived = 0, bytesSent = 0;
318
         var bytesReceived = 0, bytesSent = 0;
306
         if(now.stat("bytesReceived"))
319
         if(now.stat("bytesReceived"))
307
         {
320
         {
308
-            bytesReceived = now.stat("bytesReceived") - before.stat("bytesReceived");
321
+            bytesReceived = now.stat("bytesReceived") -
322
+                before.stat("bytesReceived");
309
         }
323
         }
310
 
324
 
311
         if(now.stat("bytesSent"))
325
         if(now.stat("bytesSent"))
313
             bytesSent = now.stat("bytesSent") - before.stat("bytesSent");
327
             bytesSent = now.stat("bytesSent") - before.stat("bytesSent");
314
         }
328
         }
315
 
329
 
316
-        if(bytesReceived < 0)
330
+        var time = Math.round((now.timestamp - before.timestamp) / 1000);
331
+        if(bytesReceived <= 0 || time <= 0)
332
+        {
317
             bytesReceived = 0;
333
             bytesReceived = 0;
318
-        if(bytesSent < 0)
334
+        }
335
+        else
336
+        {
337
+            bytesReceived = Math.round(((bytesReceived * 8) / time) / 1000);
338
+        }
339
+
340
+        if(bytesSent <= 0 || time <= 0)
341
+        {
319
             bytesSent = 0;
342
             bytesSent = 0;
343
+        }
344
+        else
345
+        {
346
+            bytesSent = Math.round(((bytesSent * 8) / time) / 1000);
347
+        }
320
 
348
 
321
-        var time = Math.round((now.timestamp - before.timestamp) / 1000);
322
         jidStats.setSsrcBitrate(ssrc, {
349
         jidStats.setSsrcBitrate(ssrc, {
323
-            "download": Math.round(((bytesReceived * 8) / time) / 1000),
324
-            "upload": Math.round(((bytesSent * 8) / time) / 1000)});
350
+            "download": bytesReceived,
351
+            "upload": bytesSent});
325
         var resolution = {height: null, width: null};
352
         var resolution = {height: null, width: null};
326
-        if(now.stat("googFrameHeightReceived") && now.stat("googFrameWidthReceived"))
353
+        if(now.stat("googFrameHeightReceived") &&
354
+            now.stat("googFrameWidthReceived"))
327
         {
355
         {
328
             resolution.height = now.stat("googFrameHeightReceived");
356
             resolution.height = now.stat("googFrameHeightReceived");
329
             resolution.width = now.stat("googFrameWidthReceived");
357
             resolution.width = now.stat("googFrameWidthReceived");
330
         }
358
         }
331
-        else if(now.stat("googFrameHeightSent") && now.stat("googFrameWidthSent"))
359
+        else if(now.stat("googFrameHeightSent") &&
360
+            now.stat("googFrameWidthSent"))
332
         {
361
         {
333
             resolution.height = now.stat("googFrameHeightSent");
362
             resolution.height = now.stat("googFrameHeightSent");
334
             resolution.width = now.stat("googFrameWidthSent");
363
             resolution.width = now.stat("googFrameWidthSent");
352
     var lostPackets = {download: 0, upload: 0};
381
     var lostPackets = {download: 0, upload: 0};
353
     var bitrateDownload = 0;
382
     var bitrateDownload = 0;
354
     var bitrateUpload = 0;
383
     var bitrateUpload = 0;
355
-    var resolution = {};
384
+    var resolutions = {};
356
     Object.keys(this.jid2stats).forEach(
385
     Object.keys(this.jid2stats).forEach(
357
         function (jid)
386
         function (jid)
358
         {
387
         {
362
                     var type = "upload";
391
                     var type = "upload";
363
                     if(self.jid2stats[jid].ssrc2Loss[ssrc].isDownloadStream)
392
                     if(self.jid2stats[jid].ssrc2Loss[ssrc].isDownloadStream)
364
                         type = "download";
393
                         type = "download";
365
-                    totalPackets[type] += self.jid2stats[jid].ssrc2Loss[ssrc].packetsTotal;
366
-                    lostPackets[type] += self.jid2stats[jid].ssrc2Loss[ssrc].packetsLost;
394
+                    totalPackets[type] +=
395
+                        self.jid2stats[jid].ssrc2Loss[ssrc].packetsTotal;
396
+                    lostPackets[type] +=
397
+                        self.jid2stats[jid].ssrc2Loss[ssrc].packetsLost;
367
                 }
398
                 }
368
             );
399
             );
369
             Object.keys(self.jid2stats[jid].ssrc2bitrate).forEach(
400
             Object.keys(self.jid2stats[jid].ssrc2bitrate).forEach(
370
                 function (ssrc) {
401
                 function (ssrc) {
371
-                    bitrateDownload += self.jid2stats[jid].ssrc2bitrate[ssrc].download;
372
-                    bitrateUpload += self.jid2stats[jid].ssrc2bitrate[ssrc].upload;
402
+                    bitrateDownload +=
403
+                        self.jid2stats[jid].ssrc2bitrate[ssrc].download;
404
+                    bitrateUpload +=
405
+                        self.jid2stats[jid].ssrc2bitrate[ssrc].upload;
373
                 }
406
                 }
374
             );
407
             );
375
-            resolution[jid] = self.jid2stats[jid].ssrc2resolution;
408
+            resolutions[jid] = self.jid2stats[jid].ssrc2resolution;
376
         }
409
         }
377
     );
410
     );
378
 
411
 
392
             "bitrate": PeerStats.bitrate,
425
             "bitrate": PeerStats.bitrate,
393
             "packetLoss": PeerStats.packetLoss,
426
             "packetLoss": PeerStats.packetLoss,
394
             "bandwidth": PeerStats.bandwidth,
427
             "bandwidth": PeerStats.bandwidth,
395
-            "resolution": resolution,
428
+            "resolution": resolutions,
396
             "transport": PeerStats.transport
429
             "transport": PeerStats.transport
397
         });
430
         });
398
     PeerStats.transport = [];
431
     PeerStats.transport = [];
399
 
432
 
400
-}
433
+};
401
 
434
 
402
 /**
435
 /**
403
  * Stats processing logic.
436
  * Stats processing logic.

正在加载...
取消
保存