fix live analysis multi-device lock

这个提交包含在:
cryptocommuniums-afk
2026-03-16 18:05:58 +08:00
父节点 13e59b8e8a
当前提交 f9db6ef590
修改 7 个文件,包含 221 行新增28 行删除

查看文件

@@ -78,6 +78,20 @@ test("live camera switches into viewer mode when another device already owns ana
await expect(page.getByTestId("live-camera-score-overall")).toBeVisible();
});
test("live camera retries viewer stream when owner track is not ready on first attempt", async ({ page }) => {
const state = await installAppMocks(page, {
authenticated: true,
liveViewerMode: true,
viewerSignalConflictOnce: true,
});
await page.goto("/live-camera");
await expect(page.getByText("同步观看模式")).toBeVisible();
await expect.poll(() => state.viewerSignalConflictRemaining).toBe(0);
await expect.poll(() => state.mediaSession?.viewerCount ?? 0).toBe(1);
await expect(page.getByText(/同步观看中|重新同步/).first()).toBeVisible();
});
test("live camera archives overlay videos into the library after analysis stops", async ({ page }) => {
await installAppMocks(page, { authenticated: true, videos: [] });
@@ -126,3 +140,11 @@ test("recorder flow archives a session and exposes it in videos", async ({ page
await expect(page.getByTestId("video-card")).toHaveCount(1);
await expect(page.getByText("E2E 录制")).toBeVisible();
});
test("recorder blocks local camera when another device owns live analysis", async ({ page }) => {
await installAppMocks(page, { authenticated: true, liveViewerMode: true });
await page.goto("/recorder");
await expect(page.getByText("当前账号已有其他设备正在实时分析")).toBeVisible();
await expect(page.getByTestId("recorder-start-camera-button")).toBeDisabled();
});

查看文件

@@ -100,6 +100,7 @@ type MockAppState = {
nextVideoId: number;
nextTaskId: number;
authMeNullResponsesAfterLogin: number;
viewerSignalConflictRemaining: number;
};
function trpcResult(json: unknown) {
@@ -637,15 +638,24 @@ async function handleMedia(route: Route, state: MockAppState) {
return;
}
if (path.endsWith("/signal")) {
state.mediaSession.status = "recording";
await fulfillJson(route, { type: "answer", sdp: "mock-answer" });
if (path.endsWith("/viewer-signal")) {
if (state.viewerSignalConflictRemaining > 0) {
state.viewerSignalConflictRemaining -= 1;
await route.fulfill({
status: 409,
contentType: "application/json",
body: JSON.stringify({ error: "viewer stream not ready" }),
});
return;
}
state.mediaSession.viewerCount = (state.mediaSession.viewerCount || 0) + 1;
await fulfillJson(route, { viewerId: `viewer-${state.mediaSession.viewerCount}`, type: "answer", sdp: "mock-answer" });
return;
}
if (path.endsWith("/viewer-signal")) {
state.mediaSession.viewerCount = (state.mediaSession.viewerCount || 0) + 1;
await fulfillJson(route, { viewerId: `viewer-${state.mediaSession.viewerCount}`, type: "answer", sdp: "mock-answer" });
if (path.endsWith("/signal")) {
state.mediaSession.status = "recording";
await fulfillJson(route, { type: "answer", sdp: "mock-answer" });
return;
}
@@ -714,6 +724,7 @@ export async function installAppMocks(
userName?: string;
authMeNullResponsesAfterLogin?: number;
liveViewerMode?: boolean;
viewerSignalConflictOnce?: boolean;
}
) {
const seededViewerSession = options?.liveViewerMode ? buildMediaSession(buildUser(options?.userName), "其他设备实时分析") : null;
@@ -817,6 +828,7 @@ export async function installAppMocks(
nextVideoId: 100,
nextTaskId: 1,
authMeNullResponsesAfterLogin: options?.authMeNullResponsesAfterLogin ?? 0,
viewerSignalConflictRemaining: options?.viewerSignalConflictOnce ? 1 : 0,
};
await page.addInitScript(() => {
@@ -921,9 +933,12 @@ export async function installAppMocks(
localDescription: { type: string; sdp: string } | null = null;
remoteDescription: { type: string; sdp: string } | null = null;
onconnectionstatechange: (() => void) | null = null;
ontrack: ((event: { streams: MediaStream[] }) => void) | null = null;
addTrack() {}
addTransceiver() {}
async createOffer() {
return { type: "offer", sdp: "mock-offer" };
}
@@ -937,6 +952,7 @@ export async function installAppMocks(
async setRemoteDescription(description: { type: string; sdp: string }) {
this.remoteDescription = description;
this.connectionState = "connected";
this.ontrack?.({ streams: [new MediaStream()] });
this.onconnectionstatechange?.();
}