@@ -6,12 +6,14 @@ export interface VapiCallState {
66 isSpeaking : boolean ;
77 volumeLevel : number ;
88 connectionStatus : 'disconnected' | 'connecting' | 'connected' ;
9+ isMuted : boolean ;
910}
1011
1112export interface VapiCallHandlers {
1213 startCall : ( ) => Promise < void > ;
1314 endCall : ( ) => Promise < void > ;
1415 toggleCall : ( ) => Promise < void > ;
16+ toggleMute : ( ) => void ;
1517}
1618
1719export interface UseVapiCallOptions {
@@ -47,6 +49,7 @@ export const useVapiCall = ({
4749
4850 const [ isCallActive , setIsCallActive ] = useState ( false ) ;
4951 const [ isSpeaking , setIsSpeaking ] = useState ( false ) ;
52+ const [ isMuted , setIsMuted ] = useState ( false ) ;
5053 const [ volumeLevel , setVolumeLevel ] = useState ( 0 ) ;
5154 const [ connectionStatus , setConnectionStatus ] = useState <
5255 'disconnected' | 'connecting' | 'connected'
@@ -86,6 +89,7 @@ export const useVapiCall = ({
8689 setConnectionStatus ( 'disconnected' ) ;
8790 setVolumeLevel ( 0 ) ;
8891 setIsSpeaking ( false ) ;
92+ setIsMuted ( false ) ;
8993 callbacksRef . current . onCallEnd ?.( ) ;
9094 } ;
9195
@@ -185,15 +189,28 @@ export const useVapiCall = ({
185189 }
186190 } , [ isCallActive , startCall , endCall ] ) ;
187191
192+ const toggleMute = useCallback ( ( ) => {
193+ if ( ! vapi || ! isCallActive ) {
194+ console . log ( 'Cannot toggle mute: no vapi instance or call not active' ) ;
195+ return ;
196+ }
197+
198+ const newMutedState = ! isMuted ;
199+ vapi . setMuted ( newMutedState ) ;
200+ setIsMuted ( newMutedState ) ;
201+ } , [ vapi , isCallActive , isMuted ] ) ;
202+
188203 return {
189204 // State
190205 isCallActive,
191206 isSpeaking,
192207 volumeLevel,
193208 connectionStatus,
209+ isMuted,
194210 // Handlers
195211 startCall,
196212 endCall,
197213 toggleCall,
214+ toggleMute,
198215 } ;
199216} ;
0 commit comments