reconnecting-websocket
Advanced tools
Comparing version 1.3.2 to 1.4.0
@@ -136,5 +136,8 @@ "use strict"; | ||
connect(); | ||
this.close = function () { | ||
shouldRetry = false; | ||
ws.close(); | ||
this.close = function (code, reason, keepClosed) { | ||
if (code === void 0) { code = 1000; } | ||
if (reason === void 0) { reason = ''; } | ||
if (keepClosed === void 0) { keepClosed = false; } | ||
shouldRetry = !keepClosed; | ||
ws.close(code, reason); | ||
}; | ||
@@ -141,0 +144,0 @@ this.addEventListener = function (type, listener, options) { |
@@ -155,5 +155,5 @@ type Options = { | ||
this.close = () => { | ||
shouldRetry = false; | ||
ws.close(); | ||
this.close = (code = 1000, reason = '', keepClosed = false) => { | ||
shouldRetry = !keepClosed; | ||
ws.close(code, reason); | ||
}; | ||
@@ -160,0 +160,0 @@ |
{ | ||
"name": "reconnecting-websocket", | ||
"version": "1.3.2", | ||
"version": "1.4.0", | ||
"description": "Reconnecting WebSocket", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -67,3 +67,3 @@ # Reconnecting WebSocket | ||
const defaultOptions = { | ||
constructor: (typeof WebSocket === 'function') ? WebSocket : null, | ||
constructor: isGlobalWebSocket() ? WebSocket : null, | ||
maxReconnectionDelay: 10000, | ||
@@ -87,2 +87,12 @@ minReconnectionDelay: 1500, | ||
#### Manually closing | ||
The `close` function has an additional optional parameter `keepClosed`. | ||
```javascript | ||
close(code = 1000, reason = '', keepClosed = false) | ||
``` | ||
Use the `keepClosed` parameter to keep the WebSocket closed or automatically reconnect. | ||
#### Using alternative constructor | ||
@@ -89,0 +99,0 @@ |
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
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
70634
760
130