type PreviewVideo = Pick;
/** Restore browser presentation without changing the peer or camera capture. */
export function previewPlayback(video: PreviewVideo | null) {
let disposed = false, pending = false;
return {
resume() {
if (disposed || pending || !video?.srcObject || !video.paused) return;
pending = true;
video.muted = true;
// WebKit can pause an offscreen panel and reject playback while it remains hidden.
// A later visibility/presentation check retries playback on the same stream.
void video.play().catch(() => undefined).finally(() => { pending = false; });
},
dispose() { disposed = true; },
};
}