reconnecting-websocket
Advanced tools
Comparing version 1.4.0 to 1.4.2
"use strict"; | ||
var isWebSocket = function (constructor) { | ||
return constructor | ||
&& constructor.prototype | ||
&& constructor.prototype.CLOSING === 2; | ||
}; | ||
var isGlobalWebSocket = function () { | ||
return typeof WebSocket !== 'undefined' | ||
&& WebSocket.prototype | ||
&& WebSocket.prototype.CLOSING === 2; | ||
&& isWebSocket(WebSocket); | ||
}; | ||
@@ -63,3 +67,3 @@ var getDefaultOptions = function () { return ({ | ||
.forEach(function (key) { return config[key] = options[key]; }); | ||
if (typeof config.constructor !== 'function') { | ||
if (!isWebSocket(config.constructor)) { | ||
throw new TypeError('WebSocket constructor not set. Set `options.constructor`'); | ||
@@ -103,3 +107,3 @@ } | ||
// @todo move to constant | ||
if (['addEventListener', 'removeEventListener', 'close'].indexOf(key) < 0) { | ||
if (['addEventListener', 'removeEventListener', 'close', 'send'].indexOf(key) < 0) { | ||
bypassProperty(ws, _this, key); | ||
@@ -145,2 +149,5 @@ } | ||
}; | ||
this.send = function (data) { | ||
ws.send(data); | ||
}; | ||
this.addEventListener = function (type, listener, options) { | ||
@@ -147,0 +154,0 @@ if (Array.isArray(listeners[type])) { |
16
index.ts
@@ -11,6 +11,10 @@ type Options = { | ||
const isWebSocket = constructor => | ||
constructor | ||
&& constructor.prototype | ||
&& constructor.prototype.CLOSING === 2; | ||
const isGlobalWebSocket = () => | ||
typeof WebSocket !== 'undefined' | ||
&& WebSocket.prototype | ||
&& WebSocket.prototype.CLOSING === 2; | ||
&& isWebSocket(WebSocket); | ||
@@ -82,3 +86,3 @@ const getDefaultOptions = () => <Options>({ | ||
if (typeof config.constructor !== 'function') { | ||
if (!isWebSocket(config.constructor)) { | ||
throw new TypeError('WebSocket constructor not set. Set `options.constructor`'); | ||
@@ -118,3 +122,3 @@ } | ||
// @todo move to constant | ||
if (['addEventListener', 'removeEventListener', 'close'].indexOf(key) < 0) { | ||
if (['addEventListener', 'removeEventListener', 'close', 'send'].indexOf(key) < 0) { | ||
bypassProperty(ws, this, key); | ||
@@ -163,2 +167,6 @@ } | ||
this.send = (data) => { | ||
ws.send(data) | ||
}; | ||
this.addEventListener = (type: string, listener: EventListener, options: any) => { | ||
@@ -165,0 +173,0 @@ if (Array.isArray(listeners[type])) { |
{ | ||
"name": "reconnecting-websocket", | ||
"version": "1.4.0", | ||
"version": "1.4.2", | ||
"description": "Reconnecting WebSocket", | ||
@@ -11,3 +11,4 @@ "main": "build/index.js", | ||
"pretest": "npm run build", | ||
"report": "nyc report --reporter=html && opn coverage/index.html" | ||
"report": "nyc report --reporter=html && opn coverage/index.html", | ||
"prepublish": "npm test" | ||
}, | ||
@@ -14,0 +15,0 @@ "keywords": [ |
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
70985
773