diff --git a/spec/unit/webrtc/mediaHandler.spec.ts b/spec/unit/webrtc/mediaHandler.spec.ts index 94396845c96..252d8d65438 100644 --- a/spec/unit/webrtc/mediaHandler.spec.ts +++ b/spec/unit/webrtc/mediaHandler.spec.ts @@ -79,6 +79,23 @@ describe('Media Handler', function() { })); }); + it("sets audio settings", async () => { + await mediaHandler.setAudioSettings({ + autoGainControl: false, + echoCancellation: true, + noiseSuppression: false, + }); + + await mediaHandler.getUserMediaStream(true, false); + expect(mockMediaDevices.getUserMedia).toHaveBeenCalledWith(expect.objectContaining({ + audio: expect.objectContaining({ + autoGainControl: { ideal: false }, + echoCancellation: { ideal: true }, + noiseSuppression: { ideal: false }, + }), + })); + }); + it("sets video device ID", async () => { await mediaHandler.setVideoInput(FAKE_VIDEO_INPUT_ID); diff --git a/src/webrtc/mediaHandler.ts b/src/webrtc/mediaHandler.ts index 3cea257caca..c4b912ef38a 100644 --- a/src/webrtc/mediaHandler.ts +++ b/src/webrtc/mediaHandler.ts @@ -40,10 +40,17 @@ export interface IScreensharingOpts { throwOnFail?: boolean; } +export interface AudioSettings { + autoGainControl: boolean; + echoCancellation: boolean; + noiseSuppression: boolean; +} + export class MediaHandler extends TypedEventEmitter< MediaHandlerEvent.LocalStreamsChanged, MediaHandlerEventHandlerMap > { private audioInput?: string; + private audioSettings?: AudioSettings; private videoInput?: string; private localUserMediaStream?: MediaStream; public userMediaStreams: MediaStream[] = []; @@ -64,7 +71,7 @@ export class MediaHandler extends TypedEventEmitter< * undefined treated as unset */ public async setAudioInput(deviceId: string): Promise { - logger.info("LOG setting audio input to", deviceId); + logger.info("Setting audio input to", deviceId); if (this.audioInput === deviceId) return; @@ -72,13 +79,24 @@ export class MediaHandler extends TypedEventEmitter< await this.updateLocalUsermediaStreams(); } + /** + * Set audio settings for MatrixCalls + * @param {AudioSettings} opts audio options to set + */ + public async setAudioSettings(opts: AudioSettings): Promise { + logger.info("Setting audio settings to", opts); + + this.audioSettings = Object.assign({}, opts) as AudioSettings; + await this.updateLocalUsermediaStreams(); + } + /** * Set a video input device to use for MatrixCalls * @param {string} deviceId the identifier for the device * undefined treated as unset */ public async setVideoInput(deviceId: string): Promise { - logger.info("LOG setting video input to", deviceId); + logger.info("Setting video input to", deviceId); if (this.videoInput === deviceId) return; @@ -362,6 +380,9 @@ export class MediaHandler extends TypedEventEmitter< audio: audio ? { deviceId: this.audioInput ? { ideal: this.audioInput } : undefined, + autoGainControl: this.audioSettings ? { ideal: this.audioSettings.autoGainControl } : undefined, + echoCancellation: this.audioSettings ? { ideal: this.audioSettings.echoCancellation } : undefined, + noiseSuppression: this.audioSettings ? { ideal: this.audioSettings.noiseSuppression } : undefined, } : false, video: video