Skip to content

Commit aa6c352

Browse files
author
Charlie Tonneslan
committed
Fix locale-dependent default device detection
The previous check used label.startsWith('Default') to detect if a track is using the system default device, but this only works when the browser locale is English. On other locales the label is translated (e.g. 'Standard' in German). Replaced with getSettings().deviceId === 'default' which is locale-independent and directly checks what we actually care about. Fixes #1194
1 parent 2eed5c4 commit aa6c352

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/core/src/components/mediaDeviceSelect.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ export type SetMediaDeviceOptions = {
1919
exact?: boolean;
2020
};
2121

22+
/**
23+
* Check if a MediaStreamTrack is using the system default device.
24+
* Uses the deviceId from getSettings() instead of the label string,
25+
* since labels are locale-dependent and can't be reliably matched.
26+
*/
27+
function isDefaultDevice(track: MediaStreamTrack): boolean {
28+
try {
29+
return track.getSettings().deviceId === 'default';
30+
} catch {
31+
return false;
32+
}
33+
}
34+
2235
export function setupDeviceSelector(
2336
kind: MediaDeviceKind,
2437
room: Room,
@@ -33,7 +46,7 @@ export function setupDeviceSelector(
3346
await localTrack.setDeviceId(options.exact ? { exact: id } : id);
3447
const actualId = await localTrack.getDeviceId(false);
3548
activeDeviceSubject.next(
36-
id === 'default' && localTrack.mediaStreamTrack.label.startsWith('Default') ? id : actualId,
49+
id === 'default' && isDefaultDevice(localTrack.mediaStreamTrack) ? id : actualId,
3750
);
3851
} else if (room) {
3952
const browser = getBrowser();
@@ -57,7 +70,7 @@ export function setupDeviceSelector(
5770
}
5871
const useDefault =
5972
(id === 'default' && !targetTrack) ||
60-
(id === 'default' && targetTrack?.mediaStreamTrack.label.startsWith('Default'));
73+
(id === 'default' && targetTrack && isDefaultDevice(targetTrack.mediaStreamTrack));
6174
activeDeviceSubject.next(useDefault ? id : actualDeviceId);
6275
}
6376
};

0 commit comments

Comments
 (0)