import type { AviationStore } from '../store'; import type { PlaybackState } from '../specs/types.nitro'; /** * Subscribe to every store channel that a playback snapshot derives from: * state, current item, error, and position (playback reads `isLive` off the * position). Returns a single unsubscribe. Shared by {@link usePlayback} and * {@link usePlaybackFor}; both must subscribe to the same set or a transition * (e.g. on-demand → live) wouldn't re-evaluate the snapshot. */ export function subscribePlaybackChannels( store: AviationStore, cb: () => void ): () => void { const unsubs = [ store.subscribeState(cb), store.subscribeCurrentItem(cb), store.subscribeError(cb), store.subscribePosition(cb), ]; return () => unsubs.forEach((u) => u()); } /** Boolean playback flags derived from a raw {@link PlaybackState}. */ export function playbackFlags(state: PlaybackState): { isPlaying: boolean; isPaused: boolean; isLoaded: boolean; isBuffering: boolean; } { return { isPlaying: state === 'playing', isPaused: state === 'paused', isLoaded: state === 'ready' || state === 'playing' || state === 'paused' || state === 'buffering', isBuffering: state === 'buffering', }; }