frontend websocket

This commit is contained in:
Josh Hawkins 2025-05-26 07:23:51 -05:00
parent 21f4c52f35
commit b9627cbff6
2 changed files with 45 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import {
FrigateReview,
ModelState,
ToggleableSetting,
TrackedObjectUpdateReturnType,
} from "@/types/ws";
import { FrigateStats } from "@/types/stats";
import { createContainer } from "react-tracked";
@ -60,6 +61,7 @@ function useValue(): useValueReturn {
enabled,
snapshots,
audio,
audio_transcription,
notifications,
notifications_suspended,
autotracking,
@ -71,6 +73,9 @@ function useValue(): useValueReturn {
cameraStates[`${name}/detect/state`] = detect ? "ON" : "OFF";
cameraStates[`${name}/snapshots/state`] = snapshots ? "ON" : "OFF";
cameraStates[`${name}/audio/state`] = audio ? "ON" : "OFF";
cameraStates[`${name}/audio_transcription/state`] = audio_transcription
? "ON"
: "OFF";
cameraStates[`${name}/notifications/state`] = notifications
? "ON"
: "OFF";
@ -220,6 +225,20 @@ export function useAudioState(camera: string): {
return { payload: payload as ToggleableSetting, send };
}
export function useAudioTranscriptionState(camera: string): {
payload: ToggleableSetting;
send: (payload: ToggleableSetting, retain?: boolean) => void;
} {
const {
value: { payload },
send,
} = useWs(
`${camera}/audio_transcription/state`,
`${camera}/audio_transcription/set`,
);
return { payload: payload as ToggleableSetting, send };
}
export function useAutotrackingState(camera: string): {
payload: ToggleableSetting;
send: (payload: ToggleableSetting, retain?: boolean) => void;
@ -463,11 +482,16 @@ export function useImproveContrast(camera: string): {
return { payload: payload as ToggleableSetting, send };
}
export function useTrackedObjectUpdate(): { payload: string } {
export function useTrackedObjectUpdate(): {
payload: TrackedObjectUpdateReturnType;
} {
const {
value: { payload },
} = useWs("tracked_object_update", "");
return useDeepMemo(JSON.parse(payload as string));
const parsed = payload
? JSON.parse(payload as string)
: { type: "", id: "", camera: "" };
return { payload: useDeepMemo(parsed) };
}
export function useNotifications(camera: string): {

View File

@ -58,6 +58,7 @@ export interface FrigateCameraState {
snapshots: boolean;
record: boolean;
audio: boolean;
audio_transcription: boolean;
notifications: boolean;
notifications_suspended: number;
autotracking: boolean;
@ -84,3 +85,21 @@ export type EmbeddingsReindexProgressType = {
};
export type ToggleableSetting = "ON" | "OFF";
export type TrackedObjectUpdateType =
| "description"
| "lpr"
| "transcription"
| "face";
export type TrackedObjectUpdateReturnType = {
type: TrackedObjectUpdateType;
id: string;
camera: string;
description?: string;
name?: string;
plate?: string;
score?: number;
timestamp?: number;
text?: string;
} | null;