refactor(mediabunny): [PKG-MB-04] isolate typed playback and readiness coordination

This commit is contained in:
Harvey Zhao committed 2026-09-12 19:00:21 +08:00
1 parent 9af253a5a9
commit 5d0b128483
29 files changed
+2841 -726

No files matched your search

@@ -0,0 +1,27 @@
import type EventTarget from './EventTarget'
export function publish(events: EventTarget, current: () => boolean, names: readonly string[]): void {
for (const name of names) {
if (!current())
return
events.emit(name)
}
}
export function metadataBarrier(ready: () => void, current: () => boolean) {
let video = false
let audio = false
let published = false
function complete(part: 'audio' | 'video'): void {
if (!current() || published)
return
if (part === 'video')
video = true
else audio = true
if (video && audio) {
published = true
ready()
}
}
return { video: () => complete('video'), audio: () => complete('audio') }
}