mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Publish finished reviews to mqtt / ws and use that for source of update banner (#10072)
* Add reviews to frontend * Update ready when new review is saved * fix * Formatting
This commit is contained in:
parent
00c2caa1b7
commit
f95ce913b1
@ -1,5 +1,6 @@
|
|||||||
"""Maintain review segments in db."""
|
"""Maintain review segments in db."""
|
||||||
|
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
@ -138,7 +139,14 @@ class ReviewSegmentMaintainer(threading.Thread):
|
|||||||
|
|
||||||
def end_segment(self, segment: PendingReviewSegment) -> None:
|
def end_segment(self, segment: PendingReviewSegment) -> None:
|
||||||
"""End segment."""
|
"""End segment."""
|
||||||
self.requestor.send_data(UPSERT_REVIEW_SEGMENT, segment.end())
|
seg_data = segment.end()
|
||||||
|
self.requestor.send_data(UPSERT_REVIEW_SEGMENT, seg_data)
|
||||||
|
self.requestor.send_data(
|
||||||
|
"reviews",
|
||||||
|
json.dumps(
|
||||||
|
{"type": "end", "review": {k.name: v for k, v in seg_data.items()}}
|
||||||
|
),
|
||||||
|
)
|
||||||
self.active_review_segments[segment.camera] = None
|
self.active_review_segments[segment.camera] = None
|
||||||
|
|
||||||
def update_existing_segment(
|
def update_existing_segment(
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
import { produce, Draft } from "immer";
|
import { produce, Draft } from "immer";
|
||||||
import useWebSocket, { ReadyState } from "react-use-websocket";
|
import useWebSocket, { ReadyState } from "react-use-websocket";
|
||||||
import { FrigateConfig } from "@/types/frigateConfig";
|
import { FrigateConfig } from "@/types/frigateConfig";
|
||||||
import { FrigateEvent, ToggleableSetting } from "@/types/ws";
|
import { FrigateEvent, FrigateReview, ToggleableSetting } from "@/types/ws";
|
||||||
import { FrigateStats } from "@/types/stats";
|
import { FrigateStats } from "@/types/stats";
|
||||||
|
|
||||||
type ReducerState = {
|
type ReducerState = {
|
||||||
@ -218,7 +218,14 @@ export function useRestart(): {
|
|||||||
export function useFrigateEvents(): { payload: FrigateEvent } {
|
export function useFrigateEvents(): { payload: FrigateEvent } {
|
||||||
const {
|
const {
|
||||||
value: { payload },
|
value: { payload },
|
||||||
} = useWs(`events`, "");
|
} = useWs("events", "");
|
||||||
|
return { payload };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useFrigateReviews(): { payload: FrigateReview } {
|
||||||
|
const {
|
||||||
|
value: { payload },
|
||||||
|
} = useWs("reviews", "");
|
||||||
return { payload };
|
return { payload };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useFrigateEvents } from "@/api/ws";
|
import { useFrigateReviews } from "@/api/ws";
|
||||||
import useApiFilter from "@/hooks/use-api-filter";
|
import useApiFilter from "@/hooks/use-api-filter";
|
||||||
import useOverlayState from "@/hooks/use-overlay-state";
|
import useOverlayState from "@/hooks/use-overlay-state";
|
||||||
import { ReviewFilter, ReviewSegment } from "@/types/review";
|
import { ReviewFilter, ReviewSegment, ReviewSeverity } from "@/types/review";
|
||||||
import DesktopEventView from "@/views/events/DesktopEventView";
|
import DesktopEventView from "@/views/events/DesktopEventView";
|
||||||
import DesktopRecordingView from "@/views/events/DesktopRecordingView";
|
import DesktopRecordingView from "@/views/events/DesktopRecordingView";
|
||||||
import MobileEventView from "@/views/events/MobileEventView";
|
import MobileEventView from "@/views/events/MobileEventView";
|
||||||
@ -15,6 +15,8 @@ const API_LIMIT = 250;
|
|||||||
|
|
||||||
export default function Events() {
|
export default function Events() {
|
||||||
// recordings viewer
|
// recordings viewer
|
||||||
|
|
||||||
|
const [severity, setSeverity] = useState<ReviewSeverity>("alert");
|
||||||
const [selectedReviewId, setSelectedReviewId] = useOverlayState("review");
|
const [selectedReviewId, setSelectedReviewId] = useOverlayState("review");
|
||||||
|
|
||||||
// review filter
|
// review filter
|
||||||
@ -97,6 +99,11 @@ export default function Events() {
|
|||||||
setSize(size + 1);
|
setSize(size + 1);
|
||||||
}, [size]);
|
}, [size]);
|
||||||
|
|
||||||
|
const reloadData = useCallback(() => {
|
||||||
|
setSize(1);
|
||||||
|
updateSegments();
|
||||||
|
}, [])
|
||||||
|
|
||||||
// preview videos
|
// preview videos
|
||||||
|
|
||||||
const previewTimes = useMemo(() => {
|
const previewTimes = useMemo(() => {
|
||||||
@ -196,22 +203,21 @@ export default function Events() {
|
|||||||
|
|
||||||
// review updates
|
// review updates
|
||||||
|
|
||||||
const { payload: eventUpdate } = useFrigateEvents();
|
const { payload: reviewUpdate } = useFrigateReviews();
|
||||||
const [hasUpdate, setHasUpdate] = useState(false);
|
const [hasUpdate, setHasUpdate] = useState(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!eventUpdate) {
|
if (!reviewUpdate || hasUpdate) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if event is ended and was saved, update events list
|
|
||||||
if (
|
if (
|
||||||
eventUpdate.type == "end" &&
|
reviewUpdate.type == "end" &&
|
||||||
(eventUpdate.after.has_clip || eventUpdate.after.has_snapshot)
|
reviewUpdate.review.severity == severity
|
||||||
) {
|
) {
|
||||||
setHasUpdate(true);
|
setHasUpdate(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, [eventUpdate]);
|
}, [reviewUpdate]);
|
||||||
|
|
||||||
if (selectedData) {
|
if (selectedData) {
|
||||||
return (
|
return (
|
||||||
@ -229,11 +235,13 @@ export default function Events() {
|
|||||||
relevantPreviews={allPreviews}
|
relevantPreviews={allPreviews}
|
||||||
reachedEnd={isDone}
|
reachedEnd={isDone}
|
||||||
isValidating={isValidating}
|
isValidating={isValidating}
|
||||||
|
severity={severity}
|
||||||
hasUpdate={hasUpdate}
|
hasUpdate={hasUpdate}
|
||||||
|
setSeverity={setSeverity}
|
||||||
setHasUpdate={setHasUpdate}
|
setHasUpdate={setHasUpdate}
|
||||||
loadNextPage={onLoadNextPage}
|
loadNextPage={onLoadNextPage}
|
||||||
markItemAsReviewed={markItemAsReviewed}
|
markItemAsReviewed={markItemAsReviewed}
|
||||||
pullLatestData={updateSegments}
|
pullLatestData={reloadData}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -246,12 +254,14 @@ export default function Events() {
|
|||||||
reachedEnd={isDone}
|
reachedEnd={isDone}
|
||||||
isValidating={isValidating}
|
isValidating={isValidating}
|
||||||
filter={reviewFilter}
|
filter={reviewFilter}
|
||||||
|
severity={severity}
|
||||||
hasUpdate={hasUpdate}
|
hasUpdate={hasUpdate}
|
||||||
|
setSeverity={setSeverity}
|
||||||
setHasUpdate={setHasUpdate}
|
setHasUpdate={setHasUpdate}
|
||||||
loadNextPage={onLoadNextPage}
|
loadNextPage={onLoadNextPage}
|
||||||
markItemAsReviewed={markItemAsReviewed}
|
markItemAsReviewed={markItemAsReviewed}
|
||||||
onSelectReview={setSelectedReviewId}
|
onSelectReview={setSelectedReviewId}
|
||||||
pullLatestData={updateSegments}
|
pullLatestData={reloadData}
|
||||||
updateFilter={onUpdateFilter}
|
updateFilter={onUpdateFilter}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { ReviewSegment } from "./review";
|
||||||
|
|
||||||
type FrigateObjectState = {
|
type FrigateObjectState = {
|
||||||
id: string;
|
id: string;
|
||||||
camera: string;
|
camera: string;
|
||||||
@ -27,6 +29,11 @@ type FrigateObjectState = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface FrigateReview {
|
||||||
|
type: "new" | "update" | "end";
|
||||||
|
review: ReviewSegment;
|
||||||
|
}
|
||||||
|
|
||||||
export interface FrigateEvent {
|
export interface FrigateEvent {
|
||||||
type: "new" | "update" | "end";
|
type: "new" | "update" | "end";
|
||||||
before: FrigateObjectState;
|
before: FrigateObjectState;
|
||||||
|
@ -18,7 +18,9 @@ type DesktopEventViewProps = {
|
|||||||
reachedEnd: boolean;
|
reachedEnd: boolean;
|
||||||
isValidating: boolean;
|
isValidating: boolean;
|
||||||
filter?: ReviewFilter;
|
filter?: ReviewFilter;
|
||||||
|
severity: ReviewSeverity;
|
||||||
hasUpdate: boolean;
|
hasUpdate: boolean;
|
||||||
|
setSeverity: (severity: ReviewSeverity) => void;
|
||||||
setHasUpdate: (hasUpdated: boolean) => void;
|
setHasUpdate: (hasUpdated: boolean) => void;
|
||||||
loadNextPage: () => void;
|
loadNextPage: () => void;
|
||||||
markItemAsReviewed: (reviewId: string) => void;
|
markItemAsReviewed: (reviewId: string) => void;
|
||||||
@ -33,7 +35,9 @@ export default function DesktopEventView({
|
|||||||
reachedEnd,
|
reachedEnd,
|
||||||
isValidating,
|
isValidating,
|
||||||
filter,
|
filter,
|
||||||
|
severity,
|
||||||
hasUpdate,
|
hasUpdate,
|
||||||
|
setSeverity,
|
||||||
setHasUpdate,
|
setHasUpdate,
|
||||||
loadNextPage,
|
loadNextPage,
|
||||||
markItemAsReviewed,
|
markItemAsReviewed,
|
||||||
@ -42,7 +46,6 @@ export default function DesktopEventView({
|
|||||||
updateFilter,
|
updateFilter,
|
||||||
}: DesktopEventViewProps) {
|
}: DesktopEventViewProps) {
|
||||||
const { data: config } = useSWR<FrigateConfig>("config");
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
const [severity, setSeverity] = useState<ReviewSeverity>("alert");
|
|
||||||
const contentRef = useRef<HTMLDivElement | null>(null);
|
const contentRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
// review paging
|
// review paging
|
||||||
|
@ -14,7 +14,9 @@ type MobileEventViewProps = {
|
|||||||
relevantPreviews?: Preview[];
|
relevantPreviews?: Preview[];
|
||||||
reachedEnd: boolean;
|
reachedEnd: boolean;
|
||||||
isValidating: boolean;
|
isValidating: boolean;
|
||||||
|
severity: ReviewSeverity;
|
||||||
hasUpdate: boolean;
|
hasUpdate: boolean;
|
||||||
|
setSeverity: (severity: ReviewSeverity) => void;
|
||||||
setHasUpdate: (hasUpdated: boolean) => void;
|
setHasUpdate: (hasUpdated: boolean) => void;
|
||||||
loadNextPage: () => void;
|
loadNextPage: () => void;
|
||||||
markItemAsReviewed: (reviewId: string) => void;
|
markItemAsReviewed: (reviewId: string) => void;
|
||||||
@ -25,14 +27,15 @@ export default function MobileEventView({
|
|||||||
relevantPreviews,
|
relevantPreviews,
|
||||||
reachedEnd,
|
reachedEnd,
|
||||||
isValidating,
|
isValidating,
|
||||||
|
severity,
|
||||||
hasUpdate,
|
hasUpdate,
|
||||||
|
setSeverity,
|
||||||
setHasUpdate,
|
setHasUpdate,
|
||||||
loadNextPage,
|
loadNextPage,
|
||||||
markItemAsReviewed,
|
markItemAsReviewed,
|
||||||
pullLatestData,
|
pullLatestData,
|
||||||
}: MobileEventViewProps) {
|
}: MobileEventViewProps) {
|
||||||
const { data: config } = useSWR<FrigateConfig>("config");
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
const [severity, setSeverity] = useState<ReviewSeverity>("alert");
|
|
||||||
const contentRef = useRef<HTMLDivElement | null>(null);
|
const contentRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
// review paging
|
// review paging
|
||||||
|
Loading…
Reference in New Issue
Block a user