mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-19 20:13:01 +03:00
Implement banner for stopping debug replay (#25022)
* Implement banner for stopping debug replay * Tweaks for review issue * Fix failures
This commit is contained in:
@@ -7,6 +7,10 @@
|
||||
*/
|
||||
|
||||
import { test, expect, type FrigateApp } from "../fixtures/frigate-test";
|
||||
import {
|
||||
activeSessionStatus,
|
||||
noSessionStatus,
|
||||
} from "../fixtures/mock-data/debug-replay";
|
||||
|
||||
// the selection is seeded around the playback position, so land near the
|
||||
// live edge
|
||||
@@ -183,6 +187,114 @@ test.describe("Debug Replay from History @high", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// both layouts render the same form, so these run on desktop and mobile
|
||||
test.describe("Debug Replay form with an active session @high", () => {
|
||||
test("shows a banner that stops the running session", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
let active = true;
|
||||
let stopCalled = false;
|
||||
|
||||
await frigateApp.installDefaults();
|
||||
await frigateApp.page.route("**/api/debug_replay/status", (route) =>
|
||||
route.fulfill({
|
||||
json: active
|
||||
? activeSessionStatus({ sourceCamera: "front_door" })
|
||||
: noSessionStatus(),
|
||||
}),
|
||||
);
|
||||
await frigateApp.page.route("**/api/debug_replay/stop", (route) => {
|
||||
if (route.request().method() === "POST") {
|
||||
stopCalled = true;
|
||||
active = false;
|
||||
}
|
||||
return route.fulfill({ json: { success: true } });
|
||||
});
|
||||
await openRecordingView(frigateApp);
|
||||
|
||||
const form = await openDebugReplayForm(frigateApp);
|
||||
const banner = form.getByRole("alert");
|
||||
const startButton = form.getByRole("button", { name: "Start Replay" });
|
||||
|
||||
await expect(banner).toContainText(
|
||||
"A debug replay session is already running for Front Door",
|
||||
{ timeout: 5_000 },
|
||||
);
|
||||
await expect(startButton).toBeDisabled();
|
||||
|
||||
await banner.getByRole("button", { name: "Stop Replay" }).click();
|
||||
|
||||
await expect.poll(() => stopCalled, { timeout: 5_000 }).toBe(true);
|
||||
await expect(banner).toBeHidden({ timeout: 5_000 });
|
||||
await expect(startButton).toBeEnabled();
|
||||
});
|
||||
|
||||
test.describe("after the session already ended", () => {
|
||||
// the stop endpoint answers 400 when no session is active, which
|
||||
// Chromium echoes to the console; the text carries no URL, so match the
|
||||
// 400 echo itself
|
||||
test.use({
|
||||
expectedErrors: [
|
||||
/^Failed to load resource: the server responded with a status of 400\b/,
|
||||
],
|
||||
});
|
||||
|
||||
test("stopping clears the banner", async ({ frigateApp }) => {
|
||||
let active = true;
|
||||
|
||||
await frigateApp.installDefaults();
|
||||
await frigateApp.page.route("**/api/debug_replay/status", (route) =>
|
||||
route.fulfill({
|
||||
json: active ? activeSessionStatus() : noSessionStatus(),
|
||||
}),
|
||||
);
|
||||
// the server tore the session down after the form loaded its status,
|
||||
// e.g. because startup failed
|
||||
await frigateApp.page.route("**/api/debug_replay/stop", (route) => {
|
||||
active = false;
|
||||
return route.fulfill({
|
||||
status: 400,
|
||||
json: { success: false, message: "No active replay session" },
|
||||
});
|
||||
});
|
||||
await openRecordingView(frigateApp);
|
||||
|
||||
const form = await openDebugReplayForm(frigateApp);
|
||||
const banner = form.getByRole("alert");
|
||||
|
||||
await expect(banner).toBeVisible({ timeout: 5_000 });
|
||||
await banner.getByRole("button", { name: "Stop Replay" }).click();
|
||||
|
||||
await expect(banner).toBeHidden({ timeout: 5_000 });
|
||||
await expect(
|
||||
form.getByRole("button", { name: "Start Replay" }),
|
||||
).toBeEnabled();
|
||||
await expect(
|
||||
frigateApp.page.getByText(/Failed to stop debug replay/),
|
||||
).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
test("shows no banner when nothing is running", async ({ frigateApp }) => {
|
||||
await frigateApp.installDefaults();
|
||||
await frigateApp.page.route("**/api/debug_replay/status", (route) =>
|
||||
route.fulfill({ json: noSessionStatus() }),
|
||||
);
|
||||
await openRecordingView(frigateApp);
|
||||
|
||||
const statusLoaded = frigateApp.page.waitForResponse(
|
||||
"**/api/debug_replay/status",
|
||||
);
|
||||
const form = await openDebugReplayForm(frigateApp);
|
||||
await statusLoaded;
|
||||
|
||||
await expect(
|
||||
form.getByRole("button", { name: "Start Replay" }),
|
||||
).toBeEnabled();
|
||||
await expect(form.getByRole("alert")).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Debug Replay from History — mobile @high @mobile", () => {
|
||||
test("a reselected range lands once and stays put", async ({
|
||||
frigateApp,
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
"starting": "Starting replay...",
|
||||
"startLabel": "Start",
|
||||
"endLabel": "End",
|
||||
"activeSession": {
|
||||
"description": "A debug replay session is already running for {{camera}}. Stop it to start a new one.",
|
||||
"stop": "Stop Replay",
|
||||
"stopping": "Stopping..."
|
||||
},
|
||||
"toast": {
|
||||
"error": "Failed to start debug replay: {{error}}",
|
||||
"alreadyActive": "A replay session is already active",
|
||||
|
||||
@@ -20,10 +20,14 @@ import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { SelectSeparator } from "../ui/select";
|
||||
import ActivityIndicator from "../indicators/activity-indicator";
|
||||
import { LuBug, LuPlay, LuX } from "react-icons/lu";
|
||||
import { LuBug, LuPlay, LuTriangleAlert, LuX } from "react-icons/lu";
|
||||
import useSWR from "swr";
|
||||
import { ExportMode } from "@/types/filter";
|
||||
import { TimeRange } from "@/types/timeline";
|
||||
import { DebugReplayStatus } from "@/types/replay";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useCameraFriendlyName } from "@/hooks/use-camera-friendly-name";
|
||||
import { Alert, AlertDescription } from "../ui/alert";
|
||||
import { CustomTimeSelector } from "./CustomTimeSelector";
|
||||
|
||||
const REPLAY_TIME_OPTIONS = ["1", "5", "timeline", "custom"] as const;
|
||||
@@ -56,6 +60,44 @@ export function DebugReplayContent({
|
||||
}: DebugReplayContentProps) {
|
||||
const { t } = useTranslation(["views/replay"]);
|
||||
|
||||
// Only one replay session can run at a time, so check on open rather than
|
||||
// letting the user configure a range only to hit a 409 on start
|
||||
const { data: replayStatus, mutate: refreshReplayStatus } =
|
||||
useSWR<DebugReplayStatus>("debug_replay/status");
|
||||
const replayActive = replayStatus?.active ?? false;
|
||||
const activeSourceCamera = useCameraFriendlyName(
|
||||
replayStatus?.source_camera ?? undefined,
|
||||
);
|
||||
const [isStopping, setIsStopping] = useState(false);
|
||||
|
||||
const handleStopActive = useCallback(() => {
|
||||
setIsStopping(true);
|
||||
|
||||
axios
|
||||
.post("debug_replay/stop")
|
||||
.catch((error) => {
|
||||
// 400 means no session is active, e.g. startup failed and the
|
||||
// server already cleaned it up, so there is nothing to stop
|
||||
if (error.response?.status === 400) {
|
||||
return;
|
||||
}
|
||||
|
||||
const errorMessage =
|
||||
error.response?.data?.message ||
|
||||
error.response?.data?.detail ||
|
||||
"Unknown error";
|
||||
toast.error(t("dialog.toast.stopError", { error: errorMessage }), {
|
||||
position: "top-center",
|
||||
});
|
||||
})
|
||||
// refresh on failure too, otherwise a session that ended on its own
|
||||
// leaves the banner up and Start disabled until the dialog reopens
|
||||
.then(() => refreshReplayStatus())
|
||||
.finally(() => {
|
||||
setIsStopping(false);
|
||||
});
|
||||
}, [refreshReplayStatus, t]);
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
{isDesktop && (
|
||||
@@ -68,6 +110,34 @@ export function DebugReplayContent({
|
||||
</>
|
||||
)}
|
||||
|
||||
{replayActive && (
|
||||
<Alert
|
||||
variant="warning"
|
||||
className="mt-4 flex items-start gap-2 [&>svg+div]:translate-y-0 [&>svg]:static [&>svg~*]:pl-0"
|
||||
>
|
||||
<LuTriangleAlert className="mt-0.5 size-5 shrink-0" />
|
||||
<div className="flex flex-1 flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<AlertDescription>
|
||||
{t("dialog.activeSession.description", {
|
||||
camera: activeSourceCamera,
|
||||
})}
|
||||
</AlertDescription>
|
||||
<Button
|
||||
className="flex shrink-0 items-center gap-2 self-start sm:self-auto"
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
disabled={isStopping}
|
||||
onClick={handleStopActive}
|
||||
>
|
||||
{isStopping && <ActivityIndicator className="size-4" />}
|
||||
{isStopping
|
||||
? t("dialog.activeSession.stopping")
|
||||
: t("dialog.activeSession.stop")}
|
||||
</Button>
|
||||
</div>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{/* Time range */}
|
||||
<div className="mt-4 flex flex-col gap-2">
|
||||
<RadioGroup
|
||||
@@ -122,7 +192,7 @@ export function DebugReplayContent({
|
||||
</Button>
|
||||
<Button
|
||||
variant="select"
|
||||
disabled={isStarting}
|
||||
disabled={isStarting || isStopping || replayActive}
|
||||
onClick={() => {
|
||||
if (selectedOption === "timeline") {
|
||||
setRange({
|
||||
|
||||
@@ -51,15 +51,7 @@ import { useDocDomain } from "@/hooks/use-doc-domain";
|
||||
import DebugDrawingLayer from "@/components/overlay/DebugDrawingLayer";
|
||||
import { getPrimaryModel } from "@/utils/modelUtil";
|
||||
import { IoMdArrowRoundBack } from "react-icons/io";
|
||||
|
||||
type DebugReplayStatus = {
|
||||
active: boolean;
|
||||
replay_camera: string | null;
|
||||
source_camera: string | null;
|
||||
start_time: number | null;
|
||||
end_time: number | null;
|
||||
live_ready: boolean;
|
||||
};
|
||||
import { DebugReplayStatus } from "@/types/replay";
|
||||
|
||||
type DebugReplayJobResults = {
|
||||
current_step: "preparing_clip" | "starting_camera" | null;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
export type DebugReplayStatus = {
|
||||
active: boolean;
|
||||
replay_camera: string | null;
|
||||
source_camera: string | null;
|
||||
start_time: number | null;
|
||||
end_time: number | null;
|
||||
live_ready: boolean;
|
||||
};
|
||||
Reference in New Issue
Block a user