|
@@ -5,6 +5,39 @@ var RTCBrowserType = require("../RTC/RTCBrowserType");
|
5
|
5
|
/* Whether we support the browser we are running into for logging statistics */
|
6
|
6
|
var browserSupported = RTCBrowserType.isChrome() ||
|
7
|
7
|
RTCBrowserType.isOpera();
|
|
8
|
+
|
|
9
|
+var keyMap = {};
|
|
10
|
+keyMap[RTCBrowserType.RTC_BROWSER_FIREFOX] = {
|
|
11
|
+ "ssrc": "ssrc",
|
|
12
|
+ "packetsReceived": "packetsReceived",
|
|
13
|
+ "packetsLost": "packetsLost",
|
|
14
|
+ "packetsSent": "packetsSent",
|
|
15
|
+ "bytesReceived": "bytesReceived",
|
|
16
|
+ "bytesSent": "bytesSent"
|
|
17
|
+};
|
|
18
|
+keyMap[RTCBrowserType.RTC_BROWSER_CHROME] = {
|
|
19
|
+ "receiveBandwidth": "googAvailableReceiveBandwidth",
|
|
20
|
+ "sendBandwidth": "googAvailableSendBandwidth",
|
|
21
|
+ "remoteAddress": "googRemoteAddress",
|
|
22
|
+ "transportType": "googTransportType",
|
|
23
|
+ "localAddress": "googLocalAddress",
|
|
24
|
+ "activeConnection": "googActiveConnection",
|
|
25
|
+ "ssrc": "ssrc",
|
|
26
|
+ "packetsReceived": "packetsReceived",
|
|
27
|
+ "packetsSent": "packetsSent",
|
|
28
|
+ "packetsLost": "packetsLost",
|
|
29
|
+ "bytesReceived": "bytesReceived",
|
|
30
|
+ "bytesSent": "bytesSent",
|
|
31
|
+ "googFrameHeightReceived": "googFrameHeightReceived",
|
|
32
|
+ "googFrameWidthReceived": "googFrameWidthReceived",
|
|
33
|
+ "googFrameHeightSent": "googFrameHeightSent",
|
|
34
|
+ "googFrameWidthSent": "googFrameWidthSent",
|
|
35
|
+ "audioInputLevel": "audioInputLevel",
|
|
36
|
+ "audioOutputLevel": "audioOutputLevel"
|
|
37
|
+};
|
|
38
|
+keyMap[RTCBrowserType.RTC_BROWSER_OPERA] =
|
|
39
|
+ keyMap[RTCBrowserType.RTC_BROWSER_CHROME];
|
|
40
|
+
|
8
|
41
|
/**
|
9
|
42
|
* Calculates packet lost percent using the number of lost packets and the
|
10
|
43
|
* number of all packet.
|
|
@@ -27,6 +60,42 @@ function getStatValue(item, name) {
|
27
|
60
|
item.stat(key) : item[key];
|
28
|
61
|
}
|
29
|
62
|
|
|
63
|
+function formatAudioLevel(audioLevel) {
|
|
64
|
+ return Math.min(Math.max(audioLevel, 0), 1);
|
|
65
|
+}
|
|
66
|
+
|
|
67
|
+/**
|
|
68
|
+ * Checks whether a certain record should be included in the logged statistics.
|
|
69
|
+ */
|
|
70
|
+function acceptStat(reportId, reportType, statName) {
|
|
71
|
+ if (reportType == "googCandidatePair" && statName == "googChannelId")
|
|
72
|
+ return false;
|
|
73
|
+
|
|
74
|
+ if (reportType == "ssrc") {
|
|
75
|
+ if (statName == "googTrackId" ||
|
|
76
|
+ statName == "transportId" ||
|
|
77
|
+ statName == "ssrc")
|
|
78
|
+ return false;
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ return true;
|
|
82
|
+}
|
|
83
|
+
|
|
84
|
+/**
|
|
85
|
+ * Checks whether a certain record should be included in the logged statistics.
|
|
86
|
+ */
|
|
87
|
+function acceptReport(id, type) {
|
|
88
|
+ if (id.substring(0, 15) == "googCertificate" ||
|
|
89
|
+ id.substring(0, 9) == "googTrack" ||
|
|
90
|
+ id.substring(0, 20) == "googLibjingleSession")
|
|
91
|
+ return false;
|
|
92
|
+
|
|
93
|
+ if (type == "googComponent")
|
|
94
|
+ return false;
|
|
95
|
+
|
|
96
|
+ return true;
|
|
97
|
+}
|
|
98
|
+
|
30
|
99
|
/**
|
31
|
100
|
* Peer statistics data holder.
|
32
|
101
|
* @constructor
|
|
@@ -39,42 +108,22 @@ function PeerStats()
|
39
|
108
|
this.ssrc2resolution = {};
|
40
|
109
|
}
|
41
|
110
|
|
42
|
|
-/**
|
43
|
|
- * The bandwidth
|
44
|
|
- * @type {{}}
|
45
|
|
- */
|
46
|
|
-PeerStats.bandwidth = {};
|
47
|
|
-
|
48
|
|
-/**
|
49
|
|
- * The bit rate
|
50
|
|
- * @type {{}}
|
51
|
|
- */
|
52
|
|
-PeerStats.bitrate = {};
|
53
|
|
-
|
54
|
|
-/**
|
55
|
|
- * The packet loss rate
|
56
|
|
- * @type {{}}
|
57
|
|
- */
|
58
|
|
-PeerStats.packetLoss = null;
|
59
|
|
-
|
60
|
111
|
/**
|
61
|
112
|
* Sets packets loss rate for given <tt>ssrc</tt> that blong to the peer
|
62
|
113
|
* represented by this instance.
|
63
|
|
- * @param ssrc audio or video RTP stream SSRC.
|
64
|
114
|
* @param lossRate new packet loss rate value to be set.
|
65
|
115
|
*/
|
66
|
|
-PeerStats.prototype.setSsrcLoss = function (ssrc, lossRate)
|
|
116
|
+PeerStats.prototype.setSsrcLoss = function (lossRate)
|
67
|
117
|
{
|
68
|
|
- this.ssrc2Loss[ssrc] = lossRate;
|
|
118
|
+ this.ssrc2Loss = lossRate;
|
69
|
119
|
};
|
70
|
120
|
|
71
|
121
|
/**
|
72
|
|
- * Sets resolution for given <tt>ssrc</tt> that belong to the peer
|
|
122
|
+ * Sets resolution that belong to the ssrc
|
73
|
123
|
* represented by this instance.
|
74
|
|
- * @param ssrc audio or video RTP stream SSRC.
|
75
|
124
|
* @param resolution new resolution value to be set.
|
76
|
125
|
*/
|
77
|
|
-PeerStats.prototype.setSsrcResolution = function (ssrc, resolution)
|
|
126
|
+PeerStats.prototype.setSsrcResolution = function (resolution)
|
78
|
127
|
{
|
79
|
128
|
if(resolution === null && this.ssrc2resolution[ssrc])
|
80
|
129
|
{
|
|
@@ -116,16 +165,34 @@ PeerStats.prototype.setSsrcAudioLevel = function (ssrc, audioLevel)
|
116
|
165
|
this.ssrc2AudioLevel[ssrc] = formatAudioLevel(audioLevel);
|
117
|
166
|
};
|
118
|
167
|
|
119
|
|
-function formatAudioLevel(audioLevel) {
|
120
|
|
- return Math.min(Math.max(audioLevel, 0), 1);
|
121
|
|
-}
|
|
168
|
+function ConferenceStats() {
|
122
|
169
|
|
123
|
|
-/**
|
124
|
|
- * Array with the transport information.
|
125
|
|
- * @type {Array}
|
126
|
|
- */
|
127
|
|
-PeerStats.transport = [];
|
128
|
170
|
|
|
171
|
+ /**
|
|
172
|
+ * The bandwidth
|
|
173
|
+ * @type {{}}
|
|
174
|
+ */
|
|
175
|
+ this.bandwidth = {};
|
|
176
|
+
|
|
177
|
+ /**
|
|
178
|
+ * The bit rate
|
|
179
|
+ * @type {{}}
|
|
180
|
+ */
|
|
181
|
+ this.bitrate = {};
|
|
182
|
+
|
|
183
|
+ /**
|
|
184
|
+ * The packet loss rate
|
|
185
|
+ * @type {{}}
|
|
186
|
+ */
|
|
187
|
+ this.packetLoss = null;
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+ /**
|
|
191
|
+ * Array with the transport information.
|
|
192
|
+ * @type {Array}
|
|
193
|
+ */
|
|
194
|
+ this.transport = [];
|
|
195
|
+}
|
129
|
196
|
|
130
|
197
|
/**
|
131
|
198
|
* <tt>StatsCollector</tt> registers for stats updates of given
|
|
@@ -138,9 +205,10 @@ PeerStats.transport = [];
|
138
|
205
|
* @param interval stats refresh interval given in ms.
|
139
|
206
|
* @param {function(StatsCollector)} audioLevelsUpdateCallback the callback
|
140
|
207
|
* called on stats update.
|
|
208
|
+ * @param config {object} supports the following properties - disableAudioLevels, disableStats, logStats
|
141
|
209
|
* @constructor
|
142
|
210
|
*/
|
143
|
|
-function StatsCollector(peerconnection, audioLevelsInterval, statsInterval, eventEmitter)
|
|
211
|
+function StatsCollector(peerconnection, audioLevelsInterval, statsInterval, eventEmitter, config)
|
144
|
212
|
{
|
145
|
213
|
this.peerconnection = peerconnection;
|
146
|
214
|
this.baselineAudioLevelsReport = null;
|
|
@@ -149,6 +217,8 @@ function StatsCollector(peerconnection, audioLevelsInterval, statsInterval, even
|
149
|
217
|
this.baselineStatsReport = null;
|
150
|
218
|
this.audioLevelsIntervalId = null;
|
151
|
219
|
this.eventEmitter = eventEmitter;
|
|
220
|
+ this.config = config || {};
|
|
221
|
+ this.conferenceStats = new ConferenceStats();
|
152
|
222
|
|
153
|
223
|
/**
|
154
|
224
|
* Gather PeerConnection stats once every this many milliseconds.
|
|
@@ -185,8 +255,8 @@ function StatsCollector(peerconnection, audioLevelsInterval, statsInterval, even
|
185
|
255
|
|
186
|
256
|
this.statsIntervalId = null;
|
187
|
257
|
this.statsIntervalMilis = statsInterval;
|
188
|
|
- // Map of jids to PeerStats
|
189
|
|
- this.jid2stats = {};
|
|
258
|
+ // Map of ssrcs to PeerStats
|
|
259
|
+ this.ssrc2stats = {};
|
190
|
260
|
}
|
191
|
261
|
|
192
|
262
|
module.exports = StatsCollector;
|
|
@@ -235,118 +305,84 @@ StatsCollector.prototype.errorCallback = function (error)
|
235
|
305
|
StatsCollector.prototype.start = function ()
|
236
|
306
|
{
|
237
|
307
|
var self = this;
|
238
|
|
- if (!config.disableAudioLevels) {
|
239
|
|
- this.audioLevelsIntervalId = setInterval(
|
240
|
|
- function () {
|
241
|
|
- // Interval updates
|
242
|
|
- self.peerconnection.getStats(
|
243
|
|
- function (report) {
|
244
|
|
- var results = null;
|
245
|
|
- if (!report || !report.result ||
|
246
|
|
- typeof report.result != 'function') {
|
247
|
|
- results = report;
|
248
|
|
- }
|
249
|
|
- else {
|
250
|
|
- results = report.result();
|
251
|
|
- }
|
252
|
|
- //console.error("Got interval report", results);
|
253
|
|
- self.currentAudioLevelsReport = results;
|
254
|
|
- self.processAudioLevelReport();
|
255
|
|
- self.baselineAudioLevelsReport =
|
256
|
|
- self.currentAudioLevelsReport;
|
257
|
|
- },
|
258
|
|
- self.errorCallback
|
259
|
|
- );
|
260
|
|
- },
|
261
|
|
- self.audioLevelsIntervalMilis
|
262
|
|
- );
|
263
|
|
- }
|
264
|
|
-
|
265
|
|
- if (!config.disableStats && browserSupported) {
|
266
|
|
- this.statsIntervalId = setInterval(
|
267
|
|
- function () {
|
268
|
|
- // Interval updates
|
269
|
|
- self.peerconnection.getStats(
|
270
|
|
- function (report) {
|
271
|
|
- var results = null;
|
272
|
|
- if (!report || !report.result ||
|
273
|
|
- typeof report.result != 'function') {
|
274
|
|
- //firefox
|
275
|
|
- results = report;
|
276
|
|
- }
|
277
|
|
- else {
|
278
|
|
- //chrome
|
279
|
|
- results = report.result();
|
280
|
|
- }
|
281
|
|
- //console.error("Got interval report", results);
|
282
|
|
- self.currentStatsReport = results;
|
283
|
|
- try {
|
284
|
|
- self.processStatsReport();
|
285
|
|
- }
|
286
|
|
- catch (e) {
|
287
|
|
- console.error("Unsupported key:" + e, e);
|
288
|
|
- }
|
289
|
|
-
|
290
|
|
- self.baselineStatsReport = self.currentStatsReport;
|
291
|
|
- },
|
292
|
|
- self.errorCallback
|
293
|
|
- );
|
294
|
|
- },
|
295
|
|
- self.statsIntervalMilis
|
296
|
|
- );
|
297
|
|
- }
|
298
|
|
-
|
299
|
|
- if (config.logStats && browserSupported) {
|
300
|
|
- this.gatherStatsIntervalId = setInterval(
|
301
|
|
- function () {
|
302
|
|
- self.peerconnection.getStats(
|
303
|
|
- function (report) {
|
304
|
|
- self.addStatsToBeLogged(report.result());
|
305
|
|
- },
|
306
|
|
- function () {
|
|
308
|
+ this.audioLevelsIntervalId = setInterval(
|
|
309
|
+ function () {
|
|
310
|
+ // Interval updates
|
|
311
|
+ self.peerconnection.getStats(
|
|
312
|
+ function (report) {
|
|
313
|
+ var results = null;
|
|
314
|
+ if (!report || !report.result ||
|
|
315
|
+ typeof report.result != 'function') {
|
|
316
|
+ results = report;
|
307
|
317
|
}
|
308
|
|
- );
|
309
|
|
- },
|
310
|
|
- this.GATHER_INTERVAL
|
311
|
|
- );
|
312
|
|
-
|
313
|
|
- this.logStatsIntervalId = setInterval(
|
314
|
|
- function() { self.logStats(); },
|
315
|
|
- this.LOG_INTERVAL);
|
316
|
|
- }
|
317
|
|
-};
|
318
|
|
-
|
319
|
|
-/**
|
320
|
|
- * Checks whether a certain record should be included in the logged statistics.
|
321
|
|
- */
|
322
|
|
-function acceptStat(reportId, reportType, statName) {
|
323
|
|
- if (reportType == "googCandidatePair" && statName == "googChannelId")
|
324
|
|
- return false;
|
325
|
|
-
|
326
|
|
- if (reportType == "ssrc") {
|
327
|
|
- if (statName == "googTrackId" ||
|
328
|
|
- statName == "transportId" ||
|
329
|
|
- statName == "ssrc")
|
330
|
|
- return false;
|
331
|
|
- }
|
332
|
|
-
|
333
|
|
- return true;
|
334
|
|
-}
|
335
|
|
-
|
336
|
|
-/**
|
337
|
|
- * Checks whether a certain record should be included in the logged statistics.
|
338
|
|
- */
|
339
|
|
-function acceptReport(id, type) {
|
340
|
|
- if (id.substring(0, 15) == "googCertificate" ||
|
341
|
|
- id.substring(0, 9) == "googTrack" ||
|
342
|
|
- id.substring(0, 20) == "googLibjingleSession")
|
343
|
|
- return false;
|
344
|
|
-
|
345
|
|
- if (type == "googComponent")
|
346
|
|
- return false;
|
|
318
|
+ else {
|
|
319
|
+ results = report.result();
|
|
320
|
+ }
|
|
321
|
+ //console.error("Got interval report", results);
|
|
322
|
+ self.currentAudioLevelsReport = results;
|
|
323
|
+ self.processAudioLevelReport();
|
|
324
|
+ self.baselineAudioLevelsReport =
|
|
325
|
+ self.currentAudioLevelsReport;
|
|
326
|
+ },
|
|
327
|
+ self.errorCallback
|
|
328
|
+ );
|
|
329
|
+ },
|
|
330
|
+ self.audioLevelsIntervalMilis
|
|
331
|
+ );
|
347
|
332
|
|
348
|
|
- return true;
|
349
|
|
-}
|
|
333
|
+// if (!this.config.disableStats && browserSupported) {
|
|
334
|
+// this.statsIntervalId = setInterval(
|
|
335
|
+// function () {
|
|
336
|
+// // Interval updates
|
|
337
|
+// self.peerconnection.getStats(
|
|
338
|
+// function (report) {
|
|
339
|
+// var results = null;
|
|
340
|
+// if (!report || !report.result ||
|
|
341
|
+// typeof report.result != 'function') {
|
|
342
|
+// //firefox
|
|
343
|
+// results = report;
|
|
344
|
+// }
|
|
345
|
+// else {
|
|
346
|
+// //chrome
|
|
347
|
+// results = report.result();
|
|
348
|
+// }
|
|
349
|
+// //console.error("Got interval report", results);
|
|
350
|
+// self.currentStatsReport = results;
|
|
351
|
+// try {
|
|
352
|
+// self.processStatsReport();
|
|
353
|
+// }
|
|
354
|
+// catch (e) {
|
|
355
|
+// console.error("Unsupported key:" + e, e);
|
|
356
|
+// }
|
|
357
|
+//
|
|
358
|
+// self.baselineStatsReport = self.currentStatsReport;
|
|
359
|
+// },
|
|
360
|
+// self.errorCallback
|
|
361
|
+// );
|
|
362
|
+// },
|
|
363
|
+// self.statsIntervalMilis
|
|
364
|
+// );
|
|
365
|
+// }
|
|
366
|
+//
|
|
367
|
+// if (this.config.logStats && browserSupported) {
|
|
368
|
+// this.gatherStatsIntervalId = setInterval(
|
|
369
|
+// function () {
|
|
370
|
+// self.peerconnection.getStats(
|
|
371
|
+// function (report) {
|
|
372
|
+// self.addStatsToBeLogged(report.result());
|
|
373
|
+// },
|
|
374
|
+// function () {
|
|
375
|
+// }
|
|
376
|
+// );
|
|
377
|
+// },
|
|
378
|
+// this.GATHER_INTERVAL
|
|
379
|
+// );
|
|
380
|
+//
|
|
381
|
+// this.logStatsIntervalId = setInterval(
|
|
382
|
+// function() { self.logStats(); },
|
|
383
|
+// this.LOG_INTERVAL);
|
|
384
|
+// }
|
|
385
|
+};
|
350
|
386
|
|
351
|
387
|
/**
|
352
|
388
|
* Converts the stats to the format used for logging, and saves the data in
|
|
@@ -380,45 +416,16 @@ StatsCollector.prototype.addStatsToBeLogged = function (reports) {
|
380
|
416
|
});
|
381
|
417
|
};
|
382
|
418
|
|
383
|
|
-StatsCollector.prototype.logStats = function () {
|
384
|
419
|
|
385
|
|
- if(!APP.xmpp.sendLogs(this.statsToBeLogged))
|
386
|
|
- return;
|
387
|
|
- // Reset the stats
|
388
|
|
- this.statsToBeLogged.stats = {};
|
389
|
|
- this.statsToBeLogged.timestamps = [];
|
390
|
|
-};
|
391
|
|
-var keyMap = {};
|
392
|
|
-keyMap[RTCBrowserType.RTC_BROWSER_FIREFOX] = {
|
393
|
|
- "ssrc": "ssrc",
|
394
|
|
- "packetsReceived": "packetsReceived",
|
395
|
|
- "packetsLost": "packetsLost",
|
396
|
|
- "packetsSent": "packetsSent",
|
397
|
|
- "bytesReceived": "bytesReceived",
|
398
|
|
- "bytesSent": "bytesSent"
|
399
|
|
-};
|
400
|
|
-keyMap[RTCBrowserType.RTC_BROWSER_CHROME] = {
|
401
|
|
- "receiveBandwidth": "googAvailableReceiveBandwidth",
|
402
|
|
- "sendBandwidth": "googAvailableSendBandwidth",
|
403
|
|
- "remoteAddress": "googRemoteAddress",
|
404
|
|
- "transportType": "googTransportType",
|
405
|
|
- "localAddress": "googLocalAddress",
|
406
|
|
- "activeConnection": "googActiveConnection",
|
407
|
|
- "ssrc": "ssrc",
|
408
|
|
- "packetsReceived": "packetsReceived",
|
409
|
|
- "packetsSent": "packetsSent",
|
410
|
|
- "packetsLost": "packetsLost",
|
411
|
|
- "bytesReceived": "bytesReceived",
|
412
|
|
- "bytesSent": "bytesSent",
|
413
|
|
- "googFrameHeightReceived": "googFrameHeightReceived",
|
414
|
|
- "googFrameWidthReceived": "googFrameWidthReceived",
|
415
|
|
- "googFrameHeightSent": "googFrameHeightSent",
|
416
|
|
- "googFrameWidthSent": "googFrameWidthSent",
|
417
|
|
- "audioInputLevel": "audioInputLevel",
|
418
|
|
- "audioOutputLevel": "audioOutputLevel"
|
419
|
|
-};
|
420
|
|
-keyMap[RTCBrowserType.RTC_BROWSER_OPERA] =
|
421
|
|
- keyMap[RTCBrowserType.RTC_BROWSER_CHROME];
|
|
420
|
+//FIXME:
|
|
421
|
+//StatsCollector.prototype.logStats = function () {
|
|
422
|
+//
|
|
423
|
+// if(!APP.xmpp.sendLogs(this.statsToBeLogged))
|
|
424
|
+// return;
|
|
425
|
+// // Reset the stats
|
|
426
|
+// this.statsToBeLogged.stats = {};
|
|
427
|
+// this.statsToBeLogged.timestamps = [];
|
|
428
|
+//};
|
422
|
429
|
|
423
|
430
|
|
424
|
431
|
/**
|
|
@@ -434,7 +441,7 @@ StatsCollector.prototype.processStatsReport = function () {
|
434
|
441
|
try {
|
435
|
442
|
if (getStatValue(now, 'receiveBandwidth') ||
|
436
|
443
|
getStatValue(now, 'sendBandwidth')) {
|
437
|
|
- PeerStats.bandwidth = {
|
|
444
|
+ this.conferenceStats.bandwidth = {
|
438
|
445
|
"download": Math.round(
|
439
|
446
|
(getStatValue(now, 'receiveBandwidth')) / 1000),
|
440
|
447
|
"upload": Math.round(
|
|
@@ -457,18 +464,18 @@ StatsCollector.prototype.processStatsReport = function () {
|
457
|
464
|
if(!ip || !type || !localIP || active != "true")
|
458
|
465
|
continue;
|
459
|
466
|
var addressSaved = false;
|
460
|
|
- for(var i = 0; i < PeerStats.transport.length; i++)
|
|
467
|
+ for(var i = 0; i < this.conferenceStats.transport.length; i++)
|
461
|
468
|
{
|
462
|
|
- if(PeerStats.transport[i].ip == ip &&
|
463
|
|
- PeerStats.transport[i].type == type &&
|
464
|
|
- PeerStats.transport[i].localip == localIP)
|
|
469
|
+ if(this.conferenceStats.transport[i].ip == ip &&
|
|
470
|
+ this.conferenceStats.transport[i].type == type &&
|
|
471
|
+ this.conferenceStats.transport[i].localip == localIP)
|
465
|
472
|
{
|
466
|
473
|
addressSaved = true;
|
467
|
474
|
}
|
468
|
475
|
}
|
469
|
476
|
if(addressSaved)
|
470
|
477
|
continue;
|
471
|
|
- PeerStats.transport.push({localip: localIP, ip: ip, type: type});
|
|
478
|
+ this.conferenceStats.transport.push({localip: localIP, ip: ip, type: type});
|
472
|
479
|
continue;
|
473
|
480
|
}
|
474
|
481
|
|
|
@@ -479,7 +486,7 @@ StatsCollector.prototype.processStatsReport = function () {
|
479
|
486
|
|
480
|
487
|
var local = this.currentStatsReport[now.localCandidateId];
|
481
|
488
|
var remote = this.currentStatsReport[now.remoteCandidateId];
|
482
|
|
- PeerStats.transport.push({localip: local.ipAddress + ":" + local.portNumber,
|
|
489
|
+ this.conferenceStats.transport.push({localip: local.ipAddress + ":" + local.portNumber,
|
483
|
490
|
ip: remote.ipAddress + ":" + remote.portNumber, type: local.transport});
|
484
|
491
|
|
485
|
492
|
}
|
|
@@ -498,16 +505,11 @@ StatsCollector.prototype.processStatsReport = function () {
|
498
|
505
|
var ssrc = getStatValue(now, 'ssrc');
|
499
|
506
|
if(!ssrc)
|
500
|
507
|
continue;
|
501
|
|
- var jid = APP.xmpp.getJidFromSSRC(ssrc);
|
502
|
|
- if (!jid && (Date.now() - now.timestamp) < 3000) {
|
503
|
|
- console.warn("No jid for ssrc: " + ssrc);
|
504
|
|
- continue;
|
505
|
|
- }
|
506
|
508
|
|
507
|
|
- var jidStats = this.jid2stats[jid];
|
508
|
|
- if (!jidStats) {
|
509
|
|
- jidStats = new PeerStats();
|
510
|
|
- this.jid2stats[jid] = jidStats;
|
|
509
|
+ var ssrcStats = this.ssrc2stats[ssrc];
|
|
510
|
+ if (!ssrcStats) {
|
|
511
|
+ ssrcStats = new PeerStats();
|
|
512
|
+ this.ssrc2stats[ssrc] = ssrcStats;
|
511
|
513
|
}
|
512
|
514
|
|
513
|
515
|
|
|
@@ -544,7 +546,7 @@ StatsCollector.prototype.processStatsReport = function () {
|
544
|
546
|
lossRate = 0;
|
545
|
547
|
var packetsTotal = (packetRate + lossRate);
|
546
|
548
|
|
547
|
|
- jidStats.setSsrcLoss(ssrc,
|
|
549
|
+ ssrcStats.setSsrcLoss(ssrc,
|
548
|
550
|
{"packetsTotal": packetsTotal,
|
549
|
551
|
"packetsLost": lossRate,
|
550
|
552
|
"isDownloadStream": isDownloadStream});
|
|
@@ -582,7 +584,7 @@ StatsCollector.prototype.processStatsReport = function () {
|
582
|
584
|
bytesSent = Math.round(((bytesSent * 8) / time) / 1000);
|
583
|
585
|
}
|
584
|
586
|
|
585
|
|
- jidStats.setSsrcBitrate(ssrc, {
|
|
587
|
+ ssrcStats.setSsrcBitrate(ssrc, {
|
586
|
588
|
"download": bytesReceived,
|
587
|
589
|
"upload": bytesSent});
|
588
|
590
|
|
|
@@ -603,11 +605,11 @@ StatsCollector.prototype.processStatsReport = function () {
|
603
|
605
|
|
604
|
606
|
if(resolution.height && resolution.width)
|
605
|
607
|
{
|
606
|
|
- jidStats.setSsrcResolution(ssrc, resolution);
|
|
608
|
+ ssrcStats.setSsrcResolution(ssrc, resolution);
|
607
|
609
|
}
|
608
|
610
|
else
|
609
|
611
|
{
|
610
|
|
- jidStats.setSsrcResolution(ssrc, null);
|
|
612
|
+ ssrcStats.setSsrcResolution(ssrc, null);
|
611
|
613
|
}
|
612
|
614
|
|
613
|
615
|
|
|
@@ -620,38 +622,38 @@ StatsCollector.prototype.processStatsReport = function () {
|
620
|
622
|
var bitrateDownload = 0;
|
621
|
623
|
var bitrateUpload = 0;
|
622
|
624
|
var resolutions = {};
|
623
|
|
- Object.keys(this.jid2stats).forEach(
|
|
625
|
+ Object.keys(this.ssrc2stats).forEach(
|
624
|
626
|
function (jid)
|
625
|
627
|
{
|
626
|
|
- Object.keys(self.jid2stats[jid].ssrc2Loss).forEach(
|
|
628
|
+ Object.keys(self.ssrc2stats[jid].ssrc2Loss).forEach(
|
627
|
629
|
function (ssrc)
|
628
|
630
|
{
|
629
|
631
|
var type = "upload";
|
630
|
|
- if(self.jid2stats[jid].ssrc2Loss[ssrc].isDownloadStream)
|
|
632
|
+ if(self.ssrc2stats[jid].ssrc2Loss[ssrc].isDownloadStream)
|
631
|
633
|
type = "download";
|
632
|
634
|
totalPackets[type] +=
|
633
|
|
- self.jid2stats[jid].ssrc2Loss[ssrc].packetsTotal;
|
|
635
|
+ self.ssrc2stats[jid].ssrc2Loss[ssrc].packetsTotal;
|
634
|
636
|
lostPackets[type] +=
|
635
|
|
- self.jid2stats[jid].ssrc2Loss[ssrc].packetsLost;
|
|
637
|
+ self.ssrc2stats[jid].ssrc2Loss[ssrc].packetsLost;
|
636
|
638
|
}
|
637
|
639
|
);
|
638
|
|
- Object.keys(self.jid2stats[jid].ssrc2bitrate).forEach(
|
|
640
|
+ Object.keys(self.ssrc2stats[jid].ssrc2bitrate).forEach(
|
639
|
641
|
function (ssrc) {
|
640
|
642
|
bitrateDownload +=
|
641
|
|
- self.jid2stats[jid].ssrc2bitrate[ssrc].download;
|
|
643
|
+ self.ssrc2stats[jid].ssrc2bitrate[ssrc].download;
|
642
|
644
|
bitrateUpload +=
|
643
|
|
- self.jid2stats[jid].ssrc2bitrate[ssrc].upload;
|
|
645
|
+ self.ssrc2stats[jid].ssrc2bitrate[ssrc].upload;
|
644
|
646
|
|
645
|
|
- delete self.jid2stats[jid].ssrc2bitrate[ssrc];
|
|
647
|
+ delete self.ssrc2stats[jid].ssrc2bitrate[ssrc];
|
646
|
648
|
}
|
647
|
649
|
);
|
648
|
|
- resolutions[jid] = self.jid2stats[jid].ssrc2resolution;
|
|
650
|
+ resolutions[jid] = self.ssrc2stats[jid].ssrc2resolution;
|
649
|
651
|
}
|
650
|
652
|
);
|
651
|
653
|
|
652
|
|
- PeerStats.bitrate = {"upload": bitrateUpload, "download": bitrateDownload};
|
|
654
|
+ this.conferenceStats.bitrate = {"upload": bitrateUpload, "download": bitrateDownload};
|
653
|
655
|
|
654
|
|
- PeerStats.packetLoss = {
|
|
656
|
+ this.conferenceStats.packetLoss = {
|
655
|
657
|
total:
|
656
|
658
|
calculatePacketLoss(lostPackets.download + lostPackets.upload,
|
657
|
659
|
totalPackets.download + totalPackets.upload),
|
|
@@ -662,13 +664,13 @@ StatsCollector.prototype.processStatsReport = function () {
|
662
|
664
|
};
|
663
|
665
|
this.eventEmitter.emit("statistics.connectionstats",
|
664
|
666
|
{
|
665
|
|
- "bitrate": PeerStats.bitrate,
|
666
|
|
- "packetLoss": PeerStats.packetLoss,
|
667
|
|
- "bandwidth": PeerStats.bandwidth,
|
|
667
|
+ "bitrate": this.conferenceStats.bitrate,
|
|
668
|
+ "packetLoss": this.conferenceStats.packetLoss,
|
|
669
|
+ "bandwidth": this.conferenceStats.bandwidth,
|
668
|
670
|
"resolution": resolutions,
|
669
|
|
- "transport": PeerStats.transport
|
|
671
|
+ "transport": this.conferenceStats.transport
|
670
|
672
|
});
|
671
|
|
- PeerStats.transport = [];
|
|
673
|
+ this.conferenceStats.transport = [];
|
672
|
674
|
|
673
|
675
|
};
|
674
|
676
|
|
|
@@ -683,7 +685,8 @@ StatsCollector.prototype.processAudioLevelReport = function () {
|
683
|
685
|
for (var idx in this.currentAudioLevelsReport) {
|
684
|
686
|
var now = this.currentAudioLevelsReport[idx];
|
685
|
687
|
|
686
|
|
- if (now.type != 'ssrc') {
|
|
688
|
+ //if we don't have "packetsReceived" this is local stream
|
|
689
|
+ if (now.type != 'ssrc' || !getStatValue(now, 'packetsReceived')) {
|
687
|
690
|
continue;
|
688
|
691
|
}
|
689
|
692
|
|
|
@@ -694,17 +697,16 @@ StatsCollector.prototype.processAudioLevelReport = function () {
|
694
|
697
|
}
|
695
|
698
|
|
696
|
699
|
var ssrc = getStatValue(now, 'ssrc');
|
697
|
|
- var jid = APP.xmpp.getJidFromSSRC(ssrc);
|
698
|
|
- if (!jid) {
|
|
700
|
+ if (!ssrc) {
|
699
|
701
|
if((Date.now() - now.timestamp) < 3000)
|
700
|
|
- console.warn("No jid for ssrc: " + ssrc);
|
|
702
|
+ console.warn("No ssrc: ");
|
701
|
703
|
continue;
|
702
|
704
|
}
|
703
|
705
|
|
704
|
|
- var jidStats = this.jid2stats[jid];
|
705
|
|
- if (!jidStats) {
|
706
|
|
- jidStats = new PeerStats();
|
707
|
|
- this.jid2stats[jid] = jidStats;
|
|
706
|
+ var ssrcStats = this.ssrc2stats[ssrc];
|
|
707
|
+ if (!ssrcStats) {
|
|
708
|
+ ssrcStats = new PeerStats();
|
|
709
|
+ this.ssrc2stats[ssrc] = ssrcStats;
|
708
|
710
|
}
|
709
|
711
|
|
710
|
712
|
// Audio level
|
|
@@ -725,9 +727,8 @@ StatsCollector.prototype.processAudioLevelReport = function () {
|
725
|
727
|
// TODO: can't find specs about what this value really is,
|
726
|
728
|
// but it seems to vary between 0 and around 32k.
|
727
|
729
|
audioLevel = audioLevel / 32767;
|
728
|
|
- jidStats.setSsrcAudioLevel(ssrc, audioLevel);
|
729
|
|
- if(jid != APP.xmpp.myJid())
|
730
|
|
- this.eventEmitter.emit("statistics.audioLevel", jid, audioLevel);
|
|
730
|
+ ssrcStats.setSsrcAudioLevel(ssrc, audioLevel);
|
|
731
|
+ this.eventEmitter.emit("statistics.audioLevel", ssrc, audioLevel);
|
731
|
732
|
}
|
732
|
733
|
}
|
733
|
734
|
};
|