import { useCallback, useSyncExternalStore } from 'react' import { voiceSession, type VoiceSessionSnapshot } from './session' const INITIAL: VoiceSessionSnapshot = voiceSession.getSnapshot() export function useVoiceSession(): VoiceSessionSnapshot { const subscribe = useCallback( (onChange: () => void) => voiceSession.subscribe(() => onChange()), [], ) const getSnapshot = useCallback(() => voiceSession.getSnapshot(), []) return useSyncExternalStore(subscribe, getSnapshot, () => INITIAL) }