mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-10 13:15:25 +03:00
Cleanup visibility listener
This commit is contained in:
parent
ff849b6f7d
commit
a13388c507
@ -246,19 +246,27 @@ function MSEPlayer({
|
||||
// check visibility
|
||||
|
||||
useEffect(() => {
|
||||
if (!playbackEnabled) {
|
||||
if (!playbackEnabled || !visibilityCheck) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ("hidden" in document && visibilityCheck) {
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (document.hidden) {
|
||||
onDisconnect();
|
||||
} else if (videoRef.current?.isConnected) {
|
||||
onConnect();
|
||||
}
|
||||
});
|
||||
if (!("hidden" in document)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const listener = () => {
|
||||
if (document.hidden) {
|
||||
onDisconnect();
|
||||
} else if (videoRef.current?.isConnected) {
|
||||
onConnect();
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener("visibilitychange", listener);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("visibilitychange", listener);
|
||||
};
|
||||
}, [playbackEnabled, visibilityCheck, onConnect, onDisconnect]);
|
||||
|
||||
// control pip
|
||||
|
||||
Loading…
Reference in New Issue
Block a user