Listen to Events
React to conversation and avatar activity in your app.
Basic pattern
import { Experience } from '@liforma/client';
const experience = await Experience.startSession({
experienceId: 'exp_…'
});
experience.on('message', ({ role, text, final }) => {
if (role === 'assistant' && final) {
appendToChatLog(text);
}
});
experience.on('modeChange', ({ mode }) => {
setMicIndicator(mode === 'listening');
});
experience.on('close', ({ reason }) => {
navigateAway(reason);
});
await experience.attach({ container: '#avatar' }); Common use cases
| Goal | Event |
|---|---|
| Show transcript | message |
| Mic/speaker indicator | modeChange |
| Sync UI with world state | stateUpdate |
| Handle user closing avatar | close |