@@ -148,17 +148,21 @@ const useLayercodeAgent = (
148148 } , [ preferredInputDeviceId ] ) ;
149149
150150 useEffect ( ( ) => {
151- if ( typeof window === 'undefined' ) {
151+ // Only refresh input devices if audioInput is enabled
152+ // This prevents requesting microphone permissions when audio is disabled
153+ if ( typeof window === 'undefined' || ! audioInput ) {
152154 return ;
153155 }
154156
155157 refreshInputDevices ( ) . catch ( ( error ) => {
156158 console . warn ( 'Layercode: failed to load microphone devices' , error ) ;
157159 } ) ;
158- } , [ refreshInputDevices ] ) ;
160+ } , [ refreshInputDevices , audioInput ] ) ;
159161
160162 useEffect ( ( ) => {
161- if ( typeof window === 'undefined' || typeof navigator === 'undefined' ) {
163+ // Only watch for device changes if audioInput is enabled
164+ // This prevents requesting microphone permissions when audio is disabled
165+ if ( typeof window === 'undefined' || typeof navigator === 'undefined' || ! audioInput ) {
162166 return ;
163167 }
164168
@@ -176,11 +180,11 @@ const useLayercodeAgent = (
176180 return ( ) => {
177181 unsubscribe ?.( ) ;
178182 } ;
179- } , [ ] ) ;
183+ } , [ audioInput ] ) ;
180184
181185 const createClient = useCallback (
182186 ( initialConversationId : string | null ) => {
183- console . log ( 'Creating LayercodeClient instance' ) ;
187+ console . log ( 'Creating LayercodeClient instance with audioInput:' , audioInput , 'audioOutput:' , audioOutput ) ;
184188 const client = new LayercodeClient ( {
185189 agentId,
186190 conversationId : initialConversationId ,
@@ -310,19 +314,19 @@ const useLayercodeAgent = (
310314 } , [ ] ) ;
311315
312316 const setAudioInput = useCallback (
313- ( state : React . SetStateAction < boolean > ) => {
317+ async ( state : React . SetStateAction < boolean > ) => {
314318 _setAudioInput ( state ) ;
315319 const next = typeof state === 'function' ? ( state as ( prev : boolean ) => boolean ) ( audioInput ) : state ;
316- clientRef . current ?. setAudioInput ( next ) ;
320+ await clientRef . current ?. setAudioInput ( next ) ;
317321 } ,
318322 [ _setAudioInput , clientRef , audioInput ]
319323 ) ;
320324
321325 const setAudioOutput = useCallback (
322- ( state : React . SetStateAction < boolean > ) => {
326+ async ( state : React . SetStateAction < boolean > ) => {
323327 _setAudioOutput ( state ) ;
324328 const next = typeof state === 'function' ? ( state as ( prev : boolean ) => boolean ) ( audioOutput ) : state ;
325- clientRef . current ?. setAudioOutput ( next ) ;
329+ await clientRef . current ?. setAudioOutput ( next ) ;
326330 } ,
327331 [ _setAudioOutput , clientRef , audioOutput ]
328332 ) ;
0 commit comments