reconnecting-websocket
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -54,2 +54,3 @@ "use strict"; | ||
var shouldRetry = true; | ||
var savedOnClose = null; | ||
var listeners = {}; | ||
@@ -136,2 +137,5 @@ // require new to construct | ||
reassignEventListeners(ws, oldWs, listeners); | ||
// because when closing with fastClose=true, it is saved and set to null to avoid double calls | ||
ws.onclose = ws.onclose || savedOnClose; | ||
savedOnClose = null; | ||
}; | ||
@@ -156,5 +160,7 @@ log('init'); | ||
// execute close listeners soon with a fake closeEvent | ||
// and remove all close listeners from the WS instance | ||
// so they don't get fired on the real close. | ||
// and remove them from the WS instance so they | ||
// don't get fired on the real close. | ||
handleClose(); | ||
ws.removeEventListener('close', handleClose); | ||
// run and remove level2 | ||
if (Array.isArray(listeners.close)) { | ||
@@ -167,3 +173,5 @@ listeners.close.forEach(function (_a) { | ||
} | ||
// remove level0 | ||
if (ws.onclose) { | ||
savedOnClose = ws.onclose; | ||
ws.onclose(fakeCloseEvent_1); | ||
@@ -170,0 +178,0 @@ ws.onclose = null; |
27
index.ts
@@ -1,10 +0,1 @@ | ||
/* | ||
Ready state constants | ||
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#Ready_state_constants | ||
CONNECTING 0 The connection is not yet open. | ||
OPEN 1 The connection is open and ready to communicate. | ||
CLOSING 2 The connection is in the process of closing. | ||
CLOSED 3 The connection is closed or couldn't be opened. | ||
*/ | ||
type Options = { | ||
@@ -57,3 +48,3 @@ constructor?: new(url: string, protocols?: string | string[]) => WebSocket; | ||
const reassignEventListeners = (ws: WebSocket, oldWs, listeners) => { | ||
const reassignEventListeners = (ws: WebSocket, oldWs: WebSocket, listeners) => { | ||
Object.keys(listeners).forEach(type => { | ||
@@ -79,2 +70,3 @@ listeners[type].forEach(([listener, options]) => { | ||
let shouldRetry = true; | ||
let savedOnClose = null; | ||
const listeners: any = {}; | ||
@@ -164,2 +156,6 @@ | ||
reassignEventListeners(ws, oldWs, listeners); | ||
// because when closing with fastClose=true, it is saved and set to null to avoid double calls | ||
ws.onclose = ws.onclose || savedOnClose; | ||
savedOnClose = null; | ||
}; | ||
@@ -186,7 +182,7 @@ | ||
// execute close listeners soon with a fake closeEvent | ||
// and remove all close listeners from the WS instance | ||
// so they don't get fired on the real close. | ||
// and remove them from the WS instance so they | ||
// don't get fired on the real close. | ||
handleClose(); | ||
ws.removeEventListener('close', handleClose); | ||
// run and remove level2 | ||
if (Array.isArray(listeners.close)) { | ||
@@ -198,4 +194,5 @@ listeners.close.forEach(([listener, options]) => { | ||
} | ||
// remove level0 | ||
if (ws.onclose) { | ||
savedOnClose = ws.onclose; | ||
ws.onclose(fakeCloseEvent); | ||
@@ -202,0 +199,0 @@ ws.onclose = null; |
{ | ||
"name": "reconnecting-websocket", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Reconnecting WebSocket", | ||
@@ -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
21441
419
0