@rtcstats/rtcstats-js 2.2.3 → 2.3.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 +2 -1
- package/media.js +6 -3
- package/package.json +1 -1
- package/peerconnection.js +4 -4
- package/rtcstats.js +4 -4
- package/trace-websocket.js +2 -2
package/README.md
CHANGED
|
@@ -3,7 +3,8 @@ This is part of the [monorepo](https://github.com/rtcstats/rtcstats) for rtcstat
|
|
|
3
3
|
dump-importer (supporting rtcstats and webrtc-internals formats).
|
|
4
4
|
|
|
5
5
|
It is part of a bigger offering that includes [rtcstats.com](https://rtcstats.com),
|
|
6
|
-
|
|
6
|
+
the hosted WebRTC observability service that reads collected dumps and returns Observations,
|
|
7
|
+
an Experience Score, and a plain-English AI summary of what went wrong on the call.
|
|
7
8
|
|
|
8
9
|
For a complete reference of every getStats() metric rtcstats collects and analyzes, see
|
|
9
10
|
the [WebRTC Stats Reference](https://rtcstats.com/kb/webrtc-stats-reference-page).
|
package/media.js
CHANGED
|
@@ -10,9 +10,12 @@ import {compressMethod, dumpTrackWithStreams} from '@rtcstats/rtcstats-shared';
|
|
|
10
10
|
* @param {string} property - the track whose property (e.g. `enabled`) should be wrapped.
|
|
11
11
|
* @param {function} trace - RTCStats trace callback.
|
|
12
12
|
*/
|
|
13
|
-
function wrapTrackProperty(track, property, trace) {
|
|
13
|
+
function wrapTrackProperty(track, property, trace, MediaStreamTrack) {
|
|
14
14
|
const prop = Object.getOwnPropertyDescriptor(
|
|
15
15
|
MediaStreamTrack.prototype, property);
|
|
16
|
+
if (!prop || !prop.get || !prop.set) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
16
19
|
|
|
17
20
|
// Replace the property with a custom one
|
|
18
21
|
Object.defineProperty(track, property, {
|
|
@@ -69,8 +72,8 @@ export function wrapGetUserMedia(trace, {navigator, MediaStreamTrack}) {
|
|
|
69
72
|
track.addEventListener('ended', () => {
|
|
70
73
|
trace('MediaStreamTrack.onended', null, track.id, track.__rtcStatsId);
|
|
71
74
|
});
|
|
72
|
-
wrapTrackProperty(track, 'enabled', trace);
|
|
73
|
-
wrapTrackProperty(track, 'contentHint', trace);
|
|
75
|
+
wrapTrackProperty(track, 'enabled', trace, MediaStreamTrack);
|
|
76
|
+
wrapTrackProperty(track, 'contentHint', trace, MediaStreamTrack);
|
|
74
77
|
});
|
|
75
78
|
return stream;
|
|
76
79
|
}, (err) => {
|
package/package.json
CHANGED
package/peerconnection.js
CHANGED
|
@@ -91,7 +91,7 @@ export function wrapRTCPeerConnection(trace, window, {getStatsInterval}) {
|
|
|
91
91
|
}
|
|
92
92
|
let lastComputePressureRecord;
|
|
93
93
|
if (window.PressureObserver && getStatsInterval) {
|
|
94
|
-
const observer = new PressureObserver((records) => {
|
|
94
|
+
const observer = new window.PressureObserver((records) => {
|
|
95
95
|
const lastRecord = records[records.length - 1]; // Usually only one record.
|
|
96
96
|
lastComputePressureRecord = [Date.now(), lastRecord];
|
|
97
97
|
});
|
|
@@ -153,9 +153,9 @@ export function wrapRTCPeerConnection(trace, window, {getStatsInterval}) {
|
|
|
153
153
|
e.transceiver.sender.__rtcStatsId = pcId;
|
|
154
154
|
e.transceiver.sender.__rtcStatsSenderId = e.track.id;
|
|
155
155
|
}
|
|
156
|
-
if (e.track.kind === 'video') {
|
|
156
|
+
if (e.track.kind === 'video' && window.document?.querySelectorAll) {
|
|
157
157
|
setTimeout(() => {
|
|
158
|
-
document.querySelectorAll('video').forEach(el => {
|
|
158
|
+
window.document.querySelectorAll('video').forEach(el => {
|
|
159
159
|
if (!el.srcObject) return;
|
|
160
160
|
if (el.srcObject.getTracks().indexOf(e.track) === -1) return;
|
|
161
161
|
el.addEventListener('resize', () => {
|
|
@@ -188,7 +188,7 @@ export function wrapRTCPeerConnection(trace, window, {getStatsInterval}) {
|
|
|
188
188
|
let statsInterval;
|
|
189
189
|
const statsIdMap = {};
|
|
190
190
|
const getStats = async (reason) => {
|
|
191
|
-
if (pc.signalingState === 'closed') {
|
|
191
|
+
if (pc.signalingState === 'closed' || pc.connectionState === 'closed') {
|
|
192
192
|
if (statsInterval) {
|
|
193
193
|
window.clearInterval(statsInterval);
|
|
194
194
|
}
|
package/rtcstats.js
CHANGED
|
@@ -7,15 +7,15 @@ import {WebSocketTrace} from './trace-websocket.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @returns {function} RTCStats trace function.
|
|
9
9
|
*/
|
|
10
|
-
export function wrapRTCStatsWithDefaultOptions(config = {getStatsInterval: 1000}) {
|
|
10
|
+
export function wrapRTCStatsWithDefaultOptions(config = {getStatsInterval: 1000}, target = globalThis) {
|
|
11
11
|
const trace = new WebSocketTrace(config);
|
|
12
12
|
|
|
13
13
|
// Wrap RTCPeerConnection-related APIs and events
|
|
14
|
-
wrapRTCPeerConnection(trace,
|
|
14
|
+
wrapRTCPeerConnection(trace, target, config);
|
|
15
15
|
// Wrap getUserMedia, getDisplayMedia and related events.
|
|
16
|
-
wrapGetUserMedia(trace,
|
|
16
|
+
wrapGetUserMedia(trace, target);
|
|
17
17
|
// Wrap enumerateDevices.
|
|
18
|
-
wrapEnumerateDevices(trace,
|
|
18
|
+
wrapEnumerateDevices(trace, target);
|
|
19
19
|
|
|
20
20
|
return trace;
|
|
21
21
|
}
|
package/trace-websocket.js
CHANGED
|
@@ -68,8 +68,8 @@ export function WebSocketTrace(config = {}) {
|
|
|
68
68
|
userAgentData: navigator.userAgentData,
|
|
69
69
|
deviceMemory: navigator.deviceMemory,
|
|
70
70
|
screen: {
|
|
71
|
-
width: window.screen
|
|
72
|
-
height: window.screen
|
|
71
|
+
width: window.screen?.availWidth,
|
|
72
|
+
height: window.screen?.availHeight,
|
|
73
73
|
devicePixelRatio: window.devicePixelRatio,
|
|
74
74
|
},
|
|
75
75
|
window: {
|