Prefer audio device 0 if no device preference has been saved
This commit is contained in:
parent
04b7a29229
commit
a4c6003f34
1 changed files with 15 additions and 19 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue