mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-15 00:04:59 +08:00
Handle pagehide and visibilitychange events in safari
This commit is contained in:
parent
323808f495
commit
8554184beb
@ -161,9 +161,12 @@ export function useVideoRoom(manager, roomId, timeout = 5000) {
|
||||
}
|
||||
|
||||
// iOS doesn't fire beforeunload event, so leave the call when you hide the page.
|
||||
const unloadEvent = isIOS() ? "visibilitychange" : "beforeunload";
|
||||
if (isIOS()) {
|
||||
window.addEventListener("pagehide", onBeforeUnload);
|
||||
document.addEventListener("visibilitychange", onBeforeUnload);
|
||||
}
|
||||
|
||||
window.addEventListener(unloadEvent, onBeforeUnload);
|
||||
window.addEventListener("beforeunload", onBeforeUnload);
|
||||
|
||||
const onParticipantsChanged = () => {
|
||||
setState((prevState) => ({
|
||||
@ -219,7 +222,9 @@ export function useVideoRoom(manager, roomId, timeout = 5000) {
|
||||
return () => {
|
||||
manager.client.removeListener("Room", roomCallback);
|
||||
manager.removeListener("participants_changed", onParticipantsChanged);
|
||||
window.removeEventListener(unloadEvent, onBeforeUnload);
|
||||
window.removeEventListener("pagehide", onBeforeUnload);
|
||||
document.removeEventListener("visibilitychange", onBeforeUnload);
|
||||
window.removeEventListener("beforeunload", onBeforeUnload);
|
||||
clearTimeout(timeoutId);
|
||||
manager.leaveCall();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user