Overview
Elbia Lambda's WebSocket API enables real-time, full-duplex communication between client and server. This guide covers authentication, connection setup, available methods, and event handling.
Key Features
- Real-time bidirectional communication
- Automatic session persistence
- Secured with OAuth 2.0
- Message rate limiting
Connection Flow
1. Establish WebSocket connection with authentication token 2. Receive session confirmation event 3. Send/receive application/data messages 4. Gracefully close connection when done
Getting Started
1. Requirements
- Elbia Lambda account
- Valid API token with scopes
- WebSocket library compatible client
2. Connect to WebSocket
// JavaScript Example const socket = new WebSocket('wss://api.elbialambda.cloud/v1/ws', { headers: { 'Authorization': "Bearer YOUR_API_TOKEN" } });
Replace YOUR_API_TOKEN
with your actual API token from the dashboard.
Methods
connect()
Establish secure WebSocket connection to Elbia Lambda API.
Parameters
- -
apiToken
(string): Valid OAuth token - -
region
(string): Preferred server location - -
channel
(string): WebSocket topic
Response
Connection established with 201 Created
handshake.
publishMessage()
Send message to connected channel.
Parameters
- -
channelId
(string) - -
payload
(object): JSON data
Response
Returns MessageId
for tracking.
subscribeToChannel()
Subscribe to receive updates from specific channel.
Parameters
- -
channelId
(string) - -
filters
(object): Subscription filters
Response
Confirmation payload with subscription status.
Events
onMessageReceived
→ clientFired when a new message is received from the server.
{ "event": "message_received", "channel_id": "CH_43210987654321", "data": { "temperature": 22.5, "location": "warehouse-42" } }
onChannelClosed
→ serverNotification when a channel is terminated.
{ "event": "channel_closed", "reason": "rate_limit_exceeded", "code": 429 }
onSubscriptionUpdated
→ clientUpdates about active subscriptions and filters.
{ "event": "subscription_updated", "channel_id": "CH_98765432109876", "subscription": { "filter": { "type": "device", "location": "warehouse-42" } } }
Best Practices
Rate Limit Awareness
Implement backoff strategy when handling rate limiting. Wait for 429 Too Many Requests
events.
Channel Management
Use subscribeToChannel().close()
when no longer needing updates.
Data Formats
Always send and receive data in valid JSON format. Avoid binary payloads.