Skip to content

Commit 28f353d

Browse files
committed
webrtc: add advanced audio settings
autoGainControl, echoCancellation, and noiseSuppression are audio processing options that are usually enabled by default on WebRTC input tracks. This commit adds the possibility to enable/disable them, as they can be undesirable in some cases (audiophile use cases). For example, one might want to stream electronic dance music, which is basically noise, so it should not be suppressed in that specific case. Note that these are not exact settings, they are set as "ideal" in order not to break anything on devices where those constraints are not implemented. Signed-off-by: László Várady <[email protected]>
1 parent e35ede0 commit 28f353d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/webrtc/mediaHandler.ts

+21
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ import { logger } from "../logger";
2121
import { MatrixClient } from "../client";
2222
import { CallState } from "./call";
2323

24+
export interface AudioSettings {
25+
autoGainControl: boolean;
26+
echoCancellation: boolean;
27+
noiseSuppression: boolean;
28+
}
29+
2430
export class MediaHandler {
2531
private audioInput: string;
32+
private audioSettings?: AudioSettings;
2633
private videoInput: string;
2734
private localUserMediaStream?: MediaStream;
2835
public userMediaStreams: MediaStream[] = [];
@@ -44,6 +51,17 @@ export class MediaHandler {
4451
await this.updateLocalUsermediaStreams();
4552
}
4653

54+
/**
55+
* Set audio settings for MatrixCalls
56+
* @param {AudioSettings} opts audio options to set
57+
*/
58+
public async setAudioSettings(opts: AudioSettings): Promise<void> {
59+
logger.info("LOG settings audio settings to", opts);
60+
61+
this.audioSettings = Object.assign({}, opts) as AudioSettings;
62+
await this.updateLocalUsermediaStreams();
63+
}
64+
4765
/**
4866
* Set a video input device to use for MatrixCalls
4967
* @param {string} deviceId the identifier for the device
@@ -253,6 +271,9 @@ export class MediaHandler {
253271
audio: audio
254272
? {
255273
deviceId: this.audioInput ? { ideal: this.audioInput } : undefined,
274+
autoGainControl: this.audioSettings ? { ideal: this.audioSettings.autoGainControl } : undefined,
275+
echoCancellation: this.audioSettings ? { ideal: this.audioSettings.echoCancellation } : undefined,
276+
noiseSuppression: this.audioSettings ? { ideal: this.audioSettings.noiseSuppression } : undefined,
256277
}
257278
: false,
258279
video: video

0 commit comments

Comments
 (0)