| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839 |
- "use strict";
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
- var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
- /* This header is placed at the beginning of the output file and defines the
- special `__require`, `__getFilename`, and `__getDirname` functions.
- */
- (function () {
- /* __modules is an Array of functions; each function is a module added
- to the project */
- var __modules = {},
- /* __modulesCache is an Array of cached modules, much like
- `require.cache`. Once a module is executed, it is cached. */
- __modulesCache = {},
- /* __moduleIsCached - an Array of booleans, `true` if module is cached. */
- __moduleIsCached = {};
- /* If the module with the specified `uid` is cached, return it;
- otherwise, execute and cache it first. */
- function __require(uid, parentUid) {
- if (!__moduleIsCached[uid]) {
- // Populate the cache initially with an empty `exports` Object
- __modulesCache[uid] = { "exports": {}, "loaded": false };
- __moduleIsCached[uid] = true;
- if (uid === 0 && typeof require === "function") {
- require.main = __modulesCache[0];
- } else {
- __modulesCache[uid].parent = __modulesCache[parentUid];
- }
- /* Note: if this module requires itself, or if its depenedencies
- require it, they will only see an empty Object for now */
- // Now load the module
- __modules[uid].call(this, __modulesCache[uid], __modulesCache[uid].exports);
- __modulesCache[uid].loaded = true;
- }
- return __modulesCache[uid].exports;
- }
- /* This function is the replacement for all `__filename` references within a
- project file. The idea is to return the correct `__filename` as if the
- file was not concatenated at all. Therefore, we should return the
- filename relative to the output file's path.
-
- `path` is the path relative to the output file's path at the time the
- project file was concatenated and added to the output file.
- */
- function __getFilename(path) {
- return require("path").resolve(__dirname + "/" + path);
- }
- /* Same deal as __getFilename.
- `path` is the path relative to the output file's path at the time the
- project file was concatenated and added to the output file.
- */
- function __getDirname(path) {
- return require("path").resolve(__dirname + "/" + path + "/../");
- }
- /********** End of header **********/
- /********** Start module 0: /home/blake/Repositories/ws-wrapper/lib/wrapper.js **********/
- __modules[0] = function (module, exports) {
- "use strict";
- var WebSocketChannel = __require(1, 0);
- var WebSocketWrapper = function (_WebSocketChannel) {
- _inherits(WebSocketWrapper, _WebSocketChannel);
- function WebSocketWrapper(socket, options) {
- _classCallCheck(this, WebSocketWrapper);
- var _this = _possibleConstructorReturn(this, (WebSocketWrapper.__proto__ || Object.getPrototypeOf(WebSocketWrapper)).call(this));
- _this._wrapper = _this;
- options = options || {};
- if (typeof options.debug === "function") {
- _this._debug = options.debug;
- } else if (options.debug === true) {
- _this._debug = console.log.bind(console);
- } else {
- _this._debug = function () {}; // no-op
- }
- if (typeof options.errorToJSON !== "function") {
- _this._errorToJSON = function (err) {
- if (typeof window === "undefined") {
- return JSON.stringify({ "message": err.message });
- } else {
- return JSON.stringify(err, Object.getOwnPropertyNames(err));
- }
- };
- } else {
- _this._errorToJSON = options.errorToJSON;
- }
- if (options.requestTimeout > 0) _this._requestTimeout = options.requestTimeout | 0;
- _this._opened = false;
- _this._pendingSend = [];
- _this._lastRequestId = 0;
- /* Object of pending requests; keys are the request ID, values are
- Objects containing `resolve` and `reject` functions used to
- resolve the request's Promise. */
- _this._pendingRequests = {};
- /* Object of WebSocketChannels (except `this` associated with this
- WebSocket); keys are the channel name. */
- _this._channels = {};
- _this._data = {};
- _this._socket = null;
- if (socket && socket.constructor) {
- _this.bind(socket);
- }
- return _this;
- }
- _createClass(WebSocketWrapper, [{
- key: "bind",
- value: function bind(socket) {
- var _this2 = this;
- if (this._socket) {
- var s = this._socket;
- s.onopen = s.onmessage = s.onerror = s.onclose = null;
- }
- this._socket = socket;
- socket.onopen = function (event) {
- _this2._opened = true;
- _this2._debug("socket: onopen");
- for (var i = 0; i < _this2._pendingSend.length; i++) {
- if (_this2.isConnected) {
- _this2._debug("wrapper: Sending pending message:", _this2._pendingSend[i]);
- try {
- _this2._socket.send(_this2._pendingSend[i]);
- } catch (e) {
- _this2._pendingSend = _this2._pendingSend.slice(i - 1);
- throw e;
- }
- } else {
- break;
- }
- }
- _this2._pendingSend = _this2._pendingSend.slice(i);
- _this2.emit("open", event);
- };
- socket.onmessage = function (event) {
- _this2._debug("socket: onmessage", event.data);
- _this2.emit("message", event, event.data);
- _this2._onMessage(event.data);
- };
- socket.onerror = function (event) {
- _this2._debug("socket: onerror", event);
- _this2.emit("error", event);
- };
- socket.onclose = function (event) {
- var opened = _this2._opened;
- _this2._opened = false;
- _this2._debug("socket: onclose", event);
- _this2.emit("close", event, opened);
- _this2.emit("disconnect", event, opened);
- };
- if (this.isConnected) {
- socket.onopen();
- }
- return this;
- }
- }, {
- key: "abort",
- value: function abort() {
- for (var id in this._pendingRequests) {
- this._pendingRequests[id].reject(new Error("Request was aborted"));
- }
- this._pendingRequests = {};
- this._pendingSend = [];
- return this;
- }
- }, {
- key: "of",
- value: function of(namespace) {
- if (namespace == null) {
- return this;
- }
- if (!this._channels[namespace]) {
- this._channels[namespace] = new WebSocketChannel(namespace, this);
- }
- return this._channels[namespace];
- }
- }, {
- key: "send",
- value: function send(data, ignoreMaxQueueSize) {
- if (this.isConnected) {
- this._debug("wrapper: Sending message:", data);
- this._socket.send(data);
- } else if (ignoreMaxQueueSize || this._pendingSend.length < WebSocketWrapper.MAX_SEND_QUEUE_SIZE) {
- this._debug("wrapper: Queuing message:", data);
- this._pendingSend.push(data);
- } else {
- throw new Error("WebSocket is not connected and send queue is full");
- }
- return this;
- }
- }, {
- key: "disconnect",
- value: function disconnect() {
- if (this._socket) this._socket.close.apply(this._socket, arguments);
- return this;
- }
- }, {
- key: "_onMessage",
- value: function _onMessage(msg) {
- try {
- msg = JSON.parse(msg);
- if (msg["ws-wrapper"] === false) return;
- if (msg.a) {
- var argsArray = [];
- for (var i in msg.a) {
- argsArray[i] = msg.a[i];
- }
- msg.a = argsArray;
- }
- /* If `msg` does not have an `a` Array with at least 1 element,
- ignore the message because it is not a valid event/request */
- if (msg.a instanceof Array && msg.a.length >= 1 && (msg.c || WebSocketChannel.NO_WRAP_EVENTS.indexOf(msg.a[0]) < 0)) {
- var event = {
- "name": msg.a.shift(),
- "args": msg.a,
- "requestId": msg.i
- };
- var channel = msg.c == null ? this : this._channels[msg.c];
- if (!channel) {
- if (msg.i >= 0) {
- this._sendReject(msg.i, new Error("Channel '" + msg.c + "' does not exist"));
- }
- this._debug("wrapper: Event '" + event.name + "' ignored " + ("because channel '" + msg.c + "' does not exist."));
- } else if (channel._emitter.emit(event.name, event)) {
- this._debug("wrapper: Event '" + event.name + "' sent to " + "event listener");
- } else {
- if (msg.i >= 0) {
- this._sendReject(msg.i, new Error("No event listener for '" + event.name + "'" + (msg.c ? " on channel '" + msg.c + "'" : "")));
- }
- this._debug("wrapper: Event '" + event.name + "' had no " + "event listener");
- }
- } else if (this._pendingRequests[msg.i]) {
- this._debug("wrapper: Processing response for request", msg.i);
- if (msg.e !== undefined) {
- var err = msg.e;
- if (msg._ && err) {
- err = new Error(err.message);
- for (var key in msg.e) {
- err[key] = msg.e[key];
- }
- }
- this._pendingRequests[msg.i].reject(err);
- } else {
- this._pendingRequests[msg.i].resolve(msg.d);
- }
- clearTimeout(this._pendingRequests[msg.i].timer);
- delete this._pendingRequests[msg.i];
- }
- } catch (e) {
- /* Note: It's also possible for uncaught exceptions from event
- handlers to end up here. */
- }
- }
- /* The following methods are called by a WebSocketChannel to send data
- to the Socket. */
- }, {
- key: "_sendEvent",
- value: function _sendEvent(channel, eventName, args, isRequest) {
- var _this3 = this;
- var data = { "a": args };
- if (channel != null) {
- data.c = channel;
- }
- var request;
- if (isRequest) {
- /* Unless we send petabytes of data using the same socket,
- we won't worry about `_lastRequestId` getting too big. */
- data.i = ++this._lastRequestId;
- request = new Promise(function (resolve, reject) {
- var pendReq = _this3._pendingRequests[data.i] = {
- "resolve": resolve,
- "reject": reject
- };
- if (_this3._requestTimeout > 0) {
- pendReq.timer = setTimeout(function () {
- reject(new Error("Request timed out"));
- delete _this3._pendingRequests[data.i];
- }, _this3._requestTimeout);
- }
- });
- }
- this.send(JSON.stringify(data));
- return request;
- }
- }, {
- key: "_sendResolve",
- value: function _sendResolve(id, data) {
- this.send(JSON.stringify({
- "i": id,
- "d": data
- }), true /* ignore max queue length */);
- }
- }, {
- key: "_sendReject",
- value: function _sendReject(id, err) {
- var isError = err instanceof Error;
- if (isError) {
- err = JSON.parse(this._errorToJSON(err));
- }
- this.send(JSON.stringify({
- "i": id,
- "e": err,
- "_": isError ? 1 : undefined
- }), true /* ignore max queue length */);
- }
- }, {
- key: "get",
- value: function get(key) {
- return this._data[key];
- }
- }, {
- key: "set",
- value: function set(key, value) {
- this._data[key] = value;
- return this;
- }
- }, {
- key: "socket",
- get: function get() {
- return this._socket;
- },
- set: function set(socket) {
- this.bind(socket);
- }
- }, {
- key: "isConnecting",
- get: function get() {
- return this._socket && this._socket.readyState === this._socket.constructor.CONNECTING;
- }
- }, {
- key: "isConnected",
- get: function get() {
- return this._socket && this._socket.readyState === this._socket.constructor.OPEN;
- }
- }]);
- return WebSocketWrapper;
- }(WebSocketChannel);
- /* Maximum number of items in the send queue. If a user tries to send more
- messages than this number while a WebSocket is not connected, errors will
- be thrown. */
- WebSocketWrapper.MAX_SEND_QUEUE_SIZE = 10;
- module.exports = WebSocketWrapper;
- return module.exports;
- };
- /********** End of module 0: /home/blake/Repositories/ws-wrapper/lib/wrapper.js **********/
- /********** Start module 1: /home/blake/Repositories/ws-wrapper/lib/channel.js **********/
- __modules[1] = function (module, exports) {
- "use strict";
- var EventEmitter = __require(2, 1).EventEmitter;
- /* A WebSocketChannel exposes an EventEmitter-like API for sending and handling
- events or requests over the channel through the attached WebSocketWrapper.
-
- `var channel = new WebSocketChannel(name, socketWrapper);`
- - `name` - the namespace for the channel
- - `socketWrapper` - the WebSocketWrapper instance to which data should
- be sent
- */
- var WebSocketChannel = function () {
- function WebSocketChannel(name, socketWrapper) {
- _classCallCheck(this, WebSocketChannel);
- this._name = name;
- this._wrapper = socketWrapper;
- this._emitter = new EventEmitter();
- this._wrappedListeners = new WeakMap();
- }
- _createClass(WebSocketChannel, [{
- key: "on",
- /* Expose EventEmitter-like API
- When `eventName` is one of the `NO_WRAP_EVENTS`, the event handlers
- are left untouched, and the emitted events are just sent to the
- EventEmitter; otherwise, event listeners are wrapped to process the
- incoming request and the emitted events are sent to the WebSocketWrapper
- to be serialized and sent over the WebSocket. */
- value: function on(eventName, listener) {
- if (this._name == null && WebSocketChannel.NO_WRAP_EVENTS.indexOf(eventName) >= 0)
- /* Note: The following is equivalent to:
- `this._emitter.on(eventName, listener.bind(this));`
- But thanks to eventemitter3, the following is a touch faster. */
- this._emitter.on(eventName, listener, this);else this._emitter.on(eventName, this._wrapListener(listener));
- return this;
- }
- }, {
- key: "once",
- value: function once(eventName, listener) {
- if (this._name == null && WebSocketChannel.NO_WRAP_EVENTS.indexOf(eventName) >= 0) this._emitter.once(eventName, listener, this);else this._emitter.once(eventName, this._wrapListener(listener));
- return this;
- }
- }, {
- key: "removeListener",
- value: function removeListener(eventName, listener) {
- if (this._name == null && WebSocketChannel.NO_WRAP_EVENTS.indexOf(eventName) >= 0) this._emitter.removeListener(eventName, listener);else this._emitter.removeListener(eventName, this._wrappedListeners.get(listener));
- return this;
- }
- }, {
- key: "removeAllListeners",
- value: function removeAllListeners(eventName) {
- this._emitter.removeAllListeners(eventName);
- return this;
- }
- }, {
- key: "eventNames",
- value: function eventNames() {
- return this._emitter.eventNames();
- }
- }, {
- key: "listeners",
- value: function listeners(eventName) {
- if (this._name == null && WebSocketChannel.NO_WRAP_EVENTS.indexOf(eventName) >= 0) return this._emitter.listeners(eventName);else {
- return this._emitter.listeners(eventName).map(function (wrapper) {
- return wrapper._original;
- });
- }
- }
- /* The following `emit` and `request` methods will serialize and send the
- event over the WebSocket using the WebSocketWrapper. */
- }, {
- key: "emit",
- value: function emit(eventName) {
- if (this._name == null && WebSocketChannel.NO_WRAP_EVENTS.indexOf(eventName) >= 0) return this._emitter.emit.apply(this._emitter, arguments);else return this._wrapper._sendEvent(this._name, eventName, arguments);
- }
- /* Temporarily set the request timeout for the next request. */
- }, {
- key: "timeout",
- value: function timeout(tempTimeout) {
- this._tempTimeout = tempTimeout;
- return this;
- }
- }, {
- key: "request",
- value: function request(eventName) {
- var oldTimeout = this._wrapper._requestTimeout;
- if (this._tempTimeout !== undefined) {
- this._wrapper._requestTimeout = this._tempTimeout;
- delete this._tempTimeout;
- }
- var ret = this._wrapper._sendEvent(this._name, eventName, arguments, true);
- this._wrapper._requestTimeout = oldTimeout;
- return ret;
- }
- }, {
- key: "_wrapListener",
- value: function _wrapListener(listener) {
- if (typeof listener !== "function") {
- throw new TypeError("\"listener\" argument must be a function");
- }
- var wrapped = this._wrappedListeners.get(listener);
- if (!wrapped) {
- wrapped = function channelListenerWrapper(event) {
- var _this4 = this;
- /* This function is called when an event is emitted on this
- WebSocketChannel's `_emitter` when the WebSocketWrapper
- receives an incoming message for this channel. If this
- event is a request, special processing is needed to
- send the response back over the socket. Below we use
- the return value from the original `listener` to
- determine what response should be sent back.
- `this` refers to the WebSocketChannel instance
- `event` has the following properties:
- - `name`
- - `args`
- - `requestId`
- */
- try {
- var returnVal = listener.apply(this, event.args);
- } catch (err) {
- if (event.requestId >= 0) {
- /* If event listener throws, pass that Error back
- as a response to the request */
- this._wrapper._sendReject(event.requestId, err);
- }
- throw err;
- }
- if (returnVal instanceof Promise) {
- /* If event listener returns a Promise, respond once
- the Promise resolves */
- returnVal.then(function (data) {
- if (event.requestId >= 0) {
- _this4._wrapper._sendResolve(event.requestId, data);
- }
- }).catch(function (err) {
- if (event.requestId >= 0) {
- _this4._wrapper._sendReject(event.requestId, err);
- }
- });
- } else if (event.requestId >= 0) {
- /* Otherwise, assume that the `returnVal` is what
- should be passed back as the response */
- this._wrapper._sendResolve(event.requestId, returnVal);
- }
- }.bind(this); // Bind the channel to the `channelListenerWrapper`
- wrapped._original = listener;
- this._wrappedListeners.set(listener, wrapped);
- }
- return wrapped;
- }
- }, {
- key: "get",
- value: function get(key) {
- return this._wrapper.get(key);
- }
- }, {
- key: "set",
- value: function set(key, value) {
- this._wrapper.set(key, value);
- return this;
- }
- }, {
- key: "name",
- get: function get() {
- return this._name;
- },
- set: function set(name) {
- throw new Error("Setting the channel name is not allowed");
- }
- }]);
- return WebSocketChannel;
- }();
- WebSocketChannel.prototype.addListener = WebSocketChannel.prototype.on;
- WebSocketChannel.prototype.off = WebSocketChannel.prototype.removeListener;
- WebSocketChannel.NO_WRAP_EVENTS = ["open", "message", "error", "close", "disconnect"];
- module.exports = WebSocketChannel;
- return module.exports;
- };
- /********** End of module 1: /home/blake/Repositories/ws-wrapper/lib/channel.js **********/
- /********** Start module 2: /home/blake/Repositories/ws-wrapper/node_modules/eventemitter3/index.js **********/
- __modules[2] = function (module, exports) {
- 'use strict';
- var has = Object.prototype.hasOwnProperty,
- prefix = '~';
- /**
- * Constructor to create a storage for our `EE` objects.
- * An `Events` instance is a plain object whose properties are event names.
- *
- * @constructor
- * @api private
- */
- function Events() {}
- if (Object.create) {
- Events.prototype = Object.create(null);
- if (!new Events().__proto__) prefix = false;
- }
- /**
- * Representation of a single event listener.
- *
- * @param {Function} fn The listener function.
- * @param {Mixed} context The context to invoke the listener with.
- * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
- * @constructor
- * @api private
- */
- function EE(fn, context, once) {
- this.fn = fn;
- this.context = context;
- this.once = once || false;
- }
- /**
- * Minimal `EventEmitter` interface that is molded against the Node.js
- * `EventEmitter` interface.
- *
- * @constructor
- * @api public
- */
- function EventEmitter() {
- this._events = new Events();
- this._eventsCount = 0;
- }
- /**
- * Return an array listing the events for which the emitter has registered
- * listeners.
- *
- * @returns {Array}
- * @api public
- */
- EventEmitter.prototype.eventNames = function eventNames() {
- var names = [],
- events,
- name;
- if (this._eventsCount === 0) return names;
- for (name in events = this._events) {
- if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
- }
- if (Object.getOwnPropertySymbols) {
- return names.concat(Object.getOwnPropertySymbols(events));
- }
- return names;
- };
- /**
- * Return the listeners registered for a given event.
- *
- * @param {String|Symbol} event The event name.
- * @param {Boolean} exists Only check if there are listeners.
- * @returns {Array|Boolean}
- * @api public
- */
- EventEmitter.prototype.listeners = function listeners(event, exists) {
- var evt = prefix ? prefix + event : event,
- available = this._events[evt];
- if (exists) return !!available;
- if (!available) return [];
- if (available.fn) return [available.fn];
- for (var i = 0, l = available.length, ee = new Array(l); i < l; i++) {
- ee[i] = available[i].fn;
- }
- return ee;
- };
- /**
- * Calls each of the listeners registered for a given event.
- *
- * @param {String|Symbol} event The event name.
- * @returns {Boolean} `true` if the event had listeners, else `false`.
- * @api public
- */
- EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
- var evt = prefix ? prefix + event : event;
- if (!this._events[evt]) return false;
- var listeners = this._events[evt],
- len = arguments.length,
- args,
- i;
- if (listeners.fn) {
- if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
- switch (len) {
- case 1:
- return listeners.fn.call(listeners.context), true;
- case 2:
- return listeners.fn.call(listeners.context, a1), true;
- case 3:
- return listeners.fn.call(listeners.context, a1, a2), true;
- case 4:
- return listeners.fn.call(listeners.context, a1, a2, a3), true;
- case 5:
- return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
- case 6:
- return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
- }
- for (i = 1, args = new Array(len - 1); i < len; i++) {
- args[i - 1] = arguments[i];
- }
- listeners.fn.apply(listeners.context, args);
- } else {
- var length = listeners.length,
- j;
- for (i = 0; i < length; i++) {
- if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
- switch (len) {
- case 1:
- listeners[i].fn.call(listeners[i].context);break;
- case 2:
- listeners[i].fn.call(listeners[i].context, a1);break;
- case 3:
- listeners[i].fn.call(listeners[i].context, a1, a2);break;
- case 4:
- listeners[i].fn.call(listeners[i].context, a1, a2, a3);break;
- default:
- if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
- args[j - 1] = arguments[j];
- }
- listeners[i].fn.apply(listeners[i].context, args);
- }
- }
- }
- return true;
- };
- /**
- * Add a listener for a given event.
- *
- * @param {String|Symbol} event The event name.
- * @param {Function} fn The listener function.
- * @param {Mixed} [context=this] The context to invoke the listener with.
- * @returns {EventEmitter} `this`.
- * @api public
- */
- EventEmitter.prototype.on = function on(event, fn, context) {
- var listener = new EE(fn, context || this),
- evt = prefix ? prefix + event : event;
- if (!this._events[evt]) this._events[evt] = listener, this._eventsCount++;else if (!this._events[evt].fn) this._events[evt].push(listener);else this._events[evt] = [this._events[evt], listener];
- return this;
- };
- /**
- * Add a one-time listener for a given event.
- *
- * @param {String|Symbol} event The event name.
- * @param {Function} fn The listener function.
- * @param {Mixed} [context=this] The context to invoke the listener with.
- * @returns {EventEmitter} `this`.
- * @api public
- */
- EventEmitter.prototype.once = function once(event, fn, context) {
- var listener = new EE(fn, context || this, true),
- evt = prefix ? prefix + event : event;
- if (!this._events[evt]) this._events[evt] = listener, this._eventsCount++;else if (!this._events[evt].fn) this._events[evt].push(listener);else this._events[evt] = [this._events[evt], listener];
- return this;
- };
- /**
- * Remove the listeners of a given event.
- *
- * @param {String|Symbol} event The event name.
- * @param {Function} fn Only remove the listeners that match this function.
- * @param {Mixed} context Only remove the listeners that have this context.
- * @param {Boolean} once Only remove one-time listeners.
- * @returns {EventEmitter} `this`.
- * @api public
- */
- EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
- var evt = prefix ? prefix + event : event;
- if (!this._events[evt]) return this;
- if (!fn) {
- if (--this._eventsCount === 0) this._events = new Events();else delete this._events[evt];
- return this;
- }
- var listeners = this._events[evt];
- if (listeners.fn) {
- if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
- if (--this._eventsCount === 0) this._events = new Events();else delete this._events[evt];
- }
- } else {
- for (var i = 0, events = [], length = listeners.length; i < length; i++) {
- if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
- events.push(listeners[i]);
- }
- }
- if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;else if (--this._eventsCount === 0) this._events = new Events();else delete this._events[evt];
- }
- return this;
- };
- /**
- * Remove all listeners, or those of the specified event.
- *
- * @param {String|Symbol} [event] The event name.
- * @returns {EventEmitter} `this`.
- * @api public
- */
- EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
- var evt;
- if (event) {
- evt = prefix ? prefix + event : event;
- if (this._events[evt]) {
- if (--this._eventsCount === 0) this._events = new Events();else delete this._events[evt];
- }
- } else {
- this._events = new Events();
- this._eventsCount = 0;
- }
- return this;
- };
- EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
- EventEmitter.prototype.addListener = EventEmitter.prototype.on;
- EventEmitter.prototype.setMaxListeners = function setMaxListeners() {
- return this;
- };
- EventEmitter.prefixed = prefix;
- EventEmitter.EventEmitter = EventEmitter;
- if ('undefined' !== typeof module) {
- module.exports = EventEmitter;
- }
- return module.exports;
- };
- /********** End of module 2: /home/blake/Repositories/ws-wrapper/node_modules/eventemitter3/index.js **********/
- /********** Footer **********/
- if ((typeof module === "undefined" ? "undefined" : _typeof(module)) === "object") module.exports = __require(0);else return __require(0);
- })();
- /********** End of footer **********/
|