@@ -6,12 +6,14 @@ export interface VapiCallState {
6
6
isSpeaking : boolean ;
7
7
volumeLevel : number ;
8
8
connectionStatus : 'disconnected' | 'connecting' | 'connected' ;
9
+ isMuted : boolean ;
9
10
}
10
11
11
12
export interface VapiCallHandlers {
12
13
startCall : ( ) => Promise < void > ;
13
14
endCall : ( ) => Promise < void > ;
14
15
toggleCall : ( ) => Promise < void > ;
16
+ toggleMute : ( ) => void ;
15
17
}
16
18
17
19
export interface UseVapiCallOptions {
@@ -47,6 +49,7 @@ export const useVapiCall = ({
47
49
48
50
const [ isCallActive , setIsCallActive ] = useState ( false ) ;
49
51
const [ isSpeaking , setIsSpeaking ] = useState ( false ) ;
52
+ const [ isMuted , setIsMuted ] = useState ( false ) ;
50
53
const [ volumeLevel , setVolumeLevel ] = useState ( 0 ) ;
51
54
const [ connectionStatus , setConnectionStatus ] = useState <
52
55
'disconnected' | 'connecting' | 'connected'
@@ -86,6 +89,7 @@ export const useVapiCall = ({
86
89
setConnectionStatus ( 'disconnected' ) ;
87
90
setVolumeLevel ( 0 ) ;
88
91
setIsSpeaking ( false ) ;
92
+ setIsMuted ( false ) ;
89
93
callbacksRef . current . onCallEnd ?.( ) ;
90
94
} ;
91
95
@@ -185,15 +189,28 @@ export const useVapiCall = ({
185
189
}
186
190
} , [ isCallActive , startCall , endCall ] ) ;
187
191
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
+
188
203
return {
189
204
// State
190
205
isCallActive,
191
206
isSpeaking,
192
207
volumeLevel,
193
208
connectionStatus,
209
+ isMuted,
194
210
// Handlers
195
211
startCall,
196
212
endCall,
197
213
toggleCall,
214
+ toggleMute,
198
215
} ;
199
216
} ;
0 commit comments