@hyperframes/studio 0.9.56 → 0.9.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{hyperframes-player-SRLbmEDB.js → hyperframes-player-B78JDyI_.js} +1 -1
- package/dist/assets/{index-CgyBYe2L.js → index-D7ICtobF.js} +178 -178
- package/dist/assets/{index-yuN1pZrv.js → index-ww7-RmuM.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-DtvSF8bV.js → pausedVideoDecoder-Dbe8Cmab.js} +1 -1
- package/dist/index.d.ts +87 -3
- package/dist/index.html +1 -1
- package/dist/index.js +867 -774
- package/package.json +8 -8
- package/src/components/nle/NLEPreview.test.ts +35 -3
- package/src/components/nle/NLEPreview.tsx +5 -4
- package/src/hooks/gsapRuntimePatch.ts +2 -3
- package/src/hooks/gsapRuntimeReaders.test.ts +5 -40
- package/src/hooks/gsapRuntimeReaders.ts +3 -27
- package/src/hooks/useExternalFileChangeCoordinator.test.tsx +20 -0
- package/src/hooks/useExternalFileChangeCoordinator.ts +1 -1
- package/src/index.ts +17 -0
- package/src/player/components/studioShortcuts.ts +3 -2
- package/src/player/hooks/timelinePlayerTestHarness.ts +2 -0
- package/src/player/hooks/timelineSyncHydration.test.ts +28 -2
- package/src/player/hooks/timelineSyncHydration.ts +3 -7
- package/src/player/hooks/usePlaybackKeyboard.test.ts +107 -2
- package/src/player/hooks/usePlaybackKeyboard.ts +38 -1
- package/src/player/hooks/useShadowPreviewReload.ts +131 -14
- package/src/player/hooks/useTimelinePlayer.reloadStill.test.ts +241 -0
- package/src/player/hooks/useTimelinePlayer.ts +13 -1
- package/src/player/hooks/useTimelineSyncCallbacks.ts +4 -0
- package/src/sealedPreviewExports.test.ts +20 -0
- package/src/utils/externalConflictStorage.test.ts +66 -14
- package/src/utils/externalConflictStorage.ts +36 -82
- package/src/utils/gsapSoftReload.ts +2 -14
|
@@ -12,6 +12,7 @@ import { refusedPreviewStatus } from "@hyperframes/core/studio-preview-mark";
|
|
|
12
12
|
import { logReload } from "../../utils/reloadDebug";
|
|
13
13
|
import {
|
|
14
14
|
useTimelineSyncCallbacks,
|
|
15
|
+
planShadowAlone,
|
|
15
16
|
planShadowReload,
|
|
16
17
|
planShadowPromotion,
|
|
17
18
|
planShadowDiscard,
|
|
@@ -33,6 +34,28 @@ import { READY_TIMEOUT_CAUSE, useShadowReloadRetry } from "./useShadowReloadRetr
|
|
|
33
34
|
export const SHADOW_READY_TIMEOUT_MS = 15_000;
|
|
34
35
|
// A busy machine can need more than one budget; the shadow keeps loading for this many before it is dropped.
|
|
35
36
|
export const SHADOW_READY_BUDGETS = 3;
|
|
37
|
+
const STILL_RELEASE_MAX_MS = 3_000;
|
|
38
|
+
|
|
39
|
+
type HeldStill = {
|
|
40
|
+
release: () => void;
|
|
41
|
+
time: number | null;
|
|
42
|
+
playing: boolean;
|
|
43
|
+
liveSlot: PreviewIframeSlot;
|
|
44
|
+
liveIframe: HTMLIFrameElement;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function releaseAfterPaint(iframe: HTMLIFrameElement | null, release: () => void) {
|
|
48
|
+
let done = false;
|
|
49
|
+
const go = () => {
|
|
50
|
+
if (done) return;
|
|
51
|
+
done = true;
|
|
52
|
+
release();
|
|
53
|
+
};
|
|
54
|
+
setTimeout(go, STILL_RELEASE_MAX_MS);
|
|
55
|
+
void (restoreSeekPainted(iframe) ?? Promise.resolve()).then(() =>
|
|
56
|
+
requestAnimationFrame(() => requestAnimationFrame(go)),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
36
59
|
|
|
37
60
|
function restoreSeekPainted(iframe: HTMLIFrameElement | null): Promise<void> | undefined {
|
|
38
61
|
if (!iframe) return undefined;
|
|
@@ -83,6 +106,8 @@ type UseShadowPreviewReloadParams = Omit<
|
|
|
83
106
|
onReloadFailed?: (message: string) => void;
|
|
84
107
|
/** Puts the promoted document at the live frame's time, playing if the live frame was. */
|
|
85
108
|
handOverPlayback: (time: number, playing: boolean) => void;
|
|
109
|
+
/** Covers the stage with the live frame so a reload holds one page; returns what drops it, null keeps two pages. */
|
|
110
|
+
holdStill?: (live: HTMLIFrameElement) => Promise<(() => void) | null>;
|
|
86
111
|
};
|
|
87
112
|
|
|
88
113
|
export function useShadowPreviewReload({
|
|
@@ -100,6 +125,7 @@ export function useShadowPreviewReload({
|
|
|
100
125
|
onPromoted,
|
|
101
126
|
onReloadFailed,
|
|
102
127
|
handOverPlayback,
|
|
128
|
+
holdStill,
|
|
103
129
|
}: UseShadowPreviewReloadParams) {
|
|
104
130
|
const shadowIframeRef = useRef<HTMLIFrameElement | null>(null);
|
|
105
131
|
const shadowProbeIntervalRef = useRef<ReturnType<typeof setInterval> | undefined>(undefined);
|
|
@@ -127,6 +153,38 @@ export function useShadowPreviewReload({
|
|
|
127
153
|
const retry = useShadowReloadRetry(shadowGenRef, shadowUrlRef, beginShadowReloadRef);
|
|
128
154
|
const promoteWhenReadyRef = useRef<(gen: number) => void>(() => {});
|
|
129
155
|
const [previewSlots, setPreviewSlots] = useState<PreviewIframeSlot[]>([{ gen: 0, role: "live" }]);
|
|
156
|
+
const slotsRef = useRef(previewSlots);
|
|
157
|
+
slotsRef.current = previewSlots;
|
|
158
|
+
const holdStillRef = useRef(holdStill);
|
|
159
|
+
holdStillRef.current = holdStill;
|
|
160
|
+
const heldRef = useRef<HeldStill | null>(null);
|
|
161
|
+
// The newest reload asked for while a still is being taken; it starts once the still is up.
|
|
162
|
+
const holdingUrlRef = useRef<string | null>(null);
|
|
163
|
+
const holdTokenRef = useRef(0);
|
|
164
|
+
|
|
165
|
+
const restoringRef = useRef<(() => void) | null>(null);
|
|
166
|
+
const dropRestoring = useCallback(() => {
|
|
167
|
+
const release = restoringRef.current;
|
|
168
|
+
restoringRef.current = null;
|
|
169
|
+
release?.();
|
|
170
|
+
}, []);
|
|
171
|
+
const restoreLive = useCallback(
|
|
172
|
+
(held: HeldStill) => {
|
|
173
|
+
dropRestoring();
|
|
174
|
+
setPreviewSlots([held.liveSlot]);
|
|
175
|
+
pendingSeekRef.current = held.time;
|
|
176
|
+
restoringRef.current = held.release;
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
if (restoringRef.current === held.release) dropRestoring();
|
|
179
|
+
}, SHADOW_READY_TIMEOUT_MS);
|
|
180
|
+
},
|
|
181
|
+
[pendingSeekRef, dropRestoring],
|
|
182
|
+
);
|
|
183
|
+
const onLiveLoaded = useCallback(() => {
|
|
184
|
+
const release = restoringRef.current;
|
|
185
|
+
restoringRef.current = null;
|
|
186
|
+
if (release) releaseAfterPaint(iframeRef.current, release);
|
|
187
|
+
}, [iframeRef]);
|
|
130
188
|
|
|
131
189
|
const stopPendingShadow = useCallback(() => {
|
|
132
190
|
clearTimeout(readyTimerRef.current);
|
|
@@ -153,7 +211,10 @@ export function useShadowPreviewReload({
|
|
|
153
211
|
shadowIframeRef.current = null;
|
|
154
212
|
isRefreshingRef.current = false;
|
|
155
213
|
pendingSeekRef.current = null;
|
|
156
|
-
|
|
214
|
+
const held = heldRef.current;
|
|
215
|
+
heldRef.current = null;
|
|
216
|
+
if (held) restoreLive(held);
|
|
217
|
+
else setPreviewSlots(planShadowDiscard);
|
|
157
218
|
setPreviewReloading(false);
|
|
158
219
|
const message = `The preview did not reload (${cause}). It was still waiting for ${waitingFor}.${got} The previous preview is still showing.`;
|
|
159
220
|
logReload("shadow-failed", { cause, waitingFor });
|
|
@@ -163,7 +224,7 @@ export function useShadowPreviewReload({
|
|
|
163
224
|
onReloadFailedRef.current?.(message);
|
|
164
225
|
retry.afterFailure(cause, failedGen);
|
|
165
226
|
},
|
|
166
|
-
[stopPendingShadow, retry, isRefreshingRef, pendingSeekRef],
|
|
227
|
+
[stopPendingShadow, retry, isRefreshingRef, pendingSeekRef, restoreLive],
|
|
167
228
|
);
|
|
168
229
|
|
|
169
230
|
const gestureSavesOnScreen = useCallback(() => {
|
|
@@ -195,11 +256,10 @@ export function useShadowPreviewReload({
|
|
|
195
256
|
return waitThenRetry(gen, "gesture", (retry) =>
|
|
196
257
|
afterStudioManualEditGestures(liveDoc, retry),
|
|
197
258
|
);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
)
|
|
202
|
-
return false;
|
|
259
|
+
// Behind a still the live page is gone, so it has no saves to count; only the file revision tells.
|
|
260
|
+
const savesSame =
|
|
261
|
+
heldRef.current !== null || gestureSavesOnScreen() === savesAtRequestRef.current;
|
|
262
|
+
if (savesSame && studioFileRevision() === revisionAtRequestRef.current) return false;
|
|
203
263
|
if (isStudioEditSaving()) return waitThenRetry(gen, "save", afterStudioPendingEdits);
|
|
204
264
|
logReload("shadow-reloaded-after-gesture-save", { gen });
|
|
205
265
|
const url = new URL(shadowUrlRef.current, window.location.origin);
|
|
@@ -224,9 +284,11 @@ export function useShadowPreviewReload({
|
|
|
224
284
|
const { shadow, pending } = promotable;
|
|
225
285
|
stopPendingShadow();
|
|
226
286
|
// The live frame kept playing, stopped at the end or was seeked while the shadow loaded.
|
|
287
|
+
const held = heldRef.current;
|
|
288
|
+
heldRef.current = null;
|
|
227
289
|
const live = getAdapter();
|
|
228
|
-
const liveTime = live?.getTime();
|
|
229
|
-
const playing = usePlayerStore.getState().isPlaying;
|
|
290
|
+
const liveTime = held ? held.time : live?.getTime();
|
|
291
|
+
const playing = held ? held.playing : usePlayerStore.getState().isPlaying;
|
|
230
292
|
live?.pause();
|
|
231
293
|
// The store takes the new document's timeline only now that it is the one on screen, and reads it there.
|
|
232
294
|
const retired = iframeRef.current;
|
|
@@ -237,6 +299,7 @@ export function useShadowPreviewReload({
|
|
|
237
299
|
applyPreviewAudioState();
|
|
238
300
|
setPreviewSlots((prev) => planShadowPromotion(prev, gen));
|
|
239
301
|
if (liveTime != null) handOverPlaybackRef.current(liveTime, playing);
|
|
302
|
+
if (held) releaseAfterPaint(shadow, held.release);
|
|
240
303
|
announcePreviewPromoted({ retired, live: shadow });
|
|
241
304
|
onPromotedRef.current?.();
|
|
242
305
|
setPreviewReloading(false);
|
|
@@ -349,8 +412,8 @@ export function useShadowPreviewReload({
|
|
|
349
412
|
armReadyTimerRef.current(gen);
|
|
350
413
|
}, []);
|
|
351
414
|
|
|
352
|
-
const
|
|
353
|
-
(url: string) => {
|
|
415
|
+
const startShadowReload = useCallback(
|
|
416
|
+
(url: string, alone: boolean) => {
|
|
354
417
|
retry.started();
|
|
355
418
|
shadowGenRef.current += 1;
|
|
356
419
|
const gen = shadowGenRef.current;
|
|
@@ -361,12 +424,55 @@ export function useShadowPreviewReload({
|
|
|
361
424
|
savesAtRequestRef.current = gestureSavesOnScreen();
|
|
362
425
|
revisionAtRequestRef.current = studioFileRevision();
|
|
363
426
|
armReadyTimer(gen);
|
|
364
|
-
setPreviewSlots((prev) =>
|
|
427
|
+
setPreviewSlots((prev) =>
|
|
428
|
+
alone ? planShadowAlone(gen, url) : planShadowReload(prev, gen, url),
|
|
429
|
+
);
|
|
365
430
|
// Thumbnails of the edit wait for the new preview instead of competing with it.
|
|
366
431
|
setPreviewReloading(true);
|
|
367
432
|
},
|
|
368
433
|
[retry, stopPendingShadow, armReadyTimer, gestureSavesOnScreen],
|
|
369
434
|
);
|
|
435
|
+
|
|
436
|
+
const beginShadowReload = useCallback(
|
|
437
|
+
(url: string) => {
|
|
438
|
+
const live = iframeRef.current;
|
|
439
|
+
const take = holdStillRef.current;
|
|
440
|
+
if (heldRef.current || !take || !live?.isConnected) {
|
|
441
|
+
startShadowReload(url, heldRef.current !== null);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
if (holdingUrlRef.current !== null) {
|
|
445
|
+
holdingUrlRef.current = url;
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
holdingUrlRef.current = url;
|
|
449
|
+
const token = ++holdTokenRef.current;
|
|
450
|
+
// Paused first, so the still is the frame the reload resumes from.
|
|
451
|
+
const playing = usePlayerStore.getState().isPlaying;
|
|
452
|
+
getAdapter()?.pause();
|
|
453
|
+
const time = getAdapter()?.getTime() ?? null;
|
|
454
|
+
const liveSlot = slotsRef.current.find((slot) => slot.role === "live");
|
|
455
|
+
void new Promise<(() => void) | null>((resolve) => resolve(take(live)))
|
|
456
|
+
// expected: a still that cannot be taken keeps both pages for this reload, as before
|
|
457
|
+
.catch(() => null)
|
|
458
|
+
.then((release) => {
|
|
459
|
+
if (token !== holdTokenRef.current) {
|
|
460
|
+
release?.();
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
const latest = holdingUrlRef.current ?? url;
|
|
464
|
+
holdingUrlRef.current = null;
|
|
465
|
+
if (release && liveSlot && iframeRef.current === live) {
|
|
466
|
+
heldRef.current = { release, time, playing, liveSlot, liveIframe: live };
|
|
467
|
+
} else {
|
|
468
|
+
release?.();
|
|
469
|
+
if (playing) getAdapter()?.play();
|
|
470
|
+
}
|
|
471
|
+
startShadowReload(latest, heldRef.current !== null);
|
|
472
|
+
});
|
|
473
|
+
},
|
|
474
|
+
[iframeRef, getAdapter, startShadowReload],
|
|
475
|
+
);
|
|
370
476
|
beginShadowReloadRef.current = beginShadowReload;
|
|
371
477
|
|
|
372
478
|
// Composition switch (not an edit reload): drop any in-flight shadow.
|
|
@@ -378,9 +484,15 @@ export function useShadowPreviewReload({
|
|
|
378
484
|
isRefreshingRef.current = false;
|
|
379
485
|
pendingSeekRef.current = null;
|
|
380
486
|
usePlayerStore.getState().setTimelineReady(false);
|
|
381
|
-
|
|
487
|
+
const held = heldRef.current;
|
|
488
|
+
heldRef.current = null;
|
|
489
|
+
holdingUrlRef.current = null;
|
|
490
|
+
holdTokenRef.current += 1;
|
|
491
|
+
dropRestoring();
|
|
492
|
+
setPreviewSlots(held ? [held.liveSlot] : planShadowDiscard);
|
|
493
|
+
held?.release();
|
|
382
494
|
setPreviewReloading(false);
|
|
383
|
-
}, [retry, stopPendingShadow, isRefreshingRef, pendingSeekRef]);
|
|
495
|
+
}, [retry, stopPendingShadow, isRefreshingRef, pendingSeekRef, dropRestoring]);
|
|
384
496
|
|
|
385
497
|
// Hiding the tab pauses the budget; showing it again restarts the full budget for a pending shadow.
|
|
386
498
|
useMountEffect(() => {
|
|
@@ -397,6 +509,10 @@ export function useShadowPreviewReload({
|
|
|
397
509
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
398
510
|
retry.cancel();
|
|
399
511
|
stopPendingShadow();
|
|
512
|
+
heldRef.current?.release();
|
|
513
|
+
heldRef.current = null;
|
|
514
|
+
holdTokenRef.current += 1;
|
|
515
|
+
dropRestoring();
|
|
400
516
|
setPreviewReloading(false);
|
|
401
517
|
};
|
|
402
518
|
});
|
|
@@ -410,5 +526,6 @@ export function useShadowPreviewReload({
|
|
|
410
526
|
beginShadowReload,
|
|
411
527
|
resetPreviewSlots,
|
|
412
528
|
previewGeneration,
|
|
529
|
+
onLiveLoaded,
|
|
413
530
|
};
|
|
414
531
|
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
// fails without the fix: a reload kept the live page beside its own until promotion, so a heavy project held two whole
|
|
3
|
+
// pages (1.7x the app's resident memory) and ran out of memory. A host that can show the live
|
|
4
|
+
// frame as a still now gets one page at a time.
|
|
5
|
+
|
|
6
|
+
import { act } from "react";
|
|
7
|
+
import { createRoot } from "react-dom/client";
|
|
8
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
9
|
+
import { SHADOW_READY_BUDGETS, SHADOW_READY_TIMEOUT_MS } from "./useShadowPreviewReload";
|
|
10
|
+
import { usePlayerStore } from "../store/playerStore";
|
|
11
|
+
import {
|
|
12
|
+
makeAdapterWindow,
|
|
13
|
+
makeFakeIframe,
|
|
14
|
+
renderTimelinePlayerHarness,
|
|
15
|
+
resetPlayerStore,
|
|
16
|
+
} from "./timelinePlayerTestHarness";
|
|
17
|
+
|
|
18
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
19
|
+
|
|
20
|
+
vi.mock("../../utils/gsapSoftReload", async (importOriginal) => ({
|
|
21
|
+
...(await importOriginal<typeof import("../../utils/gsapSoftReload")>()),
|
|
22
|
+
ensureMotionPathPluginLoaded: vi.fn(),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
vi.useRealTimers();
|
|
27
|
+
vi.restoreAllMocks();
|
|
28
|
+
document.body.innerHTML = "";
|
|
29
|
+
resetPlayerStore();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const unmount = (root: ReturnType<typeof createRoot>) => act(() => root.unmount());
|
|
33
|
+
|
|
34
|
+
/** A loaded live preview at 3 s, and a reload asked for with `hold` as the host's still. */
|
|
35
|
+
async function reloadWithStill(
|
|
36
|
+
hold: (live: HTMLIFrameElement) => Promise<(() => void) | null>,
|
|
37
|
+
{ playing = false } = {},
|
|
38
|
+
) {
|
|
39
|
+
const harness = renderTimelinePlayerHarness({ holdPreviewStill: hold });
|
|
40
|
+
const { adapter, win } = makeAdapterWindow();
|
|
41
|
+
adapter.getTime = vi.fn(() => 3);
|
|
42
|
+
const live = makeFakeIframe(win);
|
|
43
|
+
act(() => {
|
|
44
|
+
harness.getApi().iframeRef.current = live;
|
|
45
|
+
harness.getApi().onIframeLoad();
|
|
46
|
+
});
|
|
47
|
+
if (playing) act(() => usePlayerStore.getState().setIsPlaying(true));
|
|
48
|
+
await act(async () => {
|
|
49
|
+
harness.getApi().refreshPlayer();
|
|
50
|
+
await Promise.resolve();
|
|
51
|
+
});
|
|
52
|
+
return { ...harness, live, liveAdapter: adapter };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
describe("a reload behind the host's still", () => {
|
|
56
|
+
it("drops the live page before the reload's page loads, and the still once the new page shows the live time", async () => {
|
|
57
|
+
const release = vi.fn();
|
|
58
|
+
const hold = vi.fn(async () => release);
|
|
59
|
+
const { getApi, root, live } = await reloadWithStill(hold);
|
|
60
|
+
|
|
61
|
+
expect(hold).toHaveBeenCalledWith(live);
|
|
62
|
+
const slots = getApi().previewSlots;
|
|
63
|
+
expect(slots.map((slot) => slot.role)).toEqual(["shadow"]);
|
|
64
|
+
expect(release).not.toHaveBeenCalled();
|
|
65
|
+
|
|
66
|
+
const { adapter, win } = makeAdapterWindow();
|
|
67
|
+
adapter.seek = vi.fn(adapter.seek);
|
|
68
|
+
const next = makeFakeIframe(win);
|
|
69
|
+
const gen = slots[0]!.gen;
|
|
70
|
+
act(() => {
|
|
71
|
+
getApi().setShadowIframeNode(next);
|
|
72
|
+
getApi().onShadowIframeLoad(gen);
|
|
73
|
+
getApi().onShadowReadyChange(gen, true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(getApi().previewSlots).toEqual([{ gen, role: "live", url: slots[0]!.url }]);
|
|
77
|
+
expect(getApi().iframeRef.current).toBe(next);
|
|
78
|
+
expect(adapter.seek).toHaveBeenCalledWith(3);
|
|
79
|
+
await vi.waitFor(() => expect(release).toHaveBeenCalledTimes(1));
|
|
80
|
+
unmount(root);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("resumes a playing preview from where the still was taken", async () => {
|
|
84
|
+
const { getApi, root } = await reloadWithStill(async () => () => {}, { playing: true });
|
|
85
|
+
const gen = getApi().previewSlots[0]!.gen;
|
|
86
|
+
const { adapter, win } = makeAdapterWindow();
|
|
87
|
+
adapter.getDuration = vi.fn(() => 10);
|
|
88
|
+
adapter.seek = vi.fn(adapter.seek);
|
|
89
|
+
adapter.play = vi.fn(adapter.play);
|
|
90
|
+
act(() => {
|
|
91
|
+
getApi().setShadowIframeNode(makeFakeIframe(win));
|
|
92
|
+
getApi().onShadowIframeLoad(gen);
|
|
93
|
+
getApi().onShadowReadyChange(gen, true);
|
|
94
|
+
});
|
|
95
|
+
expect(adapter.seek).toHaveBeenCalledWith(3);
|
|
96
|
+
expect(adapter.play).toHaveBeenCalled();
|
|
97
|
+
unmount(root);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("brings the live page back at its time when the reload gives up, and drops the still once it loads", async () => {
|
|
101
|
+
vi.useFakeTimers();
|
|
102
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
103
|
+
const release = vi.fn();
|
|
104
|
+
const onPreviewReloadFailed = vi.fn();
|
|
105
|
+
const harness = renderTimelinePlayerHarness({
|
|
106
|
+
holdPreviewStill: async () => release,
|
|
107
|
+
onPreviewReloadFailed,
|
|
108
|
+
});
|
|
109
|
+
const { adapter, win } = makeAdapterWindow();
|
|
110
|
+
adapter.getTime = vi.fn(() => 3);
|
|
111
|
+
const live = makeFakeIframe(win);
|
|
112
|
+
act(() => {
|
|
113
|
+
harness.getApi().iframeRef.current = live;
|
|
114
|
+
harness.getApi().onIframeLoad();
|
|
115
|
+
});
|
|
116
|
+
await act(async () => {
|
|
117
|
+
harness.getApi().refreshPlayer();
|
|
118
|
+
await Promise.resolve();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
act(() => void vi.advanceTimersByTime(SHADOW_READY_TIMEOUT_MS * SHADOW_READY_BUDGETS));
|
|
122
|
+
expect(onPreviewReloadFailed).toHaveBeenCalledWith(expect.stringContaining("too long"));
|
|
123
|
+
expect(harness.getApi().previewSlots).toEqual([{ gen: 0, role: "live" }]);
|
|
124
|
+
expect(release).not.toHaveBeenCalled();
|
|
125
|
+
|
|
126
|
+
// The live slot mounts again and loads at once, as a cached page does: that load drops the still.
|
|
127
|
+
act(() => {
|
|
128
|
+
harness.getApi().iframeRef.current = makeFakeIframe(makeAdapterWindow().win);
|
|
129
|
+
harness.getApi().onIframeLoad();
|
|
130
|
+
vi.advanceTimersByTime(3_000);
|
|
131
|
+
});
|
|
132
|
+
expect(release).toHaveBeenCalledTimes(1);
|
|
133
|
+
unmount(harness.root);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("drops a still kept for a give-up even if the live page never loads again", async () => {
|
|
137
|
+
vi.useFakeTimers();
|
|
138
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
139
|
+
const release = vi.fn();
|
|
140
|
+
const harness = renderTimelinePlayerHarness({ holdPreviewStill: async () => release });
|
|
141
|
+
act(() => {
|
|
142
|
+
harness.getApi().iframeRef.current = makeFakeIframe(makeAdapterWindow().win);
|
|
143
|
+
harness.getApi().onIframeLoad();
|
|
144
|
+
});
|
|
145
|
+
await act(async () => {
|
|
146
|
+
harness.getApi().refreshPlayer();
|
|
147
|
+
await Promise.resolve();
|
|
148
|
+
});
|
|
149
|
+
act(() => void vi.advanceTimersByTime(SHADOW_READY_TIMEOUT_MS * SHADOW_READY_BUDGETS));
|
|
150
|
+
expect(release).not.toHaveBeenCalled();
|
|
151
|
+
act(() => void vi.advanceTimersByTime(SHADOW_READY_TIMEOUT_MS));
|
|
152
|
+
expect(release).toHaveBeenCalledTimes(1);
|
|
153
|
+
unmount(harness.root);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("drops a still that answers after the composition switched, and starts no reload for the old one", async () => {
|
|
157
|
+
let answer: (release: () => void) => void = () => {};
|
|
158
|
+
const release = vi.fn();
|
|
159
|
+
const harness = renderTimelinePlayerHarness({
|
|
160
|
+
holdPreviewStill: () => new Promise((resolve) => (answer = resolve)),
|
|
161
|
+
});
|
|
162
|
+
const live = makeFakeIframe(makeAdapterWindow().win);
|
|
163
|
+
act(() => {
|
|
164
|
+
harness.getApi().iframeRef.current = live;
|
|
165
|
+
harness.getApi().onIframeLoad();
|
|
166
|
+
});
|
|
167
|
+
act(() => harness.getApi().refreshPlayer());
|
|
168
|
+
act(() => harness.getApi().resetPreviewSlots());
|
|
169
|
+
await act(async () => {
|
|
170
|
+
answer(release);
|
|
171
|
+
await Promise.resolve();
|
|
172
|
+
});
|
|
173
|
+
expect(release).toHaveBeenCalledTimes(1);
|
|
174
|
+
expect(harness.getApi().previewSlots).toEqual([{ gen: 0, role: "live" }]);
|
|
175
|
+
unmount(harness.root);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("keeps both pages for a reload when the host has no still to show, and a playing preview plays on", async () => {
|
|
179
|
+
const harness = renderTimelinePlayerHarness({ holdPreviewStill: async () => null });
|
|
180
|
+
const { adapter, win } = makeAdapterWindow();
|
|
181
|
+
adapter.play = vi.fn(adapter.play);
|
|
182
|
+
act(() => {
|
|
183
|
+
harness.getApi().iframeRef.current = makeFakeIframe(win);
|
|
184
|
+
harness.getApi().onIframeLoad();
|
|
185
|
+
});
|
|
186
|
+
act(() => usePlayerStore.getState().setIsPlaying(true));
|
|
187
|
+
await act(async () => {
|
|
188
|
+
harness.getApi().refreshPlayer();
|
|
189
|
+
await Promise.resolve();
|
|
190
|
+
});
|
|
191
|
+
expect(harness.getApi().previewSlots.map((slot) => slot.role)).toEqual(["live", "shadow"]);
|
|
192
|
+
expect(adapter.play).toHaveBeenCalled();
|
|
193
|
+
unmount(harness.root);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("a host that throws while taking the still keeps both pages and a playing preview plays on", async () => {
|
|
197
|
+
const harness = renderTimelinePlayerHarness({
|
|
198
|
+
holdPreviewStill: () => {
|
|
199
|
+
throw new Error("capture unavailable");
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
const { adapter, win } = makeAdapterWindow();
|
|
203
|
+
adapter.play = vi.fn(adapter.play);
|
|
204
|
+
act(() => {
|
|
205
|
+
harness.getApi().iframeRef.current = makeFakeIframe(win);
|
|
206
|
+
harness.getApi().onIframeLoad();
|
|
207
|
+
});
|
|
208
|
+
act(() => usePlayerStore.getState().setIsPlaying(true));
|
|
209
|
+
await act(async () => {
|
|
210
|
+
expect(() => harness.getApi().refreshPlayer()).not.toThrow();
|
|
211
|
+
await Promise.resolve();
|
|
212
|
+
await Promise.resolve();
|
|
213
|
+
});
|
|
214
|
+
expect(harness.getApi().previewSlots.map((slot) => slot.role)).toEqual(["live", "shadow"]);
|
|
215
|
+
expect(adapter.play).toHaveBeenCalled();
|
|
216
|
+
unmount(harness.root);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("pauses a playing preview before the still is taken, so the reload resumes from the frame it shows", async () => {
|
|
220
|
+
const order: string[] = [];
|
|
221
|
+
const harness = renderTimelinePlayerHarness({
|
|
222
|
+
holdPreviewStill: async () => {
|
|
223
|
+
order.push("still");
|
|
224
|
+
return () => {};
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
const { adapter, win } = makeAdapterWindow();
|
|
228
|
+
act(() => {
|
|
229
|
+
harness.getApi().iframeRef.current = makeFakeIframe(win);
|
|
230
|
+
harness.getApi().onIframeLoad();
|
|
231
|
+
});
|
|
232
|
+
act(() => usePlayerStore.getState().setIsPlaying(true));
|
|
233
|
+
adapter.pause = vi.fn(() => void order.push("pause"));
|
|
234
|
+
await act(async () => {
|
|
235
|
+
harness.getApi().refreshPlayer();
|
|
236
|
+
await Promise.resolve();
|
|
237
|
+
});
|
|
238
|
+
expect(order).toEqual(["pause", "still"]);
|
|
239
|
+
unmount(harness.root);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
@@ -51,6 +51,7 @@ export interface UseTimelinePlayerOptions {
|
|
|
51
51
|
onShadowPromoted?: () => void;
|
|
52
52
|
/** A reload was abandoned (cause in the message); the previous preview is still showing. */
|
|
53
53
|
onPreviewReloadFailed?: (message: string) => void;
|
|
54
|
+
holdPreviewStill?: (live: HTMLIFrameElement) => Promise<(() => void) | null>;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
const publishSeek = (time: number, options?: { follow?: boolean }) =>
|
|
@@ -60,6 +61,7 @@ const publishSeek = (time: number, options?: { follow?: boolean }) =>
|
|
|
60
61
|
export function useTimelinePlayer({
|
|
61
62
|
onShadowPromoted,
|
|
62
63
|
onPreviewReloadFailed,
|
|
64
|
+
holdPreviewStill,
|
|
63
65
|
}: UseTimelinePlayerOptions = {}) {
|
|
64
66
|
const iframeRef = useRef<HTMLIFrameElement | null>(null);
|
|
65
67
|
const rafRef = useRef<number>(0);
|
|
@@ -420,6 +422,7 @@ export function useTimelinePlayer({
|
|
|
420
422
|
beginShadowReload,
|
|
421
423
|
resetPreviewSlots,
|
|
422
424
|
previewGeneration,
|
|
425
|
+
onLiveLoaded,
|
|
423
426
|
} = useShadowPreviewReload({
|
|
424
427
|
iframeRef,
|
|
425
428
|
getAdapter,
|
|
@@ -434,6 +437,7 @@ export function useTimelinePlayer({
|
|
|
434
437
|
applyPreviewAudioState,
|
|
435
438
|
onPromoted: onShadowPromoted,
|
|
436
439
|
onReloadFailed: onPreviewReloadFailed,
|
|
440
|
+
holdStill: holdPreviewStill,
|
|
437
441
|
handOverPlayback: (time, playing) => {
|
|
438
442
|
// keepPlaying: move the playhead without the paused-seek audio scrub.
|
|
439
443
|
seek(time, { keepPlaying: true, follow: false });
|
|
@@ -566,13 +570,21 @@ export function useTimelinePlayer({
|
|
|
566
570
|
});
|
|
567
571
|
}, [applyPlaybackRate, applyPreviewAudioState]);
|
|
568
572
|
|
|
573
|
+
const onLiveIframeLoad = useCallback(
|
|
574
|
+
(context?: number) => {
|
|
575
|
+
onIframeLoad(context);
|
|
576
|
+
onLiveLoaded();
|
|
577
|
+
},
|
|
578
|
+
[onIframeLoad, onLiveLoaded],
|
|
579
|
+
);
|
|
580
|
+
|
|
569
581
|
return {
|
|
570
582
|
iframeRef,
|
|
571
583
|
play,
|
|
572
584
|
pause,
|
|
573
585
|
togglePlay,
|
|
574
586
|
seek,
|
|
575
|
-
onIframeLoad,
|
|
587
|
+
onIframeLoad: onLiveIframeLoad,
|
|
576
588
|
refreshPlayer,
|
|
577
589
|
saveSeekPosition,
|
|
578
590
|
resetPlayer,
|
|
@@ -111,6 +111,10 @@ export function planShadowReload(
|
|
|
111
111
|
return live ? [live, { gen: nextGen, role: "shadow", url }] : [{ gen: nextGen, role: "live" }];
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
export function planShadowAlone(nextGen: number, url: string): PreviewIframeSlot[] {
|
|
115
|
+
return [{ gen: nextGen, role: "shadow", url }];
|
|
116
|
+
}
|
|
117
|
+
|
|
114
118
|
/** Drop any pending shadow; the live slot (and its key) is untouched. */
|
|
115
119
|
export function planShadowDiscard(slots: PreviewIframeSlot[]): PreviewIframeSlot[] {
|
|
116
120
|
return slots.filter((slot) => slot.role === "live");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import * as studio from "@hyperframes/studio";
|
|
3
|
+
import * as elements from "./player/lib/previewElements";
|
|
4
|
+
import * as selection from "./components/editor/previewSelection";
|
|
5
|
+
|
|
6
|
+
it("exports a sealed preview's checked element reads and stand-ins as the ones Studio uses", () => {
|
|
7
|
+
expect(studio.describePreviewElements).toBe(elements.describePreviewElements);
|
|
8
|
+
expect(studio.previewAncestors).toBe(elements.previewAncestors);
|
|
9
|
+
expect(studio.previewElementsAtPoint).toBe(elements.previewElementsAtPoint);
|
|
10
|
+
expect(studio.previewGeometry).toBe(elements.previewGeometry);
|
|
11
|
+
expect(studio.previewLayers).toBe(elements.previewLayers);
|
|
12
|
+
expect(studio.previewPointerTargets).toBe(elements.previewPointerTargets);
|
|
13
|
+
expect(studio.queryPreviewElements).toBe(elements.queryPreviewElements);
|
|
14
|
+
expect(studio.findPreviewElementForSelection).toBe(selection.findPreviewElementForSelection);
|
|
15
|
+
expect(studio.findPreviewElementForTimelineElement).toBe(
|
|
16
|
+
selection.findPreviewElementForTimelineElement,
|
|
17
|
+
);
|
|
18
|
+
expect(studio.readable).toBe(selection.readable);
|
|
19
|
+
expect(studio.standInFor).toBe(selection.standInFor);
|
|
20
|
+
});
|