## WebRTCClientConfig

The configuration object passed to [`createWebRTCClient()`](https://docs.cognigy.com/click-to-call/sdk/api-reference/create-click-to-call-client).

```
interface WebRTCClientConfig {
  endpointUrl: string;
  userId?: string;
  captureAudio?: boolean;
  pcConfig?: RTCConfiguration;
}
```

| Property | Type | Description | Required |
| --- | --- | --- | --- |
| `endpointUrl` | `string` | URL to fetch SIP configuration from the Cognigy Voice Gateway Endpoint. | Yes |
| `userId` | `string` | Optional user identifier for the session. | No |
| `captureAudio` | `boolean` | When set to `true`, the SDK emits the [`captureAudio`](https://docs.cognigy.com/click-to-call/sdk/event-reference/capture-audio) event with the remote `MediaStream` during a call. Defaults to `false`. | No |
| `pcConfig` | `RTCConfiguration` | Custom WebRTC peer connection configuration. Use this to specify STUN/TURN servers or other `RTCPeerConnection` settings. | No |

## WebRTCClient

The main client interface returned by [`createWebRTCClient()`](https://docs.cognigy.com/click-to-call/sdk/api-reference/create-click-to-call-client). Provides all call control, state query, and event handling methods.

| Method | Reference |
| --- | --- |
| `connect()` | [connect](https://docs.cognigy.com/click-to-call/sdk/api-reference/connect) |
| `disconnect()` | [disconnect](https://docs.cognigy.com/click-to-call/sdk/api-reference/disconnect) |
| `connectAndCall()` | [connectAndCall](https://docs.cognigy.com/click-to-call/sdk/api-reference/connect-and-call) |
| `startCall()` | [startCall](https://docs.cognigy.com/click-to-call/sdk/api-reference/start-call) |
| `endCall()` | [endCall](https://docs.cognigy.com/click-to-call/sdk/api-reference/end-call) |
| `mute()` | [mute](https://docs.cognigy.com/click-to-call/sdk/api-reference/mute) |
| `unmute()` | [unmute](https://docs.cognigy.com/click-to-call/sdk/api-reference/unmute) |
| `sendInfo()` | [sendInfo](https://docs.cognigy.com/click-to-call/sdk/api-reference/send-info) |
| `isConnected()` | [isConnected](https://docs.cognigy.com/click-to-call/sdk/api-reference/is-connected) |
| `getCurrentSession()` | [getCurrentSession](https://docs.cognigy.com/click-to-call/sdk/api-reference/get-current-session) |
| `on()` | [on](https://docs.cognigy.com/click-to-call/sdk/api-reference/on) |
| `off()` | [off](https://docs.cognigy.com/click-to-call/sdk/api-reference/off) |
| `destroy()` | [destroy](https://docs.cognigy.com/click-to-call/sdk/api-reference/destroy) |

## CallSession

Represents an active call session.

```
interface CallSession {
  id: string;
  status: SessionStatus;
  direction: 'incoming' | 'outgoing';
  startTime: Date;
  answerTime?: Date;
  duration: number;
  muted: boolean;
  localHold: boolean;
  remoteHold: boolean;
}
```

| Property | Type | Description |
| --- | --- | --- |
| `id` | `string` | Unique identifier for the call session. |
| `status` | `SessionStatus` | Current session status: `'init'`, `'ringing'`, `'answered'`, `'failed'`, or `'ended'`. |
| `direction` | `'incoming' | 'outgoing'` | Whether the call was initiated locally or received from a remote party. |
| `startTime` | `Date` | Timestamp when the session was created. |
| `answerTime` | `Date | undefined` | Timestamp when the call was answered, or `undefined` if not yet answered. |
| `duration` | `number` | Call duration in seconds since the call was answered. |
| `muted` | `boolean` | Whether the local microphone is muted. |
| `localHold` | `boolean` | Whether the call is on hold locally. |
| `remoteHold` | `boolean` | Whether the call is on hold by the remote party. |

### SessionStatus

```
type SessionStatus = 'init' | 'ringing' | 'answered' | 'failed' | 'ended';
```

## CallEndInfo

Contains information about why a call ended.

```
interface CallEndInfo {
  originator: 'local' | 'remote' | null;
  cause: string | null;
  description?: string | null;
}
```

| Property | Type | Description |
| --- | --- | --- |
| `originator` | `'local' | 'remote' | null` | Who initiated the call end — the local user, the remote party, or `null` if unknown. |
| `cause` | `string | null` | The reason the call ended, for example, `Terminated`, `Canceled`, `Rejected`. |
| `description` | `string | null | undefined` | Additional description, such as a SIP status code or SIP Reason header value. |

## Transcription Data

The [`transcription`](https://docs.cognigy.com/click-to-call/sdk/event-reference/transcription) event emits the value of the `_transcription` property from incoming SIP INFO messages. The structure depends on your Cognigy Voice Gateway configuration, but typically has the following shape:

```
interface TranscriptionData {
  messages: { text: string }[];
  originator: 'user' | 'bot';
}
```

| Property | Type | Description |
| --- | --- | --- |
| `originator` | `string` | Indicates the source of the transcription, for example, `'user'` or `'bot'`. |
| `messages` | `{ text: string }[]` | Array of message objects, each containing a `text` field. |

## WebRTCClientEvents

Type map of all event names to their callback signatures. Use this for type-safe event handling. The following events are emitted by the client:

| Event | Callback Signature |
| --- | --- |
| `connecting` | `() => void` |
| `connected` | `() => void` |
| `disconnected` | `() => void` |
| `registered` | `() => void` |
| `unregistered` | `() => void` |
| `ringing` | `(session: CallSession) => void` |
| `answered` | `(session: CallSession) => void` |
| `ended` | `(session: CallSession, endInfo: CallEndInfo) => void` |
| `failed` | `(session: CallSession, endInfo: CallEndInfo) => void` |
| `muted` | `(session: CallSession) => void` |
| `unmuted` | `(session: CallSession) => void` |
| `audioEnded` | `() => void` |
| `infoSent` | `(text: string, data: Record<string, any>) => void` |
| `infoReceived` | `(data: { originator: string, info: { body: string } }) => void` |
| `transcription` | `(transcription: { originator: string; messages: { text: string }[] }) => void` |
| `error` | `(error: Error) => void` |
| `captureAudio` | `(stream: MediaStream) => void` |

```
import type { WebRTCClientEvents } from '@cognigy/click-to-call-sdk';

const handleAnswered: WebRTCClientEvents['answered'] = (session) => {
  console.log('Call answered:', session.id);
};

client.on('answered', handleAnswered);
```

## TypeScript Usage

The SDK is written in TypeScript and ships comprehensive type definitions. All interfaces and types can be imported directly:

```
import type {
  WebRTCClient,
  CallSession,
  CallEndInfo,
  WebRTCClientEvents
} from '@cognigy/click-to-call-sdk';
```

### Type-Safe Event Handling

Use the `WebRTCClientEvents` type map for fully typed event callbacks:

```
const handleAnswered: WebRTCClientEvents['answered'] = (session) => {
  console.log('Call answered:', session.id);
};

client.on('answered', handleAnswered);
```

### Type-Safe Info Messages

When sending structured data via [`sendInfo()`](https://docs.cognigy.com/click-to-call/sdk/api-reference/send-info), you can define your data shape:

```
interface MyInfoData {
  action: string;
  payload: { key: string; value: number };
}

const data: MyInfoData = {
  action: 'update',
  payload: { key: 'score', value: 42 }
};

await client.sendInfo('custom-action', data);
```

---

Last modified on July 6, 2026.
