type VideoControlState = { playing: boolean; muted: boolean; }; type Listener = (state: VideoControlState) => void; let state: VideoControlState = { playing: false, muted: false, }; const listeners = new Set(); function emit() { listeners.forEach((listener) => listener(state)); } export function getVideoControlState(): VideoControlState { return state; } export function subscribeVideoControls(listener: Listener): () => void { listeners.add(listener); listener(state); return () => listeners.delete(listener); } export function setVideoPlaying(playing: boolean): void { if (state.playing === playing) return; state = { ...state, playing }; emit(); } export function setVideoMuted(muted: boolean): void { if (state.muted === muted) return; state = { ...state, muted }; emit(); } export function initializeVideoControls(next: Partial): void { const updated: VideoControlState = { playing: next.playing ?? state.playing, muted: next.muted ?? state.muted, }; if (updated.playing === state.playing && updated.muted === state.muted) return; state = updated; emit(); }