import { useCallback, useSyncExternalStore } from 'react' import { type VoiceSessionSnapshot, voiceSession } 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) }