text: !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.VueWsc=t():e.VueWsc=t()}(window,function(){return function(n){var o={};function r(e){if(o[e])return o[e].exports;var t=o[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,r),t.l=!0,t.exports}return r.m=n,r.c=o,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t,n){window,e.exports=function(n){var o={};function r(e){if(o[e])return o[e].exports;var t=o[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,r),t.l=!0,t.exports}return r.m=n,r.c=o,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,n){"use strict";function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}n.r(t);var r=function(){function n(e,t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),this._eventType=e,this._handler=t}return o(n.prototype,[{key:"compareTo",value:function(e){return e instanceof n&&e.eventType===this._eventType&&e.handler.toString()===this._handler.toString()}},{key:"eventType",get:function(){return this._eventType}},{key:"handler",get:function(){return this._handler}}]),n}();function i(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}var c=function(){function n(e,t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),this._id=e,this._value=t}return i(n.prototype,[{key:"id",get:function(){return this._id}},{key:"value",get:function(){return this._value},set:function(e){this._value=e}}]),n}();function s(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}var u=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._elementId=0,this._repository=[]}return s(e.prototype,[{key:"getById",value:function(t){var n=null;return this._repository.forEach(function(e){null===n&&e.id===t&&(n=e.value)}),n}},{key:"getAll",value:function(){return this._repository.map(function(e){return e.value})}},{key:"add",value:function(e){var t=new c(++this._elementId,e);return this._repository.push(t),t.id}},{key:"deleteById",value:function(o){var r=!1;return this._repository.forEach(function(e,t,n){e.id===o&&(n.splice(t,1),r=!0)}),r}},{key:"deleteByIndex",value:function(e){return void 0!==this._repository[e]&&(this._repository.splice(e,1),!0)}},{key:"clear",value:function(){this._repository=[]}},{key:"length",get:function(){return this._repository.length}}]),e}();function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function f(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function l(e,t,n){return(l="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var o=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=y(e)););return e}(e,t);if(o){var r=Object.getOwnPropertyDescriptor(o,t);return r.get?r.get.call(n):r.value}})(e,t,n||e)}function y(e){return(y=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function p(e,t){return(p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var d=function(e){function n(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),e=this,!(t=y(n).call(this))||"object"!==a(t)&&"function"!=typeof t?function(e){if(void 0!==e)return e;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}(e):t;var e,t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&p(e,t)}(n,u),f(n.prototype,[{key:"add",value:function(e){return l(y(n.prototype),"add",this).call(this,e)}},{key:"getByEventType",value:function(t){return this.getAll().filter(function(e){return e.eventType===t})}},{key:"getByHandler",value:function(t){return this.getAll().filter(function(e){return e.handler.toString()===t.toString()})}},{key:"hasByEventType",value:function(e){return Boolean(this.getByEventType(e).length)}},{key:"hasByHandler",value:function(e){return Boolean(this.getByHandler(e).length)}},{key:"deleteByEventType",value:function(t){var n=this,o=!1;return this._repository.forEach(function(e){e.value.eventType===t&&n.deleteById(e.id)&&(o=!0)}),o}},{key:"deleteByHandler",value:function(t){var n=this,o=!1;return this._repository.forEach(function(e){e.value.handler.toString()===t.toString()&&n.deleteById(e.id)&&(o=!0)}),o}}]),n}();function h(e){return(h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function b(e){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _(e,t){return(_=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var v=function(e){function n(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),e=this,!(t=b(n).apply(this,arguments))||"object"!==h(t)&&"function"!=typeof t?function(e){if(void 0!==e)return e;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}(e):t;var e,t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_(e,t)}(n,u),n}();function w(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function g(e){return(g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function m(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}var k=function(){function o(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:void 0,n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),void 0===e)throw new TypeError("Required URL parameter is missing");if("object"!==g(n))throw new TypeError("Options is must be an object");this._url=e,this._protocols=t,this._options=function(r){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{},t=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(i).filter(function(e){return Object.getOwnPropertyDescriptor(i,e).enumerable}))),t.forEach(function(e){var t,n,o;t=r,o=i[n=e],n in t?Object.defineProperty(t,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[n]=o})}return r}({},{useMessageQueue:!0,reconnection:!0,reconnectionOptions:{attempts:1/0,delay:1e3,maxDelay:5e3,increaseDelay:1e3}},n),this._webSocket=void 0,this._binaryType=void 0,this._extensions=void 0,this._protocol=void 0,this._eventHandlerRepository=new d,this._messageRepository=new v,this._reconnectionAttemptAt=Date.now(),this._currentAttempts=0,this._currentReconnectionDelay=this._options.reconnectionOptions.delay}var e,t;return t=[{key:"_standardEventTypes",get:function(){return["open","message","close","error"]}},{key:"_customEventTypes",get:function(){return["opening","closing","ready"]}}],m((e=o).prototype,[{key:"connect",value:function(){var o=this;try{this._webSocket=new window.WebSocket(this._url,this._protocols)}catch(e){throw new Error(e.message)}["binaryType","extensions","protocol"].forEach(function(e){void 0!==o["_"+e]&&(o._webSocket[e]=o[e])}),this._executeCustomEvents("opening"),this._addEventsFromStandardQueue(),this._webSocket.addEventListener("open",function(e){o._currentAttempts=0,o._currentReconnectionDelay=o._options.reconnectionOptions.delay,o._sendMessagesFromQueue(),o._executeCustomEvents("ready",e)}),this._options.reconnection&&this._webSocket.addEventListener("close",function(e){if(!e.wasClean&&o._currentAttempts<o._options.reconnectionOptions.attempts){var t=Date.now(),n=o._currentReconnectionDelay-(t-o._reconnectionAttemptAt);n<0?o.reconnect():setTimeout(function(){o.reconnect()},n),o._currentAttempts++,o._currentReconnectionDelay+=o._options.reconnectionOptions.increaseDelay,o._currentReconnectionDelay>o._options.reconnectionOptions.maxDelay&&(o._currentReconnectionDelay=o._options.reconnectionOptions.maxDelay)}})}},{key:"reconnect",value:function(){if(!(this._webSocket instanceof window.WebSocket))throw new Error("WebSocket instance is not defined");this._reconnectionAttemptAt=Date.now(),this._webSocket.readyState===window.WebSocket.OPEN&&this._webSocket.close(),this.connect()}},{key:"send",value:function(e){this._webSocket instanceof window.WebSocket&&this._webSocket.readyState===window.WebSocket.OPEN?this._webSocket.send(e):this._options.useMessageQueue&&this._messageRepository.add(e)}},{key:"close",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:1e3,t=1<arguments.length?arguments[1]:void 0;if(!(this._webSocket instanceof window.WebSocket))throw new Error("WebSocket instance is not defined");this._executeCustomEvents("closing"),this._messageRepository.clear(),this._options.reconnection&&(this._currentAttempts=this._options.reconnectionOptions.attempts);try{this._webSocket.close(e,t)}catch(e){throw new Error(e.message)}}},{key:"on",value:function(e,t){return-1<w(o._standardEventTypes).concat(w(o._customEventTypes)).indexOf(e)&&this._eventHandlerRepository.add(new r(e,t))}},{key:"off",value:function(e){var t=!1;switch(g(e)){case"number":t=this._eventHandlerRepository.deleteById(e);break;case"string":t=this._eventHandlerRepository.deleteByEventType(e);break;case"function":t=this._eventHandlerRepository.deleteByHandler(e)}return t}},{key:"_addEventsFromStandardQueue",value:function(){var n=this;o._standardEventTypes.forEach(function(e){n._webSocket.addEventListener(e,function(t){n._eventHandlerRepository.getByEventType(e).forEach(function(e){e.handler.call(n,t)})})})}},{key:"_executeCustomEvents",value:function(e){var t=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;this._eventHandlerRepository.getByEventType(e).forEach(function(e){e.handler.call(t,n)})}},{key:"_sendMessagesFromQueue",value:function(){var n=this;this._messageRepository.getAll().forEach(function(e,t){n._webSocket.readyState===window.WebSocket.OPEN&&(n.send(e),n._messageRepository.deleteByIndex(t))})}},{key:"binaryType",get:function(){return this._webSocket instanceof window.WebSocket?this._webSocket.binaryType:void 0!==this._binaryType?g(this._binaryType):"blob"},set:function(e){this._binaryType=e,this._webSocket instanceof window.WebSocket&&(this._webSocket.binaryType=e)}},{key:"bufferedAmount",get:function(){return this._webSocket instanceof window.WebSocket?this._webSocket.bufferedAmount:0}},{key:"extensions",get:function(){return this._webSocket instanceof window.WebSocket?this._webSocket.extensions:void 0!==this._extensions?g(this._extensions):""},set:function(e){this._binaryType=extensions,this._webSocket instanceof window.WebSocket&&(this._webSocket.extensions=e)}},{key:"protocol",get:function(){return this._webSocket instanceof window.WebSocket?this._webSocket.protocol:void 0!==this._protocol?g(this._protocol):""},set:function(e){this._protocol=e,this._webSocket instanceof window.WebSocket&&(this._webSocket.extensions=e)}},{key:"readyState",get:function(){return this._webSocket instanceof window.WebSocket?this._webSocket.readyState:0}},{key:"url",get:function(){return this._webSocket instanceof window.WebSocket?this._webSocket.url:this._url}}]),m(e,t),o}();t.default=k}])},function(e,t,f){"use strict";function l(e){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}f.r(t);var n={install:function(e,t,n,o){var i=["_",Math.random()].join(),c={onOpening:"opening",onOpen:"open",onMessage:"message",onClosing:"closing",onClose:"close"},r=f(0).default,s=this,u={},a={};this._fillWscRepository=function(t,e,n){switch(l(t)){case"string":u[i]=new r(t,e,n);break;case"object":Object.keys(t).forEach(function(e){u[e]=new r(t[e].url,t[e].protocols,t[e].options)})}},this._getWsc=function(e){return u[e]||u[i]},this._fillWscRepository(t,n,o),e.mixin({created:function(){var n,o,r=this;this.$options.wsc&&(a[this._uid]={},Object.keys(this.$options.wsc).forEach(function(t){switch(l(r.$options.wsc[t])){case"function":c[t]&&(void 0===a[r._uid][i]&&(a[r._uid][i]=[]),n=s._getWsc(i),o=n.on(c[t],r.$options.wsc[t].bind(r)),a[r._uid][i].push(o));break;case"object":n=s._getWsc(t),void 0===a[r._uid][t]&&(a[r._uid][t]=[]),Object.keys(r.$options.wsc[t]).forEach(function(e){c[e]&&(o=n.on(c[e],r.$options.wsc[t][e].bind(r)),a[r._uid][t].push(o))})}}))},beforeDestroy:function(){var t,n=this;a[this._uid]&&(Object.keys(a[this._uid]).forEach(function(e){t=s._getWsc(e),a[n._uid][e].forEach(function(e){t.off(e)})}),delete a[this._uid])}}),e.prototype.$wsc=function(e){var n=s._getWsc(e);if(void 0===n)throw new Error("WebSocket instance is not defined");return{connect:function(){n.connect()},send:function(e){n.send(e)},close:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:1e3,t=1<arguments.length?arguments[1]:void 0;n.close(e,t)}}}}};t.default=n}])});