Prefer audio device 0 if no device preference has been saved

This commit is contained in:
Vladimir Skuratovich 2020-10-22 14:40:31 -07:00 committed by Scott Nonnenberg
parent 04b7a29229
commit a4c6003f34

View file

@ -398,27 +398,23 @@ export class CallingClass {
available: Array<AudioDevice>,
preferred: AudioDevice | undefined
): number | undefined {
if (!preferred) {
// No preference stored
return undefined;
}
// Match by uniqueId first, if available
if (preferred.uniqueId) {
const matchIndex = available.findIndex(
d => d.uniqueId === preferred.uniqueId
);
if (matchIndex !== -1) {
return matchIndex;
if (preferred) {
// Match by uniqueId first, if available
if (preferred.uniqueId) {
const matchIndex = available.findIndex(
d => d.uniqueId === preferred.uniqueId
);
if (matchIndex !== -1) {
return matchIndex;
}
}
// Match by name second
const matchingNames = available.filter(d => d.name === preferred.name);
if (matchingNames.length > 0) {
return matchingNames[0].index;
}
}
// Match by name second
const matchingNames = available.filter(d => d.name === preferred.name);
if (matchingNames.length > 0) {
return matchingNames[0].index;
}
// Nothing matches; take the first device if there are any
// Nothing matches or no preference; take the first device if there are any
return available.length > 0 ? 0 : undefined;
}