@rtcstats/rtcstats-js 2.0.2 → 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 +36 -0
- package/media.js +1 -1
- package/package.json +3 -2
- package/rtcstats.js +1 -1
- package/trace-websocket.js +6 -2
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
|
|
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
|
|
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);
|
package/trace-websocket.js
CHANGED
|
@@ -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;
|
|
@@ -59,7 +59,11 @@ export function WebSocketTrace() {
|
|
|
59
59
|
// console.error('WS ERROR', e);
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
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
|
+
}
|
|
63
67
|
// reconnect?
|
|
64
68
|
});
|
|
65
69
|
|