mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-12-23 19:11:14 +01:00
Preview fixes (#13193)
* Handle case where preview was saved late * fix timing
This commit is contained in:
parent
8e31244fb3
commit
38a8d34ba5
@ -16,6 +16,7 @@ import { isAndroid, isChrome, isMobile } from "react-device-detect";
|
||||
import { TimeRange } from "@/types/timeline";
|
||||
import { Skeleton } from "../ui/skeleton";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { usePreviewForTimeRange } from "@/hooks/use-camera-previews";
|
||||
|
||||
type PreviewPlayerProps = {
|
||||
className?: string;
|
||||
@ -39,15 +40,11 @@ export default function PreviewPlayer({
|
||||
onClick,
|
||||
}: PreviewPlayerProps) {
|
||||
const [currentHourFrame, setCurrentHourFrame] = useState<string>();
|
||||
|
||||
const currentPreview = useMemo(() => {
|
||||
return cameraPreviews.find(
|
||||
(preview) =>
|
||||
preview.camera == camera &&
|
||||
Math.round(preview.start) >= timeRange.after &&
|
||||
Math.floor(preview.end) <= timeRange.before,
|
||||
);
|
||||
}, [cameraPreviews, camera, timeRange]);
|
||||
const currentPreview = usePreviewForTimeRange(
|
||||
cameraPreviews,
|
||||
camera,
|
||||
timeRange,
|
||||
);
|
||||
|
||||
if (currentPreview) {
|
||||
return (
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Preview } from "@/types/preview";
|
||||
import { TimeRange } from "@/types/timeline";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import useSWR from "swr";
|
||||
|
||||
type OptionalCameraPreviewProps = {
|
||||
@ -8,7 +8,6 @@ type OptionalCameraPreviewProps = {
|
||||
autoRefresh?: boolean;
|
||||
fetchPreviews?: boolean;
|
||||
};
|
||||
|
||||
export function useCameraPreviews(
|
||||
initialTimeRange: TimeRange,
|
||||
{
|
||||
@ -32,3 +31,24 @@ export function useCameraPreviews(
|
||||
|
||||
return allPreviews;
|
||||
}
|
||||
|
||||
// we need to add a buffer of 5 seconds to the end preview times
|
||||
// this ensures that if preview generation is running slowly
|
||||
// and the previews are generated 1-5 seconds late
|
||||
// it is not falsely thrown out.
|
||||
const PREVIEW_END_BUFFER = 5; // seconds
|
||||
|
||||
export function usePreviewForTimeRange(
|
||||
allPreviews: Preview[],
|
||||
camera: string,
|
||||
timeRange: TimeRange,
|
||||
) {
|
||||
return useMemo(() => {
|
||||
return allPreviews.find(
|
||||
(preview) =>
|
||||
preview.camera == camera &&
|
||||
Math.ceil(preview.start) >= timeRange.after &&
|
||||
Math.floor(preview.end) <= timeRange.before + PREVIEW_END_BUFFER,
|
||||
);
|
||||
}, [allPreviews, camera, timeRange]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user