Handle pagehide and visibilitychange events in safari
This commit is contained in:
parent
323808f495
commit
8554184beb
1 changed files with 8 additions and 3 deletions
|
|
@ -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.
|
// 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 = () => {
|
const onParticipantsChanged = () => {
|
||||||
setState((prevState) => ({
|
setState((prevState) => ({
|
||||||
|
|
@ -219,7 +222,9 @@ export function useVideoRoom(manager, roomId, timeout = 5000) {
|
||||||
return () => {
|
return () => {
|
||||||
manager.client.removeListener("Room", roomCallback);
|
manager.client.removeListener("Room", roomCallback);
|
||||||
manager.removeListener("participants_changed", onParticipantsChanged);
|
manager.removeListener("participants_changed", onParticipantsChanged);
|
||||||
window.removeEventListener(unloadEvent, onBeforeUnload);
|
window.removeEventListener("pagehide", onBeforeUnload);
|
||||||
|
document.removeEventListener("visibilitychange", onBeforeUnload);
|
||||||
|
window.removeEventListener("beforeunload", onBeforeUnload);
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
manager.leaveCall();
|
manager.leaveCall();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue