Open a session
connect() accepts optional arguments:
Send a message
The socket sends typed frames. Amessage frame submits a turn — note that on
the WebSocket the target agent is explicit; use the id resolved from your key:
Receive envelopes
Every server frame is a sequenced envelope. Register handlers withon(event, handler) — events are open, message, error, and close:
on() registers a single handler per event — calling it again for the
same event replaces the previous handler.The same handler also receives the frames of a
watched conversation:
watching,
and message / silent frames that carry sequence instead of seq. That
is why the example checks 'seq' in envelope before reading it. From SDK
3.4.2 the check is required for the handler to compile.Resume after a reconnect
Envelopes carry a monotonicseq (locally generated errors use -1). Track
the highest value you’ve processed; after a reconnect, ask the server to
replay what you missed instead of re-running the turn:
reconnectAttempts), so a typical
pattern is to send a resume frame from the open handler when lastSeq > -1.
Close the session
readyState for connection-state checks.