fix(calls): warn before unload during a joined call

Register beforeunload while joined so Ctrl+R / tab close prompts instead
of silently dropping the call. Also removes the setPipMode effect (#59).

Fixes #58

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
2026-09-12 20:28:41 -04:00
co-authored by Claude Opus 5
parent ac0ec9f42d
commit 49c4641ca8
+16 -6
View File
@@ -631,6 +631,22 @@ function CallUtils({ embed, joined }: { embed: CallEmbed; joined: boolean }) {
}, [setCallEmbed]),
);
// [Gitea #58] Warn before an accidental tab close/reload drops the user out
// of a live call. Only armed while actually joined, and torn down on
// hangup/dispose since this effect re-runs when `joined` flips back to false.
useEffect(() => {
if (!joined) return undefined;
const onBeforeUnload = (event: BeforeUnloadEvent) => {
event.preventDefault();
// Legacy browsers require returnValue to be set to show the prompt.
event.returnValue = '';
};
window.addEventListener('beforeunload', onBeforeUnload);
return () => {
window.removeEventListener('beforeunload', onBeforeUnload);
};
}, [joined]);
return null;
}
@@ -735,12 +751,6 @@ export function CallEmbedProvider({ children }: CallEmbedProviderProps) {
};
}, []);
// Sync pip mode into CallControl so it can adjust behavior accordingly
useEffect(() => {
if (!callEmbed) return;
callEmbed.control.setPipMode(!!pipMode);
}, [pipMode, callEmbed]);
// When entering pip with screenshare active (or screenshare starts while in pip),
// enable spotlight so the screenshare fills the pip window.
// When screenshare ends, release the spotlight we auto-enabled.