node-red-contrib-dyno-websocket 0.11.3
WebSocket with dynamic configuration that can be changed in runtime
red-contrib-dyno-websocket
Dynamic WebSocket client node for Node-RED.
Install
npm install node-red-contrib-dyno-websocket
Node
- Type:
dyno-websocket - Inputs:
1 - Outputs:
2(data,control)
Configuration:
url:string, can bewss://orws://schemaheaders:object?: optional, http headers to send during upgradetopic:string?: optional, given topic will be added to all outgoingmsgautoConnect:boolean?: whentrue, node attempts connection on deploy and relevant config updates
These are startup defaults and can be changed at runtime with commands.
Input Commands
Set msg.command to one of:
config-set: overwrite configuration of node. Configuration should be sent inmsg.payload. Ifurlorheadersare sent while connected, connection will be re-opened with new settings. If disconnected andautoConnectistrue, node will attempt to connect.url:stringheaders:object?topic:string?autoConnect:boolean?
config-get: return current configuration inmsg.payloadconfig-reset: reset dynamic configuration to values set in node editorcounters: return current runtime counters inmsg.payloadcounters-reset: reset runtime counters and return updated values inmsg.payloadconnectdisconnectreconnect
If msg.command is not set, msg.payload is sent to the socket:
Buffer/Uint8Array: sent as binary frameobject: sent as JSON serialized string- others: sent as
String(payload)
Outputs
Data output (output 1):
- binary frame: raw
Buffer - non-binary frame: parsed as JSON with fallback to plain-text
Control output (output 2):
Success:
{ topic?, event: string, ok: true, payload: any, counters: object }Failure:
{ topic?, event: string, ok: false, payload: { message: string, error: string, extra?: any }, counters: object }
Persistence
Node state is stored in node context (config, state) and can be inspected on Context Data page.
Note: settings will be lost after node re-deployment if Node-RED contextStorage is not set. Make sure you have at least one storage enabled, memory for example:
// add to settings.js in you node-red home folder
contextStorage: {
default: { module: "memory" },
},