# WebSockets

Choose persistent subscriptions or finite exchanges and plan explicitly for reconnects and lost streams.

Canonical URL: https://opennodeflow.dev/wiki/integration-websocket/
JSON reference: https://opennodeflow.dev/wiki/integration-websocket/index.json
Source snapshot: 2026-10-23

ONF distinguishes a host-owned **WebSocket Managed Subscription** from finite Send Frame, Request Reply and Receive Frames operations. A persistent subscription is also different from a keyed HTTP webhook callback. Select the lifecycle that matches the upstream protocol before wiring its payload.

## Configure a managed entry

Save a disabled example with the managed trigger and matching Frame Decode/JSON Decode. Configure the node's trigger mode as WebSocket and choose exactly one public url or urlSecret. A credential-bearing query URL belongs entirely in the secret, never a visible node field. Secure wss uses normal TLS validation; plain ws is accepted only for loopback fixtures.

```json
{
  "url": "wss://events.example.com/stream",
  "protocols": ["example-events-v1"],
  "connectTimeoutMs": 15000,
  "maxMessageBytes": 262144,
  "maxQueueMessages": 20,
  "maxQueueBytes": 2097152,
  "maxPendingRuns": 1,
  "reconnectMinMs": 500,
  "reconnectMaxMs": 30000
}
```

Optional subscribeSecret is a raw text subscription/auth payload sent after each open. An application heartbeat can use heartbeatSecret and heartbeatIntervalSeconds; idleTimeoutSeconds resets a silent connection. There is no universal heartbeat/pong contract. The native client supports subprotocols, not arbitrary HTTP Authorization headers, so a provider requiring those headers needs a suitable authorized relay/protocol.

## Lifecycle and backpressure

Only enabling both the saved entry and workflow automation opens the listener. Pause, disable, deletion and relevant version/config/input/secret changes stop or rebuild it. Host shutdown closes listeners. A restart rebuilds currently enabled saved entries but does not replay an interrupted external stream.

Reconnect uses capped backoff and jitter. Queue count/bytes and accepted in-flight runs are bounded per entry. Overflow rejects the incoming frame, disconnects and records the condition before retrying when capacity returns. Receive queues are volatile. Native allocation occurs before the JavaScript byte check, so configured bounds are not a hostile-peer transport allocation sandbox.

## Frame and delivery contract

A frame has eventId, kind, encoding, data, byteLength and receivedAt. Text is UTF-8; binary is Base64. The ONF receive ID is not the provider's replay key. Durable storage should retain provider event IDs/cursors when the upstream protocol supports reconciliation. No exactly-once delivery, durable receive cursor or generic subscription acknowledgement is promised.

Health exposes phases/counters/queue/retry timing without payloads or secret URLs. Use provider-side event/cursor reconciliation for gaps after reconnect; do not infer gap-free delivery from a healthy current socket.

## Finite exchanges

Send opens once, sends typed text/binary, waits for local buffering to drain and closes. Its receipt says acknowledged:false. Request Reply sends once and waits for the first or JSON-pointer-matching response, bounding unmatched traffic. Receive Frames collects a bounded list and can report partial timeout/peer-close status. Cleanup closes sockets on failure/cancellation/timeout.

Send/request require confirmWrites:true and runtime $retries:0. A lost reply can follow an accepted remote action; reconcile before repeating.

## Operations

- [WebSocket Send Frame](/wiki/reference-websocket-send/): 
- [WebSocket Request Reply](/wiki/reference-websocket-request/): 
- [WebSocket Receive Frames](/wiki/reference-websocket-receive/): 
- [WebSocket Managed Subscription](/wiki/reference-websocket-trigger-managed/): 

Local protocol fixtures establish lifecycle/contract behavior, not live service authorization or durable upstream replay.

---

## Documentation provenance

- `../OpenNodeFlow-Library/work/websocket/SETUP.md`
- `docs/WEBSOCKETS.md`

This page describes maintained source, not a live inventory or an authorization to perform actions.
