Connection Lifecycle
The WebSocket connection follows a specific lifecycle:Message Format
All WebSocket messages use SuperJSON encoding for type-safe serialization.Base Event Structure
Event type identifier (e.g.,
'module:authenticate', 'ui:configure')Event-specific payload data
Source information including plugin identity
Unique event identifier for tracing
Parent event ID for request-response correlation
Target destinations for event routing
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.
Module name (must be non-empty string)
Module instance index (must be non-negative integer)
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.
module:configure and routes it to the target module:
Heartbeat Events
transport:connection:heartbeat
Bidirectional heartbeat messages to maintain connection health.
Heartbeat message type
Heartbeat message content
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
Always include metadata.source
Always include metadata.source
The server uses source metadata for module identification and routing. Always include complete plugin identity information.
Handle authentication properly
Handle authentication properly
If the server requires authentication, wait for
module:authenticated before announcing your module.Implement heartbeat
Implement heartbeat
Send heartbeat pings at regular intervals (recommended: every 30 seconds) to prevent connection timeout.
Use event IDs for tracing
Use event IDs for tracing
Generate unique event IDs and use parentId for request-response correlation to enable end-to-end tracing.
Handle reconnection
Handle reconnection
Implement exponential backoff for reconnection attempts when connection is lost.
Error Handling
Common error scenarios:| Error Message | Cause | Solution |
|---|---|---|
not authenticated | Client sent event before authentication | Wait for authentication confirmation |
invalid JSON | Malformed message | Use SuperJSON for serialization |
invalid token | Wrong authentication token | Verify token configuration |
module not found | Target module not registered | Wait for registry sync before sending |
| Field validation errors | Invalid field values in events | Check field type and range requirements |
Next Steps
Event System
Learn about event routing and middleware
Server SDK
Use the client SDK for easy integration
