|
@@ -277,36 +277,26 @@ export default function TraceablePeerConnection(
|
277
|
277
|
}
|
278
|
278
|
};
|
279
|
279
|
|
280
|
|
- // XXX: do all non-firefox browsers which we support also support this?
|
281
|
|
- if (!browser.isFirefox() && this.maxstats) {
|
|
280
|
+ if (this.maxstats) {
|
282
|
281
|
this.statsinterval = window.setInterval(() => {
|
283
|
|
- this.peerconnection.getStats(stats => {
|
284
|
|
- const results = stats.result();
|
285
|
|
- const now = new Date();
|
286
|
|
-
|
287
|
|
- for (let i = 0; i < results.length; ++i) {
|
288
|
|
- results[i].names().forEach(name => {
|
289
|
|
- // eslint-disable-next-line no-shadow
|
290
|
|
- const id = `${results[i].id}-${name}`;
|
291
|
|
- let s = this.stats[id];
|
292
|
|
-
|
293
|
|
- if (!s) {
|
294
|
|
- this.stats[id] = s = {
|
295
|
|
- startTime: now,
|
296
|
|
- endTime: now,
|
297
|
|
- values: [],
|
298
|
|
- times: []
|
299
|
|
- };
|
300
|
|
- }
|
301
|
|
- s.values.push(results[i].stat(name));
|
302
|
|
- s.times.push(now.getTime());
|
303
|
|
- if (s.values.length > this.maxstats) {
|
304
|
|
- s.values.shift();
|
305
|
|
- s.times.shift();
|
306
|
|
- }
|
307
|
|
- s.endTime = now;
|
308
|
|
- });
|
|
282
|
+ this.getStats(stats => {
|
|
283
|
+ if (stats.result
|
|
284
|
+ && typeof stats.result === 'function') {
|
|
285
|
+ const results = stats.result();
|
|
286
|
+
|
|
287
|
+ for (let i = 0; i < results.length; ++i) {
|
|
288
|
+ const res = results[i];
|
|
289
|
+
|
|
290
|
+ res.names().forEach(name => {
|
|
291
|
+ this._processStat(res, name, res.stat(name));
|
|
292
|
+ });
|
|
293
|
+ }
|
|
294
|
+ } else {
|
|
295
|
+ stats.forEach(r => this._processStat(r, '', r));
|
309
|
296
|
}
|
|
297
|
+ }, () => {
|
|
298
|
+
|
|
299
|
+ // empty error callback
|
310
|
300
|
});
|
311
|
301
|
}, 1000);
|
312
|
302
|
}
|
|
@@ -316,6 +306,36 @@ export default function TraceablePeerConnection(
|
316
|
306
|
|
317
|
307
|
/* eslint-enable max-params */
|
318
|
308
|
|
|
309
|
+/**
|
|
310
|
+ * Process stat and adds it to the array of stats we store.
|
|
311
|
+ * @param report the current stats report.
|
|
312
|
+ * @param name the name of the report, if available
|
|
313
|
+ * @param statValue the value to add.
|
|
314
|
+ * @private
|
|
315
|
+ */
|
|
316
|
+TraceablePeerConnection.prototype._processStat
|
|
317
|
+ = function(report, name, statValue) {
|
|
318
|
+ const id = `${report.id}-${name}`;
|
|
319
|
+ let s = this.stats[id];
|
|
320
|
+ const now = new Date();
|
|
321
|
+
|
|
322
|
+ if (!s) {
|
|
323
|
+ this.stats[id] = s = {
|
|
324
|
+ startTime: now,
|
|
325
|
+ endTime: now,
|
|
326
|
+ values: [],
|
|
327
|
+ times: []
|
|
328
|
+ };
|
|
329
|
+ }
|
|
330
|
+ s.values.push(statValue);
|
|
331
|
+ s.times.push(now.getTime());
|
|
332
|
+ if (s.values.length > this.maxstats) {
|
|
333
|
+ s.values.shift();
|
|
334
|
+ s.times.shift();
|
|
335
|
+ }
|
|
336
|
+ s.endTime = now;
|
|
337
|
+ };
|
|
338
|
+
|
319
|
339
|
/**
|
320
|
340
|
* Returns a string representation of a SessionDescription object.
|
321
|
341
|
*/
|