@rtcstats/rtcstats-js 2.0.1 → 2.1.0

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
@@ -39,6 +39,42 @@ trace.connect('ws://localhost:8080' + window.location.pathname);
39
39
  const pc = new RTCPeerConnection();
40
40
  ```
41
41
 
42
+ ### Using a JWT to connect to rtcstats-server
43
+ See [the server README](https://github.com/rtcstats/rtcstats/blob/main/packages/rtcstats-server/README.md) for how to
44
+ generate JWT token with information about the user, session and conference.
45
+
46
+ If the server is configured to require an authorization token, the websocket will
47
+ be closed with a 1008 policy-violation error and a console warning is emitted.
48
+
49
+ ### Bundling
50
+ To bundle rtcstats-js including its dependencies, use
51
+ ```
52
+ npx webpack --entry ./packages/rtcstats-js/rtcstats.js --output-path ./packages/rtcstats-js/dist --output-filename rtcstats.bundle.js --mode production --output-library rtcstats
53
+ ```
54
+ then include the resulting bundle which is exported as the global `rtcstats` object:
55
+ ```
56
+ <script type="text/javascript" src="rtcstats.bundle.js"></script>
57
+ <script type="text/javascript">
58
+ const trace = rtcstats.wrapRTCStatsWithDefaultOptions();
59
+ // Do something.
60
+ </script>
61
+ ```
62
+
63
+ ### Ending a session
64
+ RTCStats sessions create a single dump file for every websocket connection. For long-running pages it may be required
65
+ to close the websocket when a "session" is done and reconnect (possibly with a new JWT):
66
+ ```
67
+ trace.connect('ws://localhost:8080/?rtcstats-token=token-1');
68
+ // Do something
69
+ trace.close()
70
+
71
+ // Reconnect.
72
+ trace.connect('ws://localhost:8080/?rtcstats-token=token-2');
73
+ ```
74
+ Note that RTCStats is not keeping track of whether all RTCPeerConnections have been closed and track from getUserMedia/getDisplayMedia
75
+ have been stopped.
76
+
77
+ ### See also
42
78
  See also the [end-to-end example](/example/) in `example/` directory and
43
79
  the (internal) API docs [here](docs/index.md).
44
80
 
package/media.js CHANGED
@@ -34,7 +34,7 @@ function wrapTrackProperty(track, property, trace) {
34
34
  * Also wraps these methods on MediaStreamTrack
35
35
  * * stop
36
36
  * * applyConstraints
37
- * The `ended` event is wrapped as are the setters fro `enabled`
37
+ * The `ended` event is wrapped as are the setters for `enabled`
38
38
  * and `contentHint`.
39
39
  *
40
40
  * @protected
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@rtcstats/rtcstats-js",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "gather WebRTC API traces and statistics",
5
5
  "main": "rtcstats.js",
6
6
  "type": "module",
7
7
  "devDependencies": {
8
8
  "@esm-bundle/chai": "^4.3.4-fix.0",
9
9
  "@puppeteer/browsers": "^2.10.9",
10
- "@web/test-runner": "^0.20.2"
10
+ "@web/test-runner": "^0.20.2",
11
+ "jsdoc-to-markdown": "^9.1.3"
11
12
  },
12
13
  "scripts": {
13
14
  "lint": "eslint *.js test/",
package/rtcstats.js CHANGED
@@ -8,7 +8,7 @@ import {WebSocketTrace} from './trace-websocket.js';
8
8
  * @returns {function} RTCStats trace function.
9
9
  */
10
10
  export function wrapRTCStatsWithDefaultOptions(config = {getStatsInterval: 1000}) {
11
- const trace = new WebSocketTrace();
11
+ const trace = new WebSocketTrace(config);
12
12
 
13
13
  // Wrap RTCPeerConnection-related APIs and events
14
14
  wrapRTCPeerConnection(trace, window, config);
@@ -2,7 +2,7 @@ import {compressMethod} from '@rtcstats/rtcstats-shared';
2
2
 
3
3
  const PROTOCOL_VERSION = '5.0';
4
4
 
5
- export function WebSocketTrace() {
5
+ export function WebSocketTrace(config = {}) {
6
6
  let buffer = [];
7
7
  let connection;
8
8
  let lastTime = 0;
@@ -23,13 +23,29 @@ export function WebSocketTrace() {
23
23
  } else {
24
24
  buffer.push(args);
25
25
  }
26
- } else if (connection.readyState >= WebSocket.CLOSING) {
26
+ } else if (connection.readyState === WebSocket.CONNECTING) {
27
+ buffer.push(args);
28
+ } else if ([WebSocket.CLOSING, WebSocket.CLOSED].includes(connection.readyState)) {
27
29
  // no-op. Possibly log?
28
30
  }
29
31
  } else {
30
32
  buffer.push(args);
31
33
  }
32
34
  };
35
+ trace('create', null, {
36
+ hardwareConcurrency: navigator.hardwareConcurrency,
37
+ userAgentData: navigator.userAgentData,
38
+ deviceMemory: navigator.deviceMemory,
39
+ screen: {
40
+ width: window.screen.availWidth,
41
+ height: window.screen.availHeight,
42
+ devicePixelRatio: window.devicePixelRatio,
43
+ },
44
+ window: {
45
+ width: window.innerWidth,
46
+ height: window.innerHeight,
47
+ },
48
+ });
33
49
 
34
50
  trace.close = () => {
35
51
  connection.close();
@@ -43,25 +59,15 @@ export function WebSocketTrace() {
43
59
  // console.error('WS ERROR', e);
44
60
  });
45
61
 
46
- connection.addEventListener('close', () => {
62
+ connection.addEventListener('close', (e) => {
63
+ if (e.code === 1008 && config.log) {
64
+ config.log('rtcstats websocket connection closed with error=1008. ' +
65
+ 'Typically this means authorization is required and failed.');
66
+ }
47
67
  // reconnect?
48
68
  });
49
69
 
50
70
  connection.addEventListener('open', () => {
51
- trace('create', null, {
52
- hardwareConcurrency: navigator.hardwareConcurrency,
53
- userAgentData: navigator.userAgentData,
54
- deviceMemory: navigator.deviceMemory,
55
- screen: {
56
- width: window.screen.availWidth,
57
- height: window.screen.availHeight,
58
- devicePixelRatio: window.devicePixelRatio,
59
- },
60
- window: {
61
- width: window.innerWidth,
62
- height: window.innerHeight,
63
- },
64
- });
65
71
  setTimeout(function flush() {
66
72
  if (!buffer.length) {
67
73
  return;