/** Bound frames in flight so image decoding cannot delay browser input. */ export class FrameDelivery { sequence = 0; pending = new Map(); canSend(time = performance.now()) { for (const [id, started] of this.pending) if (time - started > 250) this.pending.delete(id); return this.pending.size < 2; } sent(time = performance.now()) { const id = ++this.sequence; this.pending.set(id, time); return id; } acknowledge(id) { this.pending.delete(id); } clear() { this.pending.clear(); } }