@rtcstats/rtcstats-js 1.0.0 → 1.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
@@ -1,3 +1,44 @@
1
- # rtcstats.js
1
+ This is part of the [monorepo](https://github.com/rtcstats/rtcstats) for rtcstats-js
2
+ (clientside monitoring), rtcstats-server (serverside dump collection) and the updated
3
+ dump-importer (supporting rtcstats and webrtc-internals formats).
4
+
5
+ It is part of a bigger offering that includes [rtcstats.com](https://rtcstats.com),
6
+ an online service for debugging and troubleshooting WebRTC statistics.
7
+
8
+ # rtcstats-js: A Javascript client SDK for monitoring WebRTC
9
+
10
+ The Javascript SDK provides low-level logging on peerconnection API calls and periodic getStats calls for analytics/debugging purposes.
11
+ It was designed to add a negligible overhead to the application’s performance with minimal integration efforts and remains
12
+ inspired by chrome's [webrtc-internals](https://bloggeek.me/webrtc-internals/) page.
13
+
14
+ This repository is the current iteration of the [2015 rtcstats.js](https://github.com/fippo/rtcstats). The principle is still the same:
15
+ * Transparent integration by overriding RTCPeerConnection et al with techniques used by adapter.js
16
+ * Trace all RTCPeerConnection and getUserMedia API calls and events.
17
+ * Send them to a server over Websocket.
18
+
19
+ ## Usage
20
+
21
+ The main rtcstats.js exports a number of methods that facilitate this:
22
+ * `WebSocketTrace` instantiates a trace function that is passed to the other methods. It connects to a server over WebSocket.
23
+ * `wrapRTCPeerConnection` wraps RTCPeerConnection and related APIs on the supplied `window`
24
+ object and generates traces using the supplied `trace` method.
25
+ * `wrapGetUserMedia` and `wrapEnumerateDevices` do the same for the `getUserMedia`/`getDisplayMedia`,
26
+ `enumerateDevices` and related APIs such as MediaStreamTracks and HTMLVideoElement.
27
+
28
+ Typical usage looks like this:
29
+ ```
30
+ import {wrapRTCStatsWithDefaultOptions} from '@rtcstats/rtcstats-js';
31
+
32
+ // Instantiate a trace function, using the helper with default options.
33
+ // See the example for a more fine-grained approach to wrapping.
34
+ const trace = wrapRTCStatsWithDefaultOptions();
35
+
36
+ // Connect to the rtcstats-server instance.
37
+ trace.connect('ws://localhost:8080' + window.location.pathname);
38
+
39
+ const pc = new RTCPeerConnection();
40
+ ```
41
+
42
+ See also the [end-to-end example](/example/) in `example/` directory and
43
+ the (internal) API docs [here](docs/index.md).
2
44
 
3
- Javascript SDK for RTCStats. See the top-level README.md file.
package/package.json CHANGED
@@ -1,24 +1,17 @@
1
1
  {
2
2
  "name": "@rtcstats/rtcstats-js",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "gather WebRTC API traces and statistics",
5
5
  "main": "rtcstats.js",
6
6
  "type": "module",
7
7
  "devDependencies": {
8
+ "@esm-bundle/chai": "^4.3.4-fix.0",
8
9
  "@puppeteer/browsers": "^2.10.9",
9
- "jest": "^30.1.3",
10
- "karma": "^6.4.4",
11
- "karma-chai": "^0.1.0",
12
- "karma-chrome-launcher": "^3.2.0",
13
- "karma-coverage": "^2.2.1",
14
- "karma-firefox-launcher": "^2.1.3",
15
- "karma-mocha": "^2.0.1",
16
- "karma-mocha-reporter": "^2.2.5",
17
- "karma-webpack": "^5.0.1"
10
+ "@web/test-runner": "^0.20.2"
18
11
  },
19
12
  "scripts": {
20
13
  "lint": "eslint *.js test/",
21
- "coverage": "c8 karma start test/karma.conf.js",
14
+ "coverage": "web-test-runner --config test/web-test-runner.config.mjs",
22
15
  "test": "npm run lint && npm run coverage"
23
16
  },
24
17
  "repository": {
@@ -29,5 +22,8 @@
29
22
  "license": "MIT",
30
23
  "publishConfig": {
31
24
  "access": "public"
25
+ },
26
+ "dependencies": {
27
+ "@rtcstats/rtcstats-shared": "^1.0.0"
32
28
  }
33
29
  }
package/rtcstats.js CHANGED
@@ -2,6 +2,24 @@ import {wrapRTCPeerConnection} from './peerconnection.js';
2
2
  import {wrapGetUserMedia, wrapEnumerateDevices} from './media.js';
3
3
  import {WebSocketTrace} from './trace-websocket.js';
4
4
 
5
+ /**
6
+ * Wrap RTCStats WebSocket trace with default options.
7
+ *
8
+ * @returns {function} RTCStats trace function.
9
+ */
10
+ export function wrapRTCStatsWithDefaultOptions(config = {getStatsInterval: 1000}) {
11
+ const trace = new WebSocketTrace();
12
+
13
+ // Wrap RTCPeerConnection-related APIs and events
14
+ wrapRTCPeerConnection(trace, window, config);
15
+ // Wrap getUserMedia, getDisplayMedia and related events.
16
+ wrapGetUserMedia(trace, window);
17
+ // Wrap enumerateDevices.
18
+ wrapEnumerateDevices(trace, window);
19
+
20
+ return trace;
21
+ }
22
+
5
23
  export {
6
24
  wrapRTCPeerConnection,
7
25
  wrapGetUserMedia,
@@ -16,14 +16,16 @@ export function WebSocketTrace() {
16
16
  }
17
17
  const method = args[0];
18
18
  args[0] = compressMethod(method);
19
- if (connection.readyState === WebSocket.OPEN) {
20
- if (buffer.length === 0) {
21
- connection.send(JSON.stringify(args));
22
- } else {
23
- buffer.push(args);
19
+ if (connection) {
20
+ if (connection.readyState === WebSocket.OPEN) {
21
+ if (buffer.length === 0) {
22
+ connection.send(JSON.stringify(args));
23
+ } else {
24
+ buffer.push(args);
25
+ }
26
+ } else if (connection.readyState >= WebSocket.CLOSING) {
27
+ // no-op. Possibly log?
24
28
  }
25
- } else if (connection.readyState >= WebSocket.CLOSING) {
26
- // no-op. Possibly log?
27
29
  } else {
28
30
  buffer.push(args);
29
31
  }