Overview
TheTransporterOptions type configures the WebSocket-based transporter that maintains the connection between your plugin and the Atomemo Hub Server. It provides lifecycle hooks and connection settings.
Type Definition
Properties
The interval in milliseconds between heartbeat messages to keep the WebSocket connection alive.Default:
30000 (30 seconds)Example: 60000 for 60-second intervalsCallback invoked when the WebSocket connection is successfully established.Parameters:
event- Optional Event object from the WebSocket open event
Callback invoked when the WebSocket connection is closed.Parameters:
event- Optional CloseEvent object with close details
Callback invoked when a WebSocket error occurs.Parameters:Note: The SDK has built-in error handling for common errors like authentication failures.
error- The error that occurredtransport- The transport type (e.g., “websocket”)establishedConnections- Number of established connections
Callback invoked when any message is received through the WebSocket.Parameters:
message- The message object received
Usage
Transporter options are passed as part of the plugin definition:Example: Minimal Configuration
Example: With Connection Monitoring
Example: Custom Heartbeat Interval
Connection Lifecycle
- Initialization: The transporter creates a WebSocket connection to the Hub Server
- Authentication: In debug mode, the connection is authenticated with the debug API key
- Open: The
onOpencallback is triggered when the connection is established - Heartbeat: Regular heartbeat messages are sent based on
heartbeatIntervalMs - Messages: The
onMessagecallback is triggered for all incoming messages - Errors: The
onErrorcallback is triggered if connection errors occur - Close: The
onClosecallback is triggered when the connection is closed
Built-in Error Handling
The SDK includes automatic error handling for common scenarios:Authentication Failure
If the debug API key is missing or invalid, the SDK:- Detects the 401/403 error
- Logs a helpful error message
- Suggests running
atomemo plugin refresh-key - Exits the process
Connection Failure
If the WebSocket connection fails, the SDK:- Logs the error through the
onErrorcallback - Provides context about the transport and connection count
Debug Mode
In debug mode (HUB_MODE=debug), additional logging is enabled:
Environment Variables
The transporter uses these environment variables:HUB_WS_URL- WebSocket URL of the Hub Server (required)HUB_MODE- Either “debug” or “release” (default: “debug”)HUB_DEBUG_API_KEY- API key for debug mode authenticationDEBUG- Enable debug logging (auto-enabled in non-production)NODE_ENV- Environment mode (“development”, “production”, “test”)
Related Types
- PluginDefinition - Parent plugin configuration that accepts transporter options
See Also
- Transporter - The transporter API reference
- Environment Setup - Configuring environment variables
- Debug Mode - Using debug mode during development