Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,32 @@ It also supports an additional `rewriteRequestHeaders(headers, request)` functio
opening the WebSocket connection. This function should return an object with the given headers.
The default implementation forwards the `cookie` header.

## `wsReconnect`

**Experimental.** (default: `disabled`)

Reconnection feature detects and closes broken connections and reconnects automatically, see [how to detect and close broken connections](https://github.com/websockets/ws#how-to-detect-and-close-broken-connections).
The connection is considered broken if the target does not respond to the ping messages or no data is received from the target.

The `wsReconnect` option contains the configuration for the WebSocket reconnection feature.
To enable the feature, set the `wsReconnect` option to an object with the following properties:

- `pingInterval`: The interval between ping messages in ms (default: `30_000`).
- `maxReconnectionRetries`: The maximum number of reconnection retries (`1` to `Infinity`, default: `Infinity`).
- `reconnectInterval`: The interval between reconnection attempts in ms (default: `1_000`).
- `reconnectDecay`: The decay factor for the reconnection interval (default: `1.5`).
- `connectionTimeout`: The timeout for establishing the connection in ms (default: `5_000`).
- `reconnectOnClose`: Whether to reconnect on close, as long as the connection from the related client to the proxy is active (default: `false`).
- `logs`: Whether to log the reconnection process (default: `false`).

## wsHooks

- `onConnect`: A hook function that is called when the connection is established `onConnect(source, target)` (default: `undefined`).
- `onDisconnect`: A hook function that is called when the connection is closed `onDisconnect(source)` (default: `undefined`).
- `onReconnect`: A hook function that is called when the connection is reconnected `onReconnect(source, target)` (default: `undefined`).
- `onIncomingMessage`: A hook function that is called when the request is received from the client `onIncomingMessage({ data, binary })` (default: `undefined`).
- `onOutgoingMessage`: A hook function that is called when the response is received from the target `onOutgoingMessage({ data, binary })` (default: `undefined`).

## Benchmarks

The following benchmarks were generated on a dedicated server with an Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz and 64GB of RAM:
Expand Down
1 change: 1 addition & 0 deletions examples/ws-reconnection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO

Check failure on line 1 in examples/ws-reconnection.js

View workflow job for this annotation

GitHub Actions / test / Test (20, ubuntu-latest)

Newline required at end of file but not found

Check failure on line 1 in examples/ws-reconnection.js

View workflow job for this annotation

GitHub Actions / test / Test (22, ubuntu-latest)

Newline required at end of file but not found
Loading
Loading