mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-09-26 19:41:29 +08:00

* initial working konva * working multi polygons * multi zones * clean up * new zone dialog * clean up * relative coordinates and colors * fix color order * better motion tuner * objects for zones * progress * merge dev * edit pane * motion and object masks * filtering * add objects and unsaved to type * motion tuner, edit controls, tooltips * object and motion edit panes * polygon item component, switch color, object form, hover cards * working zone edit pane * working motion masks * object masks and deletion of all types * use FilterSwitch * motion tuner fixes and tweaks * clean up * tweaks * spaces in camera name * tweaks * allow dragging of points while drawing polygon * turn off editing mode when switching camera * limit interpolated coordinates and use crosshair cursor * padding * fix tooltip trigger for icons * konva tweaks * consolidate * fix top menu items on mobile
79 lines
1.8 KiB
TypeScript
79 lines
1.8 KiB
TypeScript
import { useCallback, useEffect, useState } from "react";
|
|
import CameraImage from "./CameraImage";
|
|
|
|
type AutoUpdatingCameraImageProps = {
|
|
camera: string;
|
|
searchParams?: URLSearchParams;
|
|
showFps?: boolean;
|
|
className?: string;
|
|
cameraClasses?: string;
|
|
reloadInterval?: number;
|
|
};
|
|
|
|
const MIN_LOAD_TIMEOUT_MS = 200;
|
|
|
|
export default function AutoUpdatingCameraImage({
|
|
camera,
|
|
searchParams = undefined,
|
|
showFps = true,
|
|
className,
|
|
cameraClasses,
|
|
reloadInterval = MIN_LOAD_TIMEOUT_MS,
|
|
}: AutoUpdatingCameraImageProps) {
|
|
const [key, setKey] = useState(Date.now());
|
|
const [fps, setFps] = useState<string>("0");
|
|
const [timeoutId, setTimeoutId] = useState<NodeJS.Timeout>();
|
|
|
|
useEffect(() => {
|
|
if (reloadInterval == -1) {
|
|
return;
|
|
}
|
|
|
|
setKey(Date.now());
|
|
|
|
return () => {
|
|
if (timeoutId) {
|
|
clearTimeout(timeoutId);
|
|
setTimeoutId(undefined);
|
|
}
|
|
};
|
|
// we know that these deps are correct
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [reloadInterval]);
|
|
|
|
const handleLoad = useCallback(() => {
|
|
if (reloadInterval == -1) {
|
|
return;
|
|
}
|
|
|
|
const loadTime = Date.now() - key;
|
|
|
|
if (showFps) {
|
|
setFps((1000 / Math.max(loadTime, reloadInterval)).toFixed(1));
|
|
}
|
|
|
|
setTimeoutId(
|
|
setTimeout(
|
|
() => {
|
|
setKey(Date.now());
|
|
},
|
|
loadTime > reloadInterval ? 1 : reloadInterval,
|
|
),
|
|
);
|
|
// we know that these deps are correct
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [key, setFps]);
|
|
|
|
return (
|
|
<div className={className}>
|
|
<CameraImage
|
|
camera={camera}
|
|
onload={handleLoad}
|
|
searchParams={`cache=${key}&${searchParams}`}
|
|
className={cameraClasses}
|
|
/>
|
|
{showFps ? <span className="text-xs">Displaying at {fps}fps</span> : null}
|
|
</div>
|
|
);
|
|
}
|