Websockets Node
AI-generatedOverview
This node connects to a WebSocket server using the Socket.io client library and listens for a specified event. When the event occurs, it captures the event data and outputs it as JSON. This node is useful for real-time applications where you want to react to live updates or messages pushed from a WebSocket server.
Common scenarios include:
- Receiving live notifications or alerts from a server.
- Listening to chat messages or collaborative editing events.
- Monitoring real-time data streams such as stock prices, sensor data, or game state changes.
Example: Connect to a WebSocket server at ws://example.com/my-namespace and listen for an event named message. Each time a message event is received, the node outputs the event name and its data.
Properties
| Name | Meaning |
|---|---|
| Websocket URL | The URL of the WebSocket server to connect to (e.g., ws://example.com/my-namespace). |
| Event Name | The name of the event to listen for on the WebSocket connection (e.g., message). |
Output
The node outputs an array of JSON objects, each representing an event received from the WebSocket server. Each output item has the following structure:
{
"event": "eventName",
"data": { /* event payload */ }
}
event: The name of the event that was listened for.data: The data payload sent with the event.
If the node encounters an error during execution and is configured to continue on failure, it outputs an object with an error field containing the error message.
The node does not output binary data.
Dependencies
- Requires a WebSocket server compatible with Socket.io.
- Needs an API authentication token credential to authenticate with the WebSocket server.
- Uses the
socket.io-clientlibrary internally to manage WebSocket connections.
Troubleshooting
- Connection errors: If the node fails to connect to the WebSocket server, it throws a connection error with a message describing the issue. Check the WebSocket URL and ensure the server is reachable.
- Authentication failures: Ensure the provided API authentication token is valid and has the necessary permissions.
- Event name issues: If no events are received, verify that the event name matches exactly what the server emits.
- Timeouts: The node waits 1 second after connecting to receive events before disconnecting. If events take longer to arrive, consider adjusting the implementation or triggering multiple executions.