mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-03 22:04:53 +03:00
Snapshot: simplify control wiring and scope cleanup
This commit is contained in:
parent
c5e816f8d3
commit
84c18365cc
@ -63,7 +63,6 @@ type HlsVideoPlayerProps = {
|
|||||||
isDetailMode?: boolean;
|
isDetailMode?: boolean;
|
||||||
camera?: string;
|
camera?: string;
|
||||||
currentTimeOverride?: number;
|
currentTimeOverride?: number;
|
||||||
supportsSnapshot?: boolean;
|
|
||||||
transformedOverlay?: ReactNode;
|
transformedOverlay?: ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -89,7 +88,6 @@ export default function HlsVideoPlayer({
|
|||||||
isDetailMode = false,
|
isDetailMode = false,
|
||||||
camera,
|
camera,
|
||||||
currentTimeOverride,
|
currentTimeOverride,
|
||||||
supportsSnapshot = false,
|
|
||||||
transformedOverlay,
|
transformedOverlay,
|
||||||
}: HlsVideoPlayerProps) {
|
}: HlsVideoPlayerProps) {
|
||||||
const { t } = useTranslation(["components/player", "views/live"]);
|
const { t } = useTranslation(["components/player", "views/live"]);
|
||||||
@ -271,7 +269,7 @@ export default function HlsVideoPlayer({
|
|||||||
const getVideoTime = useCallback(() => {
|
const getVideoTime = useCallback(() => {
|
||||||
const currentTime = videoRef.current?.currentTime;
|
const currentTime = videoRef.current?.currentTime;
|
||||||
|
|
||||||
if (currentTime == undefined) {
|
if (!currentTime) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,6 +298,7 @@ export default function HlsVideoPlayer({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [camera, config?.ui?.timezone, currentTime, getVideoTime, t, videoRef]);
|
}, [camera, config?.ui?.timezone, currentTime, getVideoTime, t, videoRef]);
|
||||||
|
const onSnapshot = camera ? handleSnapshot : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TransformWrapper
|
<TransformWrapper
|
||||||
@ -324,7 +323,7 @@ export default function HlsVideoPlayer({
|
|||||||
seek: true,
|
seek: true,
|
||||||
playbackRate: true,
|
playbackRate: true,
|
||||||
plusUpload: isAdmin && config?.plus?.enabled == true,
|
plusUpload: isAdmin && config?.plus?.enabled == true,
|
||||||
snapshot: supportsSnapshot,
|
snapshot: !!onSnapshot,
|
||||||
fullscreen: supportsFullscreen,
|
fullscreen: supportsFullscreen,
|
||||||
}}
|
}}
|
||||||
setControlsOpen={setControlsOpen}
|
setControlsOpen={setControlsOpen}
|
||||||
@ -351,7 +350,7 @@ export default function HlsVideoPlayer({
|
|||||||
onUploadFrame={async () => {
|
onUploadFrame={async () => {
|
||||||
const frameTime = getVideoTime();
|
const frameTime = getVideoTime();
|
||||||
|
|
||||||
if (frameTime != undefined && onUploadFrame) {
|
if (frameTime && onUploadFrame) {
|
||||||
const resp = await onUploadFrame(frameTime);
|
const resp = await onUploadFrame(frameTime);
|
||||||
|
|
||||||
if (resp && resp.status == 200) {
|
if (resp && resp.status == 200) {
|
||||||
@ -365,7 +364,7 @@ export default function HlsVideoPlayer({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onSnapshot={supportsSnapshot ? handleSnapshot : undefined}
|
onSnapshot={onSnapshot}
|
||||||
snapshotTitle={t("snapshot.takeSnapshot", { ns: "views/live" })}
|
snapshotTitle={t("snapshot.takeSnapshot", { ns: "views/live" })}
|
||||||
fullscreen={fullscreen}
|
fullscreen={fullscreen}
|
||||||
toggleFullscreen={toggleFullscreen}
|
toggleFullscreen={toggleFullscreen}
|
||||||
@ -498,7 +497,7 @@ export default function HlsVideoPlayer({
|
|||||||
|
|
||||||
const frameTime = getVideoTime();
|
const frameTime = getVideoTime();
|
||||||
|
|
||||||
if (frameTime != undefined) {
|
if (frameTime) {
|
||||||
onTimeUpdate(frameTime);
|
onTimeUpdate(frameTime);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@ -47,7 +47,6 @@ type DynamicVideoPlayerProps = {
|
|||||||
setFullResolution: React.Dispatch<React.SetStateAction<VideoResolutionType>>;
|
setFullResolution: React.Dispatch<React.SetStateAction<VideoResolutionType>>;
|
||||||
toggleFullscreen: () => void;
|
toggleFullscreen: () => void;
|
||||||
containerRef?: React.MutableRefObject<HTMLDivElement | null>;
|
containerRef?: React.MutableRefObject<HTMLDivElement | null>;
|
||||||
supportsSnapshot?: boolean;
|
|
||||||
transformedOverlay?: ReactNode;
|
transformedOverlay?: ReactNode;
|
||||||
};
|
};
|
||||||
export default function DynamicVideoPlayer({
|
export default function DynamicVideoPlayer({
|
||||||
@ -67,7 +66,6 @@ export default function DynamicVideoPlayer({
|
|||||||
setFullResolution,
|
setFullResolution,
|
||||||
toggleFullscreen,
|
toggleFullscreen,
|
||||||
containerRef,
|
containerRef,
|
||||||
supportsSnapshot = false,
|
|
||||||
transformedOverlay,
|
transformedOverlay,
|
||||||
}: DynamicVideoPlayerProps) {
|
}: DynamicVideoPlayerProps) {
|
||||||
const { t } = useTranslation(["components/player"]);
|
const { t } = useTranslation(["components/player"]);
|
||||||
@ -323,7 +321,6 @@ export default function DynamicVideoPlayer({
|
|||||||
isDetailMode={isDetailMode}
|
isDetailMode={isDetailMode}
|
||||||
camera={contextCamera || camera}
|
camera={contextCamera || camera}
|
||||||
currentTimeOverride={currentTime}
|
currentTimeOverride={currentTime}
|
||||||
supportsSnapshot={supportsSnapshot}
|
|
||||||
transformedOverlay={transformedOverlay}
|
transformedOverlay={transformedOverlay}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -103,20 +103,15 @@ export function generateSnapshotFilename(
|
|||||||
timestampSeconds?: number,
|
timestampSeconds?: number,
|
||||||
timezone?: string,
|
timezone?: string,
|
||||||
): string {
|
): string {
|
||||||
const seconds = timestampSeconds ?? Date.now() / 1000;
|
const seconds =
|
||||||
|
typeof timestampSeconds === "number" && Number.isFinite(timestampSeconds)
|
||||||
|
? timestampSeconds
|
||||||
|
: Date.now() / 1000;
|
||||||
const timestamp = formatUnixTimestampToDateTime(seconds, {
|
const timestamp = formatUnixTimestampToDateTime(seconds, {
|
||||||
timezone,
|
timezone,
|
||||||
date_format: "yyyy-MM-dd'T'HH-mm-ss",
|
date_format: "yyyy-MM-dd'T'HH-mm-ss",
|
||||||
});
|
});
|
||||||
|
return `${cameraName}_snapshot_${timestamp}.jpg`;
|
||||||
const safeTimestamp =
|
|
||||||
timestamp === "Invalid time"
|
|
||||||
? new Date(seconds * 1000)
|
|
||||||
.toISOString()
|
|
||||||
.replace(/[:.]/g, "-")
|
|
||||||
.slice(0, -5)
|
|
||||||
: timestamp;
|
|
||||||
return `${cameraName}_snapshot_${safeTimestamp}.jpg`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function grabVideoSnapshot(
|
export async function grabVideoSnapshot(
|
||||||
|
|||||||
@ -839,7 +839,6 @@ export function RecordingView({
|
|||||||
setFullResolution={setFullResolution}
|
setFullResolution={setFullResolution}
|
||||||
toggleFullscreen={toggleFullscreen}
|
toggleFullscreen={toggleFullscreen}
|
||||||
containerRef={mainLayoutRef}
|
containerRef={mainLayoutRef}
|
||||||
supportsSnapshot={true}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{isDesktop && effectiveCameras.length > 1 && (
|
{isDesktop && effectiveCameras.length > 1 && (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user