diff --git a/app/src/RoomClient.js b/app/src/RoomClient.js index 7cfd626..66c5f22 100644 --- a/app/src/RoomClient.js +++ b/app/src/RoomClient.js @@ -1001,31 +1001,35 @@ export default class RoomClient { play : false, interval : 5, - threshold : store.getState().settings.noiseThreshold }); + threshold : store.getState().settings.noiseThreshold, + history : 30 + }); + this._hark.lastVolume = -100; - // eslint-disable-next-line no-unused-vars - this._hark.on('volume_change', (volume, threshold) => + this._hark.on('volume_change', (volume) => { - volume = Math.round(volume); - - if (this._micProducer && volume !== this._micProducer.volume) + volume = Math.round(volume) + if (this._micProducer && volume !== Math.round(this._hark.lastVolume)) { - this._micProducer.volume = volume; - + if (volume < this._hark.lastVolume * 1.02) + { + volume = this._hark.lastVolume * 1.02; + } + this._hark.lastVolume = volume; store.dispatch(peerVolumeActions.setPeerVolume(this._peerId, volume)); } }); this._hark.on('speaking', () => { - this._hark.setInterval(5); store.dispatch(meActions.setIsSpeaking(true)); - if (store.getState().settings.voiceActivatedUnmute && + if ((store.getState().settings.voiceActivatedUnmute || + store.getState().me.isAutoMuted) && this._micProducer && this._micProducer.paused) { this._micProducer.resume(); - store.dispatch(meActions.setAutoMuted(false)); } + store.dispatch(meActions.setAutoMuted(false)); // sanity action }); this._hark.on('stopped_speaking', () => { @@ -1037,7 +1041,6 @@ export default class RoomClient this._micProducer.pause(); store.dispatch(meActions.setAutoMuted(true)); } - this._hark.setInterval(5); }); } @@ -1984,19 +1987,8 @@ export default class RoomClient consumer.hark = hark(stream, { play: false }); - // eslint-disable-next-line no-unused-vars - consumer.hark.on('volume_change', (dBs, threshold) => + consumer.hark.on('volume_change', (volume) => { - // The exact formula to convert from dBs (-100..0) to linear (0..1) is: - // Math.pow(10, dBs / 20) - // However it does not produce a visually useful output, so let exaggerate - // it a bit. Also, let convert it from 0..1 to 0..10 and avoid value 1 to - // minimize component renderings. - let volume = Math.round(Math.pow(10, dBs / 85) * 10); - - if (volume === 1) - volume = 0; - volume = Math.round(volume); if (consumer && volume !== consumer.volume)