> ## Documentation Index
> Fetch the complete documentation index at: https://docs-classic.cognigy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# connect

> Establishes the connection to the SIP server, and the SIP registration if the endpoint requires it, in the Click To Call SDK.

Connects to the SIP server. This method fetches the SIP configuration from the endpoint URL and validates that the widget is active. Then it initializes the SIP user agent and waits for the WebSocket connection to complete. If the endpoint requires SIP registration, it also waits for the registration. The configuration fetch has a 10-second timeout, and the connection has a 15-second timeout. This must be called before [`startCall()`](https://docs-classic.cognigy.com/click-to-call/sdk/api-reference/start-call).

## Signature

```typescript theme={null}
await client.connect();
```

## Parameters

None.

## Returns

`Promise<void>`

## Throws

An error if the client has been destroyed, the configuration fetch fails, the Click To Call widget isn't active, or the SIP connection or registration fails. Except for `Client has been destroyed`, the error messages start with `Failed to connect:`.

| Error | Cause |
| - | - |
| `Client has been destroyed` | You called `connect()` after `destroy()`. |
| `Failed to connect: Configuration fetch failed: Failed to fetch config: <status> <text>` | The endpoint URL returned an unsuccessful HTTP response. |
| `Failed to connect: Configuration fetch failed: Invalid endpoint configuration received` | The endpoint returned an invalid SIP configuration. |
| `Failed to connect: WebRTC widget is not active in the configuration` | The Click To Call widget isn't active in the endpoint configuration. |
| `Failed to connect: Operation timed out after 15000ms` | The connection wasn't established within 15 seconds. |
| `Failed to connect: Registration failed: <cause>` | The SIP registration was rejected. |

## Example

```typescript theme={null}
await client.connect();
console.log('Connected');
```

> [!NOTE]
>
> If you call `connect()` a second time, the SDK initializes a new SIP user agent. If you don't provide a `userId`, the SDK generates one.

### With Error Handling

```typescript theme={null}
try {
  await client.connect();
  console.log('Connected');
} catch (error) {
  console.error('Failed to connect:', error.message);
}
```

## More Information

* [disconnect](https://docs-classic.cognigy.com/click-to-call/sdk/api-reference/disconnect.md)
* [connectAndCall](https://docs-classic.cognigy.com/click-to-call/sdk/api-reference/connect-and-call.md)
* [startCall](https://docs-classic.cognigy.com/click-to-call/sdk/api-reference/start-call.md)
* [registered](https://docs-classic.cognigy.com/click-to-call/sdk/event-reference/registered.md) event


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.