From 6a22a3ecbdff2d0e6a4c24c8db40bb86bc01b692 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Sat, 25 Apr 2026 03:56:22 +0200 Subject: refactor: centralize editor interaction state Move timeline and preview gestures into dedicated controllers so hooks stay thin around editor state and DOM events. This also routes drag and playback synchronization through manager APIs and reuses persistent wasm surfaces so scrubbing, seeking, and preview rendering stay in sync. Made-with: Cursor --- apps/web/src/services/video-cache/service.ts | 31 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'apps/web/src/services') diff --git a/apps/web/src/services/video-cache/service.ts b/apps/web/src/services/video-cache/service.ts index 31467065..cad4fc31 100644 --- a/apps/web/src/services/video-cache/service.ts +++ b/apps/web/src/services/video-cache/service.ts @@ -21,6 +21,7 @@ export class VideoCache { private sinks = new Map(); private initPromises = new Map>(); private frameChain = new Map>(); + private seekGenerations = new Map(); async getFrameAt({ mediaId, @@ -36,11 +37,20 @@ export class VideoCache { const sinkData = this.sinks.get(mediaId); if (!sinkData) return null; + const generation = (this.seekGenerations.get(mediaId) ?? 0) + 1; + this.seekGenerations.set(mediaId, generation); + const previous = this.frameChain.get(mediaId) ?? Promise.resolve(); - const current = previous.then(() => - this.resolveFrame({ sinkData, time }), + const current = previous.then(() => { + if (this.seekGenerations.get(mediaId) !== generation) { + return sinkData.currentFrame ?? null; + } + return this.resolveFrame({ sinkData, time }); + }); + this.frameChain.set( + mediaId, + current.catch(() => {}), ); - this.frameChain.set(mediaId, current.catch(() => {})); return current; } @@ -173,18 +183,7 @@ export class VideoCache { if (frame) { sinkData.currentFrame = frame; - - // Aggressively fetch next frame immediately to fill buffer - // This matches the mediaplayer example which fetches 2 frames on start - try { - const { value: next } = await sinkData.iterator.next(); - if (next) { - sinkData.nextFrame = next; - } - } catch (e) { - console.warn("Failed to pre-fetch next frame on seek:", e); - } - + this.startPrefetch({ sinkData }); return frame; } } catch (error) { @@ -313,6 +312,8 @@ export class VideoCache { } this.initPromises.delete(mediaId); + this.frameChain.delete(mediaId); + this.seekGenerations.delete(mediaId); } clearAll(): void { -- cgit v1.3.1