NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Handle case where preview doesn't automatically changeover (#11583)
Nicolas Mowen6913cc6abcdc
diff --git a/web/src/components/player/PreviewPlayer.tsx b/web/src/components/player/PreviewPlayer.tsxindex a5f3f771c6..9275101b8d 100644--- a/web/src/components/player/PreviewPlayer.tsx+++ b/web/src/components/player/PreviewPlayer.tsx@@ -197,6 +197,7 @@ function PreviewVideoPlayer({const canvasRef = useRef<HTMLCanvasElement | null>(null);const [videoSize, setVideoSize] = useState<number[]>([0, 0]);+ const [changeoverTimeout, setChangeoverTimeout] = useState<NodeJS.Timeout>();const changeSource = useCallback((newPreview: Preview | undefined, video: HTMLVideoElement | null) => {@@ -220,6 +221,15 @@ function PreviewVideoPlayer({}setCurrentPreview(newPreview);+ const timeout = setTimeout(() => {+ if (timeout) {+ clearTimeout(timeout);+ setChangeoverTimeout(undefined);+ }++ previewRef.current?.load();+ }, 1000);+ setChangeoverTimeout(timeout);// we only want this to change when current preview changes// eslint-disable-next-line react-hooks/exhaustive-deps@@ -243,6 +253,7 @@ function PreviewVideoPlayer({);if (preview != currentPreview) {+ controller.newPreviewLoaded = false;changeSource(preview, previewRef.current);}@@ -267,7 +278,14 @@ function PreviewVideoPlayer({<imgclassName={`absolute size-full object-contain ${currentHourFrame ? "visible" : "invisible"}`}src={currentHourFrame}- onLoad={() => previewRef.current?.load()}+ onLoad={() => {+ if (changeoverTimeout) {+ clearTimeout(changeoverTimeout);+ setChangeoverTimeout(undefined);+ }++ previewRef.current?.load();+ }}/><videoref={previewRef}@@ -327,6 +345,7 @@ class PreviewVideoController extends PreviewController {private preview: Preview | undefined = undefined;private timeToSeek: number | undefined = undefined;public scrubbing = false;+ public newPreviewLoaded = true;private seeking = false;constructor(@@ -345,7 +364,12 @@ class PreviewVideoController extends PreviewController {}override scrubToTimestamp(time: number): boolean {- if (!this.previewRef.current || !this.preview || !this.timeRange) {+ if (+ !this.newPreviewLoaded ||+ !this.previewRef.current ||+ !this.preview ||+ !this.timeRange+ ) {return false;}@@ -396,6 +420,7 @@ class PreviewVideoController extends PreviewController {}previewReady() {+ this.newPreviewLoaded = true;this.seeking = false;this.previewRef.current?.pause();