> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/getting-started/first-connection.md).

# Your first connection

Connecting is the first code you write after installing an SDK. This page explains the flow conceptually; language-specific guides contain copy-paste examples.

## What `connect()` does

When you call `connect()`, the SDK performs two phases depending on transport:

### Phase 1 — Authentication (all transports)

1. Sends `appId`, `appSecret`, and `userID` to the DNotifier auth endpoint
2. Receives an auth **token** and **plan limits**
3. Sets `aiEnabled`, `messageSizeLimit`, and related properties on the client

If authentication fails (wrong secret, invalid app, plan issue), `connect()` throws an error.

### Phase 2 — Transport setup

| Transport  | What happens after auth                                                                                                                                  |
| ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`ws`**   | Opens a WebSocket to DNotifier, sends a handshake frame with the token, waits for acknowledgment, then sets `isConnected = true` and calls `onConnected` |
| **`http`** | Skips the persistent socket; sets `isConnected = true` and calls `onConnected` immediately after auth                                                    |

For your **first message** tutorial, use **`transport: "ws"`** so you can send and receive in realtime.

## Constructor options (common to all SDKs)

| Option           | Required    | Description                            |
| ---------------- | ----------- | -------------------------------------- |
| `appId`          | Yes         | From dashboard                         |
| `secret`         | Yes         | From dashboard                         |
| `transport`      | Yes         | `"ws"` or `"http"`                     |
| `userId`         | Yes         | Your end-user or service identifier    |
| `onConnected`    | Recommended | Called when ready to send              |
| `onMessage`      | Recommended | Called for incoming WebSocket messages |
| `onDisconnected` | Recommended | Called when the socket closes          |

Optional: `logs`, `url` (custom WebSocket URL), and platform-specific WebSocket injection (Node.js).

## Connection lifecycle

```
  construct DNotifier
         │
         ▼
    connect()
         │
         ├──► HTTP auth (appId + secret + userId)
         │         │
         │         ▼
         │    token + plan limits
         │
         ├──► [ws only] open WebSocket + handshake
         │
         ▼
   onConnected()
         │
         ├── send(), sendBinary(), ...
         │
         ▼
   onMessage()  ◄── incoming frames (ws only)
         │
         ▼
   onDisconnected()  ◄── socket closed or network loss
```

## After a successful connect

You can read:

* `notifier.isConnected` — `true` when ready
* `notifier.getPlanLimits()` — quotas from your plan
* `notifier.aiEnabled` — whether AI features are on
* `notifier.messageSizeLimit` — max message size in bytes
* `notifier.authToken` — token from the last auth (avoid logging in production)

## Language guides

Pick your stack for a complete, runnable example:

| Language                | Guide                                                                                                                           |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| JavaScript / TypeScript | [javascript-typescript.md](https://dnotifier.gitbook.io/product-docs/getting-started/first-connection/javascript-typescript.md) |
| Dart / Flutter          | [dart-flutter.md](https://dnotifier.gitbook.io/product-docs/getting-started/first-connection/dart-flutter.md)                   |
| Python                  | [python.md](https://dnotifier.gitbook.io/product-docs/getting-started/first-connection/python.md)                               |

.NET, Android, and iOS SDKs are coming soon — use JavaScript, Dart, or Python guides until those packages ship.

## Prerequisites checklist

* [ ] [App created](https://dnotifier.gitbook.io/product-docs/getting-started/create-app.md) with `appId` and `secret`
* [ ] [Credentials](https://dnotifier.gitbook.io/product-docs/getting-started/credentials.md) loaded from environment variables
* [ ] [SDK installed](https://dnotifier.gitbook.io/product-docs/getting-started/installation.md)
* [ ] Transport chosen — use `ws` for the first-message walkthrough

## Next step

After you connect successfully, send your first 1:1 message:

→ [**Your first message**](https://dnotifier.gitbook.io/product-docs/getting-started/first-message.md)
