diff options
author | metamuffin <metamuffin@disroot.org> | 2022-09-10 22:10:36 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-09-10 22:10:36 +0200 |
commit | bd33ef5dc96a938fe1886cc6775d7e38652c055d (patch) | |
tree | a8cba897b4bcd19488dacf60c0d5e387788069ce /client-web/source/user/local.ts | |
parent | c8a23ccb83a28808517915d3b76a8b8159e6ed4d (diff) | |
download | keks-meet-bd33ef5dc96a938fe1886cc6775d7e38652c055d.tar keks-meet-bd33ef5dc96a938fe1886cc6775d7e38652c055d.tar.bz2 keks-meet-bd33ef5dc96a938fe1886cc6775d7e38652c055d.tar.zst |
keep mic_gain in sync with prefs
Diffstat (limited to 'client-web/source/user/local.ts')
-rw-r--r-- | client-web/source/user/local.ts | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/client-web/source/user/local.ts b/client-web/source/user/local.ts index 4d11517..6fae710 100644 --- a/client-web/source/user/local.ts +++ b/client-web/source/user/local.ts @@ -1,7 +1,7 @@ /// <reference lib="dom" /> import { log } from "../logger.ts"; -import { PREFS } from "../preferences/mod.ts"; +import { on_pref_changed, PREFS } from "../preferences/mod.ts"; import { RemoteUser } from "./remote.ts"; import { get_rnnoise_node } from "../rnnoise.ts"; import { Room } from "../room.ts"; @@ -12,8 +12,6 @@ import { ediv } from "../helper.ts"; import { ChatMessage } from "../../../common/packets.d.ts"; export class LocalUser extends User { - mic_gain?: GainNode - default_gain: number = PREFS.microphone_gain constructor(room: Room, id: number) { super(room, id) @@ -110,25 +108,22 @@ export class LocalUser extends User { async create_mic_track() { log("media", "requesting user media (audio)") - const audio_contraints = PREFS.rnnoise ? { - channelCount: { ideal: 1 }, - noiseSuppression: { ideal: false }, - echoCancellation: { ideal: true }, - autoGainControl: { ideal: true }, - } : { - channelCount: { ideal: 1 }, - noiseSuppression: { ideal: PREFS.native_noise_suppression }, - echoCancellation: { ideal: PREFS.echo_cancellation }, - autoGainControl: { ideal: PREFS.auto_gain_control }, - }; - - const user_media = await window.navigator.mediaDevices.getUserMedia({ audio: audio_contraints }) + const user_media = await window.navigator.mediaDevices.getUserMedia({ + audio: { + channelCount: { ideal: 1 }, + noiseSuppression: { ideal: PREFS.rnnoise ? false : PREFS.native_noise_suppression }, + echoCancellation: { ideal: PREFS.echo_cancellation }, + autoGainControl: { ideal: PREFS.auto_gain_control }, + } + }) const context = new AudioContext() const source = context.createMediaStreamSource(user_media) const destination = context.createMediaStreamDestination() const gain = context.createGain() - gain.gain.value = this.default_gain - this.mic_gain = gain + gain.gain.value = PREFS.microphone_gain + const clear_gain_cb = on_pref_changed("microphone_gain", () => { + gain.gain.value = PREFS.microphone_gain + }) let rnnoise: RNNoiseNode; if (PREFS.rnnoise) { @@ -146,8 +141,8 @@ export class LocalUser extends User { source.disconnect() if (rnnoise) rnnoise.disconnect() gain.disconnect() + clear_gain_cb() destination.disconnect() - this.mic_gain = undefined }) return t } |