mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 20:25:26 +03:00
Don't show live view when window is not visible
This commit is contained in:
parent
8f863e1442
commit
2be7576421
@ -26,6 +26,7 @@ type LivePlayerProps = {
|
||||
cameraConfig: CameraConfig;
|
||||
preferredLiveMode?: LivePlayerMode;
|
||||
showStillWithoutActivity?: boolean;
|
||||
windowVisible?: boolean;
|
||||
};
|
||||
|
||||
type Options = { [key: string]: boolean };
|
||||
@ -35,14 +36,15 @@ export default function LivePlayer({
|
||||
cameraConfig,
|
||||
preferredLiveMode,
|
||||
showStillWithoutActivity = true,
|
||||
windowVisible = true,
|
||||
}: LivePlayerProps) {
|
||||
// camera activity
|
||||
const { activeMotion, activeAudio, activeTracking } =
|
||||
useCameraActivity(cameraConfig);
|
||||
|
||||
const cameraActive = useMemo(
|
||||
() => activeMotion || activeTracking,
|
||||
[activeMotion, activeTracking]
|
||||
() => windowVisible && (activeMotion || activeTracking),
|
||||
[activeMotion, activeTracking, windowVisible]
|
||||
);
|
||||
const liveMode = useCameraLiveMode(cameraConfig, preferredLiveMode);
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { Event as FrigateEvent } from "@/types/event";
|
||||
import { FrigateConfig } from "@/types/frigateConfig";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import useSWR from "swr";
|
||||
|
||||
function Live() {
|
||||
@ -64,6 +64,19 @@ function Live() {
|
||||
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
||||
}, [config]);
|
||||
|
||||
const [windowVisible, setWindowVisible] = useState(false);
|
||||
const visibilityListener = useCallback(() => {
|
||||
setWindowVisible(document.visibilityState == "visible");
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
addEventListener("visibilitychange", visibilityListener);
|
||||
|
||||
return () => {
|
||||
removeEventListener("visibilitychange", visibilityListener);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{events && events.length > 0 && (
|
||||
@ -94,6 +107,7 @@ function Live() {
|
||||
<LivePlayer
|
||||
key={camera.name}
|
||||
className={`mb-2 md:mb-0 rounded-2xl bg-black ${grow}`}
|
||||
windowVisible={windowVisible}
|
||||
cameraConfig={camera}
|
||||
preferredLiveMode="mse"
|
||||
/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user