@aurox/persistent-websocket-connection
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -50,2 +50,3 @@ "use strict"; | ||
onReconnecting: options.onReconnecting || noop, | ||
onConnecting: options.onConnecting || noop, | ||
onConnectionLost: options.onConnectionLost || noop, | ||
@@ -52,0 +53,0 @@ }; |
@@ -22,2 +22,3 @@ import { PersistentWebsocketConnectionOptions } from './types'; | ||
private onReconnecting; | ||
private onConnecting; | ||
private onConnectionLost; | ||
@@ -24,0 +25,0 @@ private queuedDataToSendOnReconnect; |
@@ -8,2 +8,3 @@ "use strict"; | ||
constructor(options) { | ||
this.connection = null; | ||
this.attemptingToEstablishConnection = false; | ||
@@ -25,9 +26,11 @@ this.closedExternally = false; | ||
this.send = (data) => { | ||
var _a; | ||
if (this.isConnected) { | ||
this.connection.send(data); | ||
(_a = this.connection) === null || _a === void 0 ? void 0 : _a.send(data); | ||
} | ||
}; | ||
this.sendOrQueue = (data) => { | ||
var _a; | ||
if (this.isConnected) { | ||
this.connection.send(data); | ||
(_a = this.connection) === null || _a === void 0 ? void 0 : _a.send(data); | ||
} | ||
@@ -169,2 +172,3 @@ else { | ||
this.handleOpen = () => { | ||
var _a; | ||
this.attemptingToEstablishConnection = false; | ||
@@ -189,3 +193,3 @@ this.reconnectingForcefully = false; | ||
for (const data of queue) { | ||
this.connection.send(data); | ||
(_a = this.connection) === null || _a === void 0 ? void 0 : _a.send(data); | ||
} | ||
@@ -279,2 +283,3 @@ } | ||
this.connection = new isomorphic_ws_1.default(this.url); | ||
this.onConnecting(this.connection); | ||
this.connection.onopen = this.handleOpen; | ||
@@ -296,2 +301,3 @@ this.connection.onmessage = this.handleMessage; | ||
this.onReconnecting = optionsWithDefaults.onReconnecting; | ||
this.onConnecting = optionsWithDefaults.onConnecting; | ||
this.onConnectionLost = optionsWithDefaults.onConnectionLost; | ||
@@ -302,10 +308,10 @@ this.connect(); | ||
get isConnected() { | ||
var _a; | ||
return ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.readyState) === this.connection.OPEN; | ||
var _a, _b; | ||
return ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this.connection) === null || _b === void 0 ? void 0 : _b.OPEN); | ||
} | ||
get isConnecting() { | ||
var _a; | ||
return ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.readyState) === this.connection.CONNECTING; | ||
var _a, _b; | ||
return ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this.connection) === null || _b === void 0 ? void 0 : _b.CONNECTING); | ||
} | ||
} | ||
exports.default = PersistentWebsocketConnection; |
@@ -1,2 +0,2 @@ | ||
import { MessageEvent } from 'ws'; | ||
import WebSocket, { MessageEvent } from 'ws'; | ||
export interface PersistentWebsocketConnectionPingPongOptions { | ||
@@ -38,2 +38,3 @@ enabled: boolean; | ||
onReconnecting?: (tries: number) => void; | ||
onConnecting?: (connection: WebSocket) => void; | ||
onConnectionLost?: (event: ConnectionLostEvent) => void; | ||
@@ -40,0 +41,0 @@ reconnectTimeout?: number; |
{ | ||
"name": "@aurox/persistent-websocket-connection", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Aurox Persistent Websocket Connection", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24398
491
0