@rtcstats/rtcstats-js 2.4.0 → 2.5.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
@@ -48,6 +48,7 @@ The main rtcstats.js exports a number of methods that facilitate this:
48
48
  object and generates traces using the supplied `trace` method.
49
49
  * `wrapGetUserMedia` and `wrapEnumerateDevices` do the same for the `getUserMedia`/`getDisplayMedia`,
50
50
  `enumerateDevices` and related APIs such as MediaStreamTracks and HTMLVideoElement.
51
+ * `wrapSetSinkId` does the same for HTMLMediaElement's `setSinkId` method which changes the audio output device.
51
52
 
52
53
  Typical usage looks like this:
53
54
  ```
package/media.js CHANGED
@@ -132,3 +132,30 @@ export function wrapEnumerateDevices(trace, {navigator}) {
132
132
  }
133
133
  }
134
134
 
135
+ /**
136
+ * Wraps HTMLMediaElement.setSinkId for RTCStats.
137
+ *
138
+ * @param {function} trace - RTCStats trace callback.
139
+ * @param {object} window - window object with HTMLMediaElement.
140
+ */
141
+ export function wrapSetSinkId(trace, {HTMLMediaElement}) {
142
+ if (!(HTMLMediaElement && HTMLMediaElement.prototype.setSinkId)) {
143
+ return;
144
+ }
145
+ if (HTMLMediaElement.prototype.setSinkId.__rtcStats) {
146
+ // Prevent double-wrapping.
147
+ return;
148
+ }
149
+ const origMethod = HTMLMediaElement.prototype.setSinkId;
150
+ const wrappedMethod = function(...args) {
151
+ trace('HTMLMediaElement.setSinkId', null, args[0]);
152
+ return origMethod.apply(this, args)
153
+ .then((result) => result, (err) => {
154
+ trace('HTMLMediaElement.setSinkIdOnFailure', null, err.toString(), args[0]);
155
+ return Promise.reject(err);
156
+ });
157
+ };
158
+ wrappedMethod.__rtcStats = true;
159
+ HTMLMediaElement.prototype.setSinkId = wrappedMethod;
160
+ }
161
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rtcstats/rtcstats-js",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "gather WebRTC API traces and statistics",
5
5
  "main": "rtcstats.js",
6
6
  "type": "module",
package/rtcstats.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import {wrapRTCPeerConnection} from './peerconnection.js';
2
- import {wrapGetUserMedia, wrapEnumerateDevices} from './media.js';
2
+ import {wrapGetUserMedia, wrapEnumerateDevices, wrapSetSinkId} from './media.js';
3
3
  import {WebSocketTrace} from './trace-websocket.js';
4
4
 
5
5
  /**
@@ -16,6 +16,8 @@ export function wrapRTCStatsWithDefaultOptions(config = {getStatsInterval: 1000}
16
16
  wrapGetUserMedia(trace, target);
17
17
  // Wrap enumerateDevices.
18
18
  wrapEnumerateDevices(trace, target);
19
+ // Wrap HTMLMediaElement.setSinkId.
20
+ wrapSetSinkId(trace, target);
19
21
 
20
22
  return trace;
21
23
  }
@@ -24,5 +26,6 @@ export {
24
26
  wrapRTCPeerConnection,
25
27
  wrapGetUserMedia,
26
28
  wrapEnumerateDevices,
29
+ wrapSetSinkId,
27
30
  WebSocketTrace,
28
31
  };