Skip to content

Commit 7f9b8b0

Browse files
committed
Allow controlling ping interval directly
1 parent c1a33db commit 7f9b8b0

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jsonrpc-bidirectional",
33
"description": "Bidirectional JSONRPC over web sockets or HTTP with extensive plugin support.",
4-
"version": "9.7.0",
4+
"version": "9.7.2",
55
"scripts": {
66
"build": "node --experimental-worker build.js",
77
"prepublish": "node --experimental-worker build.js && node --expose-gc --max-old-space-size=1024 --experimental-worker tests/main.js",

src/Plugins/Client/WebSocketTransport.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class WebSocketTransport extends JSONRPC.ClientPluginBase
6868
* MUST set the .rpc() bSkipWaitReadyOnConnect param (or .rpcX({skipWaitReadyOnConnect})) to true or else the call will hang forever.
6969
*
7070
*
71-
* A WebSocket ping control frame (most efficient way to ping for a WebSocket) is sent at an interval (the smallest of nKeepAliveTimeoutMilliseconds / 2 or 4000 milliseconds) by the server side (if configured to do so using a non-null nKeepAliveTimeoutMilliseconds).
71+
* A WebSocket ping control frame (most efficient way to ping for a WebSocket) is sent at an interval (if nKeepAliveIntervalMilliseconds is null then the smallest of nKeepAliveTimeoutMilliseconds / 2 or 4000 milliseconds) by the server side (if configured to do so using a non-null nKeepAliveTimeoutMilliseconds).
7272
* The client checks (if configured to do so using a non-null nKeepAliveTimeoutMilliseconds) if a ping was received since connecting or since the last ping (whichever came last).
7373
* If the ping (or pong for compatibility with other keep alive systems in other libraries) control frame is not seen by the client for nKeepAliveTimeoutMilliseconds then the client will close its WebSocket.
7474
* If the pong (or ping for compatibility with other keep alive systems in other libraries) control frame is not seen by the server for nKeepAliveTimeoutMilliseconds then the server will close its WebSocket.
@@ -85,6 +85,7 @@ class WebSocketTransport extends JSONRPC.ClientPluginBase
8585
bBidirectionalWebSocketMode = false,
8686
{
8787
nKeepAliveTimeoutMilliseconds = null,
88+
nKeepAliveIntervalMilliseconds = null,
8889

8990
bAutoReconnect = false,
9091

@@ -121,6 +122,7 @@ class WebSocketTransport extends JSONRPC.ClientPluginBase
121122
this._jsonrpcClient = jsonrpcClient;
122123

123124
this._nKeepAliveTimeoutMilliseconds = nKeepAliveTimeoutMilliseconds;
125+
this._nKeepAliveIntervalMilliseconds = nKeepAliveIntervalMilliseconds;
124126
this._nIntervalIDSendKeepAlivePing = null;
125127
this._nTimeoutIDCheckKeepAliveReceived = null;
126128

@@ -206,7 +208,7 @@ class WebSocketTransport extends JSONRPC.ClientPluginBase
206208
{
207209
this._nIntervalIDSendKeepAlivePing = setInterval(() => {
208210
webSocket.ping(fnNoop);
209-
}, Math.max(1, Math.min(4000, Math.floor(this._nKeepAliveTimeoutMilliseconds / 2))));
211+
}, this._nKeepAliveIntervalMilliseconds || Math.max(1, Math.min(4000, Math.floor(this._nKeepAliveTimeoutMilliseconds / 2))));
210212
}
211213

212214
const fnOnKeepAlive = (() => {

0 commit comments

Comments
 (0)