hark clean up; some state fixes for autoMute; fix remote hark audiolevel
parent
6331bb18b4
commit
ea84fc75c6
|
|
@ -1001,31 +1001,35 @@ export default class RoomClient
|
||||||
{
|
{
|
||||||
play : false,
|
play : false,
|
||||||
interval : 5,
|
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) =>
|
||||||
this._hark.on('volume_change', (volume, threshold) =>
|
|
||||||
{
|
{
|
||||||
volume = Math.round(volume);
|
volume = Math.round(volume)
|
||||||
|
if (this._micProducer && volume !== Math.round(this._hark.lastVolume))
|
||||||
if (this._micProducer && volume !== this._micProducer.volume)
|
|
||||||
{
|
{
|
||||||
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));
|
store.dispatch(peerVolumeActions.setPeerVolume(this._peerId, volume));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this._hark.on('speaking', () =>
|
this._hark.on('speaking', () =>
|
||||||
{
|
{
|
||||||
this._hark.setInterval(5);
|
|
||||||
store.dispatch(meActions.setIsSpeaking(true));
|
store.dispatch(meActions.setIsSpeaking(true));
|
||||||
if (store.getState().settings.voiceActivatedUnmute &&
|
if ((store.getState().settings.voiceActivatedUnmute ||
|
||||||
|
store.getState().me.isAutoMuted) &&
|
||||||
this._micProducer &&
|
this._micProducer &&
|
||||||
this._micProducer.paused)
|
this._micProducer.paused)
|
||||||
{
|
{
|
||||||
this._micProducer.resume();
|
this._micProducer.resume();
|
||||||
store.dispatch(meActions.setAutoMuted(false));
|
|
||||||
}
|
}
|
||||||
|
store.dispatch(meActions.setAutoMuted(false)); // sanity action
|
||||||
});
|
});
|
||||||
this._hark.on('stopped_speaking', () =>
|
this._hark.on('stopped_speaking', () =>
|
||||||
{
|
{
|
||||||
|
|
@ -1037,7 +1041,6 @@ export default class RoomClient
|
||||||
this._micProducer.pause();
|
this._micProducer.pause();
|
||||||
store.dispatch(meActions.setAutoMuted(true));
|
store.dispatch(meActions.setAutoMuted(true));
|
||||||
}
|
}
|
||||||
this._hark.setInterval(5);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1984,19 +1987,8 @@ export default class RoomClient
|
||||||
|
|
||||||
consumer.hark = hark(stream, { play: false });
|
consumer.hark = hark(stream, { play: false });
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
consumer.hark.on('volume_change', (volume) =>
|
||||||
consumer.hark.on('volume_change', (dBs, threshold) =>
|
|
||||||
{
|
{
|
||||||
// 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);
|
volume = Math.round(volume);
|
||||||
|
|
||||||
if (consumer && volume !== consumer.volume)
|
if (consumer && volume !== consumer.volume)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue