-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vapi.stop() does not seem to work, same for vapi.send(...) #67
Comments
Did you fix it ? I am facing the same issue |
this most likely happens if there is a react bug in the code where |
I ran into the same issue—I'm going to assume that you're using a custom hook called In my case, I wrote the hook in the following way: ... other setup
export const useVapi = () => {
const vapiClient = new Vapi(vapiPublicKey, undefined, {
alwaysIncludeMicInPermissionPrompt: true,
});
const [isConnecting, setIsConnecting] = useState(false);
const [isConnected, setIsConnected] = useState(false);
const [isEndingCall, setIsEndingCall] = useState(false);
const [assistantIsSpeaking, setAssistantIsSpeaking] = useState(false);
const [volumeLevel, setVolumeLevel] = useState(0);
// Hook into vapi events
useEffect(() => {
vapiClient.on("call-start", () => {
setIsConnecting(false);
setIsConnected(true);
});
vapiClient.on("call-end", () => {
setIsConnecting(false);
setIsConnected(false);
setIsEndingCall(false);
});
vapiClient.on("speech-start", () => {
setAssistantIsSpeaking(true);
});
vapiClient.on("speech-end", () => {
setAssistantIsSpeaking(false);
});
vapiClient.on('volume-level', (level) => {
setVolumeLevel(level);
});
vapiClient.on("error", (error) => {
console.error(error);
setIsConnecting(false);
});
return () => {
vapiClient.stop();
};
}, []);
// Start call
const startCall = () => {
setIsConnecting(true);
vapiClient.start(vapiAssistantId);
};
// End call
const endCall = () => {
setIsEndingCall(true);
vapiClient.stop();
};
return {
isConnecting,
isConnected,
isEndingCall,
assistantIsSpeaking,
volumeLevel,
startCall,
endCall,
};
}; The issue was that every time the hook runs (which can happen on any re-render of the component using this hook), a new instance of Vapi was being created. Two solutions:
In my case, I ended up using ... other setup
export const useVapi = () => {
const vapiClient = useMemo(() => new Vapi(vapiPublicKey, undefined, {
alwaysIncludeMicInPermissionPrompt: true,
}), []);
... rest is the same |
Even though I can successfully start a call using
vapi.start
when I invokevapi.stop
nothing happens. I even triedvapi.send
to ask the agent to end the call, but that function doesn't seem to work either. Tried2.1.4
and2.1.3
versions.Am i missing something?
The text was updated successfully, but these errors were encountered: