packages icon indicating copy to clipboard operation
packages copied to clipboard

Conversation controls should no-op or expose capability state when disconnected

Open kalvin807 opened this issue 7 months ago • 2 comments

Why

  1. App code had to wrap sendUserActivity() behind status === "connected" checks.
  2. setMicMuted is failing in text-only conversations. App code had to check if a conversation is going to be voice or text before starting a conversation

What

  1. make calls like sendUserActivity() safely no-op when no active conversation exists
  2. make micMuted and setMuted() should be harmless in text-only mode

kalvin807 avatar Apr 14 '26 15:04 kalvin807

The initial intent of having these throw is that this should be handled by disabling the UI causing these calls instead and therefore it would never happen that a user would be able to set mic muted if the button to mute was disabled in text-only mode, etc. For the case of the sendUserActivity, I do see it's annoying to have to check the connected state, but it's also kind of weird that we allow an action to be performed which doesn't do what the developer is asking for (in this case we're not sending the user activity anywhere) 🤔

I'm a bit torn, between convenience and correctness, when deciding on what the "right" DX would be here.

kraenhansen avatar Apr 23 '26 12:04 kraenhansen

One more case for point 2, and this one has no app call in it at all. useConversation({ volume }) applies the volume in an effect once a conversation exists (packages/react/src/conversation/useConversation.ts:78-82 on main). For a text-only session that conversation is a TextConversation, and its setVolume throws setVolume is not supported in text conversations (packages/client/src/TextConversation.ts:11-13).

Because the throw happens inside a React effect, with no error boundary it unmounts the whole root. We hit it on @elevenlabs/react 1.15.1 / @elevenlabs/client 1.24.0 as a blank page the moment a textOnly: true session connected.

function Chat() {
  const { startSession } = useConversation({ agentId: "<any agent>", textOnly: true, volume: 0.8 });
  return <button onClick={() => startSession()}>start</button>;
}
// rendered inside <ConversationProvider>

So the "disable the UI that causes the call" answer above can't apply here, because the hook makes the call itself. #538 gave TextConversation "explicit no-op implementations" of the voice methods (public setVolume(): void {}), which is what I expected, but by the 1.0.0 release (2ad1d25f) they throw.

I'd much rather the hook skipped volume (and micMuted) for a text conversation than every caller having to know. For now we pass volume only while useRawConversation() is a VoiceConversation.

carlos-cubas avatar Oct 04 '26 21:10 carlos-cubas