@aurox/persistent-websocket-connection
Advanced tools
Comparing version 0.4.0 to 0.4.1
export * from './constants'; | ||
export * from './types'; | ||
export { default as default } from './PersistentWebsocketConnection'; | ||
import { PersistentWebsocketConnection, PersistentWebsocketConnectionEvents } from './PersistentWebsocketConnection'; | ||
export { PersistentWebsocketConnectionEvents }; | ||
export default PersistentWebsocketConnection; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = void 0; | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./constants"), exports); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
var PersistentWebsocketConnection_1 = require("./PersistentWebsocketConnection"); | ||
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return tslib_1.__importDefault(PersistentWebsocketConnection_1).default; } }); | ||
(0, tslib_1.__exportStar)(require("./constants"), exports); | ||
(0, tslib_1.__exportStar)(require("./types"), exports); | ||
const PersistentWebsocketConnection_1 = require("./PersistentWebsocketConnection"); | ||
exports.default = PersistentWebsocketConnection_1.PersistentWebsocketConnection; |
@@ -1,3 +0,15 @@ | ||
import { PersistentWebsocketConnectionOptions } from './types'; | ||
export default class PersistentWebsocketConnection { | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
import { PersistentWebsocketConnectionOptions, ConnectionLostReason } from './types'; | ||
export interface PersistentWebsocketConnectionEvents { | ||
'connecting': () => void; | ||
'connected': () => void; | ||
'pong': () => void; | ||
'heartbeat': () => void; | ||
'connection-lost': (reason: ConnectionLostReason, error?: string) => void; | ||
'reconnecting': (attempt: number) => void; | ||
'reconnected': () => void; | ||
'data': (data: string) => void; | ||
'stopped': () => void; | ||
} | ||
export declare class PersistentWebsocketConnection extends TypedEmitter<PersistentWebsocketConnectionEvents> { | ||
private connection; | ||
@@ -4,0 +16,0 @@ private logger; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PersistentWebsocketConnection = void 0; | ||
const tslib_1 = require("tslib"); | ||
const isomorphic_ws_1 = tslib_1.__importDefault(require("isomorphic-ws")); | ||
const isomorphic_ws_1 = (0, tslib_1.__importDefault)(require("isomorphic-ws")); | ||
const tiny_typed_emitter_1 = require("tiny-typed-emitter"); | ||
const defaults_1 = require("./defaults"); | ||
class PersistentWebsocketConnection { | ||
class PersistentWebsocketConnection extends tiny_typed_emitter_1.TypedEmitter { | ||
constructor(options) { | ||
super(); | ||
this.connection = null; | ||
@@ -54,2 +57,3 @@ this.attemptingToEstablishConnection = false; | ||
this.logger.debug(`Connection to ${this.url} closed gracefully.`); | ||
this.emit('stopped'); | ||
}; | ||
@@ -81,2 +85,3 @@ this.forceReconnect = () => { | ||
this.onReconnecting(this.reconnectingTries); | ||
this.emit('reconnecting', this.reconnectingTries); | ||
if (!this.attemptingToEstablishConnection) { | ||
@@ -147,2 +152,3 @@ this.logger.debug(`Attempting to reconnect to ${this.url}.`); | ||
if (!preventDefault) { | ||
this.emit('connection-lost', reason, error); | ||
this.reconnectWithDelay(); | ||
@@ -188,2 +194,3 @@ } | ||
this.closedDuoToPongOrHeartbeatTimeout = false; | ||
this.emit('connected'); | ||
if (!this.initialConnectionEstablished) { | ||
@@ -199,2 +206,3 @@ this.logger.debug(`Connection to ${this.url} was successfully established.`); | ||
this.onReconnect(this.send); | ||
this.emit('reconnected'); | ||
} | ||
@@ -244,2 +252,3 @@ if (this.queuedDataToSendOnReconnect.length > 0) { | ||
if (this.pingPongOptions.doCheckHeartbeat(event)) { | ||
this.emit('heartbeat'); | ||
clearTimeout(this.pingPongTimer); | ||
@@ -258,2 +267,3 @@ clearTimeout(this.pingPongToleranceTimer); | ||
else if (!this.pingPongOptions.heartbeatOnly && this.pingPongOptions.doCheckPong(event)) { | ||
this.emit('pong'); | ||
clearTimeout(this.pingPongTimer); | ||
@@ -272,3 +282,5 @@ clearTimeout(this.pingPongToleranceTimer); | ||
} | ||
this.onData(event.data === 'string' ? event.data : event.data.toString()); | ||
const data = event.data === 'string' ? event.data : event.data.toString(); | ||
this.onData(data); | ||
this.emit('data', data); | ||
}; | ||
@@ -305,2 +317,3 @@ this.checkConnection = () => { | ||
this.onConnecting(this.connection); | ||
this.emit('connecting'); | ||
this.connection.onopen = this.handleOpen; | ||
@@ -311,3 +324,3 @@ this.connection.onmessage = this.handleMessage; | ||
}; | ||
const optionsWithDefaults = defaults_1.getOptionsWithDefaults(options); | ||
const optionsWithDefaults = (0, defaults_1.getOptionsWithDefaults)(options); | ||
this.logger = optionsWithDefaults.logger; | ||
@@ -338,2 +351,2 @@ this.url = optionsWithDefaults.url; | ||
} | ||
exports.default = PersistentWebsocketConnection; | ||
exports.PersistentWebsocketConnection = PersistentWebsocketConnection; |
{ | ||
"name": "@aurox/persistent-websocket-connection", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Aurox Persistent Websocket Connection", | ||
@@ -19,16 +19,17 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^4.29.1", | ||
"@typescript-eslint/parser": "^4.29.1", | ||
"@typescript-eslint/eslint-plugin": "^4.31.0", | ||
"@typescript-eslint/parser": "^4.31.0", | ||
"eslint": "^7.32.0", | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^10.2.0", | ||
"typescript": "^4.3.5" | ||
"ts-node": "^10.2.1", | ||
"typescript": "^4.4.2" | ||
}, | ||
"dependencies": { | ||
"@types/node": "^16.6.1", | ||
"@types/node": "^16.9.1", | ||
"@types/ws": "^7.4.7", | ||
"isomorphic-ws": "^4.0.1", | ||
"tiny-typed-emitter": "^2.1.0", | ||
"tslib": "^2.3.1", | ||
"ws": "^8.1.0" | ||
"ws": "^8.2.2" | ||
} | ||
} |
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
27437
554
6
+ Addedtiny-typed-emitter@^2.1.0
+ Addedtiny-typed-emitter@2.1.0(transitive)
Updated@types/node@^16.9.1
Updatedws@^8.2.2