New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@patternplate/websocket-client

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@patternplate/websocket-client - npm Package Compare versions

Comparing version 2.0.0-16 to 2.0.0-17

license.md

178

lib/index.js

@@ -1,22 +0,10 @@

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
const _require = require("events"),
EventEmitter = _require.EventEmitter;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var _require = require("events"),
EventEmitter = _require.EventEmitter;
module.exports.WebSocketClient =
/*#__PURE__*/
function () {
function WebSocketClient(_ref) {
var src = _ref.src,
reconnect = _ref.reconnect,
interval = _ref.interval;
_classCallCheck(this, WebSocketClient);
module.exports.WebSocketClient = class WebSocketClient {
constructor({
src,
reconnect,
interval
}) {
this.src = src;

@@ -30,108 +18,70 @@ this.reconnect = reconnect;

_createClass(WebSocketClient, [{
key: "open",
value: function open() {
var _this = this;
open() {
const exec = (type, args) => this.ee.listeners(type).forEach(l => l(...args));
var exec = function exec(type, args) {
return _this.ee.listeners(type).forEach(function (l) {
return l.apply(void 0, _toConsumableArray(args));
});
};
const open = () => {
this.instance = new global.WebSocket(this.src); // Make Chrome behave and close the websocket connection
// before unloading the browsing context. Ref: https://github.com/websockets/ws/issues/1256
var open = function open() {
_this.instance = new global.WebSocket(_this.src); // Make Chrome behave and close the websocket connection
// before unloading the browsing context. Ref: https://github.com/websockets/ws/issues/1256
global.addEventListener("beforeunload", this.close);
this.instance.addEventListener("open", (...args) => {
this.opened = true;
exec("open", args);
});
this.instance.addEventListener("close", (...args) => {
global.removeEventListener("beforeunload", this.close);
this.opened = false;
exec("close", args);
});
this.instance.addEventListener("error", (...args) => {
global.removeEventListener("beforeunload", this.close);
this.opened = false;
exec("error", args);
});
this.instance.addEventListener("message", (...args) => {
exec("message", args);
});
};
global.addEventListener("beforeunload", _this.close);
open();
_this.instance.addEventListener("open", function () {
_this.opened = true;
if (this.reconnect) {
this.loop = setInterval(() => {
if (this.ended || this.opened) {
return;
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
open();
}, this.interval);
}
}
exec("open", args);
});
close() {
this.ended = true;
_this.instance.addEventListener("close", function () {
global.removeEventListener("beforeunload", _this.close);
_this.opened = false;
if (this.opened) {
this.instance.close();
}
}
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
onOpen(handler) {
this.ee.on("open", handler);
}
exec("close", args);
});
onClose(handler) {
this.ee.on("close", handler);
this.instance.addEventListener("close", handler);
}
_this.instance.addEventListener("error", function () {
global.removeEventListener("beforeunload", _this.close);
_this.opened = false;
onError(handler) {
this.ee.on("error", handler);
this.instance.addEventListener("error", handler);
}
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
onMessage(handler) {
this.ee.on("message", handler);
this.instance.addEventListener("message", handler);
}
exec("error", args);
});
_this.instance.addEventListener("message", function () {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
exec("message", args);
});
};
open();
if (this.reconnect) {
this.loop = setInterval(function () {
if (_this.ended || _this.opened) {
return;
}
open();
}, this.interval);
}
}
}, {
key: "close",
value: function close() {
this.ended = true;
if (this.opened) {
this.instance.close();
}
}
}, {
key: "onOpen",
value: function onOpen(handler) {
this.ee.on("open", handler);
}
}, {
key: "onClose",
value: function onClose(handler) {
this.ee.on("close", handler);
this.instance.addEventListener("close", handler);
}
}, {
key: "onError",
value: function onError(handler) {
this.ee.on("error", handler);
this.instance.addEventListener("error", handler);
}
}, {
key: "onMessage",
value: function onMessage(handler) {
this.ee.on("message", handler);
this.instance.addEventListener("message", handler);
}
}]);
return WebSocketClient;
}();
};
//# sourceMappingURL=index.js.map
{
"name": "@patternplate/websocket-client",
"version": "2.0.0-16",
"version": "2.0.0-17",
"description": "Websocket client with automatic retries",

@@ -28,13 +28,4 @@ "scripts": {

"babel": {
"sourceMaps": true,
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"node": "4"
}
}
]
"module:@patternplate/babel-preset"
]

@@ -44,5 +35,4 @@ },

"@babel/cli": "^7.0.0-beta.40",
"@babel/core": "^7.0.0-beta.40",
"@babel/preset-env": "^7.0.0-beta.40"
"@patternplate/babel-preset": "^2.0.0-17"
}
}

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