1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
import { describe, expect, test } from "bun:test";
import {
DEFAULT_AUDIO_INPUT_DEVICE_ID,
buildVoiceOverAudioConstraints,
normalizeSelectedDeviceId,
type VoiceOverInputDevice,
} from "@/voiceover/devices";
const devices: VoiceOverInputDevice[] = [
{
deviceId: DEFAULT_AUDIO_INPUT_DEVICE_ID,
label: "System default microphone",
isDefault: true,
},
{
deviceId: "blue-yeti-snowball",
label: "Blue Snowball",
isDefault: false,
},
];
describe("buildVoiceOverAudioConstraints", () => {
test("uses default processing constraints without an exact device", () => {
const constraints = buildVoiceOverAudioConstraints({ deviceId: null });
expect(constraints.audio).toEqual({
echoCancellation: true,
noiseSuppression: true,
autoGainControl: true,
});
});
test("adds an exact device constraint for a selected microphone", () => {
const constraints = buildVoiceOverAudioConstraints({
deviceId: "blue-yeti-snowball",
});
expect(constraints.audio).toEqual({
deviceId: { exact: "blue-yeti-snowball" },
echoCancellation: true,
noiseSuppression: true,
autoGainControl: true,
});
});
});
describe("normalizeSelectedDeviceId", () => {
test("keeps the selected device when it is still present", () => {
expect(
normalizeSelectedDeviceId({
deviceId: "blue-yeti-snowball",
devices,
}),
).toBe("blue-yeti-snowball");
});
test("clears a selected device when it is no longer present", () => {
expect(
normalizeSelectedDeviceId({
deviceId: "missing",
devices,
}),
).toBeNull();
});
test("keeps the browser default device id", () => {
expect(
normalizeSelectedDeviceId({
deviceId: DEFAULT_AUDIO_INPUT_DEVICE_ID,
devices: [],
}),
).toBe(DEFAULT_AUDIO_INPUT_DEVICE_ID);
});
});
|