@rtcstats/rtcstats-js 2.2.1 → 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 +7 -2
- package/package.json +1 -1
- package/peerconnection.js +9 -16
- package/trace-websocket.js +26 -25
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
|
-
|
|
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
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
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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((
|
|
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
|
-
|
|
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;
|
package/trace-websocket.js
CHANGED
|
@@ -6,20 +6,16 @@ const RELOAD_COUNT_KEY = 'rtcstatsReloadCount';
|
|
|
6
6
|
export function WebSocketTrace(config = {}) {
|
|
7
7
|
let buffer = [];
|
|
8
8
|
let connection;
|
|
9
|
-
let lastTime =
|
|
9
|
+
let lastTime = 0;
|
|
10
10
|
let connectionStartTime = 0;
|
|
11
|
-
const createTime = Date.now();
|
|
12
11
|
|
|
13
12
|
// This counts the number of times the trace itself has been initialized.
|
|
14
13
|
// Typically this is done once per session and counting (re)loads based
|
|
15
14
|
// on that does not require listening for onload etc.
|
|
16
15
|
let reloadCount = undefined;
|
|
17
16
|
if (window.sessionStorage && config.countReloads) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
reloadCount = -1;
|
|
21
|
-
}
|
|
22
|
-
reloadCount = parseInt(reloadCount, 10) + 1;
|
|
17
|
+
const stored = parseInt(window.sessionStorage.getItem(RELOAD_COUNT_KEY), 10);
|
|
18
|
+
reloadCount = Number.isNaN(stored) ? 0 : stored + 1;
|
|
23
19
|
window.sessionStorage.setItem(RELOAD_COUNT_KEY, reloadCount);
|
|
24
20
|
}
|
|
25
21
|
const trace = function(...args) {
|
|
@@ -56,16 +52,38 @@ export function WebSocketTrace(config = {}) {
|
|
|
56
52
|
}
|
|
57
53
|
if (connection) {
|
|
58
54
|
connection.close();
|
|
55
|
+
connection = null;
|
|
56
|
+
// New traces need to get an absolute timestamp.
|
|
57
|
+
lastTime = 0;
|
|
59
58
|
}
|
|
60
59
|
};
|
|
61
60
|
trace.connect = (wsURL) => {
|
|
62
61
|
if (connection) {
|
|
63
62
|
connection.close();
|
|
63
|
+
lastTime = 0;
|
|
64
|
+
connection = null;
|
|
64
65
|
}
|
|
66
|
+
trace('create', null, {
|
|
67
|
+
hardwareConcurrency: navigator.hardwareConcurrency,
|
|
68
|
+
userAgentData: navigator.userAgentData,
|
|
69
|
+
deviceMemory: navigator.deviceMemory,
|
|
70
|
+
screen: {
|
|
71
|
+
width: window.screen.availWidth,
|
|
72
|
+
height: window.screen.availHeight,
|
|
73
|
+
devicePixelRatio: window.devicePixelRatio,
|
|
74
|
+
},
|
|
75
|
+
window: {
|
|
76
|
+
width: window.innerWidth,
|
|
77
|
+
height: window.innerHeight,
|
|
78
|
+
},
|
|
79
|
+
reloadCount,
|
|
80
|
+
});
|
|
65
81
|
connectionStartTime = Date.now();
|
|
66
82
|
connection = new WebSocket(wsURL, 'rtcstats#' + PROTOCOL_VERSION);
|
|
67
83
|
connection.addEventListener('error', (e) => {
|
|
68
|
-
|
|
84
|
+
if (config.log) {
|
|
85
|
+
config.log('rtcstats websocket connection error', e, connection.readyState);
|
|
86
|
+
}
|
|
69
87
|
});
|
|
70
88
|
|
|
71
89
|
connection.addEventListener('close', (e) => {
|
|
@@ -80,23 +98,6 @@ export function WebSocketTrace(config = {}) {
|
|
|
80
98
|
// Note: open is called while the socket is still authenticating.
|
|
81
99
|
// This can lead to messages being send and dropped when the token
|
|
82
100
|
// is not valid.
|
|
83
|
-
|
|
84
|
-
// Note: this does not use trace so avoids the buffer.
|
|
85
|
-
connection.send(JSON.stringify([compressMethod('create'), null, {
|
|
86
|
-
hardwareConcurrency: navigator.hardwareConcurrency,
|
|
87
|
-
userAgentData: navigator.userAgentData,
|
|
88
|
-
deviceMemory: navigator.deviceMemory,
|
|
89
|
-
screen: {
|
|
90
|
-
width: window.screen.availWidth,
|
|
91
|
-
height: window.screen.availHeight,
|
|
92
|
-
devicePixelRatio: window.devicePixelRatio,
|
|
93
|
-
},
|
|
94
|
-
window: {
|
|
95
|
-
width: window.innerWidth,
|
|
96
|
-
height: window.innerHeight,
|
|
97
|
-
},
|
|
98
|
-
reloadCount,
|
|
99
|
-
}, createTime]));
|
|
100
101
|
const connectionTime = Date.now() - connectionStartTime;
|
|
101
102
|
setTimeout(function flush() {
|
|
102
103
|
if (!buffer.length) {
|