WebSocket Stream

Streams data continuously from a WebSocket connection

Overview

This node establishes a WebSocket connection to a specified server URL and streams incoming messages continuously. It collects messages received over the WebSocket and outputs them as JSON objects. The node is useful for real-time data streaming scenarios such as receiving live updates, notifications, or event streams from WebSocket-enabled services.

Typical use cases include:

  • Consuming live chat messages or notifications.
  • Streaming real-time sensor or telemetry data.
  • Integrating with APIs that push updates via WebSocket.

The node automatically closes the connection shortly after receiving a message (500 ms delay), effectively batching messages received in quick succession before outputting them.

Properties

Name Meaning
WebSocket URL The URL of the WebSocket server to connect to. Example: ws://localhost:8080 or wss://example.com.
Reconnect on Error Whether the node should automatically attempt to reconnect if the WebSocket connection closes or encounters an error. (Note: In the provided code, this property is defined but not actively used.)

Output

The node outputs an array of JSON objects, each representing a message received from the WebSocket server during the execution period. Each object has the structure:

{
  "message": "<string>"
}
  • The message field contains the raw text content of the WebSocket message.
  • Binary data is converted to string form before output.
  • The output is emitted once the WebSocket connection closes, containing all collected messages.

No binary output is produced by this node.

Dependencies

  • Requires the ws library for WebSocket client functionality.
  • No external API keys or credentials are required.
  • The node expects a reachable WebSocket server at the specified URL.

Troubleshooting

  • Connection failures: If the node cannot connect, verify the WebSocket URL is correct and the server is accessible.
  • Unexpected closure: The node closes the connection 500 ms after receiving a message; if continuous streaming is desired, this behavior may need adjustment.
  • Error events: On WebSocket errors, the node logs the error and closes the connection, causing the execution to fail. Check network stability and server health.
  • Reconnect on Error property: Although present, automatic reconnection logic is not implemented in the current code, so enabling this option has no effect.

Links and References

Discussion