Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/core/src/components/mediaDeviceSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ export type SetMediaDeviceOptions = {
exact?: boolean;
};

/**
* Check if a MediaStreamTrack is using the system default device.
* Uses the deviceId from getSettings() instead of the label string,
* since labels are locale-dependent and can't be reliably matched.
*/
function isDefaultDevice(track: MediaStreamTrack): boolean {
try {
return track.getSettings().deviceId === 'default';
} catch {
return false;
}
}

export function setupDeviceSelector(
kind: MediaDeviceKind,
room: Room,
Expand All @@ -33,7 +46,7 @@ export function setupDeviceSelector(
await localTrack.setDeviceId(options.exact ? { exact: id } : id);
const actualId = await localTrack.getDeviceId(false);
activeDeviceSubject.next(
id === 'default' && localTrack.mediaStreamTrack.label.startsWith('Default') ? id : actualId,
id === 'default' && isDefaultDevice(localTrack.mediaStreamTrack) ? id : actualId,
);
} else if (room) {
const browser = getBrowser();
Expand All @@ -57,7 +70,7 @@ export function setupDeviceSelector(
}
const useDefault =
(id === 'default' && !targetTrack) ||
(id === 'default' && targetTrack?.mediaStreamTrack.label.startsWith('Default'));
(id === 'default' && targetTrack && isDefaultDevice(targetTrack.mediaStreamTrack));
activeDeviceSubject.next(useDefault ? id : actualDeviceId);
}
};
Expand Down
Loading