mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-25 08:07:41 +03:00
frontend websocket hooks
This commit is contained in:
parent
0c7acdf09e
commit
09082f4067
@ -10,6 +10,7 @@ import {
|
|||||||
ToggleableSetting,
|
ToggleableSetting,
|
||||||
TrackedObjectUpdateReturnType,
|
TrackedObjectUpdateReturnType,
|
||||||
TriggerStatus,
|
TriggerStatus,
|
||||||
|
FrigateAudioDetections,
|
||||||
} from "@/types/ws";
|
} from "@/types/ws";
|
||||||
import { FrigateStats } from "@/types/stats";
|
import { FrigateStats } from "@/types/stats";
|
||||||
import { createContainer } from "react-tracked";
|
import { createContainer } from "react-tracked";
|
||||||
@ -341,6 +342,13 @@ export function useFrigateEvents(): { payload: FrigateEvent } {
|
|||||||
return { payload: JSON.parse(payload as string) };
|
return { payload: JSON.parse(payload as string) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useAudioDetections(): { payload: FrigateAudioDetections } {
|
||||||
|
const {
|
||||||
|
value: { payload },
|
||||||
|
} = useWs("audio_detections", "");
|
||||||
|
return { payload: JSON.parse(payload as string) };
|
||||||
|
}
|
||||||
|
|
||||||
export function useFrigateReviews(): FrigateReview {
|
export function useFrigateReviews(): FrigateReview {
|
||||||
const {
|
const {
|
||||||
value: { payload },
|
value: { payload },
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
useAudioDetections,
|
||||||
useEnabledState,
|
useEnabledState,
|
||||||
useFrigateEvents,
|
useFrigateEvents,
|
||||||
useInitialCameraState,
|
useInitialCameraState,
|
||||||
@ -8,7 +9,7 @@ import { CameraConfig, FrigateConfig } from "@/types/frigateConfig";
|
|||||||
import { MotionData, ReviewSegment } from "@/types/review";
|
import { MotionData, ReviewSegment } from "@/types/review";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { useTimelineUtils } from "./use-timeline-utils";
|
import { useTimelineUtils } from "./use-timeline-utils";
|
||||||
import { ObjectType } from "@/types/ws";
|
import { AudioDetection, ObjectType } from "@/types/ws";
|
||||||
import useDeepMemo from "./use-deep-memo";
|
import useDeepMemo from "./use-deep-memo";
|
||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
import { useAutoFrigateStats } from "./use-stats";
|
import { useAutoFrigateStats } from "./use-stats";
|
||||||
@ -20,6 +21,7 @@ type useCameraActivityReturn = {
|
|||||||
activeTracking: boolean;
|
activeTracking: boolean;
|
||||||
activeMotion: boolean;
|
activeMotion: boolean;
|
||||||
objects: ObjectType[];
|
objects: ObjectType[];
|
||||||
|
audio_detections: AudioDetection[];
|
||||||
offline: boolean;
|
offline: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -38,6 +40,9 @@ export function useCameraActivity(
|
|||||||
return getAttributeLabels(config);
|
return getAttributeLabels(config);
|
||||||
}, [config]);
|
}, [config]);
|
||||||
const [objects, setObjects] = useState<ObjectType[] | undefined>([]);
|
const [objects, setObjects] = useState<ObjectType[] | undefined>([]);
|
||||||
|
const [audioDetections, setAudioDetections] = useState<
|
||||||
|
AudioDetection[] | undefined
|
||||||
|
>([]);
|
||||||
|
|
||||||
// init camera activity
|
// init camera activity
|
||||||
|
|
||||||
@ -51,6 +56,15 @@ export function useCameraActivity(
|
|||||||
}
|
}
|
||||||
}, [updatedCameraState, camera]);
|
}, [updatedCameraState, camera]);
|
||||||
|
|
||||||
|
const { payload: updatedAudioState } = useAudioDetections();
|
||||||
|
const memoizedAudioState = useDeepMemo(updatedAudioState);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (memoizedAudioState) {
|
||||||
|
setAudioDetections(memoizedAudioState[camera.name]);
|
||||||
|
}
|
||||||
|
}, [memoizedAudioState, camera]);
|
||||||
|
|
||||||
// handle camera activity
|
// handle camera activity
|
||||||
|
|
||||||
const hasActiveObjects = useMemo(
|
const hasActiveObjects = useMemo(
|
||||||
@ -160,6 +174,7 @@ export function useCameraActivity(
|
|||||||
: updatedCameraState?.motion === true
|
: updatedCameraState?.motion === true
|
||||||
: false,
|
: false,
|
||||||
objects: isCameraEnabled ? (objects ?? []) : [],
|
objects: isCameraEnabled ? (objects ?? []) : [],
|
||||||
|
audio_detections: isCameraEnabled ? (audioDetections ?? []) : [],
|
||||||
offline,
|
offline,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,6 +51,12 @@ export type ObjectType = {
|
|||||||
sub_label: string;
|
sub_label: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type AudioDetection = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
score: number;
|
||||||
|
};
|
||||||
|
|
||||||
export interface FrigateCameraState {
|
export interface FrigateCameraState {
|
||||||
config: {
|
config: {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
@ -69,6 +75,10 @@ export interface FrigateCameraState {
|
|||||||
};
|
};
|
||||||
motion: boolean;
|
motion: boolean;
|
||||||
objects: ObjectType[];
|
objects: ObjectType[];
|
||||||
|
audio_detections: AudioDetection[];
|
||||||
|
}
|
||||||
|
export interface FrigateAudioDetections {
|
||||||
|
[camera: string]: AudioDetection[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ModelState =
|
export type ModelState =
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user