@aurox/persistent-websocket-connection
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -5,1 +5,2 @@ export declare const DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_RECONNECT_TIMEOUT = 2000; | ||
export declare const DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_PING_PONG_TOLERANCE_TIMEOUT = 2000; | ||
export declare const DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_KEEP_ALIVE_INTERVAL = 5000; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_PING_PONG_TOLERANCE_TIMEOUT = exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_PING_PONG_INTERVAL = exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_CONNECTION_CHECK_INTERVAL = exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_RECONNECT_TIMEOUT = void 0; | ||
exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_KEEP_ALIVE_INTERVAL = exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_PING_PONG_TOLERANCE_TIMEOUT = exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_PING_PONG_INTERVAL = exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_CONNECTION_CHECK_INTERVAL = exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_RECONNECT_TIMEOUT = void 0; | ||
exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_RECONNECT_TIMEOUT = 2000; | ||
@@ -8,1 +8,2 @@ exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_CONNECTION_CHECK_INTERVAL = 500; | ||
exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_PING_PONG_TOLERANCE_TIMEOUT = 2000; | ||
exports.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_KEEP_ALIVE_INTERVAL = 5000; |
@@ -14,2 +14,5 @@ "use strict"; | ||
} | ||
function defaultDoKeepAlive(send) { | ||
send('ping'); | ||
} | ||
function noop() { | ||
@@ -43,2 +46,7 @@ return; | ||
}, | ||
keepAlive: { | ||
enabled: (options.keepAlive && options.keepAlive.enabled) || false, | ||
interval: (options.keepAlive && options.keepAlive.interval) || constants_1.DEFAULT_PERSISTENT_WEBSOCKET_CONNECTION_KEEP_ALIVE_INTERVAL, | ||
doKeepAlive: (options.keepAlive && options.keepAlive.doKeepAlive) || defaultDoKeepAlive, | ||
}, | ||
logger: { | ||
@@ -45,0 +53,0 @@ debug: (options.logger && options.logger.debug) || noop, |
@@ -9,2 +9,3 @@ import { PersistentWebsocketConnectionOptions } from './types'; | ||
private pingPongOptions; | ||
private keepAliveOptions; | ||
private backoffOptions; | ||
@@ -32,2 +33,3 @@ private attemptingToEstablishConnection; | ||
private pingPongToleranceTimer; | ||
private keepAliveTimer; | ||
get isConnected(): boolean; | ||
@@ -47,2 +49,3 @@ get isConnecting(): boolean; | ||
private ping; | ||
private keepAlive; | ||
private handleOpen; | ||
@@ -49,0 +52,0 @@ private handleClose; |
@@ -24,2 +24,3 @@ "use strict"; | ||
this.pingPongToleranceTimer = null; | ||
this.keepAliveTimer = null; | ||
this.send = (data) => { | ||
@@ -50,2 +51,3 @@ var _a; | ||
clearTimeout(this.pingPongToleranceTimer); | ||
clearTimeout(this.keepAliveTimer); | ||
this.closedExternally = true; | ||
@@ -62,2 +64,3 @@ this.closeConnection(); | ||
clearTimeout(this.pingPongToleranceTimer); | ||
clearTimeout(this.keepAliveTimer); | ||
// When forcefully reconnecting, we must reset the backoff state since it implies an urgent requirement | ||
@@ -172,2 +175,10 @@ this.resetBackoffIncrement(); | ||
}; | ||
this.keepAlive = () => { | ||
this.keepAliveTimer = setTimeout(() => { | ||
if (this.isConnected) { | ||
this.keepAliveOptions.doKeepAlive(this.send); | ||
this.keepAlive(); | ||
} | ||
}, this.keepAliveOptions.interval); | ||
}; | ||
this.handleOpen = () => { | ||
@@ -200,2 +211,5 @@ var _a; | ||
} | ||
if (this.keepAliveOptions.enabled) { | ||
this.keepAlive(); | ||
} | ||
}; | ||
@@ -206,2 +220,3 @@ this.handleClose = () => { | ||
clearTimeout(this.pingPongToleranceTimer); | ||
clearTimeout(this.keepAliveTimer); | ||
if (!this.closedExternally && !this.reconnecting) { | ||
@@ -221,2 +236,3 @@ if (this.closedDuoToPongOrHeartbeatTimeout) { | ||
clearTimeout(this.pingPongToleranceTimer); | ||
clearTimeout(this.keepAliveTimer); | ||
if (!this.closedExternally && !this.reconnecting) { | ||
@@ -271,2 +287,3 @@ this.logger.error(`Connection to ${this.url} encountered an error.`); | ||
clearTimeout(this.pingPongToleranceTimer); | ||
clearTimeout(this.keepAliveTimer); | ||
if (this.closedDuoToPongOrHeartbeatTimeout) { | ||
@@ -299,2 +316,3 @@ this.closedDuoToPongOrHeartbeatTimeout = false; | ||
this.pingPongOptions = optionsWithDefaults.pingPong; | ||
this.keepAliveOptions = optionsWithDefaults.keepAlive; | ||
this.backoffOptions = optionsWithDefaults.reconnectBackoff; | ||
@@ -301,0 +319,0 @@ this.onInitialConnectionEstablished = optionsWithDefaults.onInitialConnectionEstablished; |
@@ -25,2 +25,7 @@ import WebSocket, { MessageEvent } from 'ws'; | ||
} | ||
export interface PersistentWebsocketConnectionKeepAlive { | ||
enabled: boolean; | ||
interval: number; | ||
doKeepAlive: (send: (data: any) => void) => void; | ||
} | ||
export interface PersistentWebsocketConnectionReconnectionBackoff { | ||
@@ -46,2 +51,3 @@ enabled: boolean; | ||
pingPong?: Partial<PersistentWebsocketConnectionPingPongOptions>; | ||
keepAlive?: Partial<PersistentWebsocketConnectionKeepAlive>; | ||
} |
{ | ||
"name": "@aurox/persistent-websocket-connection", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Aurox Persistent Websocket Connection", | ||
@@ -19,16 +19,16 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^4.11.0", | ||
"@typescript-eslint/parser": "^4.11.0", | ||
"eslint": "^7.16.0", | ||
"@typescript-eslint/eslint-plugin": "^4.22.0", | ||
"@typescript-eslint/parser": "^4.22.0", | ||
"eslint": "^7.24.0", | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.3" | ||
"typescript": "^4.2.4" | ||
}, | ||
"dependencies": { | ||
"@types/node": "^14.14.16", | ||
"@types/ws": "^7.4.0", | ||
"@types/node": "^14.14.41", | ||
"@types/ws": "^7.4.1", | ||
"isomorphic-ws": "^4.0.1", | ||
"tslib": "^2.0.3", | ||
"ws": "^7.4.1" | ||
"tslib": "^2.2.0", | ||
"ws": "^7.4.4" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26133
528
Updated@types/node@^14.14.41
Updated@types/ws@^7.4.1
Updatedtslib@^2.2.0
Updatedws@^7.4.4