mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-09 04:35:25 +03:00
Only show live cameras that are currently visible
This commit is contained in:
parent
51db63e42b
commit
675ea1e55b
@ -14,6 +14,7 @@ import { isDesktop } from "react-device-detect";
|
||||
import CameraActivityIndicator from "../indicators/CameraActivityIndicator";
|
||||
|
||||
type LivePlayerProps = {
|
||||
cameraRef?: (ref: HTMLDivElement | null) => void;
|
||||
className?: string;
|
||||
cameraConfig: CameraConfig;
|
||||
preferredLiveMode?: LivePlayerMode;
|
||||
@ -26,6 +27,7 @@ type LivePlayerProps = {
|
||||
};
|
||||
|
||||
export default function LivePlayer({
|
||||
cameraRef = undefined,
|
||||
className,
|
||||
cameraConfig,
|
||||
preferredLiveMode,
|
||||
@ -140,6 +142,8 @@ export default function LivePlayer({
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={cameraRef}
|
||||
data-camera={cameraConfig.name}
|
||||
className={`relative flex justify-center ${liveMode == "jsmpeg" ? "size-full" : "w-full"} outline cursor-pointer ${
|
||||
activeTracking
|
||||
? "outline-severity_alert outline-3 rounded-2xl shadow-severity_alert"
|
||||
@ -171,13 +175,11 @@ export default function LivePlayer({
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isDesktop && (
|
||||
<div className="absolute right-2 top-2 size-4">
|
||||
{recording == "ON" && (
|
||||
<MdCircle className="size-2 drop-shadow-md shadow-danger text-danger animate-pulse" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="absolute right-2 top-2 size-4">
|
||||
{recording == "ON" && (
|
||||
<MdCircle className="size-2 drop-shadow-md shadow-danger text-danger animate-pulse" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { usePersistence } from "@/hooks/use-persistence";
|
||||
import { CameraConfig, FrigateConfig } from "@/types/frigateConfig";
|
||||
import { ReviewSegment } from "@/types/review";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { isDesktop, isMobile, isSafari } from "react-device-detect";
|
||||
import useSWR from "swr";
|
||||
|
||||
@ -79,6 +79,53 @@ export default function LiveDashboardView({
|
||||
};
|
||||
}, [visibilityListener]);
|
||||
|
||||
const [visibleCameras, setVisibleCameras] = useState<string[]>([]);
|
||||
const visibleCameraObserver = useRef<IntersectionObserver | null>(null);
|
||||
useEffect(() => {
|
||||
const visibleCameras = new Set<string>();
|
||||
visibleCameraObserver.current = new IntersectionObserver(
|
||||
(entries) => {
|
||||
entries.forEach((entry) => {
|
||||
const camera = (entry.target as HTMLElement).dataset.camera;
|
||||
|
||||
if (!camera) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry.isIntersecting) {
|
||||
visibleCameras.add(camera);
|
||||
} else {
|
||||
visibleCameras.delete(camera);
|
||||
}
|
||||
|
||||
setVisibleCameras([...visibleCameras]);
|
||||
});
|
||||
},
|
||||
{ threshold: 0.5 },
|
||||
);
|
||||
|
||||
return () => {
|
||||
visibleCameraObserver.current?.disconnect();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const cameraRef = useCallback(
|
||||
(node: HTMLElement | null) => {
|
||||
if (!visibleCameraObserver.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (node) visibleCameraObserver.current.observe(node);
|
||||
} catch (e) {
|
||||
// no op
|
||||
}
|
||||
},
|
||||
// we need to listen on the value of the ref
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[visibleCameraObserver.current],
|
||||
);
|
||||
|
||||
const birdseyeConfig = useMemo(() => config?.birdseye, [config]);
|
||||
|
||||
return (
|
||||
@ -149,9 +196,12 @@ export default function LiveDashboardView({
|
||||
}
|
||||
return (
|
||||
<LivePlayer
|
||||
cameraRef={cameraRef}
|
||||
key={camera.name}
|
||||
className={grow}
|
||||
windowVisible={windowVisible}
|
||||
windowVisible={
|
||||
windowVisible && visibleCameras.includes(camera.name)
|
||||
}
|
||||
cameraConfig={camera}
|
||||
preferredLiveMode={isSafari ? "webrtc" : "mse"}
|
||||
onClick={() => onSelectCamera(camera.name)}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user