@wtfalch/calls 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/livekit.mjs +16 -1
  2. package/package.json +2 -2
package/livekit.mjs CHANGED
@@ -76,6 +76,8 @@ export function createLiveKitAdapter({ worker, capture = {} } = {}) {
76
76
  // so the next capture (mic/camera) or the next connect() (speaker) picks up
77
77
  // what useDevice() last asked for.
78
78
  const preferredDevice = {};
79
+ // The last id per kind that useDevice() switched to without a refusal.
80
+ const workingDevice = {};
79
81
 
80
82
  function audioConstraints() {
81
83
  const deviceId = preferredDevice.audioinput;
@@ -244,7 +246,20 @@ export function createLiveKitAdapter({ worker, capture = {} } = {}) {
244
246
 
245
247
  async useDevice(kind, deviceId) {
246
248
  preferredDevice[kind] = deviceId;
247
- if (room) await room.switchActiveDevice(kind, deviceId);
249
+ if (!room) { workingDevice[kind] = deviceId; return; }
250
+ try {
251
+ await room.switchActiveDevice(kind, deviceId);
252
+ workingDevice[kind] = deviceId;
253
+ } catch (error) {
254
+ // A failed switch must not leave the next capture asking for `exact`
255
+ // on a device that just refused. Fall back to the last device that
256
+ // worked, unless a later useDevice() has already replaced this one.
257
+ if (preferredDevice[kind] === deviceId) {
258
+ if (Object.hasOwn(workingDevice, kind)) preferredDevice[kind] = workingDevice[kind];
259
+ else delete preferredDevice[kind];
260
+ }
261
+ throw error;
262
+ }
248
263
  },
249
264
 
250
265
  // Synchronous, keyed by LiveKit identity, local participant included.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wtfalch/calls",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Framework-independent SDK for Agora calls: session control (admission, guest links, moderation) and a media-ready browser call handle.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -43,7 +43,7 @@
43
43
  "README.md"
44
44
  ],
45
45
  "scripts": {
46
- "test": "node --test test/*.test.mjs",
46
+ "test": "node --test --experimental-test-module-mocks test/*.test.mjs",
47
47
  "prepack": "cp ../../LICENSE ."
48
48
  },
49
49
  "peerDependencies": {