mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-21 20:46:43 +03:00
Compare commits
1 Commits
72c3b02420
...
67845d647f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67845d647f |
@ -850,29 +850,6 @@ function FrigateCameraFeatures({
|
|||||||
}
|
}
|
||||||
}, [activeToastId, t]);
|
}, [activeToastId, t]);
|
||||||
|
|
||||||
const endEventViaBeacon = useCallback(() => {
|
|
||||||
if (!recordingEventIdRef.current) return;
|
|
||||||
|
|
||||||
const url = `${window.location.origin}/api/events/${recordingEventIdRef.current}/end`;
|
|
||||||
const payload = JSON.stringify({
|
|
||||||
end_time: Math.ceil(Date.now() / 1000),
|
|
||||||
});
|
|
||||||
|
|
||||||
// this needs to be a synchronous XMLHttpRequest to guarantee the PUT
|
|
||||||
// reaches the server before the browser kills the page
|
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
try {
|
|
||||||
xhr.open("PUT", url, false);
|
|
||||||
xhr.setRequestHeader("Content-Type", "application/json");
|
|
||||||
xhr.setRequestHeader("X-CSRF-TOKEN", "1");
|
|
||||||
xhr.setRequestHeader("X-CACHE-BYPASS", "1");
|
|
||||||
xhr.withCredentials = true;
|
|
||||||
xhr.send(payload);
|
|
||||||
} catch (e) {
|
|
||||||
// Silently ignore errors during unload
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleEventButtonClick = useCallback(() => {
|
const handleEventButtonClick = useCallback(() => {
|
||||||
if (isRecording) {
|
if (isRecording) {
|
||||||
endEvent();
|
endEvent();
|
||||||
@ -910,19 +887,8 @@ function FrigateCameraFeatures({
|
|||||||
}, [camera.name, isRestreamed, preferredLiveMode, t]);
|
}, [camera.name, isRestreamed, preferredLiveMode, t]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Handle page unload/close (browser close, tab close, refresh, navigation to external site)
|
|
||||||
const handleBeforeUnload = () => {
|
|
||||||
if (recordingEventIdRef.current) {
|
|
||||||
endEventViaBeacon();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
||||||
|
|
||||||
// ensure manual event is stopped when component unmounts
|
// ensure manual event is stopped when component unmounts
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
||||||
|
|
||||||
if (recordingEventIdRef.current) {
|
if (recordingEventIdRef.current) {
|
||||||
endEvent();
|
endEvent();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user