Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reconnecting-websocket

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reconnecting-websocket - npm Package Compare versions

Comparing version 1.3.0 to 1.3.2

build/index.d.ts

7

build/index.js
"use strict";
var isGlobalWebSocket = function () {
return typeof WebSocket !== 'undefined'
&& WebSocket.prototype
&& WebSocket.prototype.CLOSING === 2;
};
var getDefaultOptions = function () { return ({
constructor: (typeof WebSocket === 'function') ? WebSocket : null,
constructor: isGlobalWebSocket() ? WebSocket : null,
maxReconnectionDelay: 10000,

@@ -5,0 +10,0 @@ minReconnectionDelay: 1500,

35

index.ts

@@ -1,3 +0,18 @@

const getDefaultOptions = () => ({
constructor: (typeof WebSocket === 'function') ? WebSocket : null,
type Options = {
constructor?: new(url: string, protocols?: string | string[]) => WebSocket;
maxReconnectionDelay?: number;
minReconnectionDelay?: number;
reconnectionDelayGrowFactor?: number;
connectionTimeout?: number;
maxRetries?: number;
debug?: boolean;
};
const isGlobalWebSocket = () =>
typeof WebSocket !== 'undefined'
&& WebSocket.prototype
&& WebSocket.prototype.CLOSING === 2;
const getDefaultOptions = () => <Options>({
constructor: isGlobalWebSocket() ? WebSocket : null,
maxReconnectionDelay: 10000,

@@ -20,7 +35,7 @@ minReconnectionDelay: 1500,

const initReconnectionDelay = (config) =>
const initReconnectionDelay = (config: Options) =>
(config.minReconnectionDelay + Math.random() * config.minReconnectionDelay);
const updateReconnectionDelay = (config, previousDelay) => {
let newDelay = previousDelay * config.reconnectionDelayGrowFactor;
const updateReconnectionDelay = (config: Options, previousDelay: number) => {
const newDelay = previousDelay * config.reconnectionDelayGrowFactor;
return (newDelay > config.maxReconnectionDelay)

@@ -33,3 +48,3 @@ ? config.maxReconnectionDelay

const reassignEventListeners = (ws, oldWs, listeners) => {
const reassignEventListeners = (ws: WebSocket, oldWs, listeners) => {
Object.keys(listeners).forEach(type => {

@@ -48,5 +63,5 @@ listeners[type].forEach(([listener, options]) => {

protocols?: string|string[],
options: Object = {}
options = <Options>{}
) {
let ws;
let ws: WebSocket;
let connectingTimeout;

@@ -148,3 +163,3 @@ let reconnectDelay = 0;

this.addEventListener = (type: string, listener: Function, options: any) => {
this.addEventListener = (type: string, listener: EventListener, options: any) => {
if (Array.isArray(listeners[type])) {

@@ -160,3 +175,3 @@ if (!listeners[type].some(([l]) => l === listener)) {

this.removeEventListener = (type: string, listener: Function, options: any) => {
this.removeEventListener = (type: string, listener: EventListener, options: any) => {
if (Array.isArray(listeners[type])) {

@@ -163,0 +178,0 @@ listeners[type] = listeners[type].filter(([l]) => l !== listener);

{
"name": "reconnecting-websocket",
"version": "1.3.0",
"version": "1.3.2",
"description": "Reconnecting WebSocket",
"main": "build/index.js",
"typings": "build/index.d.ts",
"scripts": {

@@ -30,2 +31,3 @@ "build": "tsc",

"opn-cli": "^3.1.0",
"typescript": "1.8.10",
"ws": "^1.1.1"

@@ -32,0 +34,0 @@ },

@@ -63,3 +63,3 @@ # Reconnecting WebSocket

Options should be self explainatory
Options should be self explanatory

@@ -66,0 +66,0 @@ ```javascript

@@ -7,7 +7,9 @@ {

"sourceMap": false,
"outDir": "build"
"outDir": "build",
"declaration": true
},
"exclude": [
"node_modules"
"node_modules",
"build"
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc