@aurox/persistent-websocket-connection
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -26,6 +26,7 @@ import { PersistentWebsocketConnectionOptions } from './types'; | ||
private pingPongToleranceTimer; | ||
get isConnected(): boolean; | ||
get isConnecting(): boolean; | ||
constructor(options: PersistentWebsocketConnectionOptions); | ||
send: (data: any) => void; | ||
sendOrQueue: (data: any) => void; | ||
isConnected: () => boolean; | ||
stop: () => void; | ||
@@ -32,0 +33,0 @@ forceReconnect: () => void; |
@@ -21,3 +21,3 @@ "use strict"; | ||
this.send = (data) => { | ||
if (this.isConnected()) { | ||
if (this.isConnected) { | ||
this.connection.send(data); | ||
@@ -27,3 +27,3 @@ } | ||
this.sendOrQueue = (data) => { | ||
if (this.isConnected()) { | ||
if (this.isConnected) { | ||
this.connection.send(data); | ||
@@ -35,5 +35,2 @@ } | ||
}; | ||
this.isConnected = () => { | ||
return this.connection && this.connection.readyState === this.connection.OPEN; | ||
}; | ||
this.stop = () => { | ||
@@ -62,3 +59,3 @@ if (this.closedExternally) { | ||
this.reconnect = () => { | ||
if (this.closedExternally || this.isConnected()) { | ||
if (this.closedExternally || this.isConnected) { | ||
this.reconnectingTries = 0; | ||
@@ -81,3 +78,3 @@ this.reconnecting = false; | ||
this.closeConnection = () => { | ||
if (this.connection) { | ||
if (this.connection && (this.isConnected || this.isConnecting)) { | ||
try { | ||
@@ -113,3 +110,3 @@ this.connection.close(); | ||
this.pingPongTimer = setTimeout(() => { | ||
if (this.isConnected()) { | ||
if (this.isConnected) { | ||
this.pingPongToleranceTimer = setTimeout(this.handleNoPong, this.pingPongOptions.toleranceTimeout); | ||
@@ -154,3 +151,3 @@ if (!this.pingPongOptions.heartbeatOnly) { | ||
this.closedDuoToPongOrHeartbeatTimeout = false; | ||
this.handleConnectionLost('pong-or-hearbeat-timeout'); | ||
this.handleConnectionLost('pong-or-heartbeat-timeout'); | ||
} | ||
@@ -206,3 +203,3 @@ else { | ||
} | ||
if (this.initialConnectionEstablished && !this.reconnecting && !this.isConnected()) { | ||
if (this.initialConnectionEstablished && !this.reconnecting && !this.isConnected) { | ||
if (this.reconnectingForcefully) { | ||
@@ -218,3 +215,3 @@ this.logger.debug(`Connection to ${this.url} was forcefully closed.`); | ||
this.closedDuoToPongOrHeartbeatTimeout = false; | ||
this.handleConnectionLost('pong-or-hearbeat-timeout'); | ||
this.handleConnectionLost('pong-or-heartbeat-timeout'); | ||
} | ||
@@ -251,3 +248,11 @@ else { | ||
} | ||
get isConnected() { | ||
var _a; | ||
return ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.readyState) === this.connection.OPEN; | ||
} | ||
get isConnecting() { | ||
var _a; | ||
return ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.readyState) === this.connection.CONNECTING; | ||
} | ||
} | ||
exports.default = PersistentWebsocketConnection; |
@@ -19,3 +19,3 @@ import { MessageEvent } from 'ws'; | ||
} | ||
export declare type ConnectionLostReason = 'pong-or-hearbeat-timeout' | 'closed-unexpectedly' | 'error'; | ||
export declare type ConnectionLostReason = 'pong-or-heartbeat-timeout' | 'closed-unexpectedly' | 'error'; | ||
export interface ConnectionLostEvent { | ||
@@ -22,0 +22,0 @@ reason: ConnectionLostReason; |
{ | ||
"name": "@aurox/persistent-websocket-connection", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Aurox Persistent Websocket Connection", | ||
@@ -19,16 +19,16 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^2.3.1", | ||
"@typescript-eslint/parser": "^2.3.1", | ||
"eslint": "^6.4.0", | ||
"rimraf": "^3.0.0", | ||
"ts-node": "^8.4.1", | ||
"typescript": "^3.6.3" | ||
"@typescript-eslint/eslint-plugin": "^2.27.0", | ||
"@typescript-eslint/parser": "^2.27.0", | ||
"eslint": "^6.8.0", | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^8.8.2", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": { | ||
"@types/node": "^12.7.5", | ||
"@types/ws": "^6.0.3", | ||
"@types/node": "^13.11.1", | ||
"@types/ws": "^7.2.3", | ||
"isomorphic-ws": "^4.0.1", | ||
"tslib": "^1.10.0", | ||
"ws": "^7.1.2" | ||
"tslib": "^1.11.1", | ||
"ws": "^7.2.3" | ||
} | ||
} |
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
18897
400
+ Added@types/node@13.13.52(transitive)
+ Added@types/ws@7.4.7(transitive)
- Removed@types/node@12.20.55(transitive)
- Removed@types/ws@6.0.4(transitive)
Updated@types/node@^13.11.1
Updated@types/ws@^7.2.3
Updatedtslib@^1.11.1
Updatedws@^7.2.3