Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions website/src/components/Recreation/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {

/* ── the webcam ───────────────────────────────────────────────────────── */

let camReady = false;
let camPending: number | undefined;
const camSrc = "/video/webcam.mp4";

Expand All @@ -595,9 +594,6 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
cam.preload = "auto";
cam.load();
};
const onCamLoaded = () => {
camReady = true;
};
const onCamSeeked = () => {
if (camPending !== undefined) {
const q = camPending;
Expand All @@ -609,7 +605,6 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
}
}
};
cam.addEventListener("loadeddata", onCamLoaded);
cam.addEventListener("seeked", onCamSeeked);
/* ── the swatch strip ─────────────────────────────────────────────────── */

Expand All @@ -636,11 +631,24 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
};

const seekCam = (tf: number) => {
if (!camReady || cam.readyState < 2) return;
/* The element's own state, never a flag set by an event. The video
outlives the driver, so on a re-attach `loadeddata` had fired long ago
and a flag waiting for it stayed false: the bubble froze for good.
And HAVE_METADATA, not HAVE_CURRENT_DATA: a seek into an unbuffered
range drops readyState to 1 while it runs, and gating on 2 threw away
every target issued meanwhile — the last one included, so a reader who
stopped scrolling then was left on a stale frame. */
if (cam.readyState < 1) return;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const dur = Number.isFinite(cam.duration) && cam.duration > 0 ? cam.duration : 10;
const t = ((tf % dur) + dur) % dur;
if (cam.seeking) camPending = t;
else if (Math.abs((cam.currentTime || 0) - t) > 0.033) {
if (cam.seeking) {
camPending = t;
return;
}
// `seeking` drops before its `seeked` is dispatched. A pending target left
// here would be applied by that late event, over the newer one below.
camPending = undefined;
if (Math.abs((cam.currentTime || 0) - t) > 0.033) {
try {
cam.currentTime = t;
} catch {
Expand Down Expand Up @@ -905,7 +913,6 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
// The video outlives the driver — it is the same element on re-attach —
// so listeners left on it accumulate one pair per breakpoint crossing,
// each holding a dead driver's closure alive.
cam.removeEventListener("loadeddata", onCamLoaded);
cam.removeEventListener("seeked", onCamSeeked);
if (raf) cancelAnimationFrame(raf);
if (resizeRaf) cancelAnimationFrame(resizeRaf);
Expand Down
Loading