Event Handling
React to conversation events and user interactions with Anam personas
Anam personas communicate through a rich event system that lets you respond to connection changes, conversation updates, and user interactions. Understanding these events is key to building responsive, interactive applications.
How Events Work
The Anam SDK uses an event-driven architecture where your application can listen for specific events and react accordingly. This allows you to:
- Update your UI based on connection status
- Track conversation history in real-time
- Handle user interruptions gracefully
- Monitor stream quality and performance
Initialize Client
Create your Anam client with a session token
Add Event Listeners
Register listeners for the events you care about
React to Events
Update your UI and application state based on event data
Clean Up
Remove listeners when components unmount or sessions end
Available Events
Connection Events
These events track the connection lifecycle between your client and Anam’s streaming infrastructure:
CONNECTION_ESTABLISHED
Fired when the WebRTC connection is successfully established.
CONNECTION_CLOSED
Fired when the connection is terminated.
Video Events
VIDEO_PLAY_STARTED
Fired when the first video frames begin playing. Ideal for removing loading indicators.
Conversation Events
These events help you track and respond to conversation flow:
MESSAGE_HISTORY_UPDATED
Provides the complete conversation history each time a participant finishes speaking.
MESSAGE_STREAM_EVENT_RECEIVED
Provides real-time transcription updates as speech occurs.
Audio Events
INPUT_AUDIO_STREAM_STARTED
Fired when microphone input is successfully initialized.
Talk Stream Events
TALK_STREAM_INTERRUPTED
Fired when a user interrupts a TalkMessageStream
by speaking.