Fix device selection persistence bug

This commit is contained in:
Miriam Zimmerman 2024-10-07 16:32:31 -04:00 committed by GitHub
parent bad065859c
commit a3b972f6e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 157 additions and 67 deletions

View file

@ -3,20 +3,27 @@
import type { AudioDevice } from '@signalapp/ringrtc';
export function findBestMatchingAudioDeviceIndex({
available,
preferred,
}: Readonly<{
available: ReadonlyArray<AudioDevice>;
preferred: undefined | AudioDevice;
}>): undefined | number {
export function findBestMatchingAudioDeviceIndex(
{
available,
preferred,
}: Readonly<{
available: ReadonlyArray<AudioDevice>;
preferred: undefined | AudioDevice;
}>,
isWindows: boolean
): undefined | number {
if (!preferred) {
return available.length > 0 ? 0 : undefined;
}
// On Linux and Mac, the default device is at index 0.
// On Windows, there are two default devices, as presented by RingRTC:
// * The default communications device (for voice calls, at index 0)
// * the default device (for, e.g., media, at index 1)
if (
preferred.index === 0 ||
(preferred.index === 1 && available.length >= 2)
(isWindows && preferred.index === 1 && available.length >= 2)
) {
return preferred.index;
}