2024-03-26 22:03:58 +01:00
|
|
|
import ReviewCard from "@/components/card/ReviewCard";
|
|
|
|
import ReviewFilterGroup from "@/components/filter/ReviewFilterGroup";
|
2024-03-26 22:37:45 +01:00
|
|
|
import ExportDialog from "@/components/overlay/ExportDialog";
|
2024-03-12 00:31:05 +01:00
|
|
|
import PreviewPlayer, {
|
|
|
|
PreviewController,
|
|
|
|
} from "@/components/player/PreviewPlayer";
|
2024-03-13 21:24:24 +01:00
|
|
|
import { DynamicVideoController } from "@/components/player/dynamic/DynamicVideoController";
|
|
|
|
import DynamicVideoPlayer from "@/components/player/dynamic/DynamicVideoPlayer";
|
2024-03-05 20:55:44 +01:00
|
|
|
import MotionReviewTimeline from "@/components/timeline/MotionReviewTimeline";
|
2024-02-23 01:03:34 +01:00
|
|
|
import { Button } from "@/components/ui/button";
|
2024-03-26 22:03:58 +01:00
|
|
|
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
|
|
|
import { useOverlayState } from "@/hooks/use-overlay-state";
|
2024-03-26 22:37:45 +01:00
|
|
|
import { ExportMode } from "@/types/filter";
|
2024-03-12 00:31:05 +01:00
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
2024-02-28 23:23:56 +01:00
|
|
|
import { Preview } from "@/types/preview";
|
2024-03-21 14:43:37 +01:00
|
|
|
import {
|
|
|
|
MotionData,
|
2024-04-29 21:20:50 +02:00
|
|
|
REVIEW_PADDING,
|
2024-03-21 14:43:37 +01:00
|
|
|
ReviewFilter,
|
|
|
|
ReviewSegment,
|
|
|
|
ReviewSummary,
|
|
|
|
} from "@/types/review";
|
2024-03-04 05:21:30 +01:00
|
|
|
import { getChunkedTimeDay } from "@/utils/timelineUtil";
|
2024-03-26 22:03:58 +01:00
|
|
|
import {
|
|
|
|
MutableRefObject,
|
|
|
|
useCallback,
|
|
|
|
useEffect,
|
|
|
|
useMemo,
|
|
|
|
useRef,
|
|
|
|
useState,
|
|
|
|
} from "react";
|
2024-03-17 13:30:19 +01:00
|
|
|
import { isDesktop, isMobile } from "react-device-detect";
|
2024-02-23 01:03:34 +01:00
|
|
|
import { IoMdArrowRoundBack } from "react-icons/io";
|
|
|
|
import { useNavigate } from "react-router-dom";
|
2024-03-26 22:37:45 +01:00
|
|
|
import { Toaster } from "@/components/ui/sonner";
|
2024-03-05 20:55:44 +01:00
|
|
|
import useSWR from "swr";
|
2024-03-28 00:03:05 +01:00
|
|
|
import { TimeRange, TimelineType } from "@/types/timeline";
|
|
|
|
import MobileCameraDrawer from "@/components/overlay/MobileCameraDrawer";
|
|
|
|
import MobileTimelineDrawer from "@/components/overlay/MobileTimelineDrawer";
|
|
|
|
import MobileReviewSettingsDrawer from "@/components/overlay/MobileReviewSettingsDrawer";
|
|
|
|
import Logo from "@/components/Logo";
|
2024-04-08 15:35:35 +02:00
|
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
2024-04-11 22:54:09 +02:00
|
|
|
import { FaVideo } from "react-icons/fa";
|
2024-04-30 14:52:56 +02:00
|
|
|
import { VideoResolutionType } from "@/types/live";
|
|
|
|
import { ASPECT_VERTICAL_LAYOUT, ASPECT_WIDE_LAYOUT } from "@/types/record";
|
2024-05-09 23:06:29 +02:00
|
|
|
import { useResizeObserver } from "@/hooks/resize-observer";
|
|
|
|
import { cn } from "@/lib/utils";
|
2024-05-31 14:58:33 +02:00
|
|
|
import { useFullscreen } from "@/hooks/use-fullscreen";
|
2024-03-05 20:55:44 +01:00
|
|
|
|
|
|
|
const SEGMENT_DURATION = 30;
|
2024-02-23 01:03:34 +01:00
|
|
|
|
2024-03-17 13:30:19 +01:00
|
|
|
type RecordingViewProps = {
|
2024-03-05 13:03:10 +01:00
|
|
|
startCamera: string;
|
|
|
|
startTime: number;
|
2024-03-21 14:43:37 +01:00
|
|
|
reviewItems?: ReviewSegment[];
|
|
|
|
reviewSummary?: ReviewSummary;
|
2024-03-30 19:44:12 +01:00
|
|
|
timeRange: TimeRange;
|
2024-03-05 13:03:10 +01:00
|
|
|
allCameras: string[];
|
|
|
|
allPreviews?: Preview[];
|
2024-03-21 14:43:37 +01:00
|
|
|
filter?: ReviewFilter;
|
|
|
|
updateFilter: (newFilter: ReviewFilter) => void;
|
2024-03-05 13:03:10 +01:00
|
|
|
};
|
2024-03-17 13:30:19 +01:00
|
|
|
export function RecordingView({
|
2024-03-05 13:03:10 +01:00
|
|
|
startCamera,
|
|
|
|
startTime,
|
|
|
|
reviewItems,
|
2024-03-21 14:43:37 +01:00
|
|
|
reviewSummary,
|
2024-03-30 19:44:12 +01:00
|
|
|
timeRange,
|
2024-03-05 13:03:10 +01:00
|
|
|
allCameras,
|
|
|
|
allPreviews,
|
2024-03-21 14:43:37 +01:00
|
|
|
filter,
|
|
|
|
updateFilter,
|
2024-03-17 13:30:19 +01:00
|
|
|
}: RecordingViewProps) {
|
2024-03-12 00:31:05 +01:00
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
2024-03-05 13:03:10 +01:00
|
|
|
const navigate = useNavigate();
|
|
|
|
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
|
|
|
// controller state
|
|
|
|
|
|
|
|
const [mainCamera, setMainCamera] = useState(startCamera);
|
2024-03-12 00:31:05 +01:00
|
|
|
const mainControllerRef = useRef<DynamicVideoController | null>(null);
|
2024-05-09 23:06:29 +02:00
|
|
|
const mainLayoutRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
const cameraLayoutRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
const previewRowRef = useRef<HTMLDivElement | null>(null);
|
2024-03-12 00:31:05 +01:00
|
|
|
const previewRefs = useRef<{ [camera: string]: PreviewController }>({});
|
2024-03-05 13:03:10 +01:00
|
|
|
|
2024-03-10 14:17:09 +01:00
|
|
|
const [playbackStart, setPlaybackStart] = useState(startTime);
|
|
|
|
|
2024-03-12 18:08:31 +01:00
|
|
|
const mainCameraReviewItems = useMemo(
|
2024-03-21 14:43:37 +01:00
|
|
|
() => reviewItems?.filter((cam) => cam.camera == mainCamera) ?? [],
|
2024-03-12 18:08:31 +01:00
|
|
|
[reviewItems, mainCamera],
|
|
|
|
);
|
|
|
|
|
2024-03-26 22:03:58 +01:00
|
|
|
// timeline
|
|
|
|
|
|
|
|
const [timelineType, setTimelineType] = useOverlayState<TimelineType>(
|
|
|
|
"timelineType",
|
|
|
|
"timeline",
|
|
|
|
);
|
2024-03-05 13:03:10 +01:00
|
|
|
|
2024-03-30 19:44:12 +01:00
|
|
|
const chunkedTimeRange = useMemo(
|
|
|
|
() => getChunkedTimeDay(timeRange),
|
|
|
|
[timeRange],
|
|
|
|
);
|
2024-03-05 13:03:10 +01:00
|
|
|
const [selectedRangeIdx, setSelectedRangeIdx] = useState(
|
2024-03-30 19:44:12 +01:00
|
|
|
chunkedTimeRange.findIndex((chunk) => {
|
2024-03-26 22:03:58 +01:00
|
|
|
return chunk.after <= startTime && chunk.before >= startTime;
|
2024-03-05 13:03:10 +01:00
|
|
|
}),
|
|
|
|
);
|
2024-03-08 01:31:43 +01:00
|
|
|
const currentTimeRange = useMemo(
|
2024-03-30 19:44:12 +01:00
|
|
|
() => chunkedTimeRange[selectedRangeIdx],
|
|
|
|
[selectedRangeIdx, chunkedTimeRange],
|
2024-03-08 01:31:43 +01:00
|
|
|
);
|
2024-05-10 19:42:56 +02:00
|
|
|
const reviewLabels = useMemo(() => {
|
|
|
|
const uniqueLabels = new Set<string>();
|
|
|
|
|
|
|
|
reviewItems?.forEach((rev) => {
|
|
|
|
rev.data.objects.forEach((obj) =>
|
|
|
|
uniqueLabels.add(obj.replace("-verified", "")),
|
|
|
|
);
|
|
|
|
rev.data.audio.forEach((aud) => uniqueLabels.add(aud));
|
|
|
|
});
|
|
|
|
|
|
|
|
return [...uniqueLabels];
|
|
|
|
}, [reviewItems]);
|
2024-03-05 13:03:10 +01:00
|
|
|
|
2024-03-26 22:37:45 +01:00
|
|
|
// export
|
|
|
|
|
|
|
|
const [exportMode, setExportMode] = useState<ExportMode>("none");
|
|
|
|
const [exportRange, setExportRange] = useState<TimeRange>();
|
|
|
|
|
2024-03-05 13:03:10 +01:00
|
|
|
// move to next clip
|
2024-03-13 21:24:24 +01:00
|
|
|
|
|
|
|
const onClipEnded = useCallback(() => {
|
2024-03-12 00:31:05 +01:00
|
|
|
if (!mainControllerRef.current) {
|
2024-03-05 13:03:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-30 19:44:12 +01:00
|
|
|
if (selectedRangeIdx < chunkedTimeRange.length - 1) {
|
2024-03-13 21:24:24 +01:00
|
|
|
setSelectedRangeIdx(selectedRangeIdx + 1);
|
|
|
|
}
|
2024-03-30 19:44:12 +01:00
|
|
|
}, [selectedRangeIdx, chunkedTimeRange]);
|
2024-03-05 13:03:10 +01:00
|
|
|
|
|
|
|
// scrubbing and timeline state
|
|
|
|
|
|
|
|
const [scrubbing, setScrubbing] = useState(false);
|
|
|
|
const [currentTime, setCurrentTime] = useState<number>(startTime);
|
2024-03-13 15:05:01 +01:00
|
|
|
const [playerTime, setPlayerTime] = useState(startTime);
|
|
|
|
|
|
|
|
const updateSelectedSegment = useCallback(
|
2024-03-14 15:28:06 +01:00
|
|
|
(currentTime: number, updateStartTime: boolean) => {
|
2024-03-30 19:44:12 +01:00
|
|
|
const index = chunkedTimeRange.findIndex(
|
2024-03-26 22:03:58 +01:00
|
|
|
(seg) => seg.after <= currentTime && seg.before >= currentTime,
|
2024-03-13 15:05:01 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (index != -1) {
|
2024-03-14 15:28:06 +01:00
|
|
|
if (updateStartTime) {
|
|
|
|
setPlaybackStart(currentTime);
|
|
|
|
}
|
|
|
|
|
2024-03-13 21:24:24 +01:00
|
|
|
setSelectedRangeIdx(index);
|
2024-03-13 15:05:01 +01:00
|
|
|
}
|
|
|
|
},
|
2024-03-30 19:44:12 +01:00
|
|
|
[chunkedTimeRange],
|
2024-03-13 15:05:01 +01:00
|
|
|
);
|
2024-03-05 13:03:10 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-04-04 17:43:54 +02:00
|
|
|
if (scrubbing || exportRange) {
|
2024-03-08 01:31:43 +01:00
|
|
|
if (
|
2024-03-26 22:03:58 +01:00
|
|
|
currentTime > currentTimeRange.before + 60 ||
|
|
|
|
currentTime < currentTimeRange.after - 60
|
2024-03-08 01:31:43 +01:00
|
|
|
) {
|
2024-03-14 15:28:06 +01:00
|
|
|
updateSelectedSegment(currentTime, false);
|
2024-03-08 01:31:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-12 00:31:05 +01:00
|
|
|
mainControllerRef.current?.scrubToTimestamp(currentTime);
|
|
|
|
|
|
|
|
Object.values(previewRefs.current).forEach((controller) => {
|
2024-03-05 13:03:10 +01:00
|
|
|
controller.scrubToTimestamp(currentTime);
|
|
|
|
});
|
|
|
|
}
|
2024-04-04 17:43:54 +02:00
|
|
|
// we only want to seek when current time updates
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2024-03-13 15:05:01 +01:00
|
|
|
}, [
|
|
|
|
currentTime,
|
|
|
|
scrubbing,
|
|
|
|
timeRange,
|
|
|
|
currentTimeRange,
|
|
|
|
updateSelectedSegment,
|
|
|
|
]);
|
2024-03-05 13:03:10 +01:00
|
|
|
|
2024-03-13 15:05:01 +01:00
|
|
|
useEffect(() => {
|
|
|
|
if (!scrubbing) {
|
|
|
|
if (Math.abs(currentTime - playerTime) > 10) {
|
|
|
|
if (
|
2024-03-26 22:03:58 +01:00
|
|
|
currentTimeRange.after <= currentTime &&
|
|
|
|
currentTimeRange.before >= currentTime
|
2024-03-13 15:05:01 +01:00
|
|
|
) {
|
|
|
|
mainControllerRef.current?.seekToTimestamp(currentTime, true);
|
|
|
|
} else {
|
2024-03-14 15:28:06 +01:00
|
|
|
updateSelectedSegment(currentTime, true);
|
2024-03-13 15:05:01 +01:00
|
|
|
}
|
2024-03-22 17:56:53 +01:00
|
|
|
} else if (playerTime != currentTime) {
|
2024-03-22 15:31:20 +01:00
|
|
|
mainControllerRef.current?.play();
|
2024-03-13 15:05:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// we only want to seek when current time doesn't match the player update time
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2024-03-14 15:28:06 +01:00
|
|
|
}, [currentTime, scrubbing]);
|
2024-03-13 15:05:01 +01:00
|
|
|
|
2024-04-30 14:52:56 +02:00
|
|
|
const [fullResolution, setFullResolution] = useState<VideoResolutionType>({
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
});
|
|
|
|
|
2024-03-05 13:03:10 +01:00
|
|
|
const onSelectCamera = useCallback(
|
|
|
|
(newCam: string) => {
|
|
|
|
setMainCamera(newCam);
|
2024-04-30 14:52:56 +02:00
|
|
|
setFullResolution({
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
});
|
2024-03-12 00:31:05 +01:00
|
|
|
setPlaybackStart(currentTime);
|
2024-03-05 13:03:10 +01:00
|
|
|
},
|
2024-03-12 00:31:05 +01:00
|
|
|
[currentTime],
|
2024-03-05 13:03:10 +01:00
|
|
|
);
|
|
|
|
|
2024-05-09 23:06:29 +02:00
|
|
|
// fullscreen
|
|
|
|
|
2024-05-31 14:58:33 +02:00
|
|
|
const { fullscreen, toggleFullscreen } = useFullscreen(mainLayoutRef);
|
2024-05-09 23:06:29 +02:00
|
|
|
|
|
|
|
// layout
|
2024-03-05 20:55:44 +01:00
|
|
|
|
2024-03-30 19:44:12 +01:00
|
|
|
const getCameraAspect = useCallback(
|
|
|
|
(cam: string) => {
|
|
|
|
if (!config) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2024-04-30 14:52:56 +02:00
|
|
|
if (cam == mainCamera && fullResolution.width && fullResolution.height) {
|
|
|
|
return fullResolution.width / fullResolution.height;
|
|
|
|
}
|
|
|
|
|
2024-03-30 19:44:12 +01:00
|
|
|
const camera = config.cameras[cam];
|
2024-03-12 00:31:05 +01:00
|
|
|
|
2024-03-30 19:44:12 +01:00
|
|
|
if (!camera) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2024-03-16 00:28:57 +01:00
|
|
|
|
2024-03-30 19:44:12 +01:00
|
|
|
return camera.detect.width / camera.detect.height;
|
|
|
|
},
|
2024-04-30 14:52:56 +02:00
|
|
|
[config, fullResolution, mainCamera],
|
2024-03-30 19:44:12 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
const mainCameraAspect = useMemo(() => {
|
|
|
|
const aspectRatio = getCameraAspect(mainCamera);
|
|
|
|
|
|
|
|
if (!aspectRatio) {
|
|
|
|
return "normal";
|
2024-04-30 14:52:56 +02:00
|
|
|
} else if (aspectRatio > ASPECT_WIDE_LAYOUT) {
|
2024-03-16 00:28:57 +01:00
|
|
|
return "wide";
|
2024-04-30 14:52:56 +02:00
|
|
|
} else if (aspectRatio < ASPECT_VERTICAL_LAYOUT) {
|
2024-03-16 00:28:57 +01:00
|
|
|
return "tall";
|
2024-03-12 00:31:05 +01:00
|
|
|
} else {
|
2024-03-16 00:28:57 +01:00
|
|
|
return "normal";
|
2024-03-12 00:31:05 +01:00
|
|
|
}
|
2024-03-30 19:44:12 +01:00
|
|
|
}, [getCameraAspect, mainCamera]);
|
2024-03-12 00:31:05 +01:00
|
|
|
|
2024-03-16 00:28:57 +01:00
|
|
|
const grow = useMemo(() => {
|
|
|
|
if (mainCameraAspect == "wide") {
|
|
|
|
return "w-full aspect-wide";
|
2024-03-30 19:44:12 +01:00
|
|
|
} else if (mainCameraAspect == "tall") {
|
|
|
|
if (isDesktop) {
|
|
|
|
return "size-full aspect-tall flex flex-col justify-center";
|
|
|
|
} else {
|
|
|
|
return "size-full";
|
|
|
|
}
|
2024-03-16 00:28:57 +01:00
|
|
|
} else {
|
|
|
|
return "w-full aspect-video";
|
|
|
|
}
|
|
|
|
}, [mainCameraAspect]);
|
|
|
|
|
2024-05-09 23:06:29 +02:00
|
|
|
const [{ width: mainWidth, height: mainHeight }] =
|
|
|
|
useResizeObserver(cameraLayoutRef);
|
|
|
|
|
|
|
|
const mainCameraStyle = useMemo(() => {
|
|
|
|
if (isMobile || mainCameraAspect != "normal" || !config) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const camera = config.cameras[mainCamera];
|
|
|
|
|
|
|
|
if (!camera) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const aspect = camera.detect.width / camera.detect.height;
|
|
|
|
|
|
|
|
if (!aspect) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const availableHeight = mainHeight - 112;
|
|
|
|
|
|
|
|
let percent;
|
|
|
|
if (mainWidth / availableHeight < aspect) {
|
|
|
|
percent = 100;
|
|
|
|
} else {
|
|
|
|
const availableWidth = aspect * availableHeight;
|
|
|
|
percent =
|
|
|
|
(mainWidth < availableWidth
|
|
|
|
? mainWidth / availableWidth
|
|
|
|
: availableWidth / mainWidth) * 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
width: `${Math.round(percent)}%`,
|
|
|
|
};
|
|
|
|
}, [config, mainCameraAspect, mainWidth, mainHeight, mainCamera]);
|
|
|
|
|
|
|
|
const previewRowOverflows = useMemo(() => {
|
|
|
|
if (!previewRowRef.current) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
previewRowRef.current.scrollWidth > previewRowRef.current.clientWidth ||
|
|
|
|
previewRowRef.current.scrollHeight > previewRowRef.current.clientHeight
|
|
|
|
);
|
|
|
|
// we only want to update when the scroll size changes
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [previewRowRef.current?.scrollWidth, previewRowRef.current?.scrollHeight]);
|
|
|
|
|
2024-03-05 13:03:10 +01:00
|
|
|
return (
|
2024-05-14 17:06:44 +02:00
|
|
|
<div ref={contentRef} className="flex size-full flex-col pt-2">
|
2024-05-04 21:54:50 +02:00
|
|
|
<Toaster closeButton={true} />
|
2024-05-14 17:06:44 +02:00
|
|
|
<div className="relative mb-2 flex h-11 w-full items-center justify-between px-2">
|
2024-03-28 00:03:05 +01:00
|
|
|
{isMobile && (
|
2024-05-14 17:06:44 +02:00
|
|
|
<Logo className="absolute inset-x-1/2 h-8 -translate-x-1/2" />
|
2024-03-28 00:03:05 +01:00
|
|
|
)}
|
2024-05-09 23:06:29 +02:00
|
|
|
<div className={cn("flex items-center gap-2")}>
|
2024-04-11 22:54:09 +02:00
|
|
|
<Button
|
2024-05-09 23:06:29 +02:00
|
|
|
className="flex items-center gap-2.5 rounded-lg"
|
2024-04-11 22:54:09 +02:00
|
|
|
size="sm"
|
|
|
|
onClick={() => navigate(-1)}
|
|
|
|
>
|
|
|
|
<IoMdArrowRoundBack className="size-5 text-secondary-foreground" />
|
|
|
|
{isDesktop && <div className="text-primary">Back</div>}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
className="flex items-center gap-2.5 rounded-lg"
|
|
|
|
size="sm"
|
|
|
|
onClick={() => {
|
|
|
|
navigate(`/#${mainCamera}`);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<FaVideo className="size-5 text-secondary-foreground" />
|
|
|
|
{isDesktop && <div className="text-primary">Live</div>}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2024-03-26 22:03:58 +01:00
|
|
|
<div className="flex items-center justify-end gap-2">
|
2024-03-28 00:03:05 +01:00
|
|
|
<MobileCameraDrawer
|
|
|
|
allCameras={allCameras}
|
|
|
|
selected={mainCamera}
|
|
|
|
onSelectCamera={(cam) => {
|
|
|
|
setPlaybackStart(currentTime);
|
|
|
|
setMainCamera(cam);
|
|
|
|
}}
|
2024-03-26 22:03:58 +01:00
|
|
|
/>
|
|
|
|
{isDesktop && (
|
2024-03-28 00:03:05 +01:00
|
|
|
<ExportDialog
|
|
|
|
camera={mainCamera}
|
|
|
|
currentTime={currentTime}
|
2024-03-30 19:44:12 +01:00
|
|
|
latestTime={timeRange.before}
|
2024-03-28 00:03:05 +01:00
|
|
|
mode={exportMode}
|
|
|
|
range={exportRange}
|
2024-03-30 19:44:12 +01:00
|
|
|
setRange={(range) => {
|
|
|
|
setExportRange(range);
|
|
|
|
|
|
|
|
if (range != undefined) {
|
|
|
|
mainControllerRef.current?.pause();
|
|
|
|
}
|
|
|
|
}}
|
2024-03-28 00:03:05 +01:00
|
|
|
setMode={setExportMode}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{isDesktop && (
|
|
|
|
<ReviewFilterGroup
|
|
|
|
filters={["date", "general"]}
|
|
|
|
reviewSummary={reviewSummary}
|
|
|
|
filter={filter}
|
|
|
|
motionOnly={false}
|
2024-05-10 19:42:56 +02:00
|
|
|
filterLabels={reviewLabels}
|
|
|
|
onUpdateFilter={updateFilter}
|
2024-03-28 00:03:05 +01:00
|
|
|
setMotionOnly={() => {}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{isDesktop ? (
|
2024-03-26 22:03:58 +01:00
|
|
|
<ToggleGroup
|
2024-05-14 17:06:44 +02:00
|
|
|
className="*:rounded-md *:px-3 *:py-4"
|
2024-03-26 22:03:58 +01:00
|
|
|
type="single"
|
|
|
|
size="sm"
|
|
|
|
value={timelineType}
|
|
|
|
onValueChange={(value: TimelineType) =>
|
|
|
|
value ? setTimelineType(value, true) : null
|
|
|
|
} // don't allow the severity to be unselected
|
|
|
|
>
|
|
|
|
<ToggleGroupItem
|
2024-04-19 19:17:23 +02:00
|
|
|
className={`${timelineType == "timeline" ? "" : "text-muted-foreground"}`}
|
2024-03-26 22:03:58 +01:00
|
|
|
value="timeline"
|
|
|
|
aria-label="Select timeline"
|
|
|
|
>
|
|
|
|
<div className="">Timeline</div>
|
|
|
|
</ToggleGroupItem>
|
|
|
|
<ToggleGroupItem
|
2024-04-19 19:17:23 +02:00
|
|
|
className={`${timelineType == "events" ? "" : "text-muted-foreground"}`}
|
2024-03-26 22:03:58 +01:00
|
|
|
value="events"
|
|
|
|
aria-label="Select events"
|
|
|
|
>
|
|
|
|
<div className="">Events</div>
|
|
|
|
</ToggleGroupItem>
|
|
|
|
</ToggleGroup>
|
2024-03-28 00:03:05 +01:00
|
|
|
) : (
|
|
|
|
<MobileTimelineDrawer
|
|
|
|
selected={timelineType ?? "timeline"}
|
|
|
|
onSelect={setTimelineType}
|
|
|
|
/>
|
2024-03-26 22:03:58 +01:00
|
|
|
)}
|
2024-03-28 00:03:05 +01:00
|
|
|
<MobileReviewSettingsDrawer
|
|
|
|
camera={mainCamera}
|
|
|
|
filter={filter}
|
|
|
|
currentTime={currentTime}
|
2024-03-30 19:44:12 +01:00
|
|
|
latestTime={timeRange.before}
|
2024-03-28 00:03:05 +01:00
|
|
|
mode={exportMode}
|
|
|
|
range={exportRange}
|
2024-05-10 19:42:56 +02:00
|
|
|
allLabels={reviewLabels}
|
2024-03-28 00:03:05 +01:00
|
|
|
onUpdateFilter={updateFilter}
|
|
|
|
setRange={setExportRange}
|
|
|
|
setMode={setExportMode}
|
|
|
|
/>
|
2024-03-21 14:43:37 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-03-05 13:03:10 +01:00
|
|
|
|
2024-03-17 13:30:19 +01:00
|
|
|
<div
|
2024-05-09 23:06:29 +02:00
|
|
|
ref={mainLayoutRef}
|
|
|
|
className={cn(
|
2024-05-14 17:06:44 +02:00
|
|
|
"flex h-full justify-center overflow-hidden",
|
|
|
|
isDesktop ? "" : "flex-col gap-2 landscape:flex-row",
|
2024-05-09 23:06:29 +02:00
|
|
|
)}
|
2024-03-17 13:30:19 +01:00
|
|
|
>
|
2024-05-09 23:06:29 +02:00
|
|
|
<div
|
|
|
|
ref={cameraLayoutRef}
|
|
|
|
className={cn("flex flex-1 flex-wrap", isDesktop ? "w-[80%]" : "")}
|
|
|
|
>
|
2024-03-16 00:28:57 +01:00
|
|
|
<div
|
2024-05-09 23:06:29 +02:00
|
|
|
className={cn(
|
2024-05-14 17:06:44 +02:00
|
|
|
"flex size-full items-center",
|
2024-05-09 23:06:29 +02:00
|
|
|
mainCameraAspect == "tall"
|
|
|
|
? "flex-row justify-evenly"
|
|
|
|
: "flex-col justify-center gap-2",
|
|
|
|
)}
|
2024-03-16 00:28:57 +01:00
|
|
|
>
|
2024-03-12 00:31:05 +01:00
|
|
|
<div
|
|
|
|
key={mainCamera}
|
2024-05-09 23:06:29 +02:00
|
|
|
className={cn(
|
|
|
|
"relative",
|
2024-03-17 13:30:19 +01:00
|
|
|
isDesktop
|
2024-05-09 23:06:29 +02:00
|
|
|
? cn(
|
2024-05-14 17:06:44 +02:00
|
|
|
"flex justify-center px-4",
|
2024-05-09 23:06:29 +02:00
|
|
|
mainCameraAspect == "tall"
|
|
|
|
? "h-[50%] md:h-[60%] lg:h-[75%] xl:h-[90%]"
|
|
|
|
: mainCameraAspect == "wide"
|
|
|
|
? "w-full"
|
|
|
|
: "",
|
|
|
|
)
|
|
|
|
: cn(
|
2024-05-14 17:06:44 +02:00
|
|
|
"pt-2 portrait:w-full",
|
2024-05-09 23:06:29 +02:00
|
|
|
mainCameraAspect == "wide"
|
2024-05-14 17:06:44 +02:00
|
|
|
? "aspect-wide landscape:w-full"
|
|
|
|
: "aspect-video landscape:h-[94%]",
|
2024-05-09 23:06:29 +02:00
|
|
|
),
|
|
|
|
)}
|
2024-03-30 19:44:12 +01:00
|
|
|
style={{
|
2024-05-09 23:06:29 +02:00
|
|
|
width: mainCameraStyle ? mainCameraStyle.width : undefined,
|
2024-03-30 19:44:12 +01:00
|
|
|
aspectRatio: isDesktop
|
|
|
|
? mainCameraAspect == "tall"
|
|
|
|
? getCameraAspect(mainCamera)
|
|
|
|
: undefined
|
|
|
|
: Math.max(1, getCameraAspect(mainCamera) ?? 0),
|
|
|
|
}}
|
2024-03-12 00:31:05 +01:00
|
|
|
>
|
2024-03-05 13:03:10 +01:00
|
|
|
<DynamicVideoPlayer
|
2024-03-16 00:28:57 +01:00
|
|
|
className={grow}
|
2024-03-11 23:07:56 +01:00
|
|
|
camera={mainCamera}
|
2024-03-08 01:31:43 +01:00
|
|
|
timeRange={currentTimeRange}
|
2024-03-05 13:03:10 +01:00
|
|
|
cameraPreviews={allPreviews ?? []}
|
2024-03-13 21:24:24 +01:00
|
|
|
startTimestamp={playbackStart}
|
2024-03-26 22:37:45 +01:00
|
|
|
hotKeys={exportMode != "select"}
|
2024-05-09 23:06:29 +02:00
|
|
|
fullscreen={fullscreen}
|
2024-03-13 21:24:24 +01:00
|
|
|
onTimestampUpdate={(timestamp) => {
|
|
|
|
setPlayerTime(timestamp);
|
|
|
|
setCurrentTime(timestamp);
|
|
|
|
Object.values(previewRefs.current ?? {}).forEach((prev) =>
|
|
|
|
prev.scrubToTimestamp(Math.floor(timestamp)),
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
onClipEnded={onClipEnded}
|
2024-03-05 13:03:10 +01:00
|
|
|
onControllerReady={(controller) => {
|
2024-03-12 00:31:05 +01:00
|
|
|
mainControllerRef.current = controller;
|
2024-03-05 13:03:10 +01:00
|
|
|
}}
|
2024-03-26 22:37:45 +01:00
|
|
|
isScrubbing={scrubbing || exportMode == "timeline"}
|
2024-04-30 14:52:56 +02:00
|
|
|
setFullResolution={setFullResolution}
|
2024-05-31 14:58:33 +02:00
|
|
|
toggleFullscreen={toggleFullscreen}
|
2024-03-05 13:03:10 +01:00
|
|
|
/>
|
|
|
|
</div>
|
2024-03-17 13:30:19 +01:00
|
|
|
{isDesktop && (
|
|
|
|
<div
|
2024-05-09 23:06:29 +02:00
|
|
|
ref={previewRowRef}
|
|
|
|
className={cn(
|
|
|
|
"flex gap-2 overflow-auto",
|
|
|
|
mainCameraAspect == "tall"
|
2024-05-17 15:26:42 +02:00
|
|
|
? "h-full w-72 flex-col"
|
2024-05-14 17:06:44 +02:00
|
|
|
: `h-28 w-full`,
|
|
|
|
previewRowOverflows ? "" : "items-center justify-center",
|
2024-05-09 23:06:29 +02:00
|
|
|
)}
|
2024-03-17 13:30:19 +01:00
|
|
|
>
|
2024-05-09 23:06:29 +02:00
|
|
|
<div className="w-2" />
|
2024-03-17 13:30:19 +01:00
|
|
|
{allCameras.map((cam) => {
|
2024-03-30 19:44:12 +01:00
|
|
|
if (cam == mainCamera) {
|
|
|
|
return;
|
2024-03-17 13:30:19 +01:00
|
|
|
}
|
2024-03-30 19:44:12 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
key={cam}
|
|
|
|
className={
|
2024-05-17 15:26:42 +02:00
|
|
|
mainCameraAspect == "tall" ? "w-full" : "h-full"
|
2024-03-30 19:44:12 +01:00
|
|
|
}
|
|
|
|
style={{
|
|
|
|
aspectRatio: getCameraAspect(cam),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<PreviewPlayer
|
|
|
|
className="size-full"
|
|
|
|
camera={cam}
|
|
|
|
timeRange={currentTimeRange}
|
|
|
|
cameraPreviews={allPreviews ?? []}
|
|
|
|
startTime={startTime}
|
|
|
|
isScrubbing={scrubbing}
|
|
|
|
onControllerReady={(controller) => {
|
|
|
|
previewRefs.current[cam] = controller;
|
|
|
|
controller.scrubToTimestamp(startTime);
|
|
|
|
}}
|
|
|
|
onClick={() => onSelectCamera(cam)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2024-03-17 13:30:19 +01:00
|
|
|
})}
|
2024-05-09 23:06:29 +02:00
|
|
|
<div className="w-2" />
|
2024-03-17 13:30:19 +01:00
|
|
|
</div>
|
|
|
|
)}
|
2024-03-11 23:07:56 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-03-26 22:03:58 +01:00
|
|
|
<Timeline
|
|
|
|
contentRef={contentRef}
|
|
|
|
mainCamera={mainCamera}
|
2024-03-28 00:03:05 +01:00
|
|
|
timelineType={
|
|
|
|
(exportRange == undefined ? timelineType : "timeline") ?? "timeline"
|
|
|
|
}
|
2024-03-26 22:03:58 +01:00
|
|
|
timeRange={timeRange}
|
|
|
|
mainCameraReviewItems={mainCameraReviewItems}
|
|
|
|
currentTime={currentTime}
|
2024-03-26 22:37:45 +01:00
|
|
|
exportRange={exportMode == "timeline" ? exportRange : undefined}
|
2024-03-26 22:03:58 +01:00
|
|
|
setCurrentTime={setCurrentTime}
|
|
|
|
setScrubbing={setScrubbing}
|
2024-03-26 22:37:45 +01:00
|
|
|
setExportRange={setExportRange}
|
2024-03-26 22:03:58 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2024-03-05 13:03:10 +01:00
|
|
|
|
2024-03-26 22:03:58 +01:00
|
|
|
type TimelineProps = {
|
|
|
|
contentRef: MutableRefObject<HTMLDivElement | null>;
|
|
|
|
mainCamera: string;
|
|
|
|
timelineType: TimelineType;
|
2024-03-30 19:44:12 +01:00
|
|
|
timeRange: TimeRange;
|
2024-03-26 22:03:58 +01:00
|
|
|
mainCameraReviewItems: ReviewSegment[];
|
|
|
|
currentTime: number;
|
2024-03-26 22:37:45 +01:00
|
|
|
exportRange?: TimeRange;
|
2024-03-26 22:03:58 +01:00
|
|
|
setCurrentTime: React.Dispatch<React.SetStateAction<number>>;
|
|
|
|
setScrubbing: React.Dispatch<React.SetStateAction<boolean>>;
|
2024-03-26 22:37:45 +01:00
|
|
|
setExportRange: (range: TimeRange) => void;
|
2024-03-26 22:03:58 +01:00
|
|
|
};
|
|
|
|
function Timeline({
|
|
|
|
contentRef,
|
|
|
|
mainCamera,
|
|
|
|
timelineType,
|
|
|
|
timeRange,
|
|
|
|
mainCameraReviewItems,
|
|
|
|
currentTime,
|
2024-03-26 22:37:45 +01:00
|
|
|
exportRange,
|
2024-03-26 22:03:58 +01:00
|
|
|
setCurrentTime,
|
|
|
|
setScrubbing,
|
2024-03-26 22:37:45 +01:00
|
|
|
setExportRange,
|
2024-03-26 22:03:58 +01:00
|
|
|
}: TimelineProps) {
|
|
|
|
const { data: motionData } = useSWR<MotionData[]>([
|
|
|
|
"review/activity/motion",
|
|
|
|
{
|
2024-03-30 19:44:12 +01:00
|
|
|
before: timeRange.before,
|
|
|
|
after: timeRange.after,
|
2024-03-26 22:03:58 +01:00
|
|
|
scale: SEGMENT_DURATION / 2,
|
|
|
|
cameras: mainCamera,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2024-03-26 22:37:45 +01:00
|
|
|
const [exportStart, setExportStartTime] = useState<number>(0);
|
|
|
|
const [exportEnd, setExportEndTime] = useState<number>(0);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (exportRange && exportStart != 0 && exportEnd != 0) {
|
|
|
|
if (exportRange.after != exportStart) {
|
|
|
|
setCurrentTime(exportStart);
|
|
|
|
} else if (exportRange?.before != exportEnd) {
|
|
|
|
setCurrentTime(exportEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
setExportRange({ after: exportStart, before: exportEnd });
|
|
|
|
}
|
2024-04-04 17:43:54 +02:00
|
|
|
// we only want to update when the export parts change
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [exportStart, exportEnd, setExportRange, setCurrentTime]);
|
2024-03-26 22:37:45 +01:00
|
|
|
|
2024-03-28 00:03:05 +01:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={`${
|
|
|
|
isDesktop
|
2024-05-14 17:06:44 +02:00
|
|
|
? `${timelineType == "timeline" ? "w-[100px]" : "w-60"} no-scrollbar overflow-y-auto`
|
|
|
|
: "overflow-hidden portrait:flex-grow landscape:w-[20%]"
|
2024-03-28 00:03:05 +01:00
|
|
|
} relative`}
|
|
|
|
>
|
2024-05-14 17:06:44 +02:00
|
|
|
<div className="pointer-events-none absolute inset-x-0 top-0 z-20 h-[30px] w-full bg-gradient-to-b from-secondary to-transparent"></div>
|
|
|
|
<div className="pointer-events-none absolute inset-x-0 bottom-0 z-20 h-[30px] w-full bg-gradient-to-t from-secondary to-transparent"></div>
|
2024-03-28 00:03:05 +01:00
|
|
|
{timelineType == "timeline" ? (
|
2024-04-08 15:35:35 +02:00
|
|
|
motionData ? (
|
|
|
|
<MotionReviewTimeline
|
|
|
|
segmentDuration={30}
|
|
|
|
timestampSpread={15}
|
|
|
|
timelineStart={timeRange.before}
|
|
|
|
timelineEnd={timeRange.after}
|
|
|
|
showHandlebar={exportRange == undefined}
|
|
|
|
showExportHandles={exportRange != undefined}
|
|
|
|
exportStartTime={exportRange?.after}
|
|
|
|
exportEndTime={exportRange?.before}
|
|
|
|
setExportStartTime={setExportStartTime}
|
|
|
|
setExportEndTime={setExportEndTime}
|
|
|
|
handlebarTime={currentTime}
|
|
|
|
setHandlebarTime={setCurrentTime}
|
|
|
|
onlyInitialHandlebarScroll={true}
|
|
|
|
events={mainCameraReviewItems}
|
|
|
|
motion_events={motionData ?? []}
|
|
|
|
severityType="significant_motion"
|
|
|
|
contentRef={contentRef}
|
|
|
|
onHandlebarDraggingChange={(scrubbing) => setScrubbing(scrubbing)}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<Skeleton className="size-full" />
|
|
|
|
)
|
2024-03-28 00:03:05 +01:00
|
|
|
) : (
|
2024-03-28 18:53:36 +01:00
|
|
|
<div
|
2024-05-14 17:06:44 +02:00
|
|
|
className={`grid h-full grid-cols-1 gap-4 overflow-auto bg-secondary p-4 ${isDesktop ? "" : "sm:grid-cols-2"}`}
|
2024-03-28 18:53:36 +01:00
|
|
|
>
|
2024-03-28 00:03:05 +01:00
|
|
|
{mainCameraReviewItems.map((review) => {
|
|
|
|
if (review.severity == "significant_motion") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ReviewCard
|
|
|
|
key={review.id}
|
|
|
|
event={review}
|
|
|
|
currentTime={currentTime}
|
2024-03-30 19:44:12 +01:00
|
|
|
onClick={() => {
|
|
|
|
setScrubbing(true);
|
2024-04-29 21:20:50 +02:00
|
|
|
setCurrentTime(review.start_time - REVIEW_PADDING);
|
2024-03-30 19:44:12 +01:00
|
|
|
setScrubbing(false);
|
|
|
|
}}
|
2024-03-28 00:03:05 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
)}
|
2024-03-05 13:03:10 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|