text: !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AuroraAPI=t():e.AuroraAPI=t()}(window,(function(){return function(e){var t={};function o(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=e,o.c=t,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=2)}([function(e,t,o){(function(t){var o=null;"undefined"!=typeof WebSocket?o=WebSocket:"undefined"!=typeof MozWebSocket?o=MozWebSocket:void 0!==t?o=t.WebSocket||t.MozWebSocket:"undefined"!=typeof window?o=window.WebSocket||window.MozWebSocket:"undefined"!=typeof self&&(o=self.WebSocket||self.MozWebSocket),e.exports=o}).call(this,o(1))},function(e,t){var o;o=function(){return this}();try{o=o||new Function("return this")()}catch(e){"object"==typeof window&&(o=window)}e.exports=o},function(e,t,o){"use strict";o.r(t),o.d(t,"AuroraAPI",(function(){return y})),o.d(t,"AuroraWebSocket",(function(){return p}));var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),r=new Uint8Array(16);function s(){if(!n)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(r)}var i=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var u=function(e){return"string"==typeof e&&i.test(e)},c=[],d=0;d<256;++d)c.push((d+256).toString(16).substr(1));var a=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=(c[e[t+0]]+c[e[t+1]]+c[e[t+2]]+c[e[t+3]]+"-"+c[e[t+4]]+c[e[t+5]]+"-"+c[e[t+6]]+c[e[t+7]]+"-"+c[e[t+8]]+c[e[t+9]]+"-"+c[e[t+10]]+c[e[t+11]]+c[e[t+12]]+c[e[t+13]]+c[e[t+14]]+c[e[t+15]]).toLowerCase();if(!u(o))throw TypeError("Stringified UUID is invalid");return o};var f=function(e,t,o){var n=(e=e||{}).random||(e.rng||s)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){o=o||0;for(var r=0;r<16;++r)t[o+r]=n[r];return t}return a(n)},l=o(0);class p extends l{constructor(e,t){super(e),this.api=t}}class h{constructor(){this.listeners=new Map}addListener(e,t){this.listeners.set(e,t)}emit(e){void 0!==e.uuid&&this.listeners.has(e.uuid)?(this.listeners.get(e.uuid)(e),this.listeners.delete(e.uuid)):void 0!==e.code?console.error(e):console.dir(e)}}class y{constructor(){this.messageEmitter=new h}connect(e,t){if(this.socket=new p(e,this),this.socket.onclose=this.onClose,this.socket.onmessage=this.onMessage,void 0===t)return new Promise((e,t)=>{this.socket.onopen=()=>{this.onOpen(),e(this)},this.socket.onerror=e=>{this.onError(e),t(e)}});this.socket.onopen=()=>{this.onOpen(),t(null,this)},this.socket.onerror=e=>{this.onError(e),t(e)}}close(e,t){this.socket&&this.socket.close(e,t)}hasConnected(){return!!this.socket&&this.socket.readyState===this.socket.OPEN}send(e,t={},o){if(!this.socket)return console.error("WebSocket not connected");const n={type:e,uuid:f(),data:t};if(this.socket.send(JSON.stringify(n)),void 0===o)return new Promise((e,t)=>{this.messageEmitter.addListener(n.uuid,o=>{void 0!==o.code?t(o):e(o)})});this.messageEmitter.addListener(n.uuid,e=>{void 0!==e.code?o(e):o(null,e)})}onOpen(){console.log("Connection established")}onClose(e){if(e.wasClean)return console.log("Connection closed");1006===e.code?console.error("Break connection"):(console.error("Unknown error"),console.dir(e))}onMessage(e){this.api.messageEmitter.emit(JSON.parse(e.data))}onError(e){console.error("WebSocket error observed:",e)}}}]).AuroraAPI}));
  //# sourceMappingURL=aurora-api.min.js.map