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 === falsePhase 1 β Authentication
All transports authenticate the same way at connect():
SDK sends
appId,appSecret, anduserIDto the DNotifier auth endpointServer returns an auth token and plan limits
Client sets
aiEnabled,messageSizeLimit, and related properties
If authentication fails (wrong secret, invalid app, plan issue), connect() throws.
Phase 2 β WebSocket handshake (transport: "ws")
After auth succeeds:
SDK opens a WebSocket to the DNotifier realtime endpoint
Sends a handshake frame containing the auth token
Waits for server acknowledgment
Sets
isConnected = trueand invokesonConnected
Until onConnected fires, do not call send() or other realtime methods β they require an active connection.
Phase 3 β Active session
While connected you can:
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()explicitlyThe 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
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.
Next steps
Last updated