Skip to main content

Connection Lifecycle

The WebSocket connection follows a specific lifecycle:

Message Format

All WebSocket messages use SuperJSON encoding for type-safe serialization.

Base Event Structure

string
required
Event type identifier (e.g., 'module:authenticate', 'ui:configure')
T
required
Event-specific payload data
MetadataEventSource
required
Source information including plugin identity
string
required
Unique event identifier for tracing
string
Parent event ID for request-response correlation
Array<string | RouteTargetExpression>
Target destinations for event routing
boolean
Whether to bypass routing policies (requires devtools label)

Event Types

Authentication Events

module:authenticate

Sent by client to authenticate with the server.

module:authenticated

Server response indicating authentication status.

Module Registration

module:announce

Client announces itself to the module registry.
string
required
Module name (must be non-empty string)
number
Module instance index (must be non-negative integer)
MetadataEventSource
required
Module identity with plugin information

registry:modules:sync

Server broadcasts current module registry to newly connected clients.

Configuration Events

ui:configure

Sent from UI to configure a specific module.
The server transforms this into module:configure and routes it to the target module:

Heartbeat Events

transport:connection:heartbeat

Bidirectional heartbeat messages to maintain connection health.
'ping' | 'pong'
required
Heartbeat message type
MessageHeartbeat | string
required
Heartbeat message content
number
required
Unix timestamp in milliseconds

Error Events

error

Server error response.

Connection Management

Peer State

The server maintains the following state for each connected peer:

Heartbeat Timeout

Connections are automatically closed if no heartbeat is received within the configured timeout period (default: 60 seconds).

Best Practices

The server uses source metadata for module identification and routing. Always include complete plugin identity information.
If the server requires authentication, wait for module:authenticated before announcing your module.
Send heartbeat pings at regular intervals (recommended: every 30 seconds) to prevent connection timeout.
Generate unique event IDs and use parentId for request-response correlation to enable end-to-end tracing.
Implement exponential backoff for reconnection attempts when connection is lost.

Error Handling

Common error scenarios:

Next Steps

Event System

Learn about event routing and middleware

Server SDK

Use the client SDK for easy integration