Fix device selection persistence bug
This commit is contained in:
parent
bad065859c
commit
a3b972f6e7
4 changed files with 157 additions and 67 deletions
|
@ -14,10 +14,13 @@ describe('"find best matching device" helpers', () => {
|
|||
{ name: 'Big Microphone', index: 1, uniqueId: 'abc123' },
|
||||
].forEach(preferred => {
|
||||
assert.isUndefined(
|
||||
findBestMatchingAudioDeviceIndex({
|
||||
available: [],
|
||||
preferred,
|
||||
})
|
||||
findBestMatchingAudioDeviceIndex(
|
||||
{
|
||||
available: [],
|
||||
preferred,
|
||||
},
|
||||
false
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -26,14 +29,17 @@ describe('"find best matching device" helpers', () => {
|
|||
const itReturnsTheFirstAvailableDeviceIfNoneIsPreferred = () => {
|
||||
it('returns the first available device if none is preferred', () => {
|
||||
assert.strictEqual(
|
||||
findBestMatchingAudioDeviceIndex({
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: undefined,
|
||||
}),
|
||||
findBestMatchingAudioDeviceIndex(
|
||||
{
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: undefined,
|
||||
},
|
||||
false
|
||||
),
|
||||
0
|
||||
);
|
||||
});
|
||||
|
@ -41,28 +47,34 @@ describe('"find best matching device" helpers', () => {
|
|||
|
||||
const testUniqueIdMatch = () => {
|
||||
assert.strictEqual(
|
||||
findBestMatchingAudioDeviceIndex({
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: { name: 'Ignored', index: 99, uniqueId: 'device-C' },
|
||||
}),
|
||||
findBestMatchingAudioDeviceIndex(
|
||||
{
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: { name: 'Ignored', index: 99, uniqueId: 'device-C' },
|
||||
},
|
||||
false
|
||||
),
|
||||
2
|
||||
);
|
||||
};
|
||||
|
||||
const testNameMatch = () => {
|
||||
assert.strictEqual(
|
||||
findBestMatchingAudioDeviceIndex({
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: { name: 'C', index: 99, uniqueId: 'ignored' },
|
||||
}),
|
||||
findBestMatchingAudioDeviceIndex(
|
||||
{
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: { name: 'C', index: 99, uniqueId: 'ignored' },
|
||||
},
|
||||
false
|
||||
),
|
||||
2
|
||||
);
|
||||
};
|
||||
|
@ -71,14 +83,17 @@ describe('"find best matching device" helpers', () => {
|
|||
() => {
|
||||
it('returns the first available device if the preferred device is not found', () => {
|
||||
assert.strictEqual(
|
||||
findBestMatchingAudioDeviceIndex({
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: { name: 'X', index: 123, uniqueId: 'Y' },
|
||||
}),
|
||||
findBestMatchingAudioDeviceIndex(
|
||||
{
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: { name: 'X', index: 123, uniqueId: 'Y' },
|
||||
},
|
||||
false
|
||||
),
|
||||
0
|
||||
);
|
||||
});
|
||||
|
@ -89,28 +104,64 @@ describe('"find best matching device" helpers', () => {
|
|||
|
||||
itReturnsTheFirstAvailableDeviceIfNoneIsPreferred();
|
||||
|
||||
[0, 1].forEach(index => {
|
||||
it(`returns ${index} if that was the previous preferred index (and a device is available)`, () => {
|
||||
assert.strictEqual(
|
||||
findBestMatchingAudioDeviceIndex({
|
||||
it('returns 0 if that was the previous preferred index (and a device is available)', () => {
|
||||
assert.strictEqual(
|
||||
findBestMatchingAudioDeviceIndex(
|
||||
{
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: { name: 'C', index, uniqueId: 'device-C' },
|
||||
}),
|
||||
index
|
||||
);
|
||||
});
|
||||
preferred: { name: 'C', index: 0, uniqueId: 'device-C' },
|
||||
},
|
||||
false
|
||||
),
|
||||
0
|
||||
);
|
||||
});
|
||||
it('(windows) returns 1 if that was the previous preferred index (and a device is available)', () => {
|
||||
assert.strictEqual(
|
||||
findBestMatchingAudioDeviceIndex(
|
||||
{
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: { name: 'C', index: 1, uniqueId: 'device-C' },
|
||||
},
|
||||
true
|
||||
),
|
||||
1
|
||||
);
|
||||
});
|
||||
it('(non-windows) returns 2 if the preferred device was at index 1 and is now at index 2', () => {
|
||||
assert.strictEqual(
|
||||
findBestMatchingAudioDeviceIndex(
|
||||
{
|
||||
available: [
|
||||
{ name: 'A', index: 123, uniqueId: 'device-A' },
|
||||
{ name: 'B', index: 456, uniqueId: 'device-B' },
|
||||
{ name: 'C', index: 789, uniqueId: 'device-C' },
|
||||
],
|
||||
preferred: { name: 'C', index: 1, uniqueId: 'device-C' },
|
||||
},
|
||||
false
|
||||
),
|
||||
2
|
||||
);
|
||||
});
|
||||
|
||||
it("returns 0 if the previous preferred index was 1 but there's only 1 audio device", () => {
|
||||
assert.strictEqual(
|
||||
findBestMatchingAudioDeviceIndex({
|
||||
available: [{ name: 'A', index: 123, uniqueId: 'device-A' }],
|
||||
preferred: { name: 'C', index: 1, uniqueId: 'device-C' },
|
||||
}),
|
||||
findBestMatchingAudioDeviceIndex(
|
||||
{
|
||||
available: [{ name: 'A', index: 123, uniqueId: 'device-A' }],
|
||||
preferred: { name: 'C', index: 1, uniqueId: 'device-C' },
|
||||
},
|
||||
false
|
||||
),
|
||||
0
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue