Registry / messaging / node-red-contrib-dynamic-websocket

node-red-contrib-dynamic-websocket

JSON →
library1.1.1jsnpmunverified

A Node-RED custom node that establishes and manages WebSocket connections with dynamic URL switching at runtime. Version 1.1.1 requires Node >=18.0.0. Unlike the built-in WebSocket node, this node allows changing the WebSocket URL mid-flow via msg.url, supports authentication (basic, token, custom headers), advanced reconnection with exponential backoff, and message transformation with validation. It also handles self-signed certificates and binary data. The node has one input and three outputs (received messages, connection status, connection errors). It persists the last connected URL across Node-RED restarts.

npm install node-red-contrib-dynamic-websocket
INSTALL
IMPORT
SIG · NODE-RED-CONTRIB-D
N
node-red-contrib-dynamic-websocket
messagingjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

node installation
npm install node-red-contrib-dynamic-websocket
npm install dynamic-websocket
The package is a Node-RED node; install via npm in your Node-RED user directory or use the palette manager.
module import (for flow function nodes)
const DynamicWebsocket = require('node-red-contrib-dynamic-websocket');
import { DynamicWebsocket } from 'node-red-contrib-dynamic-websocket';
Node-RED uses CommonJS require; ESM imports will fail in Node-RED context.
node registration (module export)
module.exports = function(RED) { require('node-red-contrib-dynamic-websocket')(RED); }
export default function(RED) { ... }
Node-RED expects CommonJS module exports; ESM export syntax is not supported.

Sample Node-RED flow: inject sets URL, dynamic-websocket connects, outputs to three debug nodes for messages, status, and errors.

// Node-RED flow JSON example (deploy via clipboard) [ { "id": "inject1", "type": "inject", "payload": "ws://echo.websocket.org", "payloadType": "str", "topic": "url", "name": "Set URL" }, { "id": "dynamic-websocket1", "type": "dynamic-websocket", "name": "Dynamic WebSocket", "defaultUrl": "ws://echo.websocket.org", "allowSelfSigned": false, "autoReconnect": true, "reconnectAttempts": 5, "reconnectInterval": 3000, "useExponentialBackoff": true, "wires": [["debug1"], ["debug2"], ["debug3"]] }, { "id": "debug1", "type": "debug", "name": "Messages", "active": true, "console": "false", "complete": "payload" }, { "id": "debug2", "type": "debug", "name": "Status", "active": true, "console": "false", "complete": "payload" }, { "id": "debug3", "type": "debug", "name": "Errors", "active": true, "console": "false", "complete": "payload" } ]
Debug
Known issues
breakingNode.js version requirement: >=18.0.0
fix
Upgrade Node.js to version 18 or later.
affects: 1.x
gotchaNode-RED restart may cause the node to attempt reconnection to the last URL; if the URL is no longer valid, it may fail repeatedly.
fix
Send msg.close to clear the stored URL before redeploy or restart.
affects: >=1.0.0
gotchamsg.payload is always stringified before sending; sending objects directly will result in [object Object].
fix
Use msg.message property to send raw data (string or Buffer) or enable binary support for Buffers.
affects: >=1.0.0
gotchaSelf-signed certificate support is disabled by default; connections to wss:// with self-signed certs will fail silently.
fix
Set allowSelfSigned: true in node config or via msg.allowSelfSigned.
affects: >=1.0.0
deprecatedThe package does not support ESM; only CommonJS require() works in Node-RED.
fix
Use require() and avoid import/export syntax.
affects: >=1.0.0
gotchaAuto-parse JSON may fail if the server sends malformed JSON; the raw string will be emitted as payload.
fix
Check for string payloads if you expect objects; set msg.payload to parse manually.
affects: >=1.0.0
breakingMinimum Node-RED version not specified; may be incompatible with very old Node-RED versions (<1.0).
fix
Use Node-RED 1.0.0 or later.
affects: >=1.1.0
Errors
Common errors & fixes
Error: listen EADDRINUSE :::1880
Node-RED port already in use (another instance running).
fix
Kill other Node-RED process or change port in settings.js.
TypeError: Cannot read properties of undefined (reading 'type')
Missing required property 'type' in node configuration (e.g., loading flow without node-red-contrib-dynamic-websocket installed).
fix
Install the package via npm install node-red-contrib-dynamic-websocket and restart Node-RED.
Error: self signed certificate in certificate chain
WebSocket server uses a self-signed certificate but allowSelfSigned is false.
fix
Set allowSelfSigned: true in node configuration or set msg.allowSelfSigned = true before connecting.
Error: connect ECONNREFUSED ws://example.com:8080
WebSocket server is not running or unreachable.
fix
Check server address and port, ensure server is running.
Error: Invalid WebSocket frame: invalid opcode
Received binary data but binary support not enabled, or corrupt data.
fix
Enable binary support in node config or disable binary sending from server.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
node-redrequiredRuns as a Node-RED custom node; requires Node-RED runtime to be installed.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources