feat: tip before page unload while voicing

This commit is contained in:
Tristan Yang
2023-04-04 11:29:39 +08:00
parent 1f2e46fc60
commit 0b8a265bf6
+9
View File
@@ -112,11 +112,20 @@ const Voice = () => {
});
window.VOICE_CLIENT = agoraEngine;
};
const handlePageUnload = (evt: BeforeUnloadEvent) => {
console.log("unload");
if (localTrack) {
evt.preventDefault();
return (evt.returnValue = "");
}
};
window.addEventListener("beforeunload", handlePageUnload, { capture: true });
if (!window.VOICE_CLIENT) {
initializeAgoraClient();
}
return () => {
window.removeEventListener("beforeunload", handlePageUnload, { capture: true });
// if (window.VOICE_CLIENT && localTrack) {
// localTrack.close();
// localTrack = null;