@rtcstats/rtcstats-js 2.2.2 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,6 +5,9 @@ dump-importer (supporting rtcstats and webrtc-internals formats).
5
5
  It is part of a bigger offering that includes [rtcstats.com](https://rtcstats.com),
6
6
  an online service for debugging and troubleshooting WebRTC statistics.
7
7
 
8
+ For a complete reference of every getStats() metric rtcstats collects and analyzes, see
9
+ the [WebRTC Stats Reference](https://rtcstats.com/kb/webrtc-stats-reference-page).
10
+
8
11
  # rtcstats-js: A Javascript client SDK for monitoring WebRTC
9
12
 
10
13
  The Javascript SDK provides low-level logging on peerconnection API calls and periodic getStats calls for analytics/debugging purposes.
@@ -71,6 +74,7 @@ trace(method name, e.g. `:userRating`,
71
74
  * The trace function will internally add a timestamp to the event.
72
75
  * rtcstats-server will not process such events by default.
73
76
  * A dump-importer should still display a generic rendering of the event.
77
+ * Compression should not be used for custom methods.
74
78
 
75
79
  ### Using a JWT to connect to rtcstats-server
76
80
  See [the server README](https://github.com/rtcstats/rtcstats/blob/main/packages/rtcstats-server/README.md) for how to
@@ -111,6 +115,7 @@ Note that RTCStats is not keeping track of whether all RTCPeerConnections have b
111
115
  have been stopped.
112
116
 
113
117
  ### See also
114
- See also the [end-to-end example](/example/) in `example/` directory and
115
- the (internal) API docs [here](docs/index.md).
118
+ * the [end-to-end example](/example/) in `example/` directory and
119
+ * the (internal) API docs [here](docs/index.md) - note that these may not be fully up-to-date.
120
+ * the [WebRTC Stats Reference](https://rtcstats.com/kb/webrtc-stats-reference-page) which tells you what each getStats() metric means, expected values, and common issues.
116
121
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rtcstats/rtcstats-js",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "gather WebRTC API traces and statistics",
5
5
  "main": "rtcstats.js",
6
6
  "type": "module",
package/peerconnection.js CHANGED
@@ -13,7 +13,7 @@ import {map2obj, dumpTrackWithStreams, copyAndSanitizeConfig} from '@rtcstats/rt
13
13
  *
14
14
  * @protected
15
15
  * @param {function} trace - RTCStats trace callback
16
- * @param {object} window - window object from which to take the RTCRtpTransceiver protoype.
16
+ * @param {object} window - window object from which to take the RTCRtpTransceiver prototype.
17
17
  */
18
18
  function wrapRTCRtpTransceiver(trace, window) {
19
19
  if (!window.RTCRtpTransceiver) {
@@ -31,13 +31,13 @@ function wrapRTCRtpTransceiver(trace, window) {
31
31
  }
32
32
 
33
33
  /**
34
- * Wraps a RTCRtpSenderfor RTCStats. Currently applied to these methods:
34
+ * Wraps a RTCRtpSender for RTCStats. Currently applied to these methods:
35
35
  * * setParameters
36
- * * replaceTrack
36
+ * * replaceTrack
37
37
  *
38
38
  * @protected
39
39
  * @param {function} trace - RTCStats trace callback
40
- * @param {object} window - window object from which to take the RTCRtpSender protoype.
40
+ * @param {object} window - window object from which to take the RTCRtpSender prototype.
41
41
  */
42
42
  function wrapRTCRtpSender(trace, window) {
43
43
  if (!window.RTCRtpSender) {
@@ -77,7 +77,7 @@ function wrapRTCRtpSender(trace, window) {
77
77
  * Legacy methods and events are not wrapped.
78
78
  *
79
79
  * @param {function} trace - RTCStats trace callback
80
- * @param {object} window - window object from which to take the RTCPeerConnection protoype.
80
+ * @param {object} window - window object from which to take the RTCPeerConnection prototype.
81
81
  * @param {object} configuration - various configurable properties. Currently:
82
82
  * * getStatsInterval {number} - interval at which getStats will be polled.
83
83
  */
@@ -90,7 +90,7 @@ export function wrapRTCPeerConnection(trace, window, {getStatsInterval}) {
90
90
  return;
91
91
  }
92
92
  let lastComputePressureRecord;
93
- if (window.PressureObserver) {
93
+ if (window.PressureObserver && getStatsInterval) {
94
94
  const observer = new PressureObserver((records) => {
95
95
  const lastRecord = records[records.length - 1]; // Usually only one record.
96
96
  lastComputePressureRecord = [Date.now(), lastRecord];
@@ -279,7 +279,7 @@ export function wrapRTCPeerConnection(trace, window, {getStatsInterval}) {
279
279
  }
280
280
  trace(method, this.__rtcStatsId, serializedArgs);
281
281
  const transceiver = nativeMethod.apply(this, [trackOrKind, ...args]);
282
- transceiver.__rtcStatsId = this.__rtcStatsId;
282
+ transceiver.__rtcStatsId = this.__rtcStatsId;
283
283
  transceiver.sender.__rtcStatsId = this.__rtcStatsId;
284
284
  transceiver.sender.__rtcStatsSenderId = transceiver.receiver.track.id;
285
285
  trace(method + 'OnSuccess', this.__rtcStatsId, null, transceiver.receiver.track.id);
@@ -393,10 +393,9 @@ export function wrapRTCPeerConnection(trace, window, {getStatsInterval}) {
393
393
  const trackingId = compressMethod(method) + '-' + (counters[method]++);
394
394
  trace(method, this.__rtcStatsId, args[0], trackingId);
395
395
  return nativeMethod.apply(this, args)
396
- .then((description) => {
396
+ .then(() => {
397
397
  trace(method + 'OnSuccess', this.__rtcStatsId, undefined,
398
398
  trackingId);
399
- return description;
400
399
  }, (err) => {
401
400
  trace(method + 'OnFailure', this.__rtcStatsId, err.toString(),
402
401
  trackingId);
@@ -417,13 +416,7 @@ export function wrapRTCPeerConnection(trace, window, {getStatsInterval}) {
417
416
 
418
417
  // wrap static methods. Currently just generateCertificate.
419
418
  if (OrigPeerConnection.generateCertificate) {
420
- Object.defineProperty(RTCStatsPeerConnection, 'generateCertificate', {
421
- get(...args) {
422
- return args.length ?
423
- OrigPeerConnection.generateCertificate.apply(null, args)
424
- : OrigPeerConnection.generateCertificate;
425
- },
426
- });
419
+ RTCStatsPeerConnection.generateCertificate = OrigPeerConnection.generateCertificate;
427
420
  }
428
421
  window.RTCPeerConnection = RTCStatsPeerConnection;
429
422
  window.RTCPeerConnection.prototype = OrigPeerConnection.prototype;
@@ -14,11 +14,8 @@ export function WebSocketTrace(config = {}) {
14
14
  // on that does not require listening for onload etc.
15
15
  let reloadCount = undefined;
16
16
  if (window.sessionStorage && config.countReloads) {
17
- reloadCount = window.sessionStorage.getItem(RELOAD_COUNT_KEY);
18
- if (reloadCount === null || isNaN(reloadCount)) {
19
- reloadCount = -1;
20
- }
21
- reloadCount = parseInt(reloadCount, 10) + 1;
17
+ const stored = parseInt(window.sessionStorage.getItem(RELOAD_COUNT_KEY), 10);
18
+ reloadCount = Number.isNaN(stored) ? 0 : stored + 1;
22
19
  window.sessionStorage.setItem(RELOAD_COUNT_KEY, reloadCount);
23
20
  }
24
21
  const trace = function(...args) {
@@ -56,14 +53,15 @@ export function WebSocketTrace(config = {}) {
56
53
  if (connection) {
57
54
  connection.close();
58
55
  connection = null;
56
+ // New traces need to get an absolute timestamp.
57
+ lastTime = 0;
59
58
  }
60
- // New traces need to get an absolute timestamp.
61
- lastTime = 0;
62
59
  };
63
60
  trace.connect = (wsURL) => {
64
61
  if (connection) {
65
62
  connection.close();
66
63
  lastTime = 0;
64
+ connection = null;
67
65
  }
68
66
  trace('create', null, {
69
67
  hardwareConcurrency: navigator.hardwareConcurrency,
@@ -83,7 +81,9 @@ export function WebSocketTrace(config = {}) {
83
81
  connectionStartTime = Date.now();
84
82
  connection = new WebSocket(wsURL, 'rtcstats#' + PROTOCOL_VERSION);
85
83
  connection.addEventListener('error', (e) => {
86
- // console.error('WS ERROR', e);
84
+ if (config.log) {
85
+ config.log('rtcstats websocket connection error', e, connection.readyState);
86
+ }
87
87
  });
88
88
 
89
89
  connection.addEventListener('close', (e) => {