Add 'm' and 'space' shortcuts for mute/unmuting during a call

This commit is contained in:
Erik Johnston 2022-11-11 15:53:58 +00:00
parent 6ef41b924d
commit cb85733426

View file

@ -298,10 +298,14 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallReturnType {
PosthogAnalytics.instance.eventMuteCamera.track(toggleToMute);
}, [groupCall]);
const setMicrophoneMuted = useCallback((setMuted) => {
groupCall.setMicrophoneMuted(setMuted);
PosthogAnalytics.instance.eventMuteMicrophone.track(setMuted);
}, [groupCall]);
const toggleMicrophoneMuted = useCallback(() => {
const toggleToMute = !groupCall.isMicrophoneMuted();
groupCall.setMicrophoneMuted(toggleToMute);
PosthogAnalytics.instance.eventMuteMicrophone.track(toggleToMute);
setMicrophoneMuted(toggleToMute);
}, [groupCall]);
const toggleScreensharing = useCallback(async () => {
@ -395,6 +399,33 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallReturnType {
}
}, [t]);
useEffect(() => {
const keyDownListener = (event) => {
if (event.key === "m") {
toggleMicrophoneMuted();
}
if (event.key === " ") {
setMicrophoneMuted(false);
}
};
const keyUpListener = (event) => {
if (event.key === " ") {
setMicrophoneMuted(true);
}
};
window.addEventListener("keydown", keyDownListener, true);
window.addEventListener("keyup", keyUpListener, true);
return () => {
window.removeEventListener("keydown", keyDownListener, true);
window.removeEventListener("keyup", keyUpListener, true);
}
}, [toggleMicrophoneMuted, setMicrophoneMuted]);
return {
state,
calls,