mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-15 00:04:59 +08:00
Correctly handle window losing focus
This commit is contained in:
parent
d09c3d8374
commit
6855e61c47
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user