mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 12:15:25 +03:00
Add chips for activity on cameras
This commit is contained in:
parent
ae51db8ffe
commit
5976de8324
@ -228,7 +228,7 @@ export function useMotionActivity(camera: string): { payload: string } {
|
|||||||
return { payload };
|
return { payload };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAudioActivity(camera: string): { payload: string } {
|
export function useAudioActivity(camera: string): { payload: number } {
|
||||||
const {
|
const {
|
||||||
value: { payload },
|
value: { payload },
|
||||||
} = useWs(`${camera}/audio/rms`, "");
|
} = useWs(`${camera}/audio/rms`, "");
|
||||||
|
|||||||
@ -108,7 +108,7 @@ export default function DynamicCameraImage({
|
|||||||
{camera.audio.enabled_in_config && (
|
{camera.audio.enabled_in_config && (
|
||||||
<LuEar
|
<LuEar
|
||||||
className={`${
|
className={`${
|
||||||
parseInt(audioRms) >= camera.audio.min_volume
|
audioRms >= camera.audio.min_volume
|
||||||
? "text-audio"
|
? "text-audio"
|
||||||
: "text-gray-600"
|
: "text-gray-600"
|
||||||
}`}
|
}`}
|
||||||
|
|||||||
@ -11,8 +11,10 @@ import { Label } from "../ui/label";
|
|||||||
import { usePersistence } from "@/hooks/use-persistence";
|
import { usePersistence } from "@/hooks/use-persistence";
|
||||||
import MSEPlayer from "./MsePlayer";
|
import MSEPlayer from "./MsePlayer";
|
||||||
import JSMpegPlayer from "./JSMpegPlayer";
|
import JSMpegPlayer from "./JSMpegPlayer";
|
||||||
import { MdCircle } from "react-icons/md";
|
import { MdCircle, MdLeakAdd, MdSelectAll } from "react-icons/md";
|
||||||
|
import { BsSoundwave } from "react-icons/bs";
|
||||||
import Chip from "../Chip";
|
import Chip from "../Chip";
|
||||||
|
import useCameraActivity from "@/hooks/use-camera-activity";
|
||||||
|
|
||||||
const emptyObject = Object.freeze({});
|
const emptyObject = Object.freeze({});
|
||||||
|
|
||||||
@ -20,6 +22,7 @@ type LivePlayerProps = {
|
|||||||
className?: string;
|
className?: string;
|
||||||
cameraConfig: CameraConfig;
|
cameraConfig: CameraConfig;
|
||||||
liveMode?: "webrtc" | "mse" | "jsmpeg" | "debug";
|
liveMode?: "webrtc" | "mse" | "jsmpeg" | "debug";
|
||||||
|
liveChips?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Options = { [key: string]: boolean };
|
type Options = { [key: string]: boolean };
|
||||||
@ -28,14 +31,19 @@ export default function LivePlayer({
|
|||||||
className,
|
className,
|
||||||
cameraConfig,
|
cameraConfig,
|
||||||
liveMode = "mse",
|
liveMode = "mse",
|
||||||
|
liveChips = false,
|
||||||
}: LivePlayerProps) {
|
}: LivePlayerProps) {
|
||||||
const [showSettings, setShowSettings] = useState(false);
|
// camera activity
|
||||||
|
const { activeMotion, activeAudio, activeTracking } =
|
||||||
|
useCameraActivity(cameraConfig);
|
||||||
|
|
||||||
|
// debug view settings
|
||||||
|
|
||||||
|
const [showSettings, setShowSettings] = useState(false);
|
||||||
const [options, setOptions] = usePersistence(
|
const [options, setOptions] = usePersistence(
|
||||||
`${cameraConfig?.name}-feed`,
|
`${cameraConfig?.name}-feed`,
|
||||||
emptyObject
|
emptyObject
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSetOption = useCallback(
|
const handleSetOption = useCallback(
|
||||||
(id: string, value: boolean) => {
|
(id: string, value: boolean) => {
|
||||||
const newOptions = { ...options, [id]: value };
|
const newOptions = { ...options, [id]: value };
|
||||||
@ -43,7 +51,6 @@ export default function LivePlayer({
|
|||||||
},
|
},
|
||||||
[options, setOptions]
|
[options, setOptions]
|
||||||
);
|
);
|
||||||
|
|
||||||
const searchParams = useMemo(
|
const searchParams = useMemo(
|
||||||
() =>
|
() =>
|
||||||
new URLSearchParams(
|
new URLSearchParams(
|
||||||
@ -55,7 +62,6 @@ export default function LivePlayer({
|
|||||||
),
|
),
|
||||||
[options]
|
[options]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleToggleSettings = useCallback(() => {
|
const handleToggleSettings = useCallback(() => {
|
||||||
setShowSettings(!showSettings);
|
setShowSettings(!showSettings);
|
||||||
}, [showSettings, setShowSettings]);
|
}, [showSettings, setShowSettings]);
|
||||||
@ -126,6 +132,30 @@ export default function LivePlayer({
|
|||||||
return (
|
return (
|
||||||
<div className={`relative flex justify-center ${className}`}>
|
<div className={`relative flex justify-center ${className}`}>
|
||||||
{player}
|
{player}
|
||||||
|
<div className="absolute flex left-2 top-2 gap-2">
|
||||||
|
<Chip className="bg-gray-500 bg-gradient-to-br">
|
||||||
|
<MdLeakAdd
|
||||||
|
className={`w-4 h-4 ${activeMotion ? "text-motion" : "text-white"}`}
|
||||||
|
/>
|
||||||
|
<div className="ml-1 capitalize text-white text-xs">Motion</div>
|
||||||
|
</Chip>
|
||||||
|
{cameraConfig.audio.enabled_in_config && (
|
||||||
|
<Chip className="bg-gray-500 bg-gradient-to-br">
|
||||||
|
<BsSoundwave
|
||||||
|
className={`w-4 h-4 ${activeAudio ? "text-audio" : "text-white"}`}
|
||||||
|
/>
|
||||||
|
<div className="ml-1 capitalize text-white text-xs">Sound</div>
|
||||||
|
</Chip>
|
||||||
|
)}
|
||||||
|
<Chip className="bg-gray-500 bg-gradient-to-br">
|
||||||
|
<MdSelectAll
|
||||||
|
className={`w-4 h-4 ${
|
||||||
|
activeTracking ? "text-object" : "text-white"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
<div className="ml-1 capitalize text-white text-xs">Tracking</div>
|
||||||
|
</Chip>
|
||||||
|
</div>
|
||||||
<Chip className="absolute right-2 top-2 bg-gray-500 bg-gradient-to-br">
|
<Chip className="absolute right-2 top-2 bg-gray-500 bg-gradient-to-br">
|
||||||
<MdCircle className="w-2 h-2 text-danger" />
|
<MdCircle className="w-2 h-2 text-danger" />
|
||||||
<div className="ml-1 capitalize text-white text-xs">
|
<div className="ml-1 capitalize text-white text-xs">
|
||||||
|
|||||||
64
web/src/hooks/use-camera-activity.ts
Normal file
64
web/src/hooks/use-camera-activity.ts
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import {
|
||||||
|
useAudioActivity,
|
||||||
|
useFrigateEvents,
|
||||||
|
useMotionActivity,
|
||||||
|
} from "@/api/ws";
|
||||||
|
import { CameraConfig } from "@/types/frigateConfig";
|
||||||
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
|
||||||
|
type useCameraActivityReturn = {
|
||||||
|
activeTracking: boolean;
|
||||||
|
activeMotion: boolean;
|
||||||
|
activeAudio: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function useCameraActivity(
|
||||||
|
camera: CameraConfig
|
||||||
|
): useCameraActivityReturn {
|
||||||
|
const [activeObjects, setActiveObjects] = useState<string[]>([]);
|
||||||
|
const hasActiveObjects = useMemo(
|
||||||
|
() => activeObjects.length > 0,
|
||||||
|
[activeObjects]
|
||||||
|
);
|
||||||
|
|
||||||
|
const { payload: detectingMotion } = useMotionActivity(camera.name);
|
||||||
|
const { payload: event } = useFrigateEvents();
|
||||||
|
const { payload: audioRms } = useAudioActivity(camera.name);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!event) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.after.camera != camera.name) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type == "end") {
|
||||||
|
const eventIndex = activeObjects.indexOf(event.after.id);
|
||||||
|
|
||||||
|
if (eventIndex != -1) {
|
||||||
|
const newActiveObjects = [...activeObjects];
|
||||||
|
newActiveObjects.splice(eventIndex, 1);
|
||||||
|
setActiveObjects(newActiveObjects);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!event.after.stationary) {
|
||||||
|
const eventIndex = activeObjects.indexOf(event.after.id);
|
||||||
|
|
||||||
|
if (eventIndex == -1) {
|
||||||
|
const newActiveObjects = [...activeObjects, event.after.id];
|
||||||
|
setActiveObjects(newActiveObjects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [event, activeObjects]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
activeTracking: hasActiveObjects,
|
||||||
|
activeMotion: detectingMotion == "ON",
|
||||||
|
activeAudio: camera.audio.enabled_in_config
|
||||||
|
? audioRms >= camera.audio.min_volume
|
||||||
|
: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -87,6 +87,7 @@ function Live() {
|
|||||||
key={camera.name}
|
key={camera.name}
|
||||||
className={`rounded-2xl bg-black ${grow}`}
|
className={`rounded-2xl bg-black ${grow}`}
|
||||||
cameraConfig={camera}
|
cameraConfig={camera}
|
||||||
|
liveChips
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user