mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-05 04:06:44 +02:00
Voice messages were being recorded using the system default microphone instead of the device selected in Element settings. This was fixed by ensuring the preferred deviceId is correctly passed to the MediaStream constraints in VoiceRecording.ts. Added unit tests in VoiceRecording-test.ts to verify that the application correctly requests the user-selected device. Co-authored-by: Will Hunt <2072976+Half-Shot@users.noreply.github.com>
This commit is contained in:
parent
52061d624b
commit
5ba09a5f90
@ -103,10 +103,14 @@ export class VoiceRecording extends EventEmitter implements IDestroyable {
|
||||
|
||||
private async makeRecorder(): Promise<void> {
|
||||
try {
|
||||
const requestedDeviceId = MediaDeviceHandler.getAudioInput();
|
||||
const deviceIdConstraint =
|
||||
requestedDeviceId && requestedDeviceId !== "default" ? { deviceId: { exact: requestedDeviceId } } : {};
|
||||
|
||||
this.recorderStream = await navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
channelCount: CHANNELS,
|
||||
deviceId: MediaDeviceHandler.getAudioInput(),
|
||||
...deviceIdConstraint,
|
||||
autoGainControl: { ideal: MediaDeviceHandler.getAudioAutoGainControl() },
|
||||
echoCancellation: { ideal: MediaDeviceHandler.getAudioEchoCancellation() },
|
||||
noiseSuppression: { ideal: MediaDeviceHandler.getAudioNoiseSuppression() },
|
||||
|
||||
@ -120,6 +120,29 @@ describe("VoiceRecording", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("should request the selected microphone as an exact device constraint", async () => {
|
||||
MediaDeviceHandlerMock.getAudioInput.mockReturnValue("selected-mic");
|
||||
await recording.start();
|
||||
|
||||
expect(navigator.mediaDevices.getUserMedia).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
audio: expect.objectContaining({ deviceId: { exact: "selected-mic" } }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("should not force an exact microphone when default device is selected", async () => {
|
||||
MediaDeviceHandlerMock.getAudioInput.mockReturnValue("default");
|
||||
await recording.start();
|
||||
|
||||
const constraints = mocked(navigator.mediaDevices.getUserMedia).mock.calls[0][0] as MediaStreamConstraints;
|
||||
expect(constraints.audio).toEqual(
|
||||
expect.not.objectContaining({
|
||||
deviceId: expect.anything(),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when recording", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user