Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Connection lifecycle

A DNotifier realtime client moves through authentication, WebSocket handshake (when using ws), active messaging, and disconnect. Understanding this lifecycle helps you wire onConnected, onMessage, and onDisconnected correctly.


Lifecycle diagram

  construct DNotifier({ transport: "ws", userId, ... })
         β”‚
         β–Ό
    await connect()
         β”‚
         β”œβ”€β”€β–Ί HTTPS auth β†’ production API host
         β”‚         β”‚
         β”‚         β–Ό
         β”‚    token + plan limits
         β”‚
         β”œβ”€β”€β–Ί [ws only] open WebSocket + handshake
         β”‚
         β–Ό
   onConnected()
   isConnected === true
         β”‚
         β”œβ”€β”€ send(), sendBinary(), fetchChatHistory(), ...
         β”‚
         β–Ό
   onMessage()  ◄── incoming frames (ws only)
         β”‚
         β–Ό
   disconnect() or network loss
         β”‚
         β–Ό
   onDisconnected({ code, reason })
   isConnected === false

Phase 1 β€” Authentication

All transports authenticate the same way at connect():

  1. SDK sends appId, appSecret, and userID to the DNotifier auth endpoint

  2. Server returns an auth token and plan limits

  3. Client sets aiEnabled, messageSizeLimit, and related properties

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

Production auth uses api.dnotifier.com. You rarely need to configure this β€” SDKs default to the production host. Use the optional url constructor parameter only when DNotifier provides a custom WebSocket endpoint.


Phase 2 β€” WebSocket handshake (transport: "ws")

After auth succeeds:

  1. SDK opens a WebSocket to the DNotifier realtime endpoint

  2. Sends a handshake frame containing the auth token

  3. Waits for server acknowledgment

  4. Sets isConnected = true and invokes onConnected

Until onConnected fires, do not call send() or other realtime methods β€” they require an active connection.


Phase 3 β€” Active session

While connected you can:

Action
Method

Send text or structured data

send()

Send raw binary

sendBinary()

Request chat history

fetchChatHistory()

Read plan limits

getPlanLimits()

Check connection state

isConnected

Incoming messages always flow through the onMessage callback registered at construction time.


Phase 4 β€” Disconnect

Disconnect can happen when:

  • You call disconnect() explicitly

  • The network drops or the server closes the socket

  • An unrecoverable transport error occurs

The SDK invokes onDisconnected with optional code and reason. After disconnect, isConnected is false and sends will throw until you connect() again.


Properties after connect

Property
Description

isConnected

true when ready to send (ws) or authenticated (http)

aiEnabled

Whether AI is enabled for the current plan

authToken

Token from last successful auth β€” avoid logging in production

messageSizeLimit

Max message size in bytes before chunking

Dart equivalent:


HTTP transport note

With transport: "http", Phase 2 is skipped β€” there is no persistent socket. connect() authenticates and sets isConnected = true immediately. Realtime send() and onMessage are not the primary use case for HTTP; use ws for live messaging.

β†’ Choose your transport


Next steps

Last updated