The Cognigy Click To Call SDK uses an event-driven architecture. You can subscribe to events using client.on() and unsubscribe using client.off(). All events are fully typed when using TypeScript.
Connection Events
| Event | Description | Callback Parameters |
|---|
| connecting | SIP connection is starting | () |
| connected | SIP connection established | () |
| disconnected | SIP connection lost | () |
| registered | SIP client registered successfully | () |
| unregistered | SIP client unregistered | () |
Call Events
| Event | Description | Callback Parameters |
|---|
| ringing | Call is ringing (progress) | (session: CallSession) |
| answered | Call was answered by the remote party | (session: CallSession) |
| ended | Call ended normally | (session: CallSession, endInfo: CallEndInfo) |
| failed | Call failed to connect or was rejected | (session: CallSession, endInfo: CallEndInfo) |
| muted | Local microphone was muted | (session: CallSession) |
| unmuted | Local microphone was unmuted | (session: CallSession) |
Audio Events
| Event | Description | Callback Parameters |
|---|
| captureAudio | Remote audio stream is available for advanced processing. Requires captureAudio: true in the client config | (stream: MediaStream) |
| audioEnded | Remote audio stream ended | () |
Info Message Events
| Event | Description | Callback Parameters |
|---|
| infoSent | Info message was sent successfully | (text: string, data: Record<string, any>) |
| infoReceived | Info message received from the remote party | (data: { originator: string, info: { body: string } }) |
Transcription Events
| Event | Description | Callback Parameters |
|---|
| transcription | Transcription data received | (transcription: { originator: string; messages: { text: string }[] }) |
Error Events
| Event | Description | Callback Parameters |
|---|
| error | An error occurred | (error: Error) |
Unsubscribing from Events
To remove an event listener, use client.off() with the same event name and callback reference:
const onAnswered = (session) => {
console.log('Call answered:', session.id);
};
// Subscribe
client.on('answered', onAnswered);
// Unsubscribe
client.off('answered', onAnswered);
When using off(), you must pass the same function reference that was used with on(). Anonymous functions can’t be removed.