Live video on the AT Protocol
1import { v7 as uuidv7 } from "uuid";
2import { makeWindow } from "../window";
3import { E2ETest, TestEnv } from "./test-env";
4import { delay, PlayerReport } from "./util";
5
6/**
7 * This test:
8 * - Plays a stream that goes up/down every 15 seconds
9 * - Observes the player for several cycles
10 * - Checks that the player spends a reasonable amount of time in 'playing' state after each recovery
11 */
12
13const PLAYING_THRESHOLD = 0.4;
14
15export const resumeLoopTest: E2ETest = {
16 setup: async (testEnv: TestEnv) => {
17 return {
18 ...testEnv,
19 env: {
20 ...testEnv.env,
21 SP_TEST_STREAM: "true",
22 },
23 };
24 },
25 test: async (testEnv: TestEnv): Promise<string | null> => {
26 const mainWindow = await makeWindow();
27
28 const testId = uuidv7();
29 const playerId = `${testId}-intermittent`;
30 const playerConfig = {
31 name: "intermittent-stream",
32 playerId,
33 src: "intermittent-self-test", // <-- Make sure this matches your Go alias!
34 showControls: true,
35 telemetry: true,
36 forceProtocol: "webrtc",
37 };
38 const enc = encodeURIComponent(JSON.stringify([playerConfig]));
39 const load = `${testEnv.addr}/multi/${enc}`;
40
41 console.log(`Opening player at ${load}`);
42 await mainWindow.loadURL(load);
43
44 await delay(testEnv.testDuration);
45
46 const res = await fetch(
47 `${testEnv.internalAddr}/player-report/${playerId}`,
48 );
49 const data = (await res.json()) as PlayerReport;
50
51 const stateTimes = data.whatHappened || {};
52 const total = Object.values(stateTimes).reduce((a, b) => a + b, 0);
53 const playing = stateTimes["playing"] || 0;
54
55 const playingPct = total > 0 ? playing / total : 0;
56
57 console.log(
58 `Overall playing percentage: ${(playingPct * 100).toFixed(1)}%`,
59 );
60 console.log("Full state times:", JSON.stringify(stateTimes, null, 2));
61
62 mainWindow.close();
63
64 if (playingPct < PLAYING_THRESHOLD) {
65 return `Player spent too little time playing during intermittent stream (${(
66 playingPct * 100
67 ).toFixed(1)}%). Possible stall or failure to recover.`;
68 }
69
70 return null;
71 },
72};