From ff57e4daff6a40b0fb3d2a0021eff1e6e5772568 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sun, 26 May 2024 13:56:33 -0600 Subject: [PATCH] Show camera name when camera is offline --- web/src/components/player/LivePlayer.tsx | 15 +++++++++++---- web/src/hooks/use-camera-activity.ts | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/web/src/components/player/LivePlayer.tsx b/web/src/components/player/LivePlayer.tsx index 52323a4ba..a57c697d4 100644 --- a/web/src/components/player/LivePlayer.tsx +++ b/web/src/components/player/LivePlayer.tsx @@ -46,7 +46,7 @@ export default function LivePlayer({ }: LivePlayerProps) { // camera activity - const { activeMotion, activeTracking, objects } = + const { activeMotion, activeTracking, objects, offline } = useCameraActivity(cameraConfig); const cameraActive = useMemo( @@ -224,9 +224,16 @@ export default function LivePlayer({ /> -
- {activeMotion && ( - +
+ {!offline && activeMotion && ( + + )} + {offline && ( + + {cameraConfig.name.replaceAll("_", " ")} + )}
diff --git a/web/src/hooks/use-camera-activity.ts b/web/src/hooks/use-camera-activity.ts index 82cda969a..582b0f2f1 100644 --- a/web/src/hooks/use-camera-activity.ts +++ b/web/src/hooks/use-camera-activity.ts @@ -1,5 +1,6 @@ import { useFrigateEvents, + useFrigateStats, useInitialCameraState, useMotionActivity, } from "@/api/ws"; @@ -10,11 +11,13 @@ import { useTimelineUtils } from "./use-timeline-utils"; import { ObjectType } from "@/types/ws"; import useDeepMemo from "./use-deep-memo"; import { isEqual } from "lodash"; +import useStats from "./use-stats"; type useCameraActivityReturn = { activeTracking: boolean; activeMotion: boolean; objects: ObjectType[]; + offline: boolean; }; export function useCameraActivity( @@ -116,12 +119,31 @@ export function useCameraActivity( handleSetObjects(newObjects); }, [camera, updatedEvent, objects, handleSetObjects]); + // determine if camera is offline + + const { payload: frigateStats } = useFrigateStats(); + + const offline = useMemo(() => { + if (!frigateStats) { + return false; + } + + const cameras = frigateStats["cameras"]; + + if (!cameras) { + return false; + } + + return cameras[camera.name].camera_fps == 0; + }, [camera, frigateStats]); + return { activeTracking: hasActiveObjects, activeMotion: detectingMotion ? detectingMotion === "ON" : initialCameraState?.motion === true, objects, + offline, }; }