Correctly handle window losing focus

This commit is contained in:
Erik Johnston 2022-11-14 20:55:24 +00:00
parent d09c3d8374
commit 6855e61c47

View File

@ -404,6 +404,8 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallReturnType {
}
}, [t]);
const [spacebarHeld, setSpacebarHeld] = useState(false);
useEventTarget(
window,
"keydown",
@ -420,10 +422,16 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallReturnType {
} else if (event.key == "v") {
toggleLocalVideoMuted();
} else if (event.key === " ") {
setSpacebarHeld(true);
setMicrophoneMuted(false);
}
},
[toggleLocalVideoMuted, toggleMicrophoneMuted, setMicrophoneMuted]
[
toggleLocalVideoMuted,
toggleMicrophoneMuted,
setMicrophoneMuted,
setSpacebarHeld,
]
)
);
@ -439,13 +447,25 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallReturnType {
}
if (event.key === " ") {
setSpacebarHeld(false);
setMicrophoneMuted(true);
}
},
[setMicrophoneMuted]
[setMicrophoneMuted, setSpacebarHeld]
)
);
useEventTarget(
window,
"blur",
useCallback(() => {
if (spacebarHeld) {
setSpacebarHeld(false);
setMicrophoneMuted(true);
}
}, [setMicrophoneMuted, setSpacebarHeld, spacebarHeld])
);
return {
state,
calls,