Discussions
JS SDK stopListening call
9 days ago by Kris
What is the expected behavior of this call? I have a button set up that is intended to act as a mic mute. When clicked, it calls a method that calls the stopListening method. On another click, it calls startListening, and so forth as a toggle. However, if I call it while the avatar is talking, I get a 400 response, and the error states it can't stop listening because the avatar is talking or interrupting. If I call it when it's not speaking, I get a 100 response, but the avatar still listens. I'm unclear on the functionality of this call. If this doesn't work, how do I mute the mic? Do I need to write my own handler for that? Here is the method that his called on click:
async function handleMicToggle() {
if (micEnabled) {
const res = await avatar.current!.stopListening();
if (res.success) {
console.log(res.message);
setMicEnabled(false);
} else {
console.error("Error stopping avatar listening:", res.message);
}
} else {
const res = await avatar.current!.startListening();
if (res.success) {
console.log(res.message);
setMicEnabled(true);
} else {
console.error("Error starting avatar listening:", res.message);
}
}
}