@rtcstats/rtcstats-js 2.2.4 → 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/media.js CHANGED
@@ -10,7 +10,7 @@ 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
16
  if (!prop || !prop.get || !prop.set) {
@@ -72,8 +72,8 @@ export function wrapGetUserMedia(trace, {navigator, MediaStreamTrack}) {
72
72
  track.addEventListener('ended', () => {
73
73
  trace('MediaStreamTrack.onended', null, track.id, track.__rtcStatsId);
74
74
  });
75
- wrapTrackProperty(track, 'enabled', trace);
76
- wrapTrackProperty(track, 'contentHint', trace);
75
+ wrapTrackProperty(track, 'enabled', trace, MediaStreamTrack);
76
+ wrapTrackProperty(track, 'contentHint', trace, MediaStreamTrack);
77
77
  });
78
78
  return stream;
79
79
  }, (err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rtcstats/rtcstats-js",
3
- "version": "2.2.4",
3
+ "version": "2.3.0",
4
4
  "description": "gather WebRTC API traces and statistics",
5
5
  "main": "rtcstats.js",
6
6
  "type": "module",
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' && typeof document !== 'undefined' && document.querySelectorAll) {
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', () => {
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, window, config);
14
+ wrapRTCPeerConnection(trace, target, config);
15
15
  // Wrap getUserMedia, getDisplayMedia and related events.
16
- wrapGetUserMedia(trace, window);
16
+ wrapGetUserMedia(trace, target);
17
17
  // Wrap enumerateDevices.
18
- wrapEnumerateDevices(trace, window);
18
+ wrapEnumerateDevices(trace, target);
19
19
 
20
20
  return trace;
21
21
  }
@@ -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.availWidth,
72
- height: window.screen.availHeight,
71
+ width: window.screen?.availWidth,
72
+ height: window.screen?.availHeight,
73
73
  devicePixelRatio: window.devicePixelRatio,
74
74
  },
75
75
  window: {