From 132c6c9ad666e8b3d5cf176752fc23c4729a30c2 Mon Sep 17 00:00:00 2001 From: PizZaKatZe Date: Thu, 11 Mar 2021 22:51:42 +0100 Subject: [PATCH] Fix volume auto-reduction in conversations --- front/dist/index.tmpl.html | 2 +- front/src/WebRtc/AudioManager.ts | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/front/dist/index.tmpl.html b/front/dist/index.tmpl.html index eeb8bb5b..3d1b784f 100644 --- a/front/dist/index.tmpl.html +++ b/front/dist/index.tmpl.html @@ -97,7 +97,7 @@
diff --git a/front/src/WebRtc/AudioManager.ts b/front/src/WebRtc/AudioManager.ts index 735c42c3..01d978fe 100644 --- a/front/src/WebRtc/AudioManager.ts +++ b/front/src/WebRtc/AudioManager.ts @@ -78,18 +78,21 @@ class AudioManager { } private changeVolume(talking = false): void { - if (!isUndefined(this.audioPlayerElem)) { - this.audioPlayerElem.volume = this.naturalVolume(talking && this.decreaseWhileTalking); - this.audioPlayerVol.value = '' + this.audioPlayerElem.volume; - this.audioPlayerElem.muted = this.muted; + if (isUndefined(this.audioPlayerElem)) { + return; } - } - private naturalVolume(makeSofter: boolean = false): number { - const volume = this.volume - const retVol = makeSofter && !this.volumeReduced ? Math.pow(volume * 0.5, 3) : volume - this.volumeReduced = makeSofter - return retVol; + const reduceVolume = talking && this.decreaseWhileTalking; + if (reduceVolume && !this.volumeReduced) { + this.volume *= 0.5; + } else if (!reduceVolume && this.volumeReduced) { + this.volume *= 2.0; + } + this.volumeReduced = reduceVolume; + + this.audioPlayerElem.volume = this.volume; + this.audioPlayerVol.value = '' + this.volume; + this.audioPlayerElem.muted = this.muted; } private setVolume(volume: number): void {