Overview
The websocket-client node connects to a remote WebSocket
server and outputs messages received over the connection. It supports automatic reconnection,
ping/pong keep-alive, and optional per-message compression. Ideal for consuming real-time
data streams such as cryptocurrency prices, IoT telemetry feeds, and live event data.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| url | string | "" | WebSocket server URL (ws:// or wss://) |
| autoReconnect | boolean | true | Automatically reconnect on disconnection |
| reconnectDelay | number | 5000 | Delay in milliseconds before reconnect attempt |
| pingInterval | number | 30000 | Ping interval in ms for keep-alive (0 to disable) |
| enableCompression | boolean | false | Enable per-message deflate compression |
Connection Status
The node displays connection status visually and can emit status events:
Connected
WebSocket connection is active and receiving data.
Reconnecting
Connection lost. Attempting to reconnect after delay.
Disconnected
Connection closed. Auto-reconnect is disabled.
Example: Live Crypto Price Feed
Connect to a cryptocurrency exchange WebSocket API to receive live BTC/USD price updates. The node auto-reconnects if the exchange drops the connection.
// websocket-client node configuration
{
"url": "wss://stream.binance.com/ws/btcusdt@trade",
"autoReconnect": true,
"reconnectDelay": 3000,
"pingInterval": 30000,
"enableCompression": false
}
// Each incoming WebSocket message becomes msg.payload:
{
"payload": "{\"e\":\"trade\",\"s\":\"BTCUSDT\",\"p\":\"43250.50\",\"q\":\"0.015\"}",
"_msgid": "ws001"
}
// Connect to a json-parser node to parse the string,
// then use a function node to extract price:
// msg.payload = parseFloat(msg.payload.p);
// msg.topic = "crypto/btc/usd";
// return msg; Example: Real-time IoT Data Stream
Connect to a central IoT gateway broadcasting sensor readings over WebSocket. Uses compression to reduce bandwidth on constrained networks.
// websocket-client node configuration
{
"url": "wss://iot-gateway.local:8443/sensors/stream",
"autoReconnect": true,
"reconnectDelay": 5000,
"pingInterval": 15000,
"enableCompression": true
}
// Incoming message from IoT gateway:
{
"payload": {
"device_id": "rpi-sensor-03",
"readings": {
"temperature": 22.8,
"humidity": 58,
"pressure": 1013.25
},
"timestamp": "2024-01-15T14:30:00Z"
},
"_msgid": "ws002"
}
// Route to dashboard gauge nodes for display
// or to database nodes for storage Example: Home Assistant Event Stream
Subscribe to Home Assistant state change events via its WebSocket API.
// websocket-client node configuration
{
"url": "ws://homeassistant.local:8123/api/websocket",
"autoReconnect": true,
"reconnectDelay": 10000,
"pingInterval": 30000,
"enableCompression": false
}
// After authentication, subscribe to events:
// Send via a linked websocket-out:
// { "type": "subscribe_events", "event_type": "state_changed" }
// Incoming state change event:
{
"payload": {
"type": "event",
"event": {
"event_type": "state_changed",
"data": {
"entity_id": "sensor.living_room_temp",
"new_state": { "state": "23.5" }
}
}
}
} Common Use Cases
Financial Data Feeds
Stream live prices from crypto or stock exchanges
IoT Gateway Bridge
Consume sensor data from upstream WebSocket gateways
Home Automation
Connect to Home Assistant or similar automation platforms
Chat and Notifications
Receive real-time chat messages or push notifications