@@ -12,6 +12,7 @@ import {
1212 cancelResponse ,
1313 scheduleResponse ,
1414 stopVoiceSession ,
15+ type NativePlaybackState ,
1516} from '../../modules/chronicle-duplex-audio' ;
1617import {
1718 PhoneDuplexController ,
@@ -31,6 +32,7 @@ interface UseAudioStreamer {
3132 isStreaming : boolean ;
3233 isConnecting : boolean ;
3334 error : string | null ;
35+ phonePlaybackState : NativePlaybackState [ 'state' ] | null ;
3436 startStreaming : ( url : string , config ?: StreamStartConfig ) => Promise < void > ;
3537 getWebSocketReadyState : ( ) => number | undefined ;
3638 stopStreaming : ( ) => Promise < void > ;
@@ -162,6 +164,9 @@ export const useAudioStreamer = (options?: UseAudioStreamerOptions): UseAudioStr
162164 const [ isStreaming , setIsStreaming ] = useState < boolean > ( false ) ;
163165 const [ isConnecting , setIsConnecting ] = useState < boolean > ( false ) ;
164166 const [ error , setError ] = useState < string | null > ( null ) ;
167+ const [ phonePlaybackState , setPhonePlaybackState ] = useState <
168+ NativePlaybackState [ 'state' ] | null
169+ > ( null ) ;
165170
166171 const websocketRef = useRef < WebSocket | null > ( null ) ;
167172 const manuallyStoppedRef = useRef < boolean > ( false ) ;
@@ -368,6 +373,7 @@ export const useAudioStreamer = (options?: UseAudioStreamerOptions): UseAudioStr
368373 activeAudioFormatRef . current = AMBIENT_AUDIO_FORMAT ;
369374 streamConfigRef . current = undefined ;
370375 duplexUnsupportedRef . current = false ;
376+ setStateSafe ( setPhonePlaybackState , null ) ;
371377 await stopForegroundServiceNotification ( ) ;
372378 } , [ clearDuplexSocketState , sendWyomingEvent , setStateSafe ] ) ;
373379
@@ -436,6 +442,9 @@ export const useAudioStreamer = (options?: UseAudioStreamerOptions): UseAudioStr
436442 }
437443 currentUrlRef . current = trimmed ;
438444 streamConfigRef . current = requestedConfig ;
445+ if ( requestedConfig ?. phoneVoice ) {
446+ setStateSafe ( setPhonePlaybackState , null ) ;
447+ }
439448 activeAudioFormatRef . current = requestedConfig ?. phoneVoice
440449 ? phoneAudioFormat (
441450 requestedConfig . phoneVoice ,
@@ -535,6 +544,7 @@ export const useAudioStreamer = (options?: UseAudioStreamerOptions): UseAudioStr
535544 duplexControllerRef . current = controller ;
536545 duplexSubscriptionsRef . current = [
537546 addPlaybackStateListener ( ( state ) => {
547+ setStateSafe ( setPhonePlaybackState , state . state ) ;
538548 controller . nativePlaybackChanged ( state ) . catch ( ( cause ) =>
539549 console . error ( '[AudioStreamer] Playback ACK failed:' , cause )
540550 ) ;
@@ -848,6 +858,7 @@ export const useAudioStreamer = (options?: UseAudioStreamerOptions): UseAudioStr
848858 isStreaming,
849859 isConnecting,
850860 error,
861+ phonePlaybackState,
851862 startStreaming,
852863 getWebSocketReadyState,
853864 stopStreaming,
0 commit comments