@aws-amplify/pubsub 4.1.15 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@
5
5
  * @author Feross Aboukhadijeh <http://feross.org>
6
6
  * @license MIT
7
7
  */
8
- var r=n(21),o=n(22),i=n(23);function s(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(s()<t)throw new RangeError("Invalid typed array length");return c.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=c.prototype:(null===e&&(e=new c(t)),e.length=t),e}function c(e,t,n){if(!(c.TYPED_ARRAY_SUPPORT||this instanceof c))return new c(e,t,n);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return f(this,e)}return u(this,e,t,n)}function u(e,t,n,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,n,r){if(t.byteLength,n<0||t.byteLength<n)throw new RangeError("'offset' is out of bounds");if(t.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");t=void 0===n&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,n):new Uint8Array(t,n,r);c.TYPED_ARRAY_SUPPORT?(e=t).__proto__=c.prototype:e=l(e,t);return e}(e,t,n,r):"string"==typeof t?function(e,t,n){"string"==typeof n&&""!==n||(n="utf8");if(!c.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|d(t,n),o=(e=a(e,r)).write(t,n);o!==r&&(e=e.slice(0,o));return e}(e,t,n):function(e,t){if(c.isBuffer(t)){var n=0|p(t.length);return 0===(e=a(e,n)).length||t.copy(e,0,0,n),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(r=t.length)!=r?a(e,0):l(e,t);if("Buffer"===t.type&&i(t.data))return l(e,t.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function h(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function f(e,t){if(h(t),e=a(e,t<0?0:0|p(t)),!c.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)e[n]=0;return e}function l(e,t){var n=t.length<0?0:0|p(t.length);e=a(e,n);for(var r=0;r<n;r+=1)e[r]=255&t[r];return e}function p(e){if(e>=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|e}function d(e,t){if(c.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return j(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return V(e).length;default:if(r)return j(e).length;t=(""+t).toLowerCase(),r=!0}}function y(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return C(this,t,n);case"utf8":case"utf-8":return T(this,t,n);case"ascii":return I(this,t,n);case"latin1":case"binary":return R(this,t,n);case"base64":return O(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function g(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function v(e,t,n,r,o){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(o)return-1;n=e.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof t&&(t=c.from(t,r)),c.isBuffer(t))return 0===t.length?-1:b(e,t,n,r,o);if("number"==typeof t)return t&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):b(e,[t],n,r,o);throw new TypeError("val must be string, number or Buffer")}function b(e,t,n,r,o){var i,s=1,a=e.length,c=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;s=2,a/=2,c/=2,n/=2}function u(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(o){var h=-1;for(i=n;i<a;i++)if(u(e,i)===u(t,-1===h?0:i-h)){if(-1===h&&(h=i),i-h+1===c)return h*s}else-1!==h&&(i-=i-h),h=-1}else for(n+c>a&&(n=a-c),i=n;i>=0;i--){for(var f=!0,l=0;l<c;l++)if(u(e,i+l)!==u(t,l)){f=!1;break}if(f)return i}return-1}function _(e,t,n,r){n=Number(n)||0;var o=e.length-n;r?(r=Number(r))>o&&(r=o):r=o;var i=t.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;s<r;++s){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))return s;e[n+s]=a}return s}function m(e,t,n,r){return F(j(t,e.length-n),e,n,r)}function w(e,t,n,r){return F(function(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function E(e,t,n,r){return w(e,t,n,r)}function S(e,t,n,r){return F(V(t),e,n,r)}function A(e,t,n,r){return F(function(e,t){for(var n,r,o,i=[],s=0;s<e.length&&!((t-=2)<0);++s)n=e.charCodeAt(s),r=n>>8,o=n%256,i.push(o),i.push(r);return i}(t,e.length-n),e,n,r)}function O(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function T(e,t,n){n=Math.min(e.length,n);for(var r=[],o=t;o<n;){var i,s,a,c,u=e[o],h=null,f=u>239?4:u>223?3:u>191?2:1;if(o+f<=n)switch(f){case 1:u<128&&(h=u);break;case 2:128==(192&(i=e[o+1]))&&(c=(31&u)<<6|63&i)>127&&(h=c);break;case 3:i=e[o+1],s=e[o+2],128==(192&i)&&128==(192&s)&&(c=(15&u)<<12|(63&i)<<6|63&s)>2047&&(c<55296||c>57343)&&(h=c);break;case 4:i=e[o+1],s=e[o+2],a=e[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(c=(15&u)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(h=c)}null===h?(h=65533,f=1):h>65535&&(h-=65536,r.push(h>>>10&1023|55296),h=56320|1023&h),r.push(h),o+=f}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=4096));return n}(r)}t.Buffer=c,t.SlowBuffer=function(e){+e!=e&&(e=0);return c.alloc(+e)},t.INSPECT_MAX_BYTES=50,c.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=s(),c.poolSize=8192,c._augment=function(e){return e.__proto__=c.prototype,e},c.from=function(e,t,n){return u(null,e,t,n)},c.TYPED_ARRAY_SUPPORT&&(c.prototype.__proto__=Uint8Array.prototype,c.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&c[Symbol.species]===c&&Object.defineProperty(c,Symbol.species,{value:null,configurable:!0})),c.alloc=function(e,t,n){return function(e,t,n,r){return h(t),t<=0?a(e,t):void 0!==n?"string"==typeof r?a(e,t).fill(n,r):a(e,t).fill(n):a(e,t)}(null,e,t,n)},c.allocUnsafe=function(e){return f(null,e)},c.allocUnsafeSlow=function(e){return f(null,e)},c.isBuffer=function(e){return!(null==e||!e._isBuffer)},c.compare=function(e,t){if(!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,o=0,i=Math.min(n,r);o<i;++o)if(e[o]!==t[o]){n=e[o],r=t[o];break}return n<r?-1:r<n?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!i(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=c.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){var s=e[n];if(!c.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(r,o),o+=s.length}return r},c.byteLength=d,c.prototype._isBuffer=!0,c.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)g(this,t,t+1);return this},c.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},c.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},c.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?T(this,0,e):y.apply(this,arguments)},c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){var e="",n=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(e+=" ... ")),"<Buffer "+e+">"},c.prototype.compare=function(e,t,n,r,o){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),t<0||n>e.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&t>=n)return 0;if(r>=o)return-1;if(t>=n)return 1;if(this===e)return 0;for(var i=(o>>>=0)-(r>>>=0),s=(n>>>=0)-(t>>>=0),a=Math.min(i,s),u=this.slice(r,o),h=e.slice(t,n),f=0;f<a;++f)if(u[f]!==h[f]){i=u[f],s=h[f];break}return i<s?-1:s<i?1:0},c.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},c.prototype.indexOf=function(e,t,n){return v(this,e,t,n,!0)},c.prototype.lastIndexOf=function(e,t,n){return v(this,e,t,n,!1)},c.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-t;if((void 0===n||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=!1;;)switch(r){case"hex":return _(this,e,t,n);case"utf8":case"utf-8":return m(this,e,t,n);case"ascii":return w(this,e,t,n);case"latin1":case"binary":return E(this,e,t,n);case"base64":return S(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,e,t,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function I(e,t,n){var r="";n=Math.min(e.length,n);for(var o=t;o<n;++o)r+=String.fromCharCode(127&e[o]);return r}function R(e,t,n){var r="";n=Math.min(e.length,n);for(var o=t;o<n;++o)r+=String.fromCharCode(e[o]);return r}function C(e,t,n){var r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);for(var o="",i=t;i<n;++i)o+=B(e[i]);return o}function N(e,t,n){for(var r=e.slice(t,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function M(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function P(e,t,n,r,o,i){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<i)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function k(e,t,n,r){t<0&&(t=65535+t+1);for(var o=0,i=Math.min(e.length-n,2);o<i;++o)e[n+o]=(t&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function x(e,t,n,r){t<0&&(t=4294967295+t+1);for(var o=0,i=Math.min(e.length-n,4);o<i;++o)e[n+o]=t>>>8*(r?o:3-o)&255}function U(e,t,n,r,o,i){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function L(e,t,n,r,i){return i||U(e,0,n,4),o.write(e,t,n,r,23,4),n+4}function D(e,t,n,r,i){return i||U(e,0,n,8),o.write(e,t,n,r,52,8),n+8}c.prototype.slice=function(e,t){var n,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e),c.TYPED_ARRAY_SUPPORT)(n=this.subarray(e,t)).__proto__=c.prototype;else{var o=t-e;n=new c(o,void 0);for(var i=0;i<o;++i)n[i]=this[i+e]}return n},c.prototype.readUIntLE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=this[e],o=1,i=0;++i<t&&(o*=256);)r+=this[e+i]*o;return r},c.prototype.readUIntBE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=this[e+--t],o=1;t>0&&(o*=256);)r+=this[e+--t]*o;return r},c.prototype.readUInt8=function(e,t){return t||M(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return t||M(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return t||M(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return t||M(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return t||M(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=this[e],o=1,i=0;++i<t&&(o*=256);)r+=this[e+i]*o;return r>=(o*=128)&&(r-=Math.pow(2,8*t)),r},c.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=t,o=1,i=this[e+--r];r>0&&(o*=256);)i+=this[e+--r]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*t)),i},c.prototype.readInt8=function(e,t){return t||M(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){t||M(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt16BE=function(e,t){t||M(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt32LE=function(e,t){return t||M(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return t||M(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return t||M(e,4,this.length),o.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return t||M(e,4,this.length),o.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return t||M(e,8,this.length),o.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return t||M(e,8,this.length),o.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||P(this,e,t,n,Math.pow(2,8*n)-1,0);var o=1,i=0;for(this[t]=255&e;++i<n&&(o*=256);)this[t+i]=e/o&255;return t+n},c.prototype.writeUIntBE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||P(this,e,t,n,Math.pow(2,8*n)-1,0);var o=n-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+n},c.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,1,255,0),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):k(this,e,t,!0),t+2},c.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):k(this,e,t,!1),t+2},c.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):x(this,e,t,!0),t+4},c.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):x(this,e,t,!1),t+4},c.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var o=Math.pow(2,8*n-1);P(this,e,t,n,o-1,-o)}var i=0,s=1,a=0;for(this[t]=255&e;++i<n&&(s*=256);)e<0&&0===a&&0!==this[t+i-1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+n},c.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var o=Math.pow(2,8*n-1);P(this,e,t,n,o-1,-o)}var i=n-1,s=1,a=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===a&&0!==this[t+i+1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+n},c.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,1,127,-128),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):k(this,e,t,!0),t+2},c.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):k(this,e,t,!1),t+2},c.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):x(this,e,t,!0),t+4},c.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):x(this,e,t,!1),t+4},c.prototype.writeFloatLE=function(e,t,n){return L(this,e,t,!0,n)},c.prototype.writeFloatBE=function(e,t,n){return L(this,e,t,!1,n)},c.prototype.writeDoubleLE=function(e,t,n){return D(this,e,t,!0,n)},c.prototype.writeDoubleBE=function(e,t,n){return D(this,e,t,!1,n)},c.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var o,i=r-n;if(this===e&&n<t&&t<r)for(o=i-1;o>=0;--o)e[o+t]=this[o+n];else if(i<1e3||!c.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)e[o+t]=this[o+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+i),t);return i},c.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===e.length){var o=e.charCodeAt(0);o<256&&(e=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!c.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;var i;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(i=t;i<n;++i)this[i]=e;else{var s=c.isBuffer(e)?e:j(new c(e,r).toString()),a=s.length;for(i=0;i<n-t;++i)this[i+t]=s[i%a]}return this};var q=/[^+\/0-9A-Za-z-_]/g;function B(e){return e<16?"0"+e.toString(16):e.toString(16)}function j(e,t){var n;t=t||1/0;for(var r=e.length,o=null,i=[],s=0;s<r;++s){if((n=e.charCodeAt(s))>55295&&n<57344){if(!o){if(n>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(t-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((t-=1)<0)break;i.push(n)}else if(n<2048){if((t-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function V(e){return r.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(q,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function F(e,t,n,r){for(var o=0;o<r&&!(o+n>=t.length||o>=e.length);++o)t[o+n]=e[o];return o}}).call(this,n(3))},function(e,t){e.exports=n},function(e,t){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var r=new Uint8Array(16);e.exports=function(){return n(r),r}}else{var o=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),o[t]=e>>>((3&t)<<3)&255;return o}}},function(e,t){for(var n=[],r=0;r<256;++r)n[r]=(r+256).toString(16).substr(1);e.exports=function(e,t){var r=t||0,o=n;return[o[e[r++]],o[e[r++]],o[e[r++]],o[e[r++]],"-",o[e[r++]],o[e[r++]],"-",o[e[r++]],o[e[r++]],"-",o[e[r++]],o[e[r++]],"-",o[e[r++]],o[e[r++]],o[e[r++]],o[e[r++]],o[e[r++]],o[e[r++]]].join("")}},function(e,t,n){e.exports=n(12).Observable},function(e,t,n){(function(t){var n;n=function(){return function(e){var t,n=e.localStorage||(t={},{setItem:function(e,n){t[e]=n},getItem:function(e){return t[e]},removeItem:function(e){delete t[e]}}),r=1,o=2,i=3,s=4,a=5,c=6,u=7,h=8,f=9,l=10,p=11,d=12,y=13,g=14,v=function(e,t){for(var n in e)if(e.hasOwnProperty(n)){if(!t.hasOwnProperty(n)){var r="Unknown property, "+n+". Valid properties are:";for(var o in t)t.hasOwnProperty(o)&&(r=r+" "+o);throw new Error(r)}if(typeof e[n]!==t[n])throw new Error(w(_.INVALID_TYPE,[typeof e[n],n]))}},b=function(e,t){return function(){return e.apply(t,arguments)}},_={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: {0}."}},m={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},w=function(e,t){var n=e.text;if(t)for(var r,o,i=0;i<t.length;i++)if(r="{"+i+"}",(o=n.indexOf(r))>0){var s=n.substring(0,o),a=n.substring(o+r.length);n=s+t[i]+a}return n},E=[0,6,77,81,73,115,100,112,3],S=[0,4,77,81,84,84,4],A=function(e,t){for(var n in this.type=e,t)t.hasOwnProperty(n)&&(this[n]=t[n])};function O(e,t){var n,r=t,h=e[t],l=h>>4,d=h&=15;t+=1;var y=0,g=1;do{if(t==e.length)return[null,r];y+=(127&(n=e[t++]))*g,g*=128}while(0!=(128&n));var v=t+y;if(v>e.length)return[null,r];var b=new A(l);switch(l){case o:1&e[t++]&&(b.sessionPresent=!0),b.returnCode=e[t++];break;case i:var _=d>>1&3,m=R(e,t),w=M(e,t+=2,m);t+=m,_>0&&(b.messageIdentifier=R(e,t),t+=2);var E=new U(e.subarray(t,v));1==(1&d)&&(E.retained=!0),8==(8&d)&&(E.duplicate=!0),E.qos=_,E.destinationName=w,b.payloadMessage=E;break;case s:case a:case c:case u:case p:b.messageIdentifier=R(e,t);break;case f:b.messageIdentifier=R(e,t),t+=2,b.returnCode=e.subarray(t,v)}return[b,v]}function T(e,t,n){return t[n++]=e>>8,t[n++]=e%256,n}function I(e,t,n,r){return N(e,n,r=T(t,n,r)),r+t}function R(e,t){return 256*e[t]+e[t+1]}function C(e){for(var t=0,n=0;n<e.length;n++){var r=e.charCodeAt(n);r>2047?(55296<=r&&r<=56319&&(n++,t++),t+=3):r>127?t+=2:t++}return t}function N(e,t,n){for(var r=n,o=0;o<e.length;o++){var i=e.charCodeAt(o);if(55296<=i&&i<=56319){var s=e.charCodeAt(++o);if(isNaN(s))throw new Error(w(_.MALFORMED_UNICODE,[i,s]));i=s-56320+(i-55296<<10)+65536}i<=127?t[r++]=i:i<=2047?(t[r++]=i>>6&31|192,t[r++]=63&i|128):i<=65535?(t[r++]=i>>12&15|224,t[r++]=i>>6&63|128,t[r++]=63&i|128):(t[r++]=i>>18&7|240,t[r++]=i>>12&63|128,t[r++]=i>>6&63|128,t[r++]=63&i|128)}return t}function M(e,t,n){for(var r,o="",i=t;i<t+n;){var s=e[i++];if(s<128)r=s;else{var a=e[i++]-128;if(a<0)throw new Error(w(_.MALFORMED_UTF,[s.toString(16),a.toString(16),""]));if(s<224)r=64*(s-192)+a;else{var c=e[i++]-128;if(c<0)throw new Error(w(_.MALFORMED_UTF,[s.toString(16),a.toString(16),c.toString(16)]));if(s<240)r=4096*(s-224)+64*a+c;else{var u=e[i++]-128;if(u<0)throw new Error(w(_.MALFORMED_UTF,[s.toString(16),a.toString(16),c.toString(16),u.toString(16)]));if(!(s<248))throw new Error(w(_.MALFORMED_UTF,[s.toString(16),a.toString(16),c.toString(16),u.toString(16)]));r=262144*(s-240)+4096*a+64*c+u}}}r>65535&&(r-=65536,o+=String.fromCharCode(55296+(r>>10)),r=56320+(1023&r)),o+=String.fromCharCode(r)}return o}A.prototype.encode=function(){var e,t=(15&this.type)<<4,n=0,o=[],s=0;switch(void 0!==this.messageIdentifier&&(n+=2),this.type){case r:switch(this.mqttVersion){case 3:n+=E.length+3;break;case 4:n+=S.length+3}n+=C(this.clientId)+2,void 0!==this.willMessage&&(n+=C(this.willMessage.destinationName)+2,(e=this.willMessage.payloadBytes)instanceof Uint8Array||(e=new Uint8Array(u)),n+=e.byteLength+2),void 0!==this.userName&&(n+=C(this.userName)+2),void 0!==this.password&&(n+=C(this.password)+2);break;case h:t|=2;for(var a=0;a<this.topics.length;a++)o[a]=C(this.topics[a]),n+=o[a]+2;n+=this.requestedQos.length;break;case l:for(t|=2,a=0;a<this.topics.length;a++)o[a]=C(this.topics[a]),n+=o[a]+2;break;case c:t|=2;break;case i:this.payloadMessage.duplicate&&(t|=8),t=t|=this.payloadMessage.qos<<1,this.payloadMessage.retained&&(t|=1),n+=(s=C(this.payloadMessage.destinationName))+2;var u=this.payloadMessage.payloadBytes;n+=u.byteLength,u instanceof ArrayBuffer?u=new Uint8Array(u):u instanceof Uint8Array||(u=new Uint8Array(u.buffer))}var f=function(e){var t=new Array(1),n=0;do{var r=e%128;(e>>=7)>0&&(r|=128),t[n++]=r}while(e>0&&n<4);return t}(n),p=f.length+1,d=new ArrayBuffer(n+p),y=new Uint8Array(d);if(y[0]=t,y.set(f,1),this.type==i)p=I(this.payloadMessage.destinationName,s,y,p);else if(this.type==r){switch(this.mqttVersion){case 3:y.set(E,p),p+=E.length;break;case 4:y.set(S,p),p+=S.length}var g=0;this.cleanSession&&(g=2),void 0!==this.willMessage&&(g|=4,g|=this.willMessage.qos<<3,this.willMessage.retained&&(g|=32)),void 0!==this.userName&&(g|=128),void 0!==this.password&&(g|=64),y[p++]=g,p=T(this.keepAliveInterval,y,p)}switch(void 0!==this.messageIdentifier&&(p=T(this.messageIdentifier,y,p)),this.type){case r:p=I(this.clientId,C(this.clientId),y,p),void 0!==this.willMessage&&(p=I(this.willMessage.destinationName,C(this.willMessage.destinationName),y,p),p=T(e.byteLength,y,p),y.set(e,p),p+=e.byteLength),void 0!==this.userName&&(p=I(this.userName,C(this.userName),y,p)),void 0!==this.password&&(p=I(this.password,C(this.password),y,p));break;case i:y.set(u,p);break;case h:for(a=0;a<this.topics.length;a++)p=I(this.topics[a],o[a],y,p),y[p++]=this.requestedQos[a];break;case l:for(a=0;a<this.topics.length;a++)p=I(this.topics[a],o[a],y,p)}return d};var P=function(e,t){this._client=e,this._keepAliveInterval=1e3*t,this.isReset=!1;var n=new A(d).encode(),r=function(e){return function(){return o.apply(e)}},o=function(){this.isReset?(this.isReset=!1,this._client._trace("Pinger.doPing","send PINGREQ"),this._client.socket.send(n),this.timeout=setTimeout(r(this),this._keepAliveInterval)):(this._client._trace("Pinger.doPing","Timed out"),this._client._disconnected(_.PING_TIMEOUT.code,w(_.PING_TIMEOUT)))};this.reset=function(){this.isReset=!0,clearTimeout(this.timeout),this._keepAliveInterval>0&&(this.timeout=setTimeout(r(this),this._keepAliveInterval))},this.cancel=function(){clearTimeout(this.timeout)}},k=function(e,t,n,r){t||(t=30),this.timeout=setTimeout(function(e,t,n){return function(){return e.apply(t,n)}}(n,e,r),1e3*t),this.cancel=function(){clearTimeout(this.timeout)}},x=function(t,r,o,i,s){if(!("WebSocket"in e)||null===e.WebSocket)throw new Error(w(_.UNSUPPORTED,["WebSocket"]));if(!("ArrayBuffer"in e)||null===e.ArrayBuffer)throw new Error(w(_.UNSUPPORTED,["ArrayBuffer"]));for(var a in this._trace("Paho.Client",t,r,o,i,s),this.host=r,this.port=o,this.path=i,this.uri=t,this.clientId=s,this._wsuri=null,this._localKey=r+":"+o+("/mqtt"!=i?":"+i:"")+":"+s+":",this._msg_queue=[],this._buffered_msg_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0,n)0!==a.indexOf("Sent:"+this._localKey)&&0!==a.indexOf("Received:"+this._localKey)||this.restore(a)};x.prototype.host=null,x.prototype.port=null,x.prototype.path=null,x.prototype.uri=null,x.prototype.clientId=null,x.prototype.socket=null,x.prototype.connected=!1,x.prototype.maxMessageIdentifier=65536,x.prototype.connectOptions=null,x.prototype.hostIndex=null,x.prototype.onConnected=null,x.prototype.onConnectionLost=null,x.prototype.onMessageDelivered=null,x.prototype.onMessageArrived=null,x.prototype.traceFunction=null,x.prototype._msg_queue=null,x.prototype._buffered_msg_queue=null,x.prototype._connectTimeout=null,x.prototype.sendPinger=null,x.prototype.receivePinger=null,x.prototype._reconnectInterval=1,x.prototype._reconnecting=!1,x.prototype._reconnectTimeout=null,x.prototype.disconnectedPublishing=!1,x.prototype.disconnectedBufferSize=5e3,x.prototype.receiveBuffer=null,x.prototype._traceBuffer=null,x.prototype._MAX_TRACE_ENTRIES=100,x.prototype.connect=function(e){var t=this._traceMask(e,"password");if(this._trace("Client.connect",t,this.socket,this.connected),this.connected)throw new Error(w(_.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(w(_.INVALID_STATE,["already connected"]));this._reconnecting&&(this._reconnectTimeout.cancel(),this._reconnectTimeout=null,this._reconnecting=!1),this.connectOptions=e,this._reconnectInterval=1,this._reconnecting=!1,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},x.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(w(_.INVALID_STATE,["not connected"]));var n=new A(h);n.topics=e.constructor===Array?e:[e],void 0===t.qos&&(t.qos=0),n.requestedQos=[];for(var r=0;r<n.topics.length;r++)n.requestedQos[r]=t.qos;t.onSuccess&&(n.onSuccess=function(e){t.onSuccess({invocationContext:t.invocationContext,grantedQos:e})}),t.onFailure&&(n.onFailure=function(e){t.onFailure({invocationContext:t.invocationContext,errorCode:e,errorMessage:w(e)})}),t.timeout&&(n.timeOut=new k(this,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:_.SUBSCRIBE_TIMEOUT.code,errorMessage:w(_.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},x.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(w(_.INVALID_STATE,["not connected"]));var n=new A(l);n.topics=e.constructor===Array?e:[e],t.onSuccess&&(n.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(n.timeOut=new k(this,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:_.UNSUBSCRIBE_TIMEOUT.code,errorMessage:w(_.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},x.prototype.send=function(e){this._trace("Client.send",e);var t=new A(i);if(t.payloadMessage=e,this.connected)e.qos>0?this._requires_ack(t):this.onMessageDelivered&&(this._notify_msg_sent[t]=this.onMessageDelivered(t.payloadMessage)),this._schedule_message(t);else{if(!this._reconnecting||!this.disconnectedPublishing)throw new Error(w(_.INVALID_STATE,["not connected"]));if(Object.keys(this._sentMessages).length+this._buffered_msg_queue.length>this.disconnectedBufferSize)throw new Error(w(_.BUFFER_FULL,[this.disconnectedBufferSize]));e.qos>0?this._requires_ack(t):(t.sequence=++this._sequence,this._buffered_msg_queue.unshift(t))}},x.prototype.disconnect=function(){if(this._trace("Client.disconnect"),this._reconnecting&&(this._reconnectTimeout.cancel(),this._reconnectTimeout=null,this._reconnecting=!1),!this.socket)throw new Error(w(_.INVALID_STATE,["not connecting or connected"]));var e=new A(g);this._notify_msg_sent[e]=b(this._disconnected,this),this._schedule_message(e)},x.prototype.getTraceLog=function(){if(null!==this._traceBuffer){for(var e in this._trace("Client.getTraceLog",new Date),this._trace("Client.getTraceLog in flight messages",this._sentMessages.length),this._sentMessages)this._trace("_sentMessages ",e,this._sentMessages[e]);for(var e in this._receivedMessages)this._trace("_receivedMessages ",e,this._receivedMessages[e]);return this._traceBuffer}},x.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,"@VERSION@-@BUILDLEVEL@")},x.prototype.stopTrace=function(){delete this._traceBuffer},x.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this._wsuri=e,this.connected=!1,this.connectOptions.mqttVersion<4?this.socket=new WebSocket(e,["mqttv3.1"]):this.socket=new WebSocket(e,["mqtt"]),this.socket.binaryType="arraybuffer",this.socket.onopen=b(this._on_socket_open,this),this.socket.onmessage=b(this._on_socket_message,this),this.socket.onerror=b(this._on_socket_error,this),this.socket.onclose=b(this._on_socket_close,this),this.sendPinger=new P(this,this.connectOptions.keepAliveInterval),this.receivePinger=new P(this,this.connectOptions.keepAliveInterval),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this._connectTimeout=new k(this,this.connectOptions.timeout,this._disconnected,[_.CONNECT_TIMEOUT.code,w(_.CONNECT_TIMEOUT)])},x.prototype._schedule_message=function(e){this._msg_queue.unshift(e),this.connected&&this._process_queue()},x.prototype.store=function(e,t){var r={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case i:t.pubRecReceived&&(r.pubRecReceived=!0),r.payloadMessage={};for(var o="",s=t.payloadMessage.payloadBytes,a=0;a<s.length;a++)s[a]<=15?o=o+"0"+s[a].toString(16):o+=s[a].toString(16);r.payloadMessage.payloadHex=o,r.payloadMessage.qos=t.payloadMessage.qos,r.payloadMessage.destinationName=t.payloadMessage.destinationName,t.payloadMessage.duplicate&&(r.payloadMessage.duplicate=!0),t.payloadMessage.retained&&(r.payloadMessage.retained=!0),0===e.indexOf("Sent:")&&(void 0===t.sequence&&(t.sequence=++this._sequence),r.sequence=t.sequence);break;default:throw Error(w(_.INVALID_STORED_DATA,[e+this._localKey+t.messageIdentifier,r]))}n.setItem(e+this._localKey+t.messageIdentifier,JSON.stringify(r))},x.prototype.restore=function(e){var t=n.getItem(e),r=JSON.parse(t),o=new A(r.type,r);switch(r.type){case i:for(var s=r.payloadMessage.payloadHex,a=new ArrayBuffer(s.length/2),c=new Uint8Array(a),u=0;s.length>=2;){var h=parseInt(s.substring(0,2),16);s=s.substring(2,s.length),c[u++]=h}var f=new U(c);f.qos=r.payloadMessage.qos,f.destinationName=r.payloadMessage.destinationName,r.payloadMessage.duplicate&&(f.duplicate=!0),r.payloadMessage.retained&&(f.retained=!0),o.payloadMessage=f;break;default:throw Error(w(_.INVALID_STORED_DATA,[e,t]))}0===e.indexOf("Sent:"+this._localKey)?(o.payloadMessage.duplicate=!0,this._sentMessages[o.messageIdentifier]=o):0===e.indexOf("Received:"+this._localKey)&&(this._receivedMessages[o.messageIdentifier]=o)},x.prototype._process_queue=function(){for(var e=null;e=this._msg_queue.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},x.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===i&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},x.prototype._on_socket_open=function(){var e=new A(r,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},x.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),n=0;n<t.length;n+=1)this._handleMessage(t[n])},x.prototype._deframeMessages=function(e){var t=new Uint8Array(e),n=[];if(this.receiveBuffer){var r=new Uint8Array(this.receiveBuffer.length+t.length);r.set(this.receiveBuffer),r.set(t,this.receiveBuffer.length),t=r,delete this.receiveBuffer}try{for(var o=0;o<t.length;){var i=O(t,o),s=i[0];if(o=i[1],null===s)break;n.push(s)}o<t.length&&(this.receiveBuffer=t.subarray(o))}catch(e){var a="undefined"==e.hasOwnProperty("stack")?e.stack.toString():"No Error Stack Available";return void this._disconnected(_.INTERNAL_ERROR.code,w(_.INTERNAL_ERROR,[e.message,a]))}return n},x.prototype._handleMessage=function(e){this._trace("Client._handleMessage",e);try{switch(e.type){case o:if(this._connectTimeout.cancel(),this._reconnectTimeout&&this._reconnectTimeout.cancel(),this.connectOptions.cleanSession){for(var t in this._sentMessages){var r=this._sentMessages[t];n.removeItem("Sent:"+this._localKey+r.messageIdentifier)}for(var t in this._sentMessages={},this._receivedMessages){var h=this._receivedMessages[t];n.removeItem("Received:"+this._localKey+h.messageIdentifier)}this._receivedMessages={}}if(0!==e.returnCode){this._disconnected(_.CONNACK_RETURNCODE.code,w(_.CONNACK_RETURNCODE,[e.returnCode,m[e.returnCode]]));break}this.connected=!0,this.connectOptions.uris&&(this.hostIndex=this.connectOptions.uris.length);var l=[];for(var d in this._sentMessages)this._sentMessages.hasOwnProperty(d)&&l.push(this._sentMessages[d]);if(this._buffered_msg_queue.length>0)for(var v=null;v=this._buffered_msg_queue.pop();)l.push(v),this.onMessageDelivered&&(this._notify_msg_sent[v]=this.onMessageDelivered(v.payloadMessage));l=l.sort((function(e,t){return e.sequence-t.sequence}));for(var b=0,E=l.length;b<E;b++)if((r=l[b]).type==i&&r.pubRecReceived){var S=new A(c,{messageIdentifier:r.messageIdentifier});this._schedule_message(S)}else this._schedule_message(r);this.connectOptions.onSuccess&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext});var O=!1;this._reconnecting&&(O=!0,this._reconnectInterval=1,this._reconnecting=!1),this._connected(O,this._wsuri),this._process_queue();break;case i:this._receivePublish(e);break;case s:(r=this._sentMessages[e.messageIdentifier])&&(delete this._sentMessages[e.messageIdentifier],n.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(r.payloadMessage));break;case a:(r=this._sentMessages[e.messageIdentifier])&&(r.pubRecReceived=!0,S=new A(c,{messageIdentifier:e.messageIdentifier}),this.store("Sent:",r),this._schedule_message(S));break;case c:h=this._receivedMessages[e.messageIdentifier],n.removeItem("Received:"+this._localKey+e.messageIdentifier),h&&(this._receiveMessage(h),delete this._receivedMessages[e.messageIdentifier]);var T=new A(u,{messageIdentifier:e.messageIdentifier});this._schedule_message(T);break;case u:r=this._sentMessages[e.messageIdentifier],delete this._sentMessages[e.messageIdentifier],n.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(r.payloadMessage);break;case f:(r=this._sentMessages[e.messageIdentifier])&&(r.timeOut&&r.timeOut.cancel(),128===e.returnCode[0]?r.onFailure&&r.onFailure(e.returnCode):r.onSuccess&&r.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case p:(r=this._sentMessages[e.messageIdentifier])&&(r.timeOut&&r.timeOut.cancel(),r.callback&&r.callback(),delete this._sentMessages[e.messageIdentifier]);break;case y:this.sendPinger.reset();break;case g:this._disconnected(_.INVALID_MQTT_MESSAGE_TYPE.code,w(_.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(_.INVALID_MQTT_MESSAGE_TYPE.code,w(_.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(e){var I="undefined"==e.hasOwnProperty("stack")?e.stack.toString():"No Error Stack Available";return void this._disconnected(_.INTERNAL_ERROR.code,w(_.INTERNAL_ERROR,[e.message,I]))}},x.prototype._on_socket_error=function(e){this._reconnecting||this._disconnected(_.SOCKET_ERROR.code,w(_.SOCKET_ERROR,[e.data]))},x.prototype._on_socket_close=function(){this._reconnecting||this._disconnected(_.SOCKET_CLOSE.code,w(_.SOCKET_CLOSE))},x.prototype._socket_send=function(e){if(1==e.type){var t=this._traceMask(e,"password");this._trace("Client._socket_send",t)}else this._trace("Client._socket_send",e);this.socket.send(e.encode()),this.sendPinger.reset()},x.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new A(s,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var n=new A(a,{messageIdentifier:e.messageIdentifier});this._schedule_message(n);break;default:throw Error("Invaild qos="+e.payloadMessage.qos)}},x.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},x.prototype._connected=function(e,t){this.onConnected&&this.onConnected(e,t)},x.prototype._reconnect=function(){this._trace("Client._reconnect"),this.connected||(this._reconnecting=!0,this.sendPinger.cancel(),this.receivePinger.cancel(),this._reconnectInterval<128&&(this._reconnectInterval=2*this._reconnectInterval),this.connectOptions.uris?(this.hostIndex=0,this._doConnect(this.connectOptions.uris[0])):this._doConnect(this.uri))},x.prototype._disconnected=function(e,t){if(this._trace("Client._disconnected",e,t),void 0!==e&&this._reconnecting)this._reconnectTimeout=new k(this,this._reconnectInterval,this._reconnect);else if(this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this._msg_queue=[],this._buffered_msg_queue=[],this._notify_msg_sent={},this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,1===this.socket.readyState&&this.socket.close(),delete this.socket),this.connectOptions.uris&&this.hostIndex<this.connectOptions.uris.length-1)this.hostIndex++,this._doConnect(this.connectOptions.uris[this.hostIndex]);else if(void 0===e&&(e=_.OK.code,t=w(_.OK)),this.connected){if(this.connected=!1,this.onConnectionLost&&this.onConnectionLost({errorCode:e,errorMessage:t,reconnect:this.connectOptions.reconnect,uri:this._wsuri}),e!==_.OK.code&&this.connectOptions.reconnect)return this._reconnectInterval=1,void this._reconnect()}else 4===this.connectOptions.mqttVersion&&!1===this.connectOptions.mqttVersionExplicit?(this._trace("Failed to connect V4, dropping back to V3"),this.connectOptions.mqttVersion=3,this.connectOptions.uris?(this.hostIndex=0,this._doConnect(this.connectOptions.uris[0])):this._doConnect(this.uri)):this.connectOptions.onFailure&&this.connectOptions.onFailure({invocationContext:this.connectOptions.invocationContext,errorCode:e,errorMessage:t})},x.prototype._trace=function(){if(this.traceFunction){var e=Array.prototype.slice.call(arguments);for(var t in e)void 0!==e[t]&&e.splice(t,1,JSON.stringify(e[t]));var n=e.join("");this.traceFunction({severity:"Debug",message:n})}if(null!==this._traceBuffer){t=0;for(var r=arguments.length;t<r;t++)this._traceBuffer.length==this._MAX_TRACE_ENTRIES&&this._traceBuffer.shift(),0===t||void 0===arguments[t]?this._traceBuffer.push(arguments[t]):this._traceBuffer.push(" "+JSON.stringify(arguments[t]))}},x.prototype._traceMask=function(e,t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=r==t?"******":e[r]);return n};var U=function(e){var t,n;if(!("string"==typeof e||e instanceof ArrayBuffer||ArrayBuffer.isView(e)&&!(e instanceof DataView)))throw w(_.INVALID_ARGUMENT,[e,"newPayload"]);t=e;var r=0,o=!1,i=!1;Object.defineProperties(this,{payloadString:{enumerable:!0,get:function(){return"string"==typeof t?t:M(t,0,t.length)}},payloadBytes:{enumerable:!0,get:function(){if("string"==typeof t){var e=new ArrayBuffer(C(t)),n=new Uint8Array(e);return N(t,n,0),n}return t}},destinationName:{enumerable:!0,get:function(){return n},set:function(e){if("string"!=typeof e)throw new Error(w(_.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e}},qos:{enumerable:!0,get:function(){return r},set:function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);r=e}},retained:{enumerable:!0,get:function(){return o},set:function(e){if("boolean"!=typeof e)throw new Error(w(_.INVALID_ARGUMENT,[e,"newRetained"]));o=e}},topic:{enumerable:!0,get:function(){return n},set:function(e){n=e}},duplicate:{enumerable:!0,get:function(){return i},set:function(e){i=e}}})};return{Client:function(e,t,n,r){var o;if("string"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"host"]));if(2==arguments.length){r=t;var i=(o=e).match(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/);if(!i)throw new Error(w(_.INVALID_ARGUMENT,[e,"host"]));e=i[4]||i[2],t=parseInt(i[7]),n=i[8]}else{if(3==arguments.length&&(r=n,n="/mqtt"),"number"!=typeof t||t<0)throw new Error(w(_.INVALID_TYPE,[typeof t,"port"]));if("string"!=typeof n)throw new Error(w(_.INVALID_TYPE,[typeof n,"path"]));var s=-1!==e.indexOf(":")&&"["!==e.slice(0,1)&&"]"!==e.slice(-1);o="ws://"+(s?"["+e+"]":e)+":"+t+n}for(var a=0,c=0;c<r.length;c++){var u=r.charCodeAt(c);55296<=u&&u<=56319&&c++,a++}if("string"!=typeof r||a>65535)throw new Error(w(_.INVALID_ARGUMENT,[r,"clientId"]));var h=new x(o,e,t,n,r);Object.defineProperties(this,{host:{get:function(){return e},set:function(){throw new Error(w(_.UNSUPPORTED_OPERATION))}},port:{get:function(){return t},set:function(){throw new Error(w(_.UNSUPPORTED_OPERATION))}},path:{get:function(){return n},set:function(){throw new Error(w(_.UNSUPPORTED_OPERATION))}},uri:{get:function(){return o},set:function(){throw new Error(w(_.UNSUPPORTED_OPERATION))}},clientId:{get:function(){return h.clientId},set:function(){throw new Error(w(_.UNSUPPORTED_OPERATION))}},onConnected:{get:function(){return h.onConnected},set:function(e){if("function"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"onConnected"]));h.onConnected=e}},disconnectedPublishing:{get:function(){return h.disconnectedPublishing},set:function(e){h.disconnectedPublishing=e}},disconnectedBufferSize:{get:function(){return h.disconnectedBufferSize},set:function(e){h.disconnectedBufferSize=e}},onConnectionLost:{get:function(){return h.onConnectionLost},set:function(e){if("function"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"onConnectionLost"]));h.onConnectionLost=e}},onMessageDelivered:{get:function(){return h.onMessageDelivered},set:function(e){if("function"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"onMessageDelivered"]));h.onMessageDelivered=e}},onMessageArrived:{get:function(){return h.onMessageArrived},set:function(e){if("function"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"onMessageArrived"]));h.onMessageArrived=e}},trace:{get:function(){return h.traceFunction},set:function(e){if("function"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"onTrace"]));h.traceFunction=e}}}),this.connect=function(e){if(v(e=e||{},{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",reconnect:"boolean",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),void 0===e.keepAliveInterval&&(e.keepAliveInterval=60),e.mqttVersion>4||e.mqttVersion<3)throw new Error(w(_.INVALID_ARGUMENT,[e.mqttVersion,"connectOptions.mqttVersion"]));if(void 0===e.mqttVersion?(e.mqttVersionExplicit=!1,e.mqttVersion=4):e.mqttVersionExplicit=!0,void 0!==e.password&&void 0===e.userName)throw new Error(w(_.INVALID_ARGUMENT,[e.password,"connectOptions.password"]));if(e.willMessage){if(!(e.willMessage instanceof U))throw new Error(w(_.INVALID_TYPE,[e.willMessage,"connectOptions.willMessage"]));if(e.willMessage.stringPayload=null,void 0===e.willMessage.destinationName)throw new Error(w(_.INVALID_TYPE,[typeof e.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if(void 0===e.cleanSession&&(e.cleanSession=!0),e.hosts){if(!(e.hosts instanceof Array))throw new Error(w(_.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));if(e.hosts.length<1)throw new Error(w(_.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));for(var t=!1,r=0;r<e.hosts.length;r++){if("string"!=typeof e.hosts[r])throw new Error(w(_.INVALID_TYPE,[typeof e.hosts[r],"connectOptions.hosts["+r+"]"]));if(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/.test(e.hosts[r])){if(0===r)t=!0;else if(!t)throw new Error(w(_.INVALID_ARGUMENT,[e.hosts[r],"connectOptions.hosts["+r+"]"]))}else if(t)throw new Error(w(_.INVALID_ARGUMENT,[e.hosts[r],"connectOptions.hosts["+r+"]"]))}if(t)e.uris=e.hosts;else{if(!e.ports)throw new Error(w(_.INVALID_ARGUMENT,[e.ports,"connectOptions.ports"]));if(!(e.ports instanceof Array))throw new Error(w(_.INVALID_ARGUMENT,[e.ports,"connectOptions.ports"]));if(e.hosts.length!==e.ports.length)throw new Error(w(_.INVALID_ARGUMENT,[e.ports,"connectOptions.ports"]));for(e.uris=[],r=0;r<e.hosts.length;r++){if("number"!=typeof e.ports[r]||e.ports[r]<0)throw new Error(w(_.INVALID_TYPE,[typeof e.ports[r],"connectOptions.ports["+r+"]"]));var i=e.hosts[r],s=e.ports[r],a=-1!==i.indexOf(":");o="ws://"+(a?"["+i+"]":i)+":"+s+n,e.uris.push(o)}}}h.connect(e)},this.subscribe=function(e,t){if("string"!=typeof e&&e.constructor!==Array)throw new Error("Invalid argument:"+e);if(v(t=t||{},{qos:"number",invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"}),t.timeout&&!t.onFailure)throw new Error("subscribeOptions.timeout specified with no onFailure callback.");if(void 0!==t.qos&&0!==t.qos&&1!==t.qos&&2!==t.qos)throw new Error(w(_.INVALID_ARGUMENT,[t.qos,"subscribeOptions.qos"]));h.subscribe(e,t)},this.unsubscribe=function(e,t){if("string"!=typeof e&&e.constructor!==Array)throw new Error("Invalid argument:"+e);if(v(t=t||{},{invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"}),t.timeout&&!t.onFailure)throw new Error("unsubscribeOptions.timeout specified with no onFailure callback.");h.unsubscribe(e,t)},this.send=function(e,t,n,r){var o;if(0===arguments.length)throw new Error("Invalid argument.length");if(1==arguments.length){if(!(e instanceof U)&&"string"!=typeof e)throw new Error("Invalid argument:"+typeof e);if(void 0===(o=e).destinationName)throw new Error(w(_.INVALID_ARGUMENT,[o.destinationName,"Message.destinationName"]));h.send(o)}else(o=new U(t)).destinationName=e,arguments.length>=3&&(o.qos=n),arguments.length>=4&&(o.retained=r),h.send(o)},this.publish=function(e,t,n,r){var o;if(0===arguments.length)throw new Error("Invalid argument.length");if(1==arguments.length){if(!(e instanceof U)&&"string"!=typeof e)throw new Error("Invalid argument:"+typeof e);if(void 0===(o=e).destinationName)throw new Error(w(_.INVALID_ARGUMENT,[o.destinationName,"Message.destinationName"]));h.send(o)}else(o=new U(t)).destinationName=e,arguments.length>=3&&(o.qos=n),arguments.length>=4&&(o.retained=r),h.send(o)},this.disconnect=function(){h.disconnect()},this.getTraceLog=function(){return h.getTraceLog()},this.startTrace=function(){h.startTrace()},this.stopTrace=function(){h.stopTrace()},this.isConnected=function(){return h.connected}},Message:U}}(void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},e.exports=n()}).call(this,n(3))},function(e,t,n){"use strict";var r=n(15),o=n(17);function i(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}t.parse=_,t.resolve=function(e,t){return _(e,!1,!0).resolve(t)},t.resolveObject=function(e,t){return e?_(e,!1,!0).resolveObject(t):t},t.format=function(e){o.isString(e)&&(e=_(e));return e instanceof i?e.format():i.prototype.format.call(e)},t.Url=i;var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,u=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),h=["'"].concat(u),f=["%","/","?",";","#"].concat(h),l=["/","?","#"],p=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,y={javascript:!0,"javascript:":!0},g={javascript:!0,"javascript:":!0},v={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},b=n(18);function _(e,t,n){if(e&&o.isObject(e)&&e instanceof i)return e;var r=new i;return r.parse(e,t,n),r}i.prototype.parse=function(e,t,n){if(!o.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var i=e.indexOf("?"),a=-1!==i&&i<e.indexOf("#")?"?":"#",u=e.split(a);u[0]=u[0].replace(/\\/g,"/");var _=e=u.join(a);if(_=_.trim(),!n&&1===e.split("#").length){var m=c.exec(_);if(m)return this.path=_,this.href=_,this.pathname=m[1],m[2]?(this.search=m[2],this.query=t?b.parse(this.search.substr(1)):this.search.substr(1)):t&&(this.search="",this.query={}),this}var w=s.exec(_);if(w){var E=(w=w[0]).toLowerCase();this.protocol=E,_=_.substr(w.length)}if(n||w||_.match(/^\/\/[^@\/]+@[^@\/]+/)){var S="//"===_.substr(0,2);!S||w&&g[w]||(_=_.substr(2),this.slashes=!0)}if(!g[w]&&(S||w&&!v[w])){for(var A,O,T=-1,I=0;I<l.length;I++){-1!==(R=_.indexOf(l[I]))&&(-1===T||R<T)&&(T=R)}-1!==(O=-1===T?_.lastIndexOf("@"):_.lastIndexOf("@",T))&&(A=_.slice(0,O),_=_.slice(O+1),this.auth=decodeURIComponent(A)),T=-1;for(I=0;I<f.length;I++){var R;-1!==(R=_.indexOf(f[I]))&&(-1===T||R<T)&&(T=R)}-1===T&&(T=_.length),this.host=_.slice(0,T),_=_.slice(T),this.parseHost(),this.hostname=this.hostname||"";var C="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!C)for(var N=this.hostname.split(/\./),M=(I=0,N.length);I<M;I++){var P=N[I];if(P&&!P.match(p)){for(var k="",x=0,U=P.length;x<U;x++)P.charCodeAt(x)>127?k+="x":k+=P[x];if(!k.match(p)){var L=N.slice(0,I),D=N.slice(I+1),q=P.match(d);q&&(L.push(q[1]),D.unshift(q[2])),D.length&&(_="/"+D.join(".")+_),this.hostname=L.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),C||(this.hostname=r.toASCII(this.hostname));var B=this.port?":"+this.port:"",j=this.hostname||"";this.host=j+B,this.href+=this.host,C&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==_[0]&&(_="/"+_))}if(!y[E])for(I=0,M=h.length;I<M;I++){var V=h[I];if(-1!==_.indexOf(V)){var F=encodeURIComponent(V);F===V&&(F=escape(V)),_=_.split(V).join(F)}}var G=_.indexOf("#");-1!==G&&(this.hash=_.substr(G),_=_.slice(0,G));var Y=_.indexOf("?");if(-1!==Y?(this.search=_.substr(Y),this.query=_.substr(Y+1),t&&(this.query=b.parse(this.query)),_=_.slice(0,Y)):t&&(this.search="",this.query={}),_&&(this.pathname=_),v[E]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){B=this.pathname||"";var Q=this.search||"";this.path=B+Q}return this.href=this.format(),this},i.prototype.format=function(){var e=this.auth||"";e&&(e=(e=encodeURIComponent(e)).replace(/%3A/i,":"),e+="@");var t=this.protocol||"",n=this.pathname||"",r=this.hash||"",i=!1,s="";this.host?i=e+this.host:this.hostname&&(i=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&o.isObject(this.query)&&Object.keys(this.query).length&&(s=b.stringify(this.query));var a=this.search||s&&"?"+s||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||v[t])&&!1!==i?(i="//"+(i||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):i||(i=""),r&&"#"!==r.charAt(0)&&(r="#"+r),a&&"?"!==a.charAt(0)&&(a="?"+a),t+i+(n=n.replace(/[?#]/g,(function(e){return encodeURIComponent(e)})))+(a=a.replace("#","%23"))+r},i.prototype.resolve=function(e){return this.resolveObject(_(e,!1,!0)).format()},i.prototype.resolveObject=function(e){if(o.isString(e)){var t=new i;t.parse(e,!1,!0),e=t}for(var n=new i,r=Object.keys(this),s=0;s<r.length;s++){var a=r[s];n[a]=this[a]}if(n.hash=e.hash,""===e.href)return n.href=n.format(),n;if(e.slashes&&!e.protocol){for(var c=Object.keys(e),u=0;u<c.length;u++){var h=c[u];"protocol"!==h&&(n[h]=e[h])}return v[n.protocol]&&n.hostname&&!n.pathname&&(n.path=n.pathname="/"),n.href=n.format(),n}if(e.protocol&&e.protocol!==n.protocol){if(!v[e.protocol]){for(var f=Object.keys(e),l=0;l<f.length;l++){var p=f[l];n[p]=e[p]}return n.href=n.format(),n}if(n.protocol=e.protocol,e.host||g[e.protocol])n.pathname=e.pathname;else{for(var d=(e.pathname||"").split("/");d.length&&!(e.host=d.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==d[0]&&d.unshift(""),d.length<2&&d.unshift(""),n.pathname=d.join("/")}if(n.search=e.search,n.query=e.query,n.host=e.host||"",n.auth=e.auth,n.hostname=e.hostname||e.host,n.port=e.port,n.pathname||n.search){var y=n.pathname||"",b=n.search||"";n.path=y+b}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var _=n.pathname&&"/"===n.pathname.charAt(0),m=e.host||e.pathname&&"/"===e.pathname.charAt(0),w=m||_||n.host&&e.pathname,E=w,S=n.pathname&&n.pathname.split("/")||[],A=(d=e.pathname&&e.pathname.split("/")||[],n.protocol&&!v[n.protocol]);if(A&&(n.hostname="",n.port=null,n.host&&(""===S[0]?S[0]=n.host:S.unshift(n.host)),n.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===d[0]?d[0]=e.host:d.unshift(e.host)),e.host=null),w=w&&(""===d[0]||""===S[0])),m)n.host=e.host||""===e.host?e.host:n.host,n.hostname=e.hostname||""===e.hostname?e.hostname:n.hostname,n.search=e.search,n.query=e.query,S=d;else if(d.length)S||(S=[]),S.pop(),S=S.concat(d),n.search=e.search,n.query=e.query;else if(!o.isNullOrUndefined(e.search)){if(A)n.hostname=n.host=S.shift(),(C=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=C.shift(),n.host=n.hostname=C.shift());return n.search=e.search,n.query=e.query,o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n}if(!S.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var O=S.slice(-1)[0],T=(n.host||e.host||S.length>1)&&("."===O||".."===O)||""===O,I=0,R=S.length;R>=0;R--)"."===(O=S[R])?S.splice(R,1):".."===O?(S.splice(R,1),I++):I&&(S.splice(R,1),I--);if(!w&&!E)for(;I--;I)S.unshift("..");!w||""===S[0]||S[0]&&"/"===S[0].charAt(0)||S.unshift(""),T&&"/"!==S.join("/").substr(-1)&&S.push("");var C,N=""===S[0]||S[0]&&"/"===S[0].charAt(0);A&&(n.hostname=n.host=N?"":S.length?S.shift():"",(C=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=C.shift(),n.host=n.hostname=C.shift()));return(w=w||n.host&&S.length)&&!N&&S.unshift(""),S.length?n.pathname=S.join("/"):(n.pathname=null,n.path=null),o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},i.prototype.parseHost=function(){var e=this.host,t=a.exec(e);t&&(":"!==(t=t[0])&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},function(e,t){e.exports=r},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}Object.defineProperty(t,"__esModule",{value:!0}),t.Observable=void 0;var s=function(){return"function"==typeof Symbol},a=function(e){return s()&&Boolean(Symbol[e])},c=function(e){return a(e)?Symbol[e]:"@@"+e};s()&&!a("observable")&&(Symbol.observable=Symbol("observable"));var u=c("iterator"),h=c("observable"),f=c("species");function l(e,t){var n=e[t];if(null!=n){if("function"!=typeof n)throw new TypeError(n+" is not a function");return n}}function p(e){var t=e.constructor;return void 0!==t&&null===(t=t[f])&&(t=void 0),void 0!==t?t:S}function d(e){return e instanceof S}function y(e){y.log?y.log(e):setTimeout((function(){throw e}))}function g(e){Promise.resolve().then((function(){try{e()}catch(e){y(e)}}))}function v(e){var t=e._cleanup;if(void 0!==t&&(e._cleanup=void 0,t))try{if("function"==typeof t)t();else{var n=l(t,"unsubscribe");n&&n.call(t)}}catch(e){y(e)}}function b(e){e._observer=void 0,e._queue=void 0,e._state="closed"}function _(e,t,n){e._state="running";var r=e._observer;try{var o=l(r,t);switch(t){case"next":o&&o.call(r,n);break;case"error":if(b(e),!o)throw n;o.call(r,n);break;case"complete":b(e),o&&o.call(r)}}catch(e){y(e)}"closed"===e._state?v(e):"running"===e._state&&(e._state="ready")}function m(e,t,n){if("closed"!==e._state){if("buffering"!==e._state)return"ready"!==e._state?(e._state="buffering",e._queue=[{type:t,value:n}],void g((function(){return function(e){var t=e._queue;if(t){e._queue=void 0,e._state="ready";for(var n=0;n<t.length&&(_(e,t[n].type,t[n].value),"closed"!==e._state);++n);}}(e)}))):void _(e,t,n);e._queue.push({type:t,value:n})}}var w=function(){function e(t,n){r(this,e),this._cleanup=void 0,this._observer=t,this._queue=void 0,this._state="initializing";var o=new E(this);try{this._cleanup=n.call(void 0,o)}catch(e){o.error(e)}"initializing"===this._state&&(this._state="ready")}return i(e,[{key:"unsubscribe",value:function(){"closed"!==this._state&&(b(this),v(this))}},{key:"closed",get:function(){return"closed"===this._state}}]),e}(),E=function(){function e(t){r(this,e),this._subscription=t}return i(e,[{key:"next",value:function(e){m(this._subscription,"next",e)}},{key:"error",value:function(e){m(this._subscription,"error",e)}},{key:"complete",value:function(){m(this._subscription,"complete")}},{key:"closed",get:function(){return"closed"===this._subscription._state}}]),e}(),S=function(){function e(t){if(r(this,e),!(this instanceof e))throw new TypeError("Observable cannot be called as a function");if("function"!=typeof t)throw new TypeError("Observable initializer must be a function");this._subscriber=t}return i(e,[{key:"subscribe",value:function(e){return"object"==typeof e&&null!==e||(e={next:e,error:arguments[1],complete:arguments[2]}),new w(e,this._subscriber)}},{key:"forEach",value:function(e){var t=this;return new Promise((function(n,r){if("function"==typeof e)var o=t.subscribe({next:function(t){try{e(t,i)}catch(e){r(e),o.unsubscribe()}},error:r,complete:n});else r(new TypeError(e+" is not a function"));function i(){o.unsubscribe(),n()}}))}},{key:"map",value:function(e){var t=this;if("function"!=typeof e)throw new TypeError(e+" is not a function");return new(p(this))((function(n){return t.subscribe({next:function(t){try{t=e(t)}catch(e){return n.error(e)}n.next(t)},error:function(e){n.error(e)},complete:function(){n.complete()}})}))}},{key:"filter",value:function(e){var t=this;if("function"!=typeof e)throw new TypeError(e+" is not a function");return new(p(this))((function(n){return t.subscribe({next:function(t){try{if(!e(t))return}catch(e){return n.error(e)}n.next(t)},error:function(e){n.error(e)},complete:function(){n.complete()}})}))}},{key:"reduce",value:function(e){var t=this;if("function"!=typeof e)throw new TypeError(e+" is not a function");var n=p(this),r=arguments.length>1,o=!1,i=arguments[1],s=i;return new n((function(n){return t.subscribe({next:function(t){var i=!o;if(o=!0,!i||r)try{s=e(s,t)}catch(e){return n.error(e)}else s=t},error:function(e){n.error(e)},complete:function(){if(!o&&!r)return n.error(new TypeError("Cannot reduce an empty sequence"));n.next(s),n.complete()}})}))}},{key:"concat",value:function(){for(var e=this,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var o=p(this);return new o((function(t){var r,i=0;return function e(s){r=s.subscribe({next:function(e){t.next(e)},error:function(e){t.error(e)},complete:function(){i===n.length?(r=void 0,t.complete()):e(o.from(n[i++]))}})}(e),function(){r&&(r.unsubscribe(),r=void 0)}}))}},{key:"flatMap",value:function(e){var t=this;if("function"!=typeof e)throw new TypeError(e+" is not a function");var n=p(this);return new n((function(r){var o=[],i=t.subscribe({next:function(t){if(e)try{t=e(t)}catch(e){return r.error(e)}var i=n.from(t).subscribe({next:function(e){r.next(e)},error:function(e){r.error(e)},complete:function(){var e=o.indexOf(i);e>=0&&o.splice(e,1),s()}});o.push(i)},error:function(e){r.error(e)},complete:function(){s()}});function s(){i.closed&&0===o.length&&r.complete()}return function(){o.forEach((function(e){return e.unsubscribe()})),i.unsubscribe()}}))}},{key:h,value:function(){return this}}],[{key:"from",value:function(t){var n="function"==typeof this?this:e;if(null==t)throw new TypeError(t+" is not an object");var r=l(t,h);if(r){var o=r.call(t);if(Object(o)!==o)throw new TypeError(o+" is not an object");return d(o)&&o.constructor===n?o:new n((function(e){return o.subscribe(e)}))}if(a("iterator")&&(r=l(t,u)))return new n((function(e){g((function(){if(!e.closed){var n=!0,o=!1,i=void 0;try{for(var s,a=r.call(t)[Symbol.iterator]();!(n=(s=a.next()).done);n=!0){var c=s.value;if(e.next(c),e.closed)return}}catch(e){o=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}e.complete()}}))}));if(Array.isArray(t))return new n((function(e){g((function(){if(!e.closed){for(var n=0;n<t.length;++n)if(e.next(t[n]),e.closed)return;e.complete()}}))}));throw new TypeError(t+" is not observable")}},{key:"of",value:function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var o="function"==typeof this?this:e;return new o((function(e){g((function(){if(!e.closed){for(var t=0;t<n.length;++t)if(e.next(n[t]),e.closed)return;e.complete()}}))}))}},{key:f,get:function(){return this}}]),e}();t.Observable=S,s()&&Object.defineProperty(S,Symbol("extensions"),{value:{symbol:h,hostReportError:y},configurable:!0})},function(e,t,n){var r,o,i=n(6),s=n(7),a=0,c=0;e.exports=function(e,t,n){var u=t&&n||0,h=t||[],f=(e=e||{}).node||r,l=void 0!==e.clockseq?e.clockseq:o;if(null==f||null==l){var p=i();null==f&&(f=r=[1|p[0],p[1],p[2],p[3],p[4],p[5]]),null==l&&(l=o=16383&(p[6]<<8|p[7]))}var d=void 0!==e.msecs?e.msecs:(new Date).getTime(),y=void 0!==e.nsecs?e.nsecs:c+1,g=d-a+(y-c)/1e4;if(g<0&&void 0===e.clockseq&&(l=l+1&16383),(g<0||d>a)&&void 0===e.nsecs&&(y=0),y>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");a=d,c=y,o=l;var v=(1e4*(268435455&(d+=122192928e5))+y)%4294967296;h[u++]=v>>>24&255,h[u++]=v>>>16&255,h[u++]=v>>>8&255,h[u++]=255&v;var b=d/4294967296*1e4&268435455;h[u++]=b>>>8&255,h[u++]=255&b,h[u++]=b>>>24&15|16,h[u++]=b>>>16&255,h[u++]=l>>>8|128,h[u++]=255&l;for(var _=0;_<6;++_)h[u+_]=f[_];return t||s(h)}},function(e,t,n){var r=n(6),o=n(7);e.exports=function(e,t,n){var i=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var s=(e=e||{}).random||(e.rng||r)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t)for(var a=0;a<16;++a)t[i+a]=s[a];return t||o(s)}},function(e,t,n){(function(e,r){var o;/*! https://mths.be/punycode v1.4.1 by @mathias */!function(i){t&&t.nodeType,e&&e.nodeType;var s="object"==typeof r&&r;s.global!==s&&s.window!==s&&s.self;var a,c=2147483647,u=/^xn--/,h=/[^\x20-\x7E]/,f=/[\x2E\u3002\uFF0E\uFF61]/g,l={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},p=Math.floor,d=String.fromCharCode;function y(e){throw new RangeError(l[e])}function g(e,t){for(var n=e.length,r=[];n--;)r[n]=t(e[n]);return r}function v(e,t){var n=e.split("@"),r="";return n.length>1&&(r=n[0]+"@",e=n[1]),r+g((e=e.replace(f,".")).split("."),t).join(".")}function b(e){for(var t,n,r=[],o=0,i=e.length;o<i;)(t=e.charCodeAt(o++))>=55296&&t<=56319&&o<i?56320==(64512&(n=e.charCodeAt(o++)))?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),o--):r.push(t);return r}function _(e){return g(e,(function(e){var t="";return e>65535&&(t+=d((e-=65536)>>>10&1023|55296),e=56320|1023&e),t+=d(e)})).join("")}function m(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function w(e,t,n){var r=0;for(e=n?p(e/700):e>>1,e+=p(e/t);e>455;r+=36)e=p(e/35);return p(r+36*e/(e+38))}function E(e){var t,n,r,o,i,s,a,u,h,f,l,d=[],g=e.length,v=0,b=128,m=72;for((n=e.lastIndexOf("-"))<0&&(n=0),r=0;r<n;++r)e.charCodeAt(r)>=128&&y("not-basic"),d.push(e.charCodeAt(r));for(o=n>0?n+1:0;o<g;){for(i=v,s=1,a=36;o>=g&&y("invalid-input"),((u=(l=e.charCodeAt(o++))-48<10?l-22:l-65<26?l-65:l-97<26?l-97:36)>=36||u>p((c-v)/s))&&y("overflow"),v+=u*s,!(u<(h=a<=m?1:a>=m+26?26:a-m));a+=36)s>p(c/(f=36-h))&&y("overflow"),s*=f;m=w(v-i,t=d.length+1,0==i),p(v/t)>c-b&&y("overflow"),b+=p(v/t),v%=t,d.splice(v++,0,b)}return _(d)}function S(e){var t,n,r,o,i,s,a,u,h,f,l,g,v,_,E,S=[];for(g=(e=b(e)).length,t=128,n=0,i=72,s=0;s<g;++s)(l=e[s])<128&&S.push(d(l));for(r=o=S.length,o&&S.push("-");r<g;){for(a=c,s=0;s<g;++s)(l=e[s])>=t&&l<a&&(a=l);for(a-t>p((c-n)/(v=r+1))&&y("overflow"),n+=(a-t)*v,t=a,s=0;s<g;++s)if((l=e[s])<t&&++n>c&&y("overflow"),l==t){for(u=n,h=36;!(u<(f=h<=i?1:h>=i+26?26:h-i));h+=36)E=u-f,_=36-f,S.push(d(m(f+E%_,0))),u=p(E/_);S.push(d(m(u,0))),i=w(n,v,r==o),n=0,++r}++n,++t}return S.join("")}a={version:"1.4.1",ucs2:{decode:b,encode:_},decode:E,encode:S,toASCII:function(e){return v(e,(function(e){return h.test(e)?"xn--"+S(e):e}))},toUnicode:function(e){return v(e,(function(e){return u.test(e)?E(e.slice(4).toLowerCase()):e}))}},void 0===(o=function(){return a}.call(t,n,t,e))||(e.exports=o)}()}).call(this,n(16)(e),n(3))},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";e.exports={isString:function(e){return"string"==typeof e},isObject:function(e){return"object"==typeof e&&null!==e},isNull:function(e){return null===e},isNullOrUndefined:function(e){return null==e}}},function(e,t,n){"use strict";t.decode=t.parse=n(19),t.encode=t.stringify=n(20)},function(e,t,n){"use strict";function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,n,i){t=t||"&",n=n||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var c=1e3;i&&"number"==typeof i.maxKeys&&(c=i.maxKeys);var u=e.length;c>0&&u>c&&(u=c);for(var h=0;h<u;++h){var f,l,p,d,y=e[h].replace(a,"%20"),g=y.indexOf(n);g>=0?(f=y.substr(0,g),l=y.substr(g+1)):(f=y,l=""),p=decodeURIComponent(f),d=decodeURIComponent(l),r(s,p)?o(s[p])?s[p].push(d):s[p]=[s[p],d]:s[p]=d}return s};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,n){"use strict";var r=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};e.exports=function(e,t,n,a){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?i(s(e),(function(s){var a=encodeURIComponent(r(s))+n;return o(e[s])?i(e[s],(function(e){return a+encodeURIComponent(r(e))})).join(t):a+encodeURIComponent(r(e[s]))})).join(t):a?encodeURIComponent(r(a))+n+encodeURIComponent(r(e)):""};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function i(e,t){if(e.map)return e.map(t);for(var n=[],r=0;r<e.length;r++)n.push(t(e[r],r));return n}var s=Object.keys||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t}},function(e,t,n){"use strict";t.byteLength=function(e){var t=u(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,r=u(e),s=r[0],a=r[1],c=new i(function(e,t,n){return 3*(t+n)/4-n}(0,s,a)),h=0,f=a>0?s-4:s;for(n=0;n<f;n+=4)t=o[e.charCodeAt(n)]<<18|o[e.charCodeAt(n+1)]<<12|o[e.charCodeAt(n+2)]<<6|o[e.charCodeAt(n+3)],c[h++]=t>>16&255,c[h++]=t>>8&255,c[h++]=255&t;2===a&&(t=o[e.charCodeAt(n)]<<2|o[e.charCodeAt(n+1)]>>4,c[h++]=255&t);1===a&&(t=o[e.charCodeAt(n)]<<10|o[e.charCodeAt(n+1)]<<4|o[e.charCodeAt(n+2)]>>2,c[h++]=t>>8&255,c[h++]=255&t);return c},t.fromByteArray=function(e){for(var t,n=e.length,o=n%3,i=[],s=0,a=n-o;s<a;s+=16383)i.push(h(e,s,s+16383>a?a:s+16383));1===o?(t=e[n-1],i.push(r[t>>2]+r[t<<4&63]+"==")):2===o&&(t=(e[n-2]<<8)+e[n-1],i.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"="));return i.join("")};for(var r=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=s.length;a<c;++a)r[a]=s[a],o[s.charCodeAt(a)]=a;function u(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function h(e,t,n){for(var o,i,s=[],a=t;a<n;a+=3)o=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(r[(i=o)>>18&63]+r[i>>12&63]+r[i>>6&63]+r[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(e,t){
8
+ var r=n(21),o=n(22),i=n(23);function s(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(s()<t)throw new RangeError("Invalid typed array length");return c.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=c.prototype:(null===e&&(e=new c(t)),e.length=t),e}function c(e,t,n){if(!(c.TYPED_ARRAY_SUPPORT||this instanceof c))return new c(e,t,n);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return f(this,e)}return u(this,e,t,n)}function u(e,t,n,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,n,r){if(t.byteLength,n<0||t.byteLength<n)throw new RangeError("'offset' is out of bounds");if(t.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");t=void 0===n&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,n):new Uint8Array(t,n,r);c.TYPED_ARRAY_SUPPORT?(e=t).__proto__=c.prototype:e=l(e,t);return e}(e,t,n,r):"string"==typeof t?function(e,t,n){"string"==typeof n&&""!==n||(n="utf8");if(!c.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|d(t,n),o=(e=a(e,r)).write(t,n);o!==r&&(e=e.slice(0,o));return e}(e,t,n):function(e,t){if(c.isBuffer(t)){var n=0|p(t.length);return 0===(e=a(e,n)).length||t.copy(e,0,0,n),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(r=t.length)!=r?a(e,0):l(e,t);if("Buffer"===t.type&&i(t.data))return l(e,t.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function h(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function f(e,t){if(h(t),e=a(e,t<0?0:0|p(t)),!c.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)e[n]=0;return e}function l(e,t){var n=t.length<0?0:0|p(t.length);e=a(e,n);for(var r=0;r<n;r+=1)e[r]=255&t[r];return e}function p(e){if(e>=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|e}function d(e,t){if(c.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return j(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return V(e).length;default:if(r)return j(e).length;t=(""+t).toLowerCase(),r=!0}}function y(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return R(this,t,n);case"utf8":case"utf-8":return T(this,t,n);case"ascii":return I(this,t,n);case"latin1":case"binary":return C(this,t,n);case"base64":return O(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function g(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function v(e,t,n,r,o){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(o)return-1;n=e.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof t&&(t=c.from(t,r)),c.isBuffer(t))return 0===t.length?-1:b(e,t,n,r,o);if("number"==typeof t)return t&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):b(e,[t],n,r,o);throw new TypeError("val must be string, number or Buffer")}function b(e,t,n,r,o){var i,s=1,a=e.length,c=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;s=2,a/=2,c/=2,n/=2}function u(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(o){var h=-1;for(i=n;i<a;i++)if(u(e,i)===u(t,-1===h?0:i-h)){if(-1===h&&(h=i),i-h+1===c)return h*s}else-1!==h&&(i-=i-h),h=-1}else for(n+c>a&&(n=a-c),i=n;i>=0;i--){for(var f=!0,l=0;l<c;l++)if(u(e,i+l)!==u(t,l)){f=!1;break}if(f)return i}return-1}function _(e,t,n,r){n=Number(n)||0;var o=e.length-n;r?(r=Number(r))>o&&(r=o):r=o;var i=t.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;s<r;++s){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))return s;e[n+s]=a}return s}function m(e,t,n,r){return F(j(t,e.length-n),e,n,r)}function w(e,t,n,r){return F(function(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function E(e,t,n,r){return w(e,t,n,r)}function S(e,t,n,r){return F(V(t),e,n,r)}function A(e,t,n,r){return F(function(e,t){for(var n,r,o,i=[],s=0;s<e.length&&!((t-=2)<0);++s)n=e.charCodeAt(s),r=n>>8,o=n%256,i.push(o),i.push(r);return i}(t,e.length-n),e,n,r)}function O(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function T(e,t,n){n=Math.min(e.length,n);for(var r=[],o=t;o<n;){var i,s,a,c,u=e[o],h=null,f=u>239?4:u>223?3:u>191?2:1;if(o+f<=n)switch(f){case 1:u<128&&(h=u);break;case 2:128==(192&(i=e[o+1]))&&(c=(31&u)<<6|63&i)>127&&(h=c);break;case 3:i=e[o+1],s=e[o+2],128==(192&i)&&128==(192&s)&&(c=(15&u)<<12|(63&i)<<6|63&s)>2047&&(c<55296||c>57343)&&(h=c);break;case 4:i=e[o+1],s=e[o+2],a=e[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(c=(15&u)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(h=c)}null===h?(h=65533,f=1):h>65535&&(h-=65536,r.push(h>>>10&1023|55296),h=56320|1023&h),r.push(h),o+=f}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=4096));return n}(r)}t.Buffer=c,t.SlowBuffer=function(e){+e!=e&&(e=0);return c.alloc(+e)},t.INSPECT_MAX_BYTES=50,c.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=s(),c.poolSize=8192,c._augment=function(e){return e.__proto__=c.prototype,e},c.from=function(e,t,n){return u(null,e,t,n)},c.TYPED_ARRAY_SUPPORT&&(c.prototype.__proto__=Uint8Array.prototype,c.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&c[Symbol.species]===c&&Object.defineProperty(c,Symbol.species,{value:null,configurable:!0})),c.alloc=function(e,t,n){return function(e,t,n,r){return h(t),t<=0?a(e,t):void 0!==n?"string"==typeof r?a(e,t).fill(n,r):a(e,t).fill(n):a(e,t)}(null,e,t,n)},c.allocUnsafe=function(e){return f(null,e)},c.allocUnsafeSlow=function(e){return f(null,e)},c.isBuffer=function(e){return!(null==e||!e._isBuffer)},c.compare=function(e,t){if(!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,o=0,i=Math.min(n,r);o<i;++o)if(e[o]!==t[o]){n=e[o],r=t[o];break}return n<r?-1:r<n?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!i(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=c.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){var s=e[n];if(!c.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(r,o),o+=s.length}return r},c.byteLength=d,c.prototype._isBuffer=!0,c.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)g(this,t,t+1);return this},c.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},c.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},c.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?T(this,0,e):y.apply(this,arguments)},c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){var e="",n=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(e+=" ... ")),"<Buffer "+e+">"},c.prototype.compare=function(e,t,n,r,o){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),t<0||n>e.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&t>=n)return 0;if(r>=o)return-1;if(t>=n)return 1;if(this===e)return 0;for(var i=(o>>>=0)-(r>>>=0),s=(n>>>=0)-(t>>>=0),a=Math.min(i,s),u=this.slice(r,o),h=e.slice(t,n),f=0;f<a;++f)if(u[f]!==h[f]){i=u[f],s=h[f];break}return i<s?-1:s<i?1:0},c.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},c.prototype.indexOf=function(e,t,n){return v(this,e,t,n,!0)},c.prototype.lastIndexOf=function(e,t,n){return v(this,e,t,n,!1)},c.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-t;if((void 0===n||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=!1;;)switch(r){case"hex":return _(this,e,t,n);case"utf8":case"utf-8":return m(this,e,t,n);case"ascii":return w(this,e,t,n);case"latin1":case"binary":return E(this,e,t,n);case"base64":return S(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,e,t,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function I(e,t,n){var r="";n=Math.min(e.length,n);for(var o=t;o<n;++o)r+=String.fromCharCode(127&e[o]);return r}function C(e,t,n){var r="";n=Math.min(e.length,n);for(var o=t;o<n;++o)r+=String.fromCharCode(e[o]);return r}function R(e,t,n){var r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);for(var o="",i=t;i<n;++i)o+=B(e[i]);return o}function N(e,t,n){for(var r=e.slice(t,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function M(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function P(e,t,n,r,o,i){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<i)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function k(e,t,n,r){t<0&&(t=65535+t+1);for(var o=0,i=Math.min(e.length-n,2);o<i;++o)e[n+o]=(t&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function x(e,t,n,r){t<0&&(t=4294967295+t+1);for(var o=0,i=Math.min(e.length-n,4);o<i;++o)e[n+o]=t>>>8*(r?o:3-o)&255}function U(e,t,n,r,o,i){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function L(e,t,n,r,i){return i||U(e,0,n,4),o.write(e,t,n,r,23,4),n+4}function D(e,t,n,r,i){return i||U(e,0,n,8),o.write(e,t,n,r,52,8),n+8}c.prototype.slice=function(e,t){var n,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e),c.TYPED_ARRAY_SUPPORT)(n=this.subarray(e,t)).__proto__=c.prototype;else{var o=t-e;n=new c(o,void 0);for(var i=0;i<o;++i)n[i]=this[i+e]}return n},c.prototype.readUIntLE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=this[e],o=1,i=0;++i<t&&(o*=256);)r+=this[e+i]*o;return r},c.prototype.readUIntBE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=this[e+--t],o=1;t>0&&(o*=256);)r+=this[e+--t]*o;return r},c.prototype.readUInt8=function(e,t){return t||M(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return t||M(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return t||M(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return t||M(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return t||M(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=this[e],o=1,i=0;++i<t&&(o*=256);)r+=this[e+i]*o;return r>=(o*=128)&&(r-=Math.pow(2,8*t)),r},c.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=t,o=1,i=this[e+--r];r>0&&(o*=256);)i+=this[e+--r]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*t)),i},c.prototype.readInt8=function(e,t){return t||M(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){t||M(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt16BE=function(e,t){t||M(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt32LE=function(e,t){return t||M(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return t||M(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return t||M(e,4,this.length),o.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return t||M(e,4,this.length),o.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return t||M(e,8,this.length),o.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return t||M(e,8,this.length),o.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||P(this,e,t,n,Math.pow(2,8*n)-1,0);var o=1,i=0;for(this[t]=255&e;++i<n&&(o*=256);)this[t+i]=e/o&255;return t+n},c.prototype.writeUIntBE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||P(this,e,t,n,Math.pow(2,8*n)-1,0);var o=n-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+n},c.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,1,255,0),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):k(this,e,t,!0),t+2},c.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):k(this,e,t,!1),t+2},c.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):x(this,e,t,!0),t+4},c.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):x(this,e,t,!1),t+4},c.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var o=Math.pow(2,8*n-1);P(this,e,t,n,o-1,-o)}var i=0,s=1,a=0;for(this[t]=255&e;++i<n&&(s*=256);)e<0&&0===a&&0!==this[t+i-1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+n},c.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var o=Math.pow(2,8*n-1);P(this,e,t,n,o-1,-o)}var i=n-1,s=1,a=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===a&&0!==this[t+i+1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+n},c.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,1,127,-128),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):k(this,e,t,!0),t+2},c.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):k(this,e,t,!1),t+2},c.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):x(this,e,t,!0),t+4},c.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||P(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):x(this,e,t,!1),t+4},c.prototype.writeFloatLE=function(e,t,n){return L(this,e,t,!0,n)},c.prototype.writeFloatBE=function(e,t,n){return L(this,e,t,!1,n)},c.prototype.writeDoubleLE=function(e,t,n){return D(this,e,t,!0,n)},c.prototype.writeDoubleBE=function(e,t,n){return D(this,e,t,!1,n)},c.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var o,i=r-n;if(this===e&&n<t&&t<r)for(o=i-1;o>=0;--o)e[o+t]=this[o+n];else if(i<1e3||!c.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)e[o+t]=this[o+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+i),t);return i},c.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===e.length){var o=e.charCodeAt(0);o<256&&(e=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!c.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;var i;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(i=t;i<n;++i)this[i]=e;else{var s=c.isBuffer(e)?e:j(new c(e,r).toString()),a=s.length;for(i=0;i<n-t;++i)this[i+t]=s[i%a]}return this};var q=/[^+\/0-9A-Za-z-_]/g;function B(e){return e<16?"0"+e.toString(16):e.toString(16)}function j(e,t){var n;t=t||1/0;for(var r=e.length,o=null,i=[],s=0;s<r;++s){if((n=e.charCodeAt(s))>55295&&n<57344){if(!o){if(n>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(t-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((t-=1)<0)break;i.push(n)}else if(n<2048){if((t-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function V(e){return r.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(q,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function F(e,t,n,r){for(var o=0;o<r&&!(o+n>=t.length||o>=e.length);++o)t[o+n]=e[o];return o}}).call(this,n(3))},function(e,t){e.exports=n},function(e,t){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var r=new Uint8Array(16);e.exports=function(){return n(r),r}}else{var o=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),o[t]=e>>>((3&t)<<3)&255;return o}}},function(e,t){for(var n=[],r=0;r<256;++r)n[r]=(r+256).toString(16).substr(1);e.exports=function(e,t){var r=t||0,o=n;return[o[e[r++]],o[e[r++]],o[e[r++]],o[e[r++]],"-",o[e[r++]],o[e[r++]],"-",o[e[r++]],o[e[r++]],"-",o[e[r++]],o[e[r++]],"-",o[e[r++]],o[e[r++]],o[e[r++]],o[e[r++]],o[e[r++]],o[e[r++]]].join("")}},function(e,t,n){e.exports=n(12).Observable},function(e,t,n){(function(t){var n;n=function(){return function(e){var t,n=e.localStorage||(t={},{setItem:function(e,n){t[e]=n},getItem:function(e){return t[e]},removeItem:function(e){delete t[e]}}),r=1,o=2,i=3,s=4,a=5,c=6,u=7,h=8,f=9,l=10,p=11,d=12,y=13,g=14,v=function(e,t){for(var n in e)if(e.hasOwnProperty(n)){if(!t.hasOwnProperty(n)){var r="Unknown property, "+n+". Valid properties are:";for(var o in t)t.hasOwnProperty(o)&&(r=r+" "+o);throw new Error(r)}if(typeof e[n]!==t[n])throw new Error(w(_.INVALID_TYPE,[typeof e[n],n]))}},b=function(e,t){return function(){return e.apply(t,arguments)}},_={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: {0}."}},m={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},w=function(e,t){var n=e.text;if(t)for(var r,o,i=0;i<t.length;i++)if(r="{"+i+"}",(o=n.indexOf(r))>0){var s=n.substring(0,o),a=n.substring(o+r.length);n=s+t[i]+a}return n},E=[0,6,77,81,73,115,100,112,3],S=[0,4,77,81,84,84,4],A=function(e,t){for(var n in this.type=e,t)t.hasOwnProperty(n)&&(this[n]=t[n])};function O(e,t){var n,r=t,h=e[t],l=h>>4,d=h&=15;t+=1;var y=0,g=1;do{if(t==e.length)return[null,r];y+=(127&(n=e[t++]))*g,g*=128}while(0!=(128&n));var v=t+y;if(v>e.length)return[null,r];var b=new A(l);switch(l){case o:1&e[t++]&&(b.sessionPresent=!0),b.returnCode=e[t++];break;case i:var _=d>>1&3,m=C(e,t),w=M(e,t+=2,m);t+=m,_>0&&(b.messageIdentifier=C(e,t),t+=2);var E=new U(e.subarray(t,v));1==(1&d)&&(E.retained=!0),8==(8&d)&&(E.duplicate=!0),E.qos=_,E.destinationName=w,b.payloadMessage=E;break;case s:case a:case c:case u:case p:b.messageIdentifier=C(e,t);break;case f:b.messageIdentifier=C(e,t),t+=2,b.returnCode=e.subarray(t,v)}return[b,v]}function T(e,t,n){return t[n++]=e>>8,t[n++]=e%256,n}function I(e,t,n,r){return N(e,n,r=T(t,n,r)),r+t}function C(e,t){return 256*e[t]+e[t+1]}function R(e){for(var t=0,n=0;n<e.length;n++){var r=e.charCodeAt(n);r>2047?(55296<=r&&r<=56319&&(n++,t++),t+=3):r>127?t+=2:t++}return t}function N(e,t,n){for(var r=n,o=0;o<e.length;o++){var i=e.charCodeAt(o);if(55296<=i&&i<=56319){var s=e.charCodeAt(++o);if(isNaN(s))throw new Error(w(_.MALFORMED_UNICODE,[i,s]));i=s-56320+(i-55296<<10)+65536}i<=127?t[r++]=i:i<=2047?(t[r++]=i>>6&31|192,t[r++]=63&i|128):i<=65535?(t[r++]=i>>12&15|224,t[r++]=i>>6&63|128,t[r++]=63&i|128):(t[r++]=i>>18&7|240,t[r++]=i>>12&63|128,t[r++]=i>>6&63|128,t[r++]=63&i|128)}return t}function M(e,t,n){for(var r,o="",i=t;i<t+n;){var s=e[i++];if(s<128)r=s;else{var a=e[i++]-128;if(a<0)throw new Error(w(_.MALFORMED_UTF,[s.toString(16),a.toString(16),""]));if(s<224)r=64*(s-192)+a;else{var c=e[i++]-128;if(c<0)throw new Error(w(_.MALFORMED_UTF,[s.toString(16),a.toString(16),c.toString(16)]));if(s<240)r=4096*(s-224)+64*a+c;else{var u=e[i++]-128;if(u<0)throw new Error(w(_.MALFORMED_UTF,[s.toString(16),a.toString(16),c.toString(16),u.toString(16)]));if(!(s<248))throw new Error(w(_.MALFORMED_UTF,[s.toString(16),a.toString(16),c.toString(16),u.toString(16)]));r=262144*(s-240)+4096*a+64*c+u}}}r>65535&&(r-=65536,o+=String.fromCharCode(55296+(r>>10)),r=56320+(1023&r)),o+=String.fromCharCode(r)}return o}A.prototype.encode=function(){var e,t=(15&this.type)<<4,n=0,o=[],s=0;switch(void 0!==this.messageIdentifier&&(n+=2),this.type){case r:switch(this.mqttVersion){case 3:n+=E.length+3;break;case 4:n+=S.length+3}n+=R(this.clientId)+2,void 0!==this.willMessage&&(n+=R(this.willMessage.destinationName)+2,(e=this.willMessage.payloadBytes)instanceof Uint8Array||(e=new Uint8Array(u)),n+=e.byteLength+2),void 0!==this.userName&&(n+=R(this.userName)+2),void 0!==this.password&&(n+=R(this.password)+2);break;case h:t|=2;for(var a=0;a<this.topics.length;a++)o[a]=R(this.topics[a]),n+=o[a]+2;n+=this.requestedQos.length;break;case l:for(t|=2,a=0;a<this.topics.length;a++)o[a]=R(this.topics[a]),n+=o[a]+2;break;case c:t|=2;break;case i:this.payloadMessage.duplicate&&(t|=8),t=t|=this.payloadMessage.qos<<1,this.payloadMessage.retained&&(t|=1),n+=(s=R(this.payloadMessage.destinationName))+2;var u=this.payloadMessage.payloadBytes;n+=u.byteLength,u instanceof ArrayBuffer?u=new Uint8Array(u):u instanceof Uint8Array||(u=new Uint8Array(u.buffer))}var f=function(e){var t=new Array(1),n=0;do{var r=e%128;(e>>=7)>0&&(r|=128),t[n++]=r}while(e>0&&n<4);return t}(n),p=f.length+1,d=new ArrayBuffer(n+p),y=new Uint8Array(d);if(y[0]=t,y.set(f,1),this.type==i)p=I(this.payloadMessage.destinationName,s,y,p);else if(this.type==r){switch(this.mqttVersion){case 3:y.set(E,p),p+=E.length;break;case 4:y.set(S,p),p+=S.length}var g=0;this.cleanSession&&(g=2),void 0!==this.willMessage&&(g|=4,g|=this.willMessage.qos<<3,this.willMessage.retained&&(g|=32)),void 0!==this.userName&&(g|=128),void 0!==this.password&&(g|=64),y[p++]=g,p=T(this.keepAliveInterval,y,p)}switch(void 0!==this.messageIdentifier&&(p=T(this.messageIdentifier,y,p)),this.type){case r:p=I(this.clientId,R(this.clientId),y,p),void 0!==this.willMessage&&(p=I(this.willMessage.destinationName,R(this.willMessage.destinationName),y,p),p=T(e.byteLength,y,p),y.set(e,p),p+=e.byteLength),void 0!==this.userName&&(p=I(this.userName,R(this.userName),y,p)),void 0!==this.password&&(p=I(this.password,R(this.password),y,p));break;case i:y.set(u,p);break;case h:for(a=0;a<this.topics.length;a++)p=I(this.topics[a],o[a],y,p),y[p++]=this.requestedQos[a];break;case l:for(a=0;a<this.topics.length;a++)p=I(this.topics[a],o[a],y,p)}return d};var P=function(e,t){this._client=e,this._keepAliveInterval=1e3*t,this.isReset=!1;var n=new A(d).encode(),r=function(e){return function(){return o.apply(e)}},o=function(){this.isReset?(this.isReset=!1,this._client._trace("Pinger.doPing","send PINGREQ"),this._client.socket.send(n),this.timeout=setTimeout(r(this),this._keepAliveInterval)):(this._client._trace("Pinger.doPing","Timed out"),this._client._disconnected(_.PING_TIMEOUT.code,w(_.PING_TIMEOUT)))};this.reset=function(){this.isReset=!0,clearTimeout(this.timeout),this._keepAliveInterval>0&&(this.timeout=setTimeout(r(this),this._keepAliveInterval))},this.cancel=function(){clearTimeout(this.timeout)}},k=function(e,t,n,r){t||(t=30),this.timeout=setTimeout(function(e,t,n){return function(){return e.apply(t,n)}}(n,e,r),1e3*t),this.cancel=function(){clearTimeout(this.timeout)}},x=function(t,r,o,i,s){if(!("WebSocket"in e)||null===e.WebSocket)throw new Error(w(_.UNSUPPORTED,["WebSocket"]));if(!("ArrayBuffer"in e)||null===e.ArrayBuffer)throw new Error(w(_.UNSUPPORTED,["ArrayBuffer"]));for(var a in this._trace("Paho.Client",t,r,o,i,s),this.host=r,this.port=o,this.path=i,this.uri=t,this.clientId=s,this._wsuri=null,this._localKey=r+":"+o+("/mqtt"!=i?":"+i:"")+":"+s+":",this._msg_queue=[],this._buffered_msg_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0,n)0!==a.indexOf("Sent:"+this._localKey)&&0!==a.indexOf("Received:"+this._localKey)||this.restore(a)};x.prototype.host=null,x.prototype.port=null,x.prototype.path=null,x.prototype.uri=null,x.prototype.clientId=null,x.prototype.socket=null,x.prototype.connected=!1,x.prototype.maxMessageIdentifier=65536,x.prototype.connectOptions=null,x.prototype.hostIndex=null,x.prototype.onConnected=null,x.prototype.onConnectionLost=null,x.prototype.onMessageDelivered=null,x.prototype.onMessageArrived=null,x.prototype.traceFunction=null,x.prototype._msg_queue=null,x.prototype._buffered_msg_queue=null,x.prototype._connectTimeout=null,x.prototype.sendPinger=null,x.prototype.receivePinger=null,x.prototype._reconnectInterval=1,x.prototype._reconnecting=!1,x.prototype._reconnectTimeout=null,x.prototype.disconnectedPublishing=!1,x.prototype.disconnectedBufferSize=5e3,x.prototype.receiveBuffer=null,x.prototype._traceBuffer=null,x.prototype._MAX_TRACE_ENTRIES=100,x.prototype.connect=function(e){var t=this._traceMask(e,"password");if(this._trace("Client.connect",t,this.socket,this.connected),this.connected)throw new Error(w(_.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(w(_.INVALID_STATE,["already connected"]));this._reconnecting&&(this._reconnectTimeout.cancel(),this._reconnectTimeout=null,this._reconnecting=!1),this.connectOptions=e,this._reconnectInterval=1,this._reconnecting=!1,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},x.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(w(_.INVALID_STATE,["not connected"]));var n=new A(h);n.topics=e.constructor===Array?e:[e],void 0===t.qos&&(t.qos=0),n.requestedQos=[];for(var r=0;r<n.topics.length;r++)n.requestedQos[r]=t.qos;t.onSuccess&&(n.onSuccess=function(e){t.onSuccess({invocationContext:t.invocationContext,grantedQos:e})}),t.onFailure&&(n.onFailure=function(e){t.onFailure({invocationContext:t.invocationContext,errorCode:e,errorMessage:w(e)})}),t.timeout&&(n.timeOut=new k(this,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:_.SUBSCRIBE_TIMEOUT.code,errorMessage:w(_.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},x.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(w(_.INVALID_STATE,["not connected"]));var n=new A(l);n.topics=e.constructor===Array?e:[e],t.onSuccess&&(n.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(n.timeOut=new k(this,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:_.UNSUBSCRIBE_TIMEOUT.code,errorMessage:w(_.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},x.prototype.send=function(e){this._trace("Client.send",e);var t=new A(i);if(t.payloadMessage=e,this.connected)e.qos>0?this._requires_ack(t):this.onMessageDelivered&&(this._notify_msg_sent[t]=this.onMessageDelivered(t.payloadMessage)),this._schedule_message(t);else{if(!this._reconnecting||!this.disconnectedPublishing)throw new Error(w(_.INVALID_STATE,["not connected"]));if(Object.keys(this._sentMessages).length+this._buffered_msg_queue.length>this.disconnectedBufferSize)throw new Error(w(_.BUFFER_FULL,[this.disconnectedBufferSize]));e.qos>0?this._requires_ack(t):(t.sequence=++this._sequence,this._buffered_msg_queue.unshift(t))}},x.prototype.disconnect=function(){if(this._trace("Client.disconnect"),this._reconnecting&&(this._reconnectTimeout.cancel(),this._reconnectTimeout=null,this._reconnecting=!1),!this.socket)throw new Error(w(_.INVALID_STATE,["not connecting or connected"]));var e=new A(g);this._notify_msg_sent[e]=b(this._disconnected,this),this._schedule_message(e)},x.prototype.getTraceLog=function(){if(null!==this._traceBuffer){for(var e in this._trace("Client.getTraceLog",new Date),this._trace("Client.getTraceLog in flight messages",this._sentMessages.length),this._sentMessages)this._trace("_sentMessages ",e,this._sentMessages[e]);for(var e in this._receivedMessages)this._trace("_receivedMessages ",e,this._receivedMessages[e]);return this._traceBuffer}},x.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,"@VERSION@-@BUILDLEVEL@")},x.prototype.stopTrace=function(){delete this._traceBuffer},x.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this._wsuri=e,this.connected=!1,this.connectOptions.mqttVersion<4?this.socket=new WebSocket(e,["mqttv3.1"]):this.socket=new WebSocket(e,["mqtt"]),this.socket.binaryType="arraybuffer",this.socket.onopen=b(this._on_socket_open,this),this.socket.onmessage=b(this._on_socket_message,this),this.socket.onerror=b(this._on_socket_error,this),this.socket.onclose=b(this._on_socket_close,this),this.sendPinger=new P(this,this.connectOptions.keepAliveInterval),this.receivePinger=new P(this,this.connectOptions.keepAliveInterval),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this._connectTimeout=new k(this,this.connectOptions.timeout,this._disconnected,[_.CONNECT_TIMEOUT.code,w(_.CONNECT_TIMEOUT)])},x.prototype._schedule_message=function(e){this._msg_queue.unshift(e),this.connected&&this._process_queue()},x.prototype.store=function(e,t){var r={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case i:t.pubRecReceived&&(r.pubRecReceived=!0),r.payloadMessage={};for(var o="",s=t.payloadMessage.payloadBytes,a=0;a<s.length;a++)s[a]<=15?o=o+"0"+s[a].toString(16):o+=s[a].toString(16);r.payloadMessage.payloadHex=o,r.payloadMessage.qos=t.payloadMessage.qos,r.payloadMessage.destinationName=t.payloadMessage.destinationName,t.payloadMessage.duplicate&&(r.payloadMessage.duplicate=!0),t.payloadMessage.retained&&(r.payloadMessage.retained=!0),0===e.indexOf("Sent:")&&(void 0===t.sequence&&(t.sequence=++this._sequence),r.sequence=t.sequence);break;default:throw Error(w(_.INVALID_STORED_DATA,[e+this._localKey+t.messageIdentifier,r]))}n.setItem(e+this._localKey+t.messageIdentifier,JSON.stringify(r))},x.prototype.restore=function(e){var t=n.getItem(e),r=JSON.parse(t),o=new A(r.type,r);switch(r.type){case i:for(var s=r.payloadMessage.payloadHex,a=new ArrayBuffer(s.length/2),c=new Uint8Array(a),u=0;s.length>=2;){var h=parseInt(s.substring(0,2),16);s=s.substring(2,s.length),c[u++]=h}var f=new U(c);f.qos=r.payloadMessage.qos,f.destinationName=r.payloadMessage.destinationName,r.payloadMessage.duplicate&&(f.duplicate=!0),r.payloadMessage.retained&&(f.retained=!0),o.payloadMessage=f;break;default:throw Error(w(_.INVALID_STORED_DATA,[e,t]))}0===e.indexOf("Sent:"+this._localKey)?(o.payloadMessage.duplicate=!0,this._sentMessages[o.messageIdentifier]=o):0===e.indexOf("Received:"+this._localKey)&&(this._receivedMessages[o.messageIdentifier]=o)},x.prototype._process_queue=function(){for(var e=null;e=this._msg_queue.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},x.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===i&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},x.prototype._on_socket_open=function(){var e=new A(r,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},x.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),n=0;n<t.length;n+=1)this._handleMessage(t[n])},x.prototype._deframeMessages=function(e){var t=new Uint8Array(e),n=[];if(this.receiveBuffer){var r=new Uint8Array(this.receiveBuffer.length+t.length);r.set(this.receiveBuffer),r.set(t,this.receiveBuffer.length),t=r,delete this.receiveBuffer}try{for(var o=0;o<t.length;){var i=O(t,o),s=i[0];if(o=i[1],null===s)break;n.push(s)}o<t.length&&(this.receiveBuffer=t.subarray(o))}catch(e){var a="undefined"==e.hasOwnProperty("stack")?e.stack.toString():"No Error Stack Available";return void this._disconnected(_.INTERNAL_ERROR.code,w(_.INTERNAL_ERROR,[e.message,a]))}return n},x.prototype._handleMessage=function(e){this._trace("Client._handleMessage",e);try{switch(e.type){case o:if(this._connectTimeout.cancel(),this._reconnectTimeout&&this._reconnectTimeout.cancel(),this.connectOptions.cleanSession){for(var t in this._sentMessages){var r=this._sentMessages[t];n.removeItem("Sent:"+this._localKey+r.messageIdentifier)}for(var t in this._sentMessages={},this._receivedMessages){var h=this._receivedMessages[t];n.removeItem("Received:"+this._localKey+h.messageIdentifier)}this._receivedMessages={}}if(0!==e.returnCode){this._disconnected(_.CONNACK_RETURNCODE.code,w(_.CONNACK_RETURNCODE,[e.returnCode,m[e.returnCode]]));break}this.connected=!0,this.connectOptions.uris&&(this.hostIndex=this.connectOptions.uris.length);var l=[];for(var d in this._sentMessages)this._sentMessages.hasOwnProperty(d)&&l.push(this._sentMessages[d]);if(this._buffered_msg_queue.length>0)for(var v=null;v=this._buffered_msg_queue.pop();)l.push(v),this.onMessageDelivered&&(this._notify_msg_sent[v]=this.onMessageDelivered(v.payloadMessage));l=l.sort((function(e,t){return e.sequence-t.sequence}));for(var b=0,E=l.length;b<E;b++)if((r=l[b]).type==i&&r.pubRecReceived){var S=new A(c,{messageIdentifier:r.messageIdentifier});this._schedule_message(S)}else this._schedule_message(r);this.connectOptions.onSuccess&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext});var O=!1;this._reconnecting&&(O=!0,this._reconnectInterval=1,this._reconnecting=!1),this._connected(O,this._wsuri),this._process_queue();break;case i:this._receivePublish(e);break;case s:(r=this._sentMessages[e.messageIdentifier])&&(delete this._sentMessages[e.messageIdentifier],n.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(r.payloadMessage));break;case a:(r=this._sentMessages[e.messageIdentifier])&&(r.pubRecReceived=!0,S=new A(c,{messageIdentifier:e.messageIdentifier}),this.store("Sent:",r),this._schedule_message(S));break;case c:h=this._receivedMessages[e.messageIdentifier],n.removeItem("Received:"+this._localKey+e.messageIdentifier),h&&(this._receiveMessage(h),delete this._receivedMessages[e.messageIdentifier]);var T=new A(u,{messageIdentifier:e.messageIdentifier});this._schedule_message(T);break;case u:r=this._sentMessages[e.messageIdentifier],delete this._sentMessages[e.messageIdentifier],n.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(r.payloadMessage);break;case f:(r=this._sentMessages[e.messageIdentifier])&&(r.timeOut&&r.timeOut.cancel(),128===e.returnCode[0]?r.onFailure&&r.onFailure(e.returnCode):r.onSuccess&&r.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case p:(r=this._sentMessages[e.messageIdentifier])&&(r.timeOut&&r.timeOut.cancel(),r.callback&&r.callback(),delete this._sentMessages[e.messageIdentifier]);break;case y:this.sendPinger.reset();break;case g:this._disconnected(_.INVALID_MQTT_MESSAGE_TYPE.code,w(_.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(_.INVALID_MQTT_MESSAGE_TYPE.code,w(_.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(e){var I="undefined"==e.hasOwnProperty("stack")?e.stack.toString():"No Error Stack Available";return void this._disconnected(_.INTERNAL_ERROR.code,w(_.INTERNAL_ERROR,[e.message,I]))}},x.prototype._on_socket_error=function(e){this._reconnecting||this._disconnected(_.SOCKET_ERROR.code,w(_.SOCKET_ERROR,[e.data]))},x.prototype._on_socket_close=function(){this._reconnecting||this._disconnected(_.SOCKET_CLOSE.code,w(_.SOCKET_CLOSE))},x.prototype._socket_send=function(e){if(1==e.type){var t=this._traceMask(e,"password");this._trace("Client._socket_send",t)}else this._trace("Client._socket_send",e);this.socket.send(e.encode()),this.sendPinger.reset()},x.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new A(s,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var n=new A(a,{messageIdentifier:e.messageIdentifier});this._schedule_message(n);break;default:throw Error("Invaild qos="+e.payloadMessage.qos)}},x.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},x.prototype._connected=function(e,t){this.onConnected&&this.onConnected(e,t)},x.prototype._reconnect=function(){this._trace("Client._reconnect"),this.connected||(this._reconnecting=!0,this.sendPinger.cancel(),this.receivePinger.cancel(),this._reconnectInterval<128&&(this._reconnectInterval=2*this._reconnectInterval),this.connectOptions.uris?(this.hostIndex=0,this._doConnect(this.connectOptions.uris[0])):this._doConnect(this.uri))},x.prototype._disconnected=function(e,t){if(this._trace("Client._disconnected",e,t),void 0!==e&&this._reconnecting)this._reconnectTimeout=new k(this,this._reconnectInterval,this._reconnect);else if(this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this._msg_queue=[],this._buffered_msg_queue=[],this._notify_msg_sent={},this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,1===this.socket.readyState&&this.socket.close(),delete this.socket),this.connectOptions.uris&&this.hostIndex<this.connectOptions.uris.length-1)this.hostIndex++,this._doConnect(this.connectOptions.uris[this.hostIndex]);else if(void 0===e&&(e=_.OK.code,t=w(_.OK)),this.connected){if(this.connected=!1,this.onConnectionLost&&this.onConnectionLost({errorCode:e,errorMessage:t,reconnect:this.connectOptions.reconnect,uri:this._wsuri}),e!==_.OK.code&&this.connectOptions.reconnect)return this._reconnectInterval=1,void this._reconnect()}else 4===this.connectOptions.mqttVersion&&!1===this.connectOptions.mqttVersionExplicit?(this._trace("Failed to connect V4, dropping back to V3"),this.connectOptions.mqttVersion=3,this.connectOptions.uris?(this.hostIndex=0,this._doConnect(this.connectOptions.uris[0])):this._doConnect(this.uri)):this.connectOptions.onFailure&&this.connectOptions.onFailure({invocationContext:this.connectOptions.invocationContext,errorCode:e,errorMessage:t})},x.prototype._trace=function(){if(this.traceFunction){var e=Array.prototype.slice.call(arguments);for(var t in e)void 0!==e[t]&&e.splice(t,1,JSON.stringify(e[t]));var n=e.join("");this.traceFunction({severity:"Debug",message:n})}if(null!==this._traceBuffer){t=0;for(var r=arguments.length;t<r;t++)this._traceBuffer.length==this._MAX_TRACE_ENTRIES&&this._traceBuffer.shift(),0===t||void 0===arguments[t]?this._traceBuffer.push(arguments[t]):this._traceBuffer.push(" "+JSON.stringify(arguments[t]))}},x.prototype._traceMask=function(e,t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=r==t?"******":e[r]);return n};var U=function(e){var t,n;if(!("string"==typeof e||e instanceof ArrayBuffer||ArrayBuffer.isView(e)&&!(e instanceof DataView)))throw w(_.INVALID_ARGUMENT,[e,"newPayload"]);t=e;var r=0,o=!1,i=!1;Object.defineProperties(this,{payloadString:{enumerable:!0,get:function(){return"string"==typeof t?t:M(t,0,t.length)}},payloadBytes:{enumerable:!0,get:function(){if("string"==typeof t){var e=new ArrayBuffer(R(t)),n=new Uint8Array(e);return N(t,n,0),n}return t}},destinationName:{enumerable:!0,get:function(){return n},set:function(e){if("string"!=typeof e)throw new Error(w(_.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e}},qos:{enumerable:!0,get:function(){return r},set:function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);r=e}},retained:{enumerable:!0,get:function(){return o},set:function(e){if("boolean"!=typeof e)throw new Error(w(_.INVALID_ARGUMENT,[e,"newRetained"]));o=e}},topic:{enumerable:!0,get:function(){return n},set:function(e){n=e}},duplicate:{enumerable:!0,get:function(){return i},set:function(e){i=e}}})};return{Client:function(e,t,n,r){var o;if("string"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"host"]));if(2==arguments.length){r=t;var i=(o=e).match(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/);if(!i)throw new Error(w(_.INVALID_ARGUMENT,[e,"host"]));e=i[4]||i[2],t=parseInt(i[7]),n=i[8]}else{if(3==arguments.length&&(r=n,n="/mqtt"),"number"!=typeof t||t<0)throw new Error(w(_.INVALID_TYPE,[typeof t,"port"]));if("string"!=typeof n)throw new Error(w(_.INVALID_TYPE,[typeof n,"path"]));var s=-1!==e.indexOf(":")&&"["!==e.slice(0,1)&&"]"!==e.slice(-1);o="ws://"+(s?"["+e+"]":e)+":"+t+n}for(var a=0,c=0;c<r.length;c++){var u=r.charCodeAt(c);55296<=u&&u<=56319&&c++,a++}if("string"!=typeof r||a>65535)throw new Error(w(_.INVALID_ARGUMENT,[r,"clientId"]));var h=new x(o,e,t,n,r);Object.defineProperties(this,{host:{get:function(){return e},set:function(){throw new Error(w(_.UNSUPPORTED_OPERATION))}},port:{get:function(){return t},set:function(){throw new Error(w(_.UNSUPPORTED_OPERATION))}},path:{get:function(){return n},set:function(){throw new Error(w(_.UNSUPPORTED_OPERATION))}},uri:{get:function(){return o},set:function(){throw new Error(w(_.UNSUPPORTED_OPERATION))}},clientId:{get:function(){return h.clientId},set:function(){throw new Error(w(_.UNSUPPORTED_OPERATION))}},onConnected:{get:function(){return h.onConnected},set:function(e){if("function"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"onConnected"]));h.onConnected=e}},disconnectedPublishing:{get:function(){return h.disconnectedPublishing},set:function(e){h.disconnectedPublishing=e}},disconnectedBufferSize:{get:function(){return h.disconnectedBufferSize},set:function(e){h.disconnectedBufferSize=e}},onConnectionLost:{get:function(){return h.onConnectionLost},set:function(e){if("function"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"onConnectionLost"]));h.onConnectionLost=e}},onMessageDelivered:{get:function(){return h.onMessageDelivered},set:function(e){if("function"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"onMessageDelivered"]));h.onMessageDelivered=e}},onMessageArrived:{get:function(){return h.onMessageArrived},set:function(e){if("function"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"onMessageArrived"]));h.onMessageArrived=e}},trace:{get:function(){return h.traceFunction},set:function(e){if("function"!=typeof e)throw new Error(w(_.INVALID_TYPE,[typeof e,"onTrace"]));h.traceFunction=e}}}),this.connect=function(e){if(v(e=e||{},{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",reconnect:"boolean",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),void 0===e.keepAliveInterval&&(e.keepAliveInterval=60),e.mqttVersion>4||e.mqttVersion<3)throw new Error(w(_.INVALID_ARGUMENT,[e.mqttVersion,"connectOptions.mqttVersion"]));if(void 0===e.mqttVersion?(e.mqttVersionExplicit=!1,e.mqttVersion=4):e.mqttVersionExplicit=!0,void 0!==e.password&&void 0===e.userName)throw new Error(w(_.INVALID_ARGUMENT,[e.password,"connectOptions.password"]));if(e.willMessage){if(!(e.willMessage instanceof U))throw new Error(w(_.INVALID_TYPE,[e.willMessage,"connectOptions.willMessage"]));if(e.willMessage.stringPayload=null,void 0===e.willMessage.destinationName)throw new Error(w(_.INVALID_TYPE,[typeof e.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if(void 0===e.cleanSession&&(e.cleanSession=!0),e.hosts){if(!(e.hosts instanceof Array))throw new Error(w(_.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));if(e.hosts.length<1)throw new Error(w(_.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));for(var t=!1,r=0;r<e.hosts.length;r++){if("string"!=typeof e.hosts[r])throw new Error(w(_.INVALID_TYPE,[typeof e.hosts[r],"connectOptions.hosts["+r+"]"]));if(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/.test(e.hosts[r])){if(0===r)t=!0;else if(!t)throw new Error(w(_.INVALID_ARGUMENT,[e.hosts[r],"connectOptions.hosts["+r+"]"]))}else if(t)throw new Error(w(_.INVALID_ARGUMENT,[e.hosts[r],"connectOptions.hosts["+r+"]"]))}if(t)e.uris=e.hosts;else{if(!e.ports)throw new Error(w(_.INVALID_ARGUMENT,[e.ports,"connectOptions.ports"]));if(!(e.ports instanceof Array))throw new Error(w(_.INVALID_ARGUMENT,[e.ports,"connectOptions.ports"]));if(e.hosts.length!==e.ports.length)throw new Error(w(_.INVALID_ARGUMENT,[e.ports,"connectOptions.ports"]));for(e.uris=[],r=0;r<e.hosts.length;r++){if("number"!=typeof e.ports[r]||e.ports[r]<0)throw new Error(w(_.INVALID_TYPE,[typeof e.ports[r],"connectOptions.ports["+r+"]"]));var i=e.hosts[r],s=e.ports[r],a=-1!==i.indexOf(":");o="ws://"+(a?"["+i+"]":i)+":"+s+n,e.uris.push(o)}}}h.connect(e)},this.subscribe=function(e,t){if("string"!=typeof e&&e.constructor!==Array)throw new Error("Invalid argument:"+e);if(v(t=t||{},{qos:"number",invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"}),t.timeout&&!t.onFailure)throw new Error("subscribeOptions.timeout specified with no onFailure callback.");if(void 0!==t.qos&&0!==t.qos&&1!==t.qos&&2!==t.qos)throw new Error(w(_.INVALID_ARGUMENT,[t.qos,"subscribeOptions.qos"]));h.subscribe(e,t)},this.unsubscribe=function(e,t){if("string"!=typeof e&&e.constructor!==Array)throw new Error("Invalid argument:"+e);if(v(t=t||{},{invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"}),t.timeout&&!t.onFailure)throw new Error("unsubscribeOptions.timeout specified with no onFailure callback.");h.unsubscribe(e,t)},this.send=function(e,t,n,r){var o;if(0===arguments.length)throw new Error("Invalid argument.length");if(1==arguments.length){if(!(e instanceof U)&&"string"!=typeof e)throw new Error("Invalid argument:"+typeof e);if(void 0===(o=e).destinationName)throw new Error(w(_.INVALID_ARGUMENT,[o.destinationName,"Message.destinationName"]));h.send(o)}else(o=new U(t)).destinationName=e,arguments.length>=3&&(o.qos=n),arguments.length>=4&&(o.retained=r),h.send(o)},this.publish=function(e,t,n,r){var o;if(0===arguments.length)throw new Error("Invalid argument.length");if(1==arguments.length){if(!(e instanceof U)&&"string"!=typeof e)throw new Error("Invalid argument:"+typeof e);if(void 0===(o=e).destinationName)throw new Error(w(_.INVALID_ARGUMENT,[o.destinationName,"Message.destinationName"]));h.send(o)}else(o=new U(t)).destinationName=e,arguments.length>=3&&(o.qos=n),arguments.length>=4&&(o.retained=r),h.send(o)},this.disconnect=function(){h.disconnect()},this.getTraceLog=function(){return h.getTraceLog()},this.startTrace=function(){h.startTrace()},this.stopTrace=function(){h.stopTrace()},this.isConnected=function(){return h.connected}},Message:U}}(void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},e.exports=n()}).call(this,n(3))},function(e,t,n){"use strict";var r=n(15),o=n(17);function i(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}t.parse=_,t.resolve=function(e,t){return _(e,!1,!0).resolve(t)},t.resolveObject=function(e,t){return e?_(e,!1,!0).resolveObject(t):t},t.format=function(e){o.isString(e)&&(e=_(e));return e instanceof i?e.format():i.prototype.format.call(e)},t.Url=i;var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,u=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),h=["'"].concat(u),f=["%","/","?",";","#"].concat(h),l=["/","?","#"],p=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,y={javascript:!0,"javascript:":!0},g={javascript:!0,"javascript:":!0},v={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},b=n(18);function _(e,t,n){if(e&&o.isObject(e)&&e instanceof i)return e;var r=new i;return r.parse(e,t,n),r}i.prototype.parse=function(e,t,n){if(!o.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var i=e.indexOf("?"),a=-1!==i&&i<e.indexOf("#")?"?":"#",u=e.split(a);u[0]=u[0].replace(/\\/g,"/");var _=e=u.join(a);if(_=_.trim(),!n&&1===e.split("#").length){var m=c.exec(_);if(m)return this.path=_,this.href=_,this.pathname=m[1],m[2]?(this.search=m[2],this.query=t?b.parse(this.search.substr(1)):this.search.substr(1)):t&&(this.search="",this.query={}),this}var w=s.exec(_);if(w){var E=(w=w[0]).toLowerCase();this.protocol=E,_=_.substr(w.length)}if(n||w||_.match(/^\/\/[^@\/]+@[^@\/]+/)){var S="//"===_.substr(0,2);!S||w&&g[w]||(_=_.substr(2),this.slashes=!0)}if(!g[w]&&(S||w&&!v[w])){for(var A,O,T=-1,I=0;I<l.length;I++){-1!==(C=_.indexOf(l[I]))&&(-1===T||C<T)&&(T=C)}-1!==(O=-1===T?_.lastIndexOf("@"):_.lastIndexOf("@",T))&&(A=_.slice(0,O),_=_.slice(O+1),this.auth=decodeURIComponent(A)),T=-1;for(I=0;I<f.length;I++){var C;-1!==(C=_.indexOf(f[I]))&&(-1===T||C<T)&&(T=C)}-1===T&&(T=_.length),this.host=_.slice(0,T),_=_.slice(T),this.parseHost(),this.hostname=this.hostname||"";var R="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!R)for(var N=this.hostname.split(/\./),M=(I=0,N.length);I<M;I++){var P=N[I];if(P&&!P.match(p)){for(var k="",x=0,U=P.length;x<U;x++)P.charCodeAt(x)>127?k+="x":k+=P[x];if(!k.match(p)){var L=N.slice(0,I),D=N.slice(I+1),q=P.match(d);q&&(L.push(q[1]),D.unshift(q[2])),D.length&&(_="/"+D.join(".")+_),this.hostname=L.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),R||(this.hostname=r.toASCII(this.hostname));var B=this.port?":"+this.port:"",j=this.hostname||"";this.host=j+B,this.href+=this.host,R&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==_[0]&&(_="/"+_))}if(!y[E])for(I=0,M=h.length;I<M;I++){var V=h[I];if(-1!==_.indexOf(V)){var F=encodeURIComponent(V);F===V&&(F=escape(V)),_=_.split(V).join(F)}}var G=_.indexOf("#");-1!==G&&(this.hash=_.substr(G),_=_.slice(0,G));var Y=_.indexOf("?");if(-1!==Y?(this.search=_.substr(Y),this.query=_.substr(Y+1),t&&(this.query=b.parse(this.query)),_=_.slice(0,Y)):t&&(this.search="",this.query={}),_&&(this.pathname=_),v[E]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){B=this.pathname||"";var Q=this.search||"";this.path=B+Q}return this.href=this.format(),this},i.prototype.format=function(){var e=this.auth||"";e&&(e=(e=encodeURIComponent(e)).replace(/%3A/i,":"),e+="@");var t=this.protocol||"",n=this.pathname||"",r=this.hash||"",i=!1,s="";this.host?i=e+this.host:this.hostname&&(i=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&o.isObject(this.query)&&Object.keys(this.query).length&&(s=b.stringify(this.query));var a=this.search||s&&"?"+s||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||v[t])&&!1!==i?(i="//"+(i||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):i||(i=""),r&&"#"!==r.charAt(0)&&(r="#"+r),a&&"?"!==a.charAt(0)&&(a="?"+a),t+i+(n=n.replace(/[?#]/g,(function(e){return encodeURIComponent(e)})))+(a=a.replace("#","%23"))+r},i.prototype.resolve=function(e){return this.resolveObject(_(e,!1,!0)).format()},i.prototype.resolveObject=function(e){if(o.isString(e)){var t=new i;t.parse(e,!1,!0),e=t}for(var n=new i,r=Object.keys(this),s=0;s<r.length;s++){var a=r[s];n[a]=this[a]}if(n.hash=e.hash,""===e.href)return n.href=n.format(),n;if(e.slashes&&!e.protocol){for(var c=Object.keys(e),u=0;u<c.length;u++){var h=c[u];"protocol"!==h&&(n[h]=e[h])}return v[n.protocol]&&n.hostname&&!n.pathname&&(n.path=n.pathname="/"),n.href=n.format(),n}if(e.protocol&&e.protocol!==n.protocol){if(!v[e.protocol]){for(var f=Object.keys(e),l=0;l<f.length;l++){var p=f[l];n[p]=e[p]}return n.href=n.format(),n}if(n.protocol=e.protocol,e.host||g[e.protocol])n.pathname=e.pathname;else{for(var d=(e.pathname||"").split("/");d.length&&!(e.host=d.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==d[0]&&d.unshift(""),d.length<2&&d.unshift(""),n.pathname=d.join("/")}if(n.search=e.search,n.query=e.query,n.host=e.host||"",n.auth=e.auth,n.hostname=e.hostname||e.host,n.port=e.port,n.pathname||n.search){var y=n.pathname||"",b=n.search||"";n.path=y+b}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var _=n.pathname&&"/"===n.pathname.charAt(0),m=e.host||e.pathname&&"/"===e.pathname.charAt(0),w=m||_||n.host&&e.pathname,E=w,S=n.pathname&&n.pathname.split("/")||[],A=(d=e.pathname&&e.pathname.split("/")||[],n.protocol&&!v[n.protocol]);if(A&&(n.hostname="",n.port=null,n.host&&(""===S[0]?S[0]=n.host:S.unshift(n.host)),n.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===d[0]?d[0]=e.host:d.unshift(e.host)),e.host=null),w=w&&(""===d[0]||""===S[0])),m)n.host=e.host||""===e.host?e.host:n.host,n.hostname=e.hostname||""===e.hostname?e.hostname:n.hostname,n.search=e.search,n.query=e.query,S=d;else if(d.length)S||(S=[]),S.pop(),S=S.concat(d),n.search=e.search,n.query=e.query;else if(!o.isNullOrUndefined(e.search)){if(A)n.hostname=n.host=S.shift(),(R=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=R.shift(),n.host=n.hostname=R.shift());return n.search=e.search,n.query=e.query,o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n}if(!S.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var O=S.slice(-1)[0],T=(n.host||e.host||S.length>1)&&("."===O||".."===O)||""===O,I=0,C=S.length;C>=0;C--)"."===(O=S[C])?S.splice(C,1):".."===O?(S.splice(C,1),I++):I&&(S.splice(C,1),I--);if(!w&&!E)for(;I--;I)S.unshift("..");!w||""===S[0]||S[0]&&"/"===S[0].charAt(0)||S.unshift(""),T&&"/"!==S.join("/").substr(-1)&&S.push("");var R,N=""===S[0]||S[0]&&"/"===S[0].charAt(0);A&&(n.hostname=n.host=N?"":S.length?S.shift():"",(R=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=R.shift(),n.host=n.hostname=R.shift()));return(w=w||n.host&&S.length)&&!N&&S.unshift(""),S.length?n.pathname=S.join("/"):(n.pathname=null,n.path=null),o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},i.prototype.parseHost=function(){var e=this.host,t=a.exec(e);t&&(":"!==(t=t[0])&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},function(e,t){e.exports=r},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}Object.defineProperty(t,"__esModule",{value:!0}),t.Observable=void 0;var s=function(){return"function"==typeof Symbol},a=function(e){return s()&&Boolean(Symbol[e])},c=function(e){return a(e)?Symbol[e]:"@@"+e};s()&&!a("observable")&&(Symbol.observable=Symbol("observable"));var u=c("iterator"),h=c("observable"),f=c("species");function l(e,t){var n=e[t];if(null!=n){if("function"!=typeof n)throw new TypeError(n+" is not a function");return n}}function p(e){var t=e.constructor;return void 0!==t&&null===(t=t[f])&&(t=void 0),void 0!==t?t:S}function d(e){return e instanceof S}function y(e){y.log?y.log(e):setTimeout((function(){throw e}))}function g(e){Promise.resolve().then((function(){try{e()}catch(e){y(e)}}))}function v(e){var t=e._cleanup;if(void 0!==t&&(e._cleanup=void 0,t))try{if("function"==typeof t)t();else{var n=l(t,"unsubscribe");n&&n.call(t)}}catch(e){y(e)}}function b(e){e._observer=void 0,e._queue=void 0,e._state="closed"}function _(e,t,n){e._state="running";var r=e._observer;try{var o=l(r,t);switch(t){case"next":o&&o.call(r,n);break;case"error":if(b(e),!o)throw n;o.call(r,n);break;case"complete":b(e),o&&o.call(r)}}catch(e){y(e)}"closed"===e._state?v(e):"running"===e._state&&(e._state="ready")}function m(e,t,n){if("closed"!==e._state){if("buffering"!==e._state)return"ready"!==e._state?(e._state="buffering",e._queue=[{type:t,value:n}],void g((function(){return function(e){var t=e._queue;if(t){e._queue=void 0,e._state="ready";for(var n=0;n<t.length&&(_(e,t[n].type,t[n].value),"closed"!==e._state);++n);}}(e)}))):void _(e,t,n);e._queue.push({type:t,value:n})}}var w=function(){function e(t,n){r(this,e),this._cleanup=void 0,this._observer=t,this._queue=void 0,this._state="initializing";var o=new E(this);try{this._cleanup=n.call(void 0,o)}catch(e){o.error(e)}"initializing"===this._state&&(this._state="ready")}return i(e,[{key:"unsubscribe",value:function(){"closed"!==this._state&&(b(this),v(this))}},{key:"closed",get:function(){return"closed"===this._state}}]),e}(),E=function(){function e(t){r(this,e),this._subscription=t}return i(e,[{key:"next",value:function(e){m(this._subscription,"next",e)}},{key:"error",value:function(e){m(this._subscription,"error",e)}},{key:"complete",value:function(){m(this._subscription,"complete")}},{key:"closed",get:function(){return"closed"===this._subscription._state}}]),e}(),S=function(){function e(t){if(r(this,e),!(this instanceof e))throw new TypeError("Observable cannot be called as a function");if("function"!=typeof t)throw new TypeError("Observable initializer must be a function");this._subscriber=t}return i(e,[{key:"subscribe",value:function(e){return"object"==typeof e&&null!==e||(e={next:e,error:arguments[1],complete:arguments[2]}),new w(e,this._subscriber)}},{key:"forEach",value:function(e){var t=this;return new Promise((function(n,r){if("function"==typeof e)var o=t.subscribe({next:function(t){try{e(t,i)}catch(e){r(e),o.unsubscribe()}},error:r,complete:n});else r(new TypeError(e+" is not a function"));function i(){o.unsubscribe(),n()}}))}},{key:"map",value:function(e){var t=this;if("function"!=typeof e)throw new TypeError(e+" is not a function");return new(p(this))((function(n){return t.subscribe({next:function(t){try{t=e(t)}catch(e){return n.error(e)}n.next(t)},error:function(e){n.error(e)},complete:function(){n.complete()}})}))}},{key:"filter",value:function(e){var t=this;if("function"!=typeof e)throw new TypeError(e+" is not a function");return new(p(this))((function(n){return t.subscribe({next:function(t){try{if(!e(t))return}catch(e){return n.error(e)}n.next(t)},error:function(e){n.error(e)},complete:function(){n.complete()}})}))}},{key:"reduce",value:function(e){var t=this;if("function"!=typeof e)throw new TypeError(e+" is not a function");var n=p(this),r=arguments.length>1,o=!1,i=arguments[1],s=i;return new n((function(n){return t.subscribe({next:function(t){var i=!o;if(o=!0,!i||r)try{s=e(s,t)}catch(e){return n.error(e)}else s=t},error:function(e){n.error(e)},complete:function(){if(!o&&!r)return n.error(new TypeError("Cannot reduce an empty sequence"));n.next(s),n.complete()}})}))}},{key:"concat",value:function(){for(var e=this,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var o=p(this);return new o((function(t){var r,i=0;return function e(s){r=s.subscribe({next:function(e){t.next(e)},error:function(e){t.error(e)},complete:function(){i===n.length?(r=void 0,t.complete()):e(o.from(n[i++]))}})}(e),function(){r&&(r.unsubscribe(),r=void 0)}}))}},{key:"flatMap",value:function(e){var t=this;if("function"!=typeof e)throw new TypeError(e+" is not a function");var n=p(this);return new n((function(r){var o=[],i=t.subscribe({next:function(t){if(e)try{t=e(t)}catch(e){return r.error(e)}var i=n.from(t).subscribe({next:function(e){r.next(e)},error:function(e){r.error(e)},complete:function(){var e=o.indexOf(i);e>=0&&o.splice(e,1),s()}});o.push(i)},error:function(e){r.error(e)},complete:function(){s()}});function s(){i.closed&&0===o.length&&r.complete()}return function(){o.forEach((function(e){return e.unsubscribe()})),i.unsubscribe()}}))}},{key:h,value:function(){return this}}],[{key:"from",value:function(t){var n="function"==typeof this?this:e;if(null==t)throw new TypeError(t+" is not an object");var r=l(t,h);if(r){var o=r.call(t);if(Object(o)!==o)throw new TypeError(o+" is not an object");return d(o)&&o.constructor===n?o:new n((function(e){return o.subscribe(e)}))}if(a("iterator")&&(r=l(t,u)))return new n((function(e){g((function(){if(!e.closed){var n=!0,o=!1,i=void 0;try{for(var s,a=r.call(t)[Symbol.iterator]();!(n=(s=a.next()).done);n=!0){var c=s.value;if(e.next(c),e.closed)return}}catch(e){o=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}e.complete()}}))}));if(Array.isArray(t))return new n((function(e){g((function(){if(!e.closed){for(var n=0;n<t.length;++n)if(e.next(t[n]),e.closed)return;e.complete()}}))}));throw new TypeError(t+" is not observable")}},{key:"of",value:function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var o="function"==typeof this?this:e;return new o((function(e){g((function(){if(!e.closed){for(var t=0;t<n.length;++t)if(e.next(n[t]),e.closed)return;e.complete()}}))}))}},{key:f,get:function(){return this}}]),e}();t.Observable=S,s()&&Object.defineProperty(S,Symbol("extensions"),{value:{symbol:h,hostReportError:y},configurable:!0})},function(e,t,n){var r,o,i=n(6),s=n(7),a=0,c=0;e.exports=function(e,t,n){var u=t&&n||0,h=t||[],f=(e=e||{}).node||r,l=void 0!==e.clockseq?e.clockseq:o;if(null==f||null==l){var p=i();null==f&&(f=r=[1|p[0],p[1],p[2],p[3],p[4],p[5]]),null==l&&(l=o=16383&(p[6]<<8|p[7]))}var d=void 0!==e.msecs?e.msecs:(new Date).getTime(),y=void 0!==e.nsecs?e.nsecs:c+1,g=d-a+(y-c)/1e4;if(g<0&&void 0===e.clockseq&&(l=l+1&16383),(g<0||d>a)&&void 0===e.nsecs&&(y=0),y>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");a=d,c=y,o=l;var v=(1e4*(268435455&(d+=122192928e5))+y)%4294967296;h[u++]=v>>>24&255,h[u++]=v>>>16&255,h[u++]=v>>>8&255,h[u++]=255&v;var b=d/4294967296*1e4&268435455;h[u++]=b>>>8&255,h[u++]=255&b,h[u++]=b>>>24&15|16,h[u++]=b>>>16&255,h[u++]=l>>>8|128,h[u++]=255&l;for(var _=0;_<6;++_)h[u+_]=f[_];return t||s(h)}},function(e,t,n){var r=n(6),o=n(7);e.exports=function(e,t,n){var i=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var s=(e=e||{}).random||(e.rng||r)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t)for(var a=0;a<16;++a)t[i+a]=s[a];return t||o(s)}},function(e,t,n){(function(e,r){var o;/*! https://mths.be/punycode v1.4.1 by @mathias */!function(i){t&&t.nodeType,e&&e.nodeType;var s="object"==typeof r&&r;s.global!==s&&s.window!==s&&s.self;var a,c=2147483647,u=/^xn--/,h=/[^\x20-\x7E]/,f=/[\x2E\u3002\uFF0E\uFF61]/g,l={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},p=Math.floor,d=String.fromCharCode;function y(e){throw new RangeError(l[e])}function g(e,t){for(var n=e.length,r=[];n--;)r[n]=t(e[n]);return r}function v(e,t){var n=e.split("@"),r="";return n.length>1&&(r=n[0]+"@",e=n[1]),r+g((e=e.replace(f,".")).split("."),t).join(".")}function b(e){for(var t,n,r=[],o=0,i=e.length;o<i;)(t=e.charCodeAt(o++))>=55296&&t<=56319&&o<i?56320==(64512&(n=e.charCodeAt(o++)))?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),o--):r.push(t);return r}function _(e){return g(e,(function(e){var t="";return e>65535&&(t+=d((e-=65536)>>>10&1023|55296),e=56320|1023&e),t+=d(e)})).join("")}function m(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function w(e,t,n){var r=0;for(e=n?p(e/700):e>>1,e+=p(e/t);e>455;r+=36)e=p(e/35);return p(r+36*e/(e+38))}function E(e){var t,n,r,o,i,s,a,u,h,f,l,d=[],g=e.length,v=0,b=128,m=72;for((n=e.lastIndexOf("-"))<0&&(n=0),r=0;r<n;++r)e.charCodeAt(r)>=128&&y("not-basic"),d.push(e.charCodeAt(r));for(o=n>0?n+1:0;o<g;){for(i=v,s=1,a=36;o>=g&&y("invalid-input"),((u=(l=e.charCodeAt(o++))-48<10?l-22:l-65<26?l-65:l-97<26?l-97:36)>=36||u>p((c-v)/s))&&y("overflow"),v+=u*s,!(u<(h=a<=m?1:a>=m+26?26:a-m));a+=36)s>p(c/(f=36-h))&&y("overflow"),s*=f;m=w(v-i,t=d.length+1,0==i),p(v/t)>c-b&&y("overflow"),b+=p(v/t),v%=t,d.splice(v++,0,b)}return _(d)}function S(e){var t,n,r,o,i,s,a,u,h,f,l,g,v,_,E,S=[];for(g=(e=b(e)).length,t=128,n=0,i=72,s=0;s<g;++s)(l=e[s])<128&&S.push(d(l));for(r=o=S.length,o&&S.push("-");r<g;){for(a=c,s=0;s<g;++s)(l=e[s])>=t&&l<a&&(a=l);for(a-t>p((c-n)/(v=r+1))&&y("overflow"),n+=(a-t)*v,t=a,s=0;s<g;++s)if((l=e[s])<t&&++n>c&&y("overflow"),l==t){for(u=n,h=36;!(u<(f=h<=i?1:h>=i+26?26:h-i));h+=36)E=u-f,_=36-f,S.push(d(m(f+E%_,0))),u=p(E/_);S.push(d(m(u,0))),i=w(n,v,r==o),n=0,++r}++n,++t}return S.join("")}a={version:"1.4.1",ucs2:{decode:b,encode:_},decode:E,encode:S,toASCII:function(e){return v(e,(function(e){return h.test(e)?"xn--"+S(e):e}))},toUnicode:function(e){return v(e,(function(e){return u.test(e)?E(e.slice(4).toLowerCase()):e}))}},void 0===(o=function(){return a}.call(t,n,t,e))||(e.exports=o)}()}).call(this,n(16)(e),n(3))},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";e.exports={isString:function(e){return"string"==typeof e},isObject:function(e){return"object"==typeof e&&null!==e},isNull:function(e){return null===e},isNullOrUndefined:function(e){return null==e}}},function(e,t,n){"use strict";t.decode=t.parse=n(19),t.encode=t.stringify=n(20)},function(e,t,n){"use strict";function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,n,i){t=t||"&",n=n||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var c=1e3;i&&"number"==typeof i.maxKeys&&(c=i.maxKeys);var u=e.length;c>0&&u>c&&(u=c);for(var h=0;h<u;++h){var f,l,p,d,y=e[h].replace(a,"%20"),g=y.indexOf(n);g>=0?(f=y.substr(0,g),l=y.substr(g+1)):(f=y,l=""),p=decodeURIComponent(f),d=decodeURIComponent(l),r(s,p)?o(s[p])?s[p].push(d):s[p]=[s[p],d]:s[p]=d}return s};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,n){"use strict";var r=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};e.exports=function(e,t,n,a){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?i(s(e),(function(s){var a=encodeURIComponent(r(s))+n;return o(e[s])?i(e[s],(function(e){return a+encodeURIComponent(r(e))})).join(t):a+encodeURIComponent(r(e[s]))})).join(t):a?encodeURIComponent(r(a))+n+encodeURIComponent(r(e)):""};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function i(e,t){if(e.map)return e.map(t);for(var n=[],r=0;r<e.length;r++)n.push(t(e[r],r));return n}var s=Object.keys||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t}},function(e,t,n){"use strict";t.byteLength=function(e){var t=u(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,r=u(e),s=r[0],a=r[1],c=new i(function(e,t,n){return 3*(t+n)/4-n}(0,s,a)),h=0,f=a>0?s-4:s;for(n=0;n<f;n+=4)t=o[e.charCodeAt(n)]<<18|o[e.charCodeAt(n+1)]<<12|o[e.charCodeAt(n+2)]<<6|o[e.charCodeAt(n+3)],c[h++]=t>>16&255,c[h++]=t>>8&255,c[h++]=255&t;2===a&&(t=o[e.charCodeAt(n)]<<2|o[e.charCodeAt(n+1)]>>4,c[h++]=255&t);1===a&&(t=o[e.charCodeAt(n)]<<10|o[e.charCodeAt(n+1)]<<4|o[e.charCodeAt(n+2)]>>2,c[h++]=t>>8&255,c[h++]=255&t);return c},t.fromByteArray=function(e){for(var t,n=e.length,o=n%3,i=[],s=0,a=n-o;s<a;s+=16383)i.push(h(e,s,s+16383>a?a:s+16383));1===o?(t=e[n-1],i.push(r[t>>2]+r[t<<4&63]+"==")):2===o&&(t=(e[n-2]<<8)+e[n-1],i.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"="));return i.join("")};for(var r=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=s.length;a<c;++a)r[a]=s[a],o[s.charCodeAt(a)]=a;function u(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function h(e,t,n){for(var o,i,s=[],a=t;a<n;a+=3)o=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(r[(i=o)>>18&63]+r[i>>12&63]+r[i>>6&63]+r[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(e,t){
9
9
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
10
- t.read=function(e,t,n,r,o){var i,s,a=8*o-r-1,c=(1<<a)-1,u=c>>1,h=-7,f=n?o-1:0,l=n?-1:1,p=e[t+f];for(f+=l,i=p&(1<<-h)-1,p>>=-h,h+=a;h>0;i=256*i+e[t+f],f+=l,h-=8);for(s=i&(1<<-h)-1,i>>=-h,h+=r;h>0;s=256*s+e[t+f],f+=l,h-=8);if(0===i)i=1-u;else{if(i===c)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,r),i-=u}return(p?-1:1)*s*Math.pow(2,i-r)},t.write=function(e,t,n,r,o,i){var s,a,c,u=8*i-o-1,h=(1<<u)-1,f=h>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:i-1,d=r?1:-1,y=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=h):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+f>=1?l/c:l*Math.pow(2,1-f))*c>=2&&(s++,c/=2),s+f>=h?(a=0,s=h):s+f>=1?(a=(t*c-1)*Math.pow(2,o),s+=f):(a=t*Math.pow(2,f-1)*Math.pow(2,o),s=0));o>=8;e[n+p]=255&a,p+=d,a/=256,o-=8);for(s=s<<o|a,u+=o;u>0;e[n+p]=255&s,p+=d,s/=256,u-=8);e[n+p-d]|=128*y}},function(e,t){var n={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},function(e,t,n){"use strict";n.r(t),n.d(t,"AbstractPubSubProvider",(function(){return h})),n.d(t,"AWSAppSyncProvider",(function(){return k})),n.d(t,"AWSAppSyncRealTimeProvider",(function(){return H})),n.d(t,"AWSIoTProvider",(function(){return se})),n.d(t,"mqttTopicMatch",(function(){return _})),n.d(t,"MqttOverWSProvider",(function(){return O})),n.d(t,"PubSub",(function(){return te})),n.d(t,"CONTROL_MSG",(function(){return ne}));var r=n(8),o=n.n(r).a,i=n(0),s=n(9),a=n(2),c=function(){return(c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},u=new i.ConsoleLogger("AbstractPubSubProvider"),h=function(){function e(e){void 0===e&&(e={}),this._config=e}return e.prototype.configure=function(e){return void 0===e&&(e={}),this._config=c(c({},e),this._config),u.debug("configure "+this.getProviderName(),this._config),this.options},e.prototype.getCategory=function(){return"PubSub"},Object.defineProperty(e.prototype,"options",{get:function(){return c({},this._config)},enumerable:!0,configurable:!0}),e}();function f(e){return(f="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)}var l,p=(l=function(e,t){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),d=function(){return(d=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},y=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},g=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},v=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n},b=new i.ConsoleLogger("MqttOverWSProvider");function _(e,t){for(var n=e.split("/"),r=n.length,o=t.split("/"),i=0;i<r;++i){var s=n[i],a=o[i];if("#"===s)return o.length>=r;if("+"!==s&&s!==a)return!1}return r===o.length}var m,w,E,S=function(){function e(){this.promises=new Map}return e.prototype.get=function(e,t){return y(this,void 0,void 0,(function(){var n;return g(this,(function(r){return(n=this.promises.get(e))||(n=t(e),this.promises.set(e,n)),[2,n]}))}))},Object.defineProperty(e.prototype,"allClients",{get:function(){return Array.from(this.promises.keys())},enumerable:!0,configurable:!0}),e.prototype.remove=function(e){this.promises.delete(e)},e}(),A="undefined"!=typeof Symbol?Symbol("topic"):"@@topic",O=function(e){function t(t){void 0===t&&(t={});var n=e.call(this,d(d({},t),{clientId:t.clientId||Object(a.v4)()}))||this;return n._clientsQueue=new S,n._topicObservers=new Map,n._clientIdObservers=new Map,n}return p(t,e),Object.defineProperty(t.prototype,"clientId",{get:function(){return this.options.clientId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"endpoint",{get:function(){return this.options.aws_pubsub_endpoint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"clientsQueue",{get:function(){return this._clientsQueue},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isSSLEnabled",{get:function(){return!this.options.aws_appsync_dangerously_connect_to_http_endpoint_for_testing},enumerable:!0,configurable:!0}),t.prototype.getTopicForValue=function(e){return"object"===f(e)&&e[A]},t.prototype.getProviderName=function(){return"MqttOverWSProvider"},t.prototype.onDisconnect=function(e){var t=this,n=e.clientId,r=e.errorCode,o=v(e,["clientId","errorCode"]);if(0!==r){b.warn(n,JSON.stringify(d({errorCode:r},o),null,2));var i=[],s=this._clientIdObservers.get(n);if(!s)return;s.forEach((function(e){e.error("Disconnected, error code: "+r),t._topicObservers.forEach((function(t,n){t.delete(e),0===t.size&&i.push(n)}))})),this._clientIdObservers.delete(n),i.forEach((function(e){t._topicObservers.delete(e)}))}},t.prototype.newClient=function(e){var t=e.url,n=e.clientId;return y(this,void 0,void 0,(function(){var e,r=this;return g(this,(function(o){switch(o.label){case 0:return b.debug("Creating new MQTT client",n),(e=new s.Client(t,n)).onMessageArrived=function(e){var t=e.destinationName,n=e.payloadString;r._onMessage(t,n)},e.onConnectionLost=function(e){var t=e.errorCode,o=v(e,["errorCode"]);r.onDisconnect(d({clientId:n,errorCode:t},o))},[4,new Promise((function(t,n){e.connect({useSSL:r.isSSLEnabled,mqttVersion:3,onSuccess:function(){return t(e)},onFailure:n})}))];case 1:return o.sent(),[2,e]}}))}))},t.prototype.connect=function(e,t){return void 0===t&&(t={}),y(this,void 0,void 0,(function(){var n=this;return g(this,(function(r){switch(r.label){case 0:return[4,this.clientsQueue.get(e,(function(e){return n.newClient(d(d({},t),{clientId:e}))}))];case 1:return[2,r.sent()]}}))}))},t.prototype.disconnect=function(e){return y(this,void 0,void 0,(function(){var t;return g(this,(function(n){switch(n.label){case 0:return[4,this.clientsQueue.get(e,(function(){return null}))];case 1:return(t=n.sent())&&t.isConnected()&&t.disconnect(),this.clientsQueue.remove(e),[2]}}))}))},t.prototype.publish=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i;return g(this,(function(s){switch(s.label){case 0:return n=[].concat(e),r=JSON.stringify(t),[4,this.endpoint];case 1:return o=s.sent(),[4,this.connect(this.clientId,{url:o})];case 2:return i=s.sent(),b.debug("Publishing to topic(s)",n.join(","),r),n.forEach((function(e){return i.send(e,r)})),[2]}}))}))},t.prototype._onMessage=function(e,t){try{var n=[];this._topicObservers.forEach((function(t,r){_(r,e)&&n.push(t)}));var r=JSON.parse(t);"object"===f(r)&&(r[A]=e),n.forEach((function(e){e.forEach((function(e){return e.next(r)}))}))}catch(e){b.warn("Error handling message",e,t)}},t.prototype.subscribe=function(e,t){var n=this;void 0===t&&(t={});var r=[].concat(e);return b.debug("Subscribing to topic(s)",r.join(",")),new o((function(e){var o;r.forEach((function(t){var r=n._topicObservers.get(t);r||(r=new Set,n._topicObservers.set(t,r)),r.add(e)}));var i=t.clientId,s=void 0===i?n.clientId:i,a=n._clientIdObservers.get(s);return a||(a=new Set),a.add(e),n._clientIdObservers.set(s,a),y(n,void 0,void 0,(function(){var n,i,a,c;return g(this,(function(u){switch(u.label){case 0:return void 0!==(n=t.url)?[3,2]:[4,this.endpoint];case 1:return a=u.sent(),[3,3];case 2:a=n,u.label=3;case 3:i=a,u.label=4;case 4:return u.trys.push([4,6,,7]),[4,this.connect(s,{url:i})];case 5:return o=u.sent(),r.forEach((function(e){o.subscribe(e)})),[3,7];case 6:return c=u.sent(),e.error(c),[3,7];case 7:return[2]}}))})),function(){return b.debug("Unsubscribing from topic(s)",r.join(",")),o&&(n._clientIdObservers.get(s).delete(e),0===n._clientIdObservers.get(s).size&&(n.disconnect(s),n._clientIdObservers.delete(s)),r.forEach((function(t){var r=n._topicObservers.get(t)||new Set;r.delete(e),0===r.size&&(n._topicObservers.delete(t),o.isConnected()&&o.unsubscribe(t))}))),null}}))},t}(h),T=function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),I=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},R=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},C=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n},N=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},M=function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(N(arguments[t]));return e},P=new i.ConsoleLogger("AWSAppSyncProvider"),k=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._topicClient=new Map,t._topicAlias=new Map,t}return T(t,e),Object.defineProperty(t.prototype,"endpoint",{get:function(){throw new Error("Not supported")},enumerable:!0,configurable:!0}),t.prototype.getProviderName=function(){return"AWSAppSyncProvider"},t.prototype.publish=function(e,t,n){return I(this,void 0,void 0,(function(){return R(this,(function(e){throw new Error("Operation not supported")}))}))},t.prototype._cleanUp=function(e){var t=this;Array.from(this._topicClient.entries()).filter((function(t){return N(t,2)[1].clientId===e})).map((function(e){return N(e,1)[0]})).forEach((function(e){return t._cleanUpForTopic(e)}))},t.prototype._cleanUpForTopic=function(e){this._topicClient.delete(e),this._topicAlias.delete(e)},t.prototype.onDisconnect=function(e){var t=this,n=e.clientId,r=e.errorCode,o=C(e,["clientId","errorCode"]);0!==r&&(Array.from(this._topicClient.entries()).filter((function(e){return N(e,2)[1].clientId===n})).map((function(e){return N(e,1)[0]})).forEach((function(e){t._topicObservers.has(e)&&(t._topicObservers.get(e).forEach((function(e){e.closed||e.error(o)})),t._topicObservers.delete(e))})),this._cleanUp(n))},t.prototype.disconnect=function(t){return I(this,void 0,void 0,(function(){return R(this,(function(n){switch(n.label){case 0:return[4,this.clientsQueue.get(t,(function(){return null}))];case 1:return n.sent(),[4,e.prototype.disconnect.call(this,t)];case 2:return n.sent(),this._cleanUp(t),[2]}}))}))},t.prototype.subscribe=function(e,t){var n=this;void 0===t&&(t={});var r=new o((function(r){var o=[].concat(e);return P.debug("Subscribing to topic(s)",o.join(",")),I(n,void 0,void 0,(function(){var e,n,i,s,a,c=this;return R(this,(function(u){switch(u.label){case 0:return o.forEach((function(e){c._topicObservers.has(e)||c._topicObservers.set(e,new Set),c._topicObservers.get(e).add(r)})),e=t.mqttConnections,n=void 0===e?[]:e,i=t.newSubscriptions,s=Object.entries(i).map((function(e){var t=N(e,2),n=t[0];return[t[1].topic,n]})),this._topicAlias=new Map(M(Array.from(this._topicAlias.entries()),s)),a=Object.entries(o.reduce((function(e,t){var r=n.find((function(e){return e.topics.indexOf(t)>-1}));if(r){var o=r.client,i=r.url;e[o]||(e[o]={url:i,topics:new Set}),e[o].topics.add(t)}return e}),{})),[4,Promise.all(a.map((function(e){var t=N(e,2),n=t[0],o=t[1],i=o.url,s=o.topics;return I(c,void 0,void 0,(function(){var e,t,o=this;return R(this,(function(a){switch(a.label){case 0:e=null,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.connect(n,{clientId:n,url:i})];case 2:return e=a.sent(),[3,4];case 3:return t=a.sent(),r.error({message:"Failed to connect",error:t}),r.complete(),[2,void 0];case 4:return s.forEach((function(t){e.isConnected()&&(e.subscribe(t),o._topicClient.set(t,e))})),[2,e]}}))}))})))];case 1:return u.sent(),[2]}}))})),function(){P.debug("Unsubscribing from topic(s)",o.join(",")),o.forEach((function(e){var t=n._topicClient.get(e);t&&t.isConnected()&&(t.unsubscribe(e),n._topicClient.delete(e),Array.from(n._topicClient.values()).some((function(e){return e===t}))||n.disconnect(t.clientId)),n._topicObservers.delete(e)}))}}));return o.from(r).map((function(e){var t=n.getTopicForValue(e),r=n._topicAlias.get(t);return e.data=Object.entries(e.data).reduce((function(e,t){var n=N(t,2),o=n[0],i=n[1];return e[r||o]=i,e}),{}),e}))},t}(O),x=n(1),U=n(10),L=n(4),D=n(11),q=n.n(D),B=n(5),j=n.n(B),V=function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),F=function(){return(F=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},G=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},Y=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},Q=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},K=new i.Logger("AWSAppSyncRealTimeProvider"),z="undefined"!=typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("amplify_default"):"@@amplify_default",J=[400,401,403];!function(e){e.GQL_CONNECTION_INIT="connection_init",e.GQL_CONNECTION_ERROR="connection_error",e.GQL_CONNECTION_ACK="connection_ack",e.GQL_START="start",e.GQL_START_ACK="start_ack",e.GQL_DATA="data",e.GQL_CONNECTION_KEEP_ALIVE="ka",e.GQL_STOP="stop",e.GQL_COMPLETE="complete",e.GQL_ERROR="error"}(m||(m={})),function(e){e[e.PENDING=0]="PENDING",e[e.CONNECTED=1]="CONNECTED",e[e.FAILED=2]="FAILED"}(w||(w={})),function(e){e[e.CLOSED=0]="CLOSED",e[e.READY=1]="READY",e[e.CONNECTING=2]="CONNECTING"}(E||(E={}));var W={accept:"application/json, text/javascript","content-encoding":"amz-1.0","content-type":"application/json; charset=UTF-8"},H=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.socketStatus=E.CLOSED,t.keepAliveTimeout=3e5,t.subscriptionObserverMap=new Map,t.promiseArray=[],t}return V(t,e),t.prototype.getProviderName=function(){return"AWSAppSyncRealTimeProvider"},t.prototype.newClient=function(){throw new Error("Not used here")},t.prototype.publish=function(e,t,n){return G(this,void 0,void 0,(function(){return Y(this,(function(e){throw new Error("Operation not supported")}))}))},t.prototype.subscribe=function(e,t){var n=this,r=t.appSyncGraphqlEndpoint;return new o((function(e){if(r){var o=Object(a.v4)();return n._startSubscriptionWithAWSAppSyncRealTime({options:t,observer:e,subscriptionId:o}).catch((function(t){e.error({errors:[F({},new x.GraphQLError(ne.REALTIME_SUBSCRIPTION_INIT_ERROR+": "+t))]}),e.complete()})),function(){return G(n,void 0,void 0,(function(){var e,t;return Y(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,3,4]),[4,this._waitForSubscriptionToBeConnected(o)];case 1:if(n.sent(),!(e=(this.subscriptionObserverMap.get(o)||{}).subscriptionState))return[2];if(e!==w.CONNECTED)throw new Error("Subscription never connected");return this._sendUnsubscriptionMessage(o),[3,4];case 2:return t=n.sent(),K.debug("Error while unsubscribing "+t),[3,4];case 3:return this._removeSubscriptionObserver(o),[7];case 4:return[2]}}))}))}}e.error({errors:[F({},new x.GraphQLError("Subscribe only available for AWS AppSync endpoint"))]}),e.complete()}))},Object.defineProperty(t.prototype,"isSSLEnabled",{get:function(){return!this.options.aws_appsync_dangerously_connect_to_http_endpoint_for_testing},enumerable:!0,configurable:!0}),t.prototype._startSubscriptionWithAWSAppSyncRealTime=function(e){var t=e.options,n=e.observer,r=e.subscriptionId;return G(this,void 0,void 0,(function(){var e,o,s,a,c,u,h,f,l,p,d,y,g,v,b,_,E,S,A,O,T,I,R,C,N,M,P=this;return Y(this,(function(k){switch(k.label){case 0:return e=t.appSyncGraphqlEndpoint,o=t.authenticationType,s=t.query,a=t.variables,c=t.apiKey,u=t.region,h=t.graphql_headers,f=void 0===h?function(){return{}}:h,l=t.additionalHeaders,p=void 0===l?{}:l,d=w.PENDING,y={query:s,variables:a},this.subscriptionObserverMap.set(r,{observer:n,query:s,variables:a,subscriptionState:d,startAckTimeoutId:null}),g=JSON.stringify(y),b=[{}],[4,this._awsRealTimeHeaderBasedAuth({apiKey:c,appSyncGraphqlEndpoint:e,authenticationType:o,payload:g,canonicalUri:"",region:u,additionalHeaders:p})];case 1:return _=[F.apply(void 0,b.concat([k.sent()]))],[4,f()];case 2:v=F.apply(void 0,[F.apply(void 0,[F.apply(void 0,_.concat([k.sent()])),p]),(M={},M[i.USER_AGENT_HEADER]=i.Constants.userAgent,M)]),E={id:r,payload:{data:g,extensions:{authorization:F({},v)}},type:m.GQL_START},S=JSON.stringify(E),k.label=3;case 3:return k.trys.push([3,5,,6]),[4,this._initializeWebSocketConnection({apiKey:c,appSyncGraphqlEndpoint:e,authenticationType:o,region:u,additionalHeaders:p})];case 4:return k.sent(),[3,6];case 5:return A=k.sent(),K.debug({err:A}),O=A.message,T=void 0===O?"":O,n.error({errors:[F({},new x.GraphQLError(ne.CONNECTION_FAILED+": "+T))]}),n.complete(),"function"==typeof(I=(this.subscriptionObserverMap.get(r)||{}).subscriptionFailedCallback)&&I(),[2];case 6:return R=this.subscriptionObserverMap.get(r),C=R.subscriptionFailedCallback,N=R.subscriptionReadyCallback,this.subscriptionObserverMap.set(r,{observer:n,subscriptionState:d,variables:a,query:s,subscriptionReadyCallback:N,subscriptionFailedCallback:C,startAckTimeoutId:setTimeout((function(){P._timeoutStartSubscriptionAck.call(P,r)}),15e3)}),this.awsRealTimeSocket&&this.awsRealTimeSocket.send(S),[2]}}))}))},t.prototype._waitForSubscriptionToBeConnected=function(e){return G(this,void 0,void 0,(function(){var t=this;return Y(this,(function(n){return this.subscriptionObserverMap.get(e).subscriptionState===w.PENDING?[2,new Promise((function(n,r){var o=t.subscriptionObserverMap.get(e),i=o.observer,s=o.subscriptionState,a=o.variables,c=o.query;t.subscriptionObserverMap.set(e,{observer:i,subscriptionState:s,variables:a,query:c,subscriptionReadyCallback:n,subscriptionFailedCallback:r})}))]:[2]}))}))},t.prototype._sendUnsubscriptionMessage=function(e){try{if(this.awsRealTimeSocket&&this.awsRealTimeSocket.readyState===WebSocket.OPEN&&this.socketStatus===E.READY){var t={id:e,type:m.GQL_STOP},n=JSON.stringify(t);this.awsRealTimeSocket.send(n)}}catch(e){K.debug({err:e})}},t.prototype._removeSubscriptionObserver=function(e){this.subscriptionObserverMap.delete(e),setTimeout(this._closeSocketIfRequired.bind(this),1e3)},t.prototype._closeSocketIfRequired=function(){if(!(this.subscriptionObserverMap.size>0))if(this.awsRealTimeSocket)if(this.awsRealTimeSocket.bufferedAmount>0)setTimeout(this._closeSocketIfRequired.bind(this),1e3);else{K.debug("closing WebSocket..."),clearTimeout(this.keepAliveTimeoutId);var e=this.awsRealTimeSocket;e.onclose=void 0,e.onerror=void 0,e.close(1e3),this.awsRealTimeSocket=null,this.socketStatus=E.CLOSED}else this.socketStatus=E.CLOSED},t.prototype._handleIncomingSubscriptionMessage=function(e){K.debug("subscription message from AWS AppSync RealTime: "+e.data);var t=JSON.parse(e.data),n=t.id,r=void 0===n?"":n,o=t.payload,s=t.type,a=this.subscriptionObserverMap.get(r)||{},c=a.observer,u=void 0===c?null:c,h=a.query,f=void 0===h?"":h,l=a.variables,p=void 0===l?{}:l,d=a.startAckTimeoutId,y=a.subscriptionReadyCallback,g=a.subscriptionFailedCallback;if(K.debug({id:r,observer:u,query:f,variables:p}),s===m.GQL_DATA&&o&&o.data)u?u.next(o):K.debug("observer not found for id: "+r);else if(s!==m.GQL_START_ACK){if(s===m.GQL_CONNECTION_KEEP_ALIVE)return clearTimeout(this.keepAliveTimeoutId),void(this.keepAliveTimeoutId=setTimeout(this._errorDisconnect.bind(this,ne.TIMEOUT_DISCONNECT),this.keepAliveTimeout));if(s===m.GQL_ERROR){v=w.FAILED;this.subscriptionObserverMap.set(r,{observer:u,query:f,variables:p,startAckTimeoutId:d,subscriptionReadyCallback:y,subscriptionFailedCallback:g,subscriptionState:v}),u.error({errors:[F({},new x.GraphQLError(ne.CONNECTION_FAILED+": "+JSON.stringify(o)))]}),clearTimeout(d),u.complete(),"function"==typeof g&&g()}}else{K.debug("subscription ready for "+JSON.stringify({query:f,variables:p})),"function"==typeof y&&y(),clearTimeout(d),function(e,t,n){i.Hub.dispatch("api",{event:e,data:t,message:n},"PubSub",z)}(ne.SUBSCRIPTION_ACK,{query:f,variables:p},"Connection established for subscription");var v=w.CONNECTED;this.subscriptionObserverMap.set(r,{observer:u,query:f,variables:p,startAckTimeoutId:null,subscriptionState:v,subscriptionReadyCallback:y,subscriptionFailedCallback:g})}},t.prototype._errorDisconnect=function(e){K.debug("Disconnect error: "+e),this.subscriptionObserverMap.forEach((function(t){var n=t.observer;n&&!n.closed&&n.error({errors:[F({},new x.GraphQLError(e))]})})),this.subscriptionObserverMap.clear(),this.awsRealTimeSocket&&this.awsRealTimeSocket.close(),this.socketStatus=E.CLOSED},t.prototype._timeoutStartSubscriptionAck=function(e){var t=this.subscriptionObserverMap.get(e)||{},n=t.observer,r=t.query,o=t.variables;n&&(this.subscriptionObserverMap.set(e,{observer:n,query:r,variables:o,subscriptionState:w.FAILED}),n&&!n.closed&&(n.error({errors:[F({},new x.GraphQLError("Subscription timeout "+JSON.stringify({query:r,variables:o})))]}),n.complete()),K.debug("timeoutStartSubscription",JSON.stringify({query:r,variables:o})))},t.prototype._initializeWebSocketConnection=function(e){var t=this,n=e.appSyncGraphqlEndpoint,r=e.authenticationType,o=e.apiKey,i=e.region,s=e.additionalHeaders;if(this.socketStatus!==E.READY)return new Promise((function(e,a){return G(t,void 0,void 0,(function(){var t,c,u,h,f,l,p,d,y,g;return Y(this,(function(v){switch(v.label){case 0:if(this.promiseArray.push({res:e,rej:a}),this.socketStatus!==E.CLOSED)return[3,5];v.label=1;case 1:return v.trys.push([1,4,,5]),this.socketStatus=E.CONNECTING,t=this.isSSLEnabled?"wss://":"ws://",c=n.replace("https://",t).replace("http://",t).replace("appsync-api","appsync-realtime-api").replace("gogi-beta","grt-beta"),u="{}",l=(f=JSON).stringify,[4,this._awsRealTimeHeaderBasedAuth({authenticationType:r,payload:u,canonicalUri:"/connect",apiKey:o,appSyncGraphqlEndpoint:n,region:i,additionalHeaders:s})];case 2:return h=l.apply(f,[v.sent()]),p=L.Buffer.from(h).toString("base64"),d=L.Buffer.from(u).toString("base64"),y=c+"?header="+p+"&payload="+d,[4,this._initializeRetryableHandshake({awsRealTimeUrl:y})];case 3:return v.sent(),this.promiseArray.forEach((function(e){var t=e.res;K.debug("Notifying connection successful"),t()})),this.socketStatus=E.READY,this.promiseArray=[],[3,5];case 4:return g=v.sent(),this.promiseArray.forEach((function(e){return(0,e.rej)(g)})),this.promiseArray=[],this.awsRealTimeSocket&&this.awsRealTimeSocket.readyState===WebSocket.OPEN&&this.awsRealTimeSocket.close(3001),this.awsRealTimeSocket=null,this.socketStatus=E.CLOSED,[3,5];case 5:return[2]}}))}))}))},t.prototype._initializeRetryableHandshake=function(e){var t=e.awsRealTimeUrl;return G(this,void 0,void 0,(function(){return Y(this,(function(e){switch(e.label){case 0:return K.debug("Initializaling retryable Handshake"),[4,Object(i.jitteredExponentialRetry)(this._initializeHandshake.bind(this),[{awsRealTimeUrl:t}],5e3)];case 1:return e.sent(),[2]}}))}))},t.prototype._initializeHandshake=function(e){var t=e.awsRealTimeUrl;return G(this,void 0,void 0,(function(){var e,n,r,o=this;return Y(this,(function(s){switch(s.label){case 0:K.debug("Initializing handshake "+t),s.label=1;case 1:return s.trys.push([1,4,,5]),[4,new Promise((function(e,n){var r=new WebSocket(t,"graphql-ws");r.onerror=function(){K.debug("WebSocket connection error")},r.onclose=function(){n(new Error("Connection handshake error"))},r.onopen=function(){return o.awsRealTimeSocket=r,e()}}))];case 2:return s.sent(),[4,new Promise((function(e,t){var n=!1;o.awsRealTimeSocket.onerror=function(e){K.debug("WebSocket error "+JSON.stringify(e))},o.awsRealTimeSocket.onclose=function(e){K.debug("WebSocket closed "+e.reason),t(new Error(JSON.stringify(e)))},o.awsRealTimeSocket.onmessage=function(r){K.debug("subscription message from AWS AppSyncRealTime: "+r.data+" ");var i=JSON.parse(r.data),s=i.type,a=i.payload,c=(void 0===a?{}:a).connectionTimeoutMs,u=void 0===c?3e5:c;if(s===m.GQL_CONNECTION_ACK)return n=!0,o.keepAliveTimeout=u,o.awsRealTimeSocket.onmessage=o._handleIncomingSubscriptionMessage.bind(o),o.awsRealTimeSocket.onerror=function(e){K.debug(e),o._errorDisconnect(ne.CONNECTION_CLOSED)},o.awsRealTimeSocket.onclose=function(e){K.debug("WebSocket closed "+e.reason),o._errorDisconnect(ne.CONNECTION_CLOSED)},void e("Cool, connected to AWS AppSyncRealTime");if(s===m.GQL_CONNECTION_ERROR){var h=i.payload,f=(void 0===h?{}:h).errors,l=Q(void 0===f?[]:f,1)[0],p=void 0===l?{}:l,d=p.errorType,y=void 0===d?"":d,g=p.errorCode;t({errorType:y,errorCode:void 0===g?0:g})}};var r={type:m.GQL_CONNECTION_INIT};o.awsRealTimeSocket.send(JSON.stringify(r)),setTimeout(function(){n||t(new Error("Connection timeout: ack from AWSRealTime was not received on 15000 ms"))}.bind(o),15e3)}))];case 3:return s.sent(),[3,5];case 4:throw e=s.sent(),n=e.errorType,r=e.errorCode,J.includes(r)?new i.NonRetryableError(n):n?new Error(n):e;case 5:return[2]}}))}))},t.prototype._awsRealTimeHeaderBasedAuth=function(e){var t=e.authenticationType,n=e.payload,r=e.canonicalUri,o=e.appSyncGraphqlEndpoint,i=e.apiKey,s=e.region,a=e.additionalHeaders;return G(this,void 0,void 0,(function(){var e,c,u;return Y(this,(function(h){switch(h.label){case 0:return e={API_KEY:this._awsRealTimeApiKeyHeader.bind(this),AWS_IAM:this._awsRealTimeIAMHeader.bind(this),OPENID_CONNECT:this._awsRealTimeOPENIDHeader.bind(this),AMAZON_COGNITO_USER_POOLS:this._awsRealTimeCUPHeader.bind(this),AWS_LAMBDA:this._customAuthHeader},"function"!=typeof(c=e[t])?(K.debug("Authentication type "+t+" not supported"),[2,""]):(u=U.parse(o).host,[4,c({payload:n,canonicalUri:r,appSyncGraphqlEndpoint:o,apiKey:i,region:s,host:u,additionalHeaders:a})]);case 1:return[2,h.sent()]}}))}))},t.prototype._awsRealTimeCUPHeader=function(e){var t=e.host;return G(this,void 0,void 0,(function(){return Y(this,(function(e){switch(e.label){case 0:return[4,j.a.currentSession()];case 1:return[2,{Authorization:e.sent().getAccessToken().getJwtToken(),host:t}]}}))}))},t.prototype._awsRealTimeOPENIDHeader=function(e){var t=e.host;return G(this,void 0,void 0,(function(){var e,n,r;return Y(this,(function(o){switch(o.label){case 0:return[4,q.a.getItem("federatedInfo")];case 1:return(n=o.sent())?(e=n.token,[3,4]):[3,2];case 2:return[4,j.a.currentAuthenticatedUser()];case 3:(r=o.sent())&&(e=r.token),o.label=4;case 4:if(!e)throw new Error("No federated jwt");return[2,{Authorization:e,host:t}]}}))}))},t.prototype._awsRealTimeApiKeyHeader=function(e){var t=e.apiKey,n=e.host;return G(this,void 0,void 0,(function(){var e,r;return Y(this,(function(o){return e=new Date,r=e.toISOString().replace(/[:\-]|\.\d{3}/g,""),[2,{host:n,"x-amz-date":r,"x-api-key":t}]}))}))},t.prototype._awsRealTimeIAMHeader=function(e){var t=e.payload,n=e.canonicalUri,r=e.appSyncGraphqlEndpoint,o=e.region;return G(this,void 0,void 0,(function(){var e,s,a;return Y(this,(function(c){switch(c.label){case 0:return e={region:o,service:"appsync"},[4,this._ensureCredentials()];case 1:if(!c.sent())throw new Error("No credentials");return[4,i.Credentials.get().then((function(e){return{secret_key:e.secretAccessKey,access_key:e.accessKeyId,session_token:e.sessionToken}}))];case 2:return s=c.sent(),a={url:""+r+n,data:t,method:"POST",headers:F({},W)},[2,i.Signer.sign(a,s,e).headers]}}))}))},t.prototype._customAuthHeader=function(e){var t=e.host,n=e.additionalHeaders;if(!n.Authorization)throw new Error("No auth token specified");return{Authorization:n.Authorization,host:t}},t.prototype._ensureCredentials=function(){return i.Credentials.get().then((function(e){if(!e)return!1;var t=i.Credentials.shear(e);return K.debug("set credentials for AWSAppSyncRealTimeProvider",t),!0})).catch((function(e){return K.warn("ensure credentials error",e),!1}))},t}(h),$=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},X=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},Z=Object(i.browserOrNode)().isNode,ee=new i.ConsoleLogger("PubSub"),te=new(function(){function e(e){this._options=e,ee.debug("PubSub Options",this._options),this._pluggables=[],this.subscribe=this.subscribe.bind(this)}return Object.defineProperty(e.prototype,"awsAppSyncProvider",{get:function(){return this._awsAppSyncProvider||(this._awsAppSyncProvider=new k(this._options)),this._awsAppSyncProvider},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"awsAppSyncRealTimeProvider",{get:function(){return this._awsAppSyncRealTimeProvider||(this._awsAppSyncRealTimeProvider=new H(this._options)),this._awsAppSyncRealTimeProvider},enumerable:!0,configurable:!0}),e.prototype.getModuleName=function(){return"PubSub"},e.prototype.configure=function(e){var t=this,n=e?e.PubSub||e:{};return ee.debug("configure PubSub",{opt:n}),this._options=Object.assign({},this._options,n),this._pluggables.map((function(e){return e.configure(t._options)})),this._options},e.prototype.addPluggable=function(e){return $(this,void 0,void 0,(function(){return X(this,(function(t){return e&&"PubSub"===e.getCategory()?(this._pluggables.push(e),[2,e.configure(this._options)]):[2]}))}))},e.prototype.removePluggable=function(e){this._pluggables=this._pluggables.filter((function(t){return t.getProviderName()!==e}))},e.prototype.getProviderByName=function(e){return e===i.INTERNAL_AWS_APPSYNC_PUBSUB_PROVIDER?this.awsAppSyncProvider:e===i.INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER?this.awsAppSyncRealTimeProvider:this._pluggables.find((function(t){return t.getProviderName()===e}))},e.prototype.getProviders=function(e){void 0===e&&(e={});var t=e.provider;if(!t)return this._pluggables;var n=this.getProviderByName(t);if(!n)throw new Error("Could not find provider named "+t);return[n]},e.prototype.publish=function(e,t,n){return $(this,void 0,void 0,(function(){return X(this,(function(r){return[2,Promise.all(this.getProviders(n).map((function(r){return r.publish(e,t,n)})))]}))}))},e.prototype.subscribe=function(e,t){if(Z&&this._options&&this._options.ssr)throw new Error("Subscriptions are not supported for Server-Side Rendering (SSR)");ee.debug("subscribe options",t);var n=this.getProviders(t);return new o((function(r){var o=n.map((function(n){return{provider:n,observable:n.subscribe(e,t)}})).map((function(e){var t=e.provider;return e.observable.subscribe({start:console.error,next:function(e){return r.next({provider:t,value:e})},error:function(e){return r.error({provider:t,error:e})}})}));return function(){return o.forEach((function(e){return e.unsubscribe()}))}}))},e}())(null);i.Amplify.register(te);var ne,re=function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),oe=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},ie=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},se=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return re(t,e),Object.defineProperty(t.prototype,"region",{get:function(){return this.options.aws_pubsub_region},enumerable:!0,configurable:!0}),t.prototype.getProviderName=function(){return"AWSIoTProvider"},Object.defineProperty(t.prototype,"endpoint",{get:function(){return oe(this,void 0,void 0,(function(){var e,t,n,r,o,s;return ie(this,(function(a){switch(a.label){case 0:return e=this.options.aws_pubsub_endpoint,t={service:"iotdevicegateway",region:this.region},[4,i.Credentials.get()];case 1:return n=a.sent(),r=n.accessKeyId,o=n.secretAccessKey,s=n.sessionToken,[2,i.Signer.signUrl(e,{access_key:r,secret_key:o,session_token:s},t)]}}))}))},enumerable:!0,configurable:!0}),t}(O);!function(e){e.CONNECTION_CLOSED="Connection closed",e.CONNECTION_FAILED="Connection failed",e.REALTIME_SUBSCRIPTION_INIT_ERROR="AppSync Realtime subscription init error",e.SUBSCRIPTION_ACK="Subscription ack",e.TIMEOUT_DISCONNECT="Timeout disconnect"}(ne||(ne={}));t.default=te}])}));
10
+ t.read=function(e,t,n,r,o){var i,s,a=8*o-r-1,c=(1<<a)-1,u=c>>1,h=-7,f=n?o-1:0,l=n?-1:1,p=e[t+f];for(f+=l,i=p&(1<<-h)-1,p>>=-h,h+=a;h>0;i=256*i+e[t+f],f+=l,h-=8);for(s=i&(1<<-h)-1,i>>=-h,h+=r;h>0;s=256*s+e[t+f],f+=l,h-=8);if(0===i)i=1-u;else{if(i===c)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,r),i-=u}return(p?-1:1)*s*Math.pow(2,i-r)},t.write=function(e,t,n,r,o,i){var s,a,c,u=8*i-o-1,h=(1<<u)-1,f=h>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:i-1,d=r?1:-1,y=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=h):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+f>=1?l/c:l*Math.pow(2,1-f))*c>=2&&(s++,c/=2),s+f>=h?(a=0,s=h):s+f>=1?(a=(t*c-1)*Math.pow(2,o),s+=f):(a=t*Math.pow(2,f-1)*Math.pow(2,o),s=0));o>=8;e[n+p]=255&a,p+=d,a/=256,o-=8);for(s=s<<o|a,u+=o;u>0;e[n+p]=255&s,p+=d,s/=256,u-=8);e[n+p-d]|=128*y}},function(e,t){var n={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},function(e,t,n){"use strict";n.r(t),n.d(t,"AbstractPubSubProvider",(function(){return h})),n.d(t,"AWSAppSyncProvider",(function(){return k})),n.d(t,"AWSAppSyncRealTimeProvider",(function(){return $})),n.d(t,"AWSIoTProvider",(function(){return ae})),n.d(t,"mqttTopicMatch",(function(){return _})),n.d(t,"MqttOverWSProvider",(function(){return O})),n.d(t,"PubSub",(function(){return ne})),n.d(t,"CONTROL_MSG",(function(){return re}));var r=n(8),o=n.n(r).a,i=n(0),s=n(9),a=n(2),c=function(){return(c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},u=new i.ConsoleLogger("AbstractPubSubProvider"),h=function(){function e(e){void 0===e&&(e={}),this._config=e}return e.prototype.configure=function(e){return void 0===e&&(e={}),this._config=c(c({},e),this._config),u.debug("configure "+this.getProviderName(),this._config),this.options},e.prototype.getCategory=function(){return"PubSub"},Object.defineProperty(e.prototype,"options",{get:function(){return c({},this._config)},enumerable:!0,configurable:!0}),e}();function f(e){return(f="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)}var l,p=(l=function(e,t){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),d=function(){return(d=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},y=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},g=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},v=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n},b=new i.ConsoleLogger("MqttOverWSProvider");function _(e,t){for(var n=e.split("/"),r=n.length,o=t.split("/"),i=0;i<r;++i){var s=n[i],a=o[i];if("#"===s)return o.length>=r;if("+"!==s&&s!==a)return!1}return r===o.length}var m,w,E,S=function(){function e(){this.promises=new Map}return e.prototype.get=function(e,t){return y(this,void 0,void 0,(function(){var n;return g(this,(function(r){return(n=this.promises.get(e))||(n=t(e),this.promises.set(e,n)),[2,n]}))}))},Object.defineProperty(e.prototype,"allClients",{get:function(){return Array.from(this.promises.keys())},enumerable:!0,configurable:!0}),e.prototype.remove=function(e){this.promises.delete(e)},e}(),A="undefined"!=typeof Symbol?Symbol("topic"):"@@topic",O=function(e){function t(t){void 0===t&&(t={});var n=e.call(this,d(d({},t),{clientId:t.clientId||Object(a.v4)()}))||this;return n._clientsQueue=new S,n._topicObservers=new Map,n._clientIdObservers=new Map,n}return p(t,e),Object.defineProperty(t.prototype,"clientId",{get:function(){return this.options.clientId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"endpoint",{get:function(){return this.options.aws_pubsub_endpoint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"clientsQueue",{get:function(){return this._clientsQueue},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isSSLEnabled",{get:function(){return!this.options.aws_appsync_dangerously_connect_to_http_endpoint_for_testing},enumerable:!0,configurable:!0}),t.prototype.getTopicForValue=function(e){return"object"===f(e)&&e[A]},t.prototype.getProviderName=function(){return"MqttOverWSProvider"},t.prototype.onDisconnect=function(e){var t=this,n=e.clientId,r=e.errorCode,o=v(e,["clientId","errorCode"]);if(0!==r){b.warn(n,JSON.stringify(d({errorCode:r},o),null,2));var i=[],s=this._clientIdObservers.get(n);if(!s)return;s.forEach((function(e){e.error("Disconnected, error code: "+r),t._topicObservers.forEach((function(t,n){t.delete(e),0===t.size&&i.push(n)}))})),this._clientIdObservers.delete(n),i.forEach((function(e){t._topicObservers.delete(e)}))}},t.prototype.newClient=function(e){var t=e.url,n=e.clientId;return y(this,void 0,void 0,(function(){var e,r=this;return g(this,(function(o){switch(o.label){case 0:return b.debug("Creating new MQTT client",n),(e=new s.Client(t,n)).onMessageArrived=function(e){var t=e.destinationName,n=e.payloadString;r._onMessage(t,n)},e.onConnectionLost=function(e){var t=e.errorCode,o=v(e,["errorCode"]);r.onDisconnect(d({clientId:n,errorCode:t},o))},[4,new Promise((function(t,n){e.connect({useSSL:r.isSSLEnabled,mqttVersion:3,onSuccess:function(){return t(e)},onFailure:n})}))];case 1:return o.sent(),[2,e]}}))}))},t.prototype.connect=function(e,t){return void 0===t&&(t={}),y(this,void 0,void 0,(function(){var n=this;return g(this,(function(r){switch(r.label){case 0:return[4,this.clientsQueue.get(e,(function(e){return n.newClient(d(d({},t),{clientId:e}))}))];case 1:return[2,r.sent()]}}))}))},t.prototype.disconnect=function(e){return y(this,void 0,void 0,(function(){var t;return g(this,(function(n){switch(n.label){case 0:return[4,this.clientsQueue.get(e,(function(){return null}))];case 1:return(t=n.sent())&&t.isConnected()&&t.disconnect(),this.clientsQueue.remove(e),[2]}}))}))},t.prototype.publish=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i;return g(this,(function(s){switch(s.label){case 0:return n=[].concat(e),r=JSON.stringify(t),[4,this.endpoint];case 1:return o=s.sent(),[4,this.connect(this.clientId,{url:o})];case 2:return i=s.sent(),b.debug("Publishing to topic(s)",n.join(","),r),n.forEach((function(e){return i.send(e,r)})),[2]}}))}))},t.prototype._onMessage=function(e,t){try{var n=[];this._topicObservers.forEach((function(t,r){_(r,e)&&n.push(t)}));var r=JSON.parse(t);"object"===f(r)&&(r[A]=e),n.forEach((function(e){e.forEach((function(e){return e.next(r)}))}))}catch(e){b.warn("Error handling message",e,t)}},t.prototype.subscribe=function(e,t){var n=this;void 0===t&&(t={});var r=[].concat(e);return b.debug("Subscribing to topic(s)",r.join(",")),new o((function(e){var o;r.forEach((function(t){var r=n._topicObservers.get(t);r||(r=new Set,n._topicObservers.set(t,r)),r.add(e)}));var i=t.clientId,s=void 0===i?n.clientId:i,a=n._clientIdObservers.get(s);return a||(a=new Set),a.add(e),n._clientIdObservers.set(s,a),y(n,void 0,void 0,(function(){var n,i,a,c;return g(this,(function(u){switch(u.label){case 0:return void 0!==(n=t.url)?[3,2]:[4,this.endpoint];case 1:return a=u.sent(),[3,3];case 2:a=n,u.label=3;case 3:i=a,u.label=4;case 4:return u.trys.push([4,6,,7]),[4,this.connect(s,{url:i})];case 5:return o=u.sent(),r.forEach((function(e){o.subscribe(e)})),[3,7];case 6:return c=u.sent(),e.error(c),[3,7];case 7:return[2]}}))})),function(){return b.debug("Unsubscribing from topic(s)",r.join(",")),o&&(n._clientIdObservers.get(s).delete(e),0===n._clientIdObservers.get(s).size&&(n.disconnect(s),n._clientIdObservers.delete(s)),r.forEach((function(t){var r=n._topicObservers.get(t)||new Set;r.delete(e),0===r.size&&(n._topicObservers.delete(t),o.isConnected()&&o.unsubscribe(t))}))),null}}))},t}(h),T=function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),I=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},C=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},R=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n},N=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},M=function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(N(arguments[t]));return e},P=new i.ConsoleLogger("AWSAppSyncProvider"),k=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._topicClient=new Map,t._topicAlias=new Map,t}return T(t,e),Object.defineProperty(t.prototype,"endpoint",{get:function(){throw new Error("Not supported")},enumerable:!0,configurable:!0}),t.prototype.getProviderName=function(){return"AWSAppSyncProvider"},t.prototype.publish=function(e,t,n){return I(this,void 0,void 0,(function(){return C(this,(function(e){throw new Error("Operation not supported")}))}))},t.prototype._cleanUp=function(e){var t=this;Array.from(this._topicClient.entries()).filter((function(t){return N(t,2)[1].clientId===e})).map((function(e){return N(e,1)[0]})).forEach((function(e){return t._cleanUpForTopic(e)}))},t.prototype._cleanUpForTopic=function(e){this._topicClient.delete(e),this._topicAlias.delete(e)},t.prototype.onDisconnect=function(e){var t=this,n=e.clientId,r=e.errorCode,o=R(e,["clientId","errorCode"]);0!==r&&(Array.from(this._topicClient.entries()).filter((function(e){return N(e,2)[1].clientId===n})).map((function(e){return N(e,1)[0]})).forEach((function(e){t._topicObservers.has(e)&&(t._topicObservers.get(e).forEach((function(e){e.closed||e.error(o)})),t._topicObservers.delete(e))})),this._cleanUp(n))},t.prototype.disconnect=function(t){return I(this,void 0,void 0,(function(){return C(this,(function(n){switch(n.label){case 0:return[4,this.clientsQueue.get(t,(function(){return null}))];case 1:return n.sent(),[4,e.prototype.disconnect.call(this,t)];case 2:return n.sent(),this._cleanUp(t),[2]}}))}))},t.prototype.subscribe=function(e,t){var n=this;void 0===t&&(t={});var r=new o((function(r){var o=[].concat(e);return P.debug("Subscribing to topic(s)",o.join(",")),I(n,void 0,void 0,(function(){var e,n,i,s,a,c=this;return C(this,(function(u){switch(u.label){case 0:return o.forEach((function(e){c._topicObservers.has(e)||c._topicObservers.set(e,new Set),c._topicObservers.get(e).add(r)})),e=t.mqttConnections,n=void 0===e?[]:e,i=t.newSubscriptions,s=Object.entries(i).map((function(e){var t=N(e,2),n=t[0];return[t[1].topic,n]})),this._topicAlias=new Map(M(Array.from(this._topicAlias.entries()),s)),a=Object.entries(o.reduce((function(e,t){var r=n.find((function(e){return e.topics.indexOf(t)>-1}));if(r){var o=r.client,i=r.url;e[o]||(e[o]={url:i,topics:new Set}),e[o].topics.add(t)}return e}),{})),[4,Promise.all(a.map((function(e){var t=N(e,2),n=t[0],o=t[1],i=o.url,s=o.topics;return I(c,void 0,void 0,(function(){var e,t,o=this;return C(this,(function(a){switch(a.label){case 0:e=null,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.connect(n,{clientId:n,url:i})];case 2:return e=a.sent(),[3,4];case 3:return t=a.sent(),r.error({message:"Failed to connect",error:t}),r.complete(),[2,void 0];case 4:return s.forEach((function(t){e.isConnected()&&(e.subscribe(t),o._topicClient.set(t,e))})),[2,e]}}))}))})))];case 1:return u.sent(),[2]}}))})),function(){P.debug("Unsubscribing from topic(s)",o.join(",")),o.forEach((function(e){var t=n._topicClient.get(e);t&&t.isConnected()&&(t.unsubscribe(e),n._topicClient.delete(e),Array.from(n._topicClient.values()).some((function(e){return e===t}))||n.disconnect(t.clientId)),n._topicObservers.delete(e)}))}}));return o.from(r).map((function(e){var t=n.getTopicForValue(e),r=n._topicAlias.get(t);return e.data=Object.entries(e.data).reduce((function(e,t){var n=N(t,2),o=n[0],i=n[1];return e[r||o]=i,e}),{}),e}))},t}(O),x=n(1),U=n(10),L=n(4),D=n(11),q=n.n(D),B=n(5),j=n.n(B),V=function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),F=function(){return(F=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},G=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},Y=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},Q=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},K=new i.Logger("AWSAppSyncRealTimeProvider"),z="undefined"!=typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("amplify_default"):"@@amplify_default",J=[400,401,403];!function(e){e.GQL_CONNECTION_INIT="connection_init",e.GQL_CONNECTION_ERROR="connection_error",e.GQL_CONNECTION_ACK="connection_ack",e.GQL_START="start",e.GQL_START_ACK="start_ack",e.GQL_DATA="data",e.GQL_CONNECTION_KEEP_ALIVE="ka",e.GQL_STOP="stop",e.GQL_COMPLETE="complete",e.GQL_ERROR="error"}(m||(m={})),function(e){e[e.PENDING=0]="PENDING",e[e.CONNECTED=1]="CONNECTED",e[e.FAILED=2]="FAILED"}(w||(w={})),function(e){e[e.CLOSED=0]="CLOSED",e[e.READY=1]="READY",e[e.CONNECTING=2]="CONNECTING"}(E||(E={}));var W={accept:"application/json, text/javascript","content-encoding":"amz-1.0","content-type":"application/json; charset=UTF-8"},H=/^https:\/\/\w{26}\.appsync\-api\.\w{2}(?:(?:\-\w{2,})+)\-\d\.amazonaws.com\/graphql$/i,$=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.socketStatus=E.CLOSED,t.keepAliveTimeout=3e5,t.subscriptionObserverMap=new Map,t.promiseArray=[],t}return V(t,e),t.prototype.getProviderName=function(){return"AWSAppSyncRealTimeProvider"},t.prototype.newClient=function(){throw new Error("Not used here")},t.prototype.publish=function(e,t,n){return G(this,void 0,void 0,(function(){return Y(this,(function(e){throw new Error("Operation not supported")}))}))},t.prototype.isCustomDomain=function(e){return null===e.match(H)},t.prototype.subscribe=function(e,t){var n=this,r=t.appSyncGraphqlEndpoint;return new o((function(e){if(r){var o=Object(a.v4)();return n._startSubscriptionWithAWSAppSyncRealTime({options:t,observer:e,subscriptionId:o}).catch((function(t){e.error({errors:[F({},new x.GraphQLError(re.REALTIME_SUBSCRIPTION_INIT_ERROR+": "+t))]}),e.complete()})),function(){return G(n,void 0,void 0,(function(){var e,t;return Y(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,3,4]),[4,this._waitForSubscriptionToBeConnected(o)];case 1:if(n.sent(),!(e=(this.subscriptionObserverMap.get(o)||{}).subscriptionState))return[2];if(e!==w.CONNECTED)throw new Error("Subscription never connected");return this._sendUnsubscriptionMessage(o),[3,4];case 2:return t=n.sent(),K.debug("Error while unsubscribing "+t),[3,4];case 3:return this._removeSubscriptionObserver(o),[7];case 4:return[2]}}))}))}}e.error({errors:[F({},new x.GraphQLError("Subscribe only available for AWS AppSync endpoint"))]}),e.complete()}))},Object.defineProperty(t.prototype,"isSSLEnabled",{get:function(){return!this.options.aws_appsync_dangerously_connect_to_http_endpoint_for_testing},enumerable:!0,configurable:!0}),t.prototype._startSubscriptionWithAWSAppSyncRealTime=function(e){var t=e.options,n=e.observer,r=e.subscriptionId;return G(this,void 0,void 0,(function(){var e,o,s,a,c,u,h,f,l,p,d,y,g,v,b,_,E,S,A,O,T,I,C,R,N,M,P=this;return Y(this,(function(k){switch(k.label){case 0:return e=t.appSyncGraphqlEndpoint,o=t.authenticationType,s=t.query,a=t.variables,c=t.apiKey,u=t.region,h=t.graphql_headers,f=void 0===h?function(){return{}}:h,l=t.additionalHeaders,p=void 0===l?{}:l,d=w.PENDING,y={query:s,variables:a},this.subscriptionObserverMap.set(r,{observer:n,query:s,variables:a,subscriptionState:d,startAckTimeoutId:null}),g=JSON.stringify(y),b=[{}],[4,this._awsRealTimeHeaderBasedAuth({apiKey:c,appSyncGraphqlEndpoint:e,authenticationType:o,payload:g,canonicalUri:"",region:u,additionalHeaders:p})];case 1:return _=[F.apply(void 0,b.concat([k.sent()]))],[4,f()];case 2:v=F.apply(void 0,[F.apply(void 0,[F.apply(void 0,_.concat([k.sent()])),p]),(M={},M[i.USER_AGENT_HEADER]=i.Constants.userAgent,M)]),E={id:r,payload:{data:g,extensions:{authorization:F({},v)}},type:m.GQL_START},S=JSON.stringify(E),k.label=3;case 3:return k.trys.push([3,5,,6]),[4,this._initializeWebSocketConnection({apiKey:c,appSyncGraphqlEndpoint:e,authenticationType:o,region:u,additionalHeaders:p})];case 4:return k.sent(),[3,6];case 5:return A=k.sent(),K.debug({err:A}),O=A.message,T=void 0===O?"":O,n.error({errors:[F({},new x.GraphQLError(re.CONNECTION_FAILED+": "+T))]}),n.complete(),"function"==typeof(I=(this.subscriptionObserverMap.get(r)||{}).subscriptionFailedCallback)&&I(),[2];case 6:return C=this.subscriptionObserverMap.get(r),R=C.subscriptionFailedCallback,N=C.subscriptionReadyCallback,this.subscriptionObserverMap.set(r,{observer:n,subscriptionState:d,variables:a,query:s,subscriptionReadyCallback:N,subscriptionFailedCallback:R,startAckTimeoutId:setTimeout((function(){P._timeoutStartSubscriptionAck.call(P,r)}),15e3)}),this.awsRealTimeSocket&&this.awsRealTimeSocket.send(S),[2]}}))}))},t.prototype._waitForSubscriptionToBeConnected=function(e){return G(this,void 0,void 0,(function(){var t=this;return Y(this,(function(n){return this.subscriptionObserverMap.get(e).subscriptionState===w.PENDING?[2,new Promise((function(n,r){var o=t.subscriptionObserverMap.get(e),i=o.observer,s=o.subscriptionState,a=o.variables,c=o.query;t.subscriptionObserverMap.set(e,{observer:i,subscriptionState:s,variables:a,query:c,subscriptionReadyCallback:n,subscriptionFailedCallback:r})}))]:[2]}))}))},t.prototype._sendUnsubscriptionMessage=function(e){try{if(this.awsRealTimeSocket&&this.awsRealTimeSocket.readyState===WebSocket.OPEN&&this.socketStatus===E.READY){var t={id:e,type:m.GQL_STOP},n=JSON.stringify(t);this.awsRealTimeSocket.send(n)}}catch(e){K.debug({err:e})}},t.prototype._removeSubscriptionObserver=function(e){this.subscriptionObserverMap.delete(e),setTimeout(this._closeSocketIfRequired.bind(this),1e3)},t.prototype._closeSocketIfRequired=function(){if(!(this.subscriptionObserverMap.size>0))if(this.awsRealTimeSocket)if(this.awsRealTimeSocket.bufferedAmount>0)setTimeout(this._closeSocketIfRequired.bind(this),1e3);else{K.debug("closing WebSocket..."),clearTimeout(this.keepAliveTimeoutId);var e=this.awsRealTimeSocket;e.onclose=void 0,e.onerror=void 0,e.close(1e3),this.awsRealTimeSocket=null,this.socketStatus=E.CLOSED}else this.socketStatus=E.CLOSED},t.prototype._handleIncomingSubscriptionMessage=function(e){K.debug("subscription message from AWS AppSync RealTime: "+e.data);var t=JSON.parse(e.data),n=t.id,r=void 0===n?"":n,o=t.payload,s=t.type,a=this.subscriptionObserverMap.get(r)||{},c=a.observer,u=void 0===c?null:c,h=a.query,f=void 0===h?"":h,l=a.variables,p=void 0===l?{}:l,d=a.startAckTimeoutId,y=a.subscriptionReadyCallback,g=a.subscriptionFailedCallback;if(K.debug({id:r,observer:u,query:f,variables:p}),s===m.GQL_DATA&&o&&o.data)u?u.next(o):K.debug("observer not found for id: "+r);else if(s!==m.GQL_START_ACK){if(s===m.GQL_CONNECTION_KEEP_ALIVE)return clearTimeout(this.keepAliveTimeoutId),void(this.keepAliveTimeoutId=setTimeout(this._errorDisconnect.bind(this,re.TIMEOUT_DISCONNECT),this.keepAliveTimeout));if(s===m.GQL_ERROR){v=w.FAILED;this.subscriptionObserverMap.set(r,{observer:u,query:f,variables:p,startAckTimeoutId:d,subscriptionReadyCallback:y,subscriptionFailedCallback:g,subscriptionState:v}),u.error({errors:[F({},new x.GraphQLError(re.CONNECTION_FAILED+": "+JSON.stringify(o)))]}),clearTimeout(d),u.complete(),"function"==typeof g&&g()}}else{K.debug("subscription ready for "+JSON.stringify({query:f,variables:p})),"function"==typeof y&&y(),clearTimeout(d),function(e,t,n){i.Hub.dispatch("api",{event:e,data:t,message:n},"PubSub",z)}(re.SUBSCRIPTION_ACK,{query:f,variables:p},"Connection established for subscription");var v=w.CONNECTED;this.subscriptionObserverMap.set(r,{observer:u,query:f,variables:p,startAckTimeoutId:null,subscriptionState:v,subscriptionReadyCallback:y,subscriptionFailedCallback:g})}},t.prototype._errorDisconnect=function(e){K.debug("Disconnect error: "+e),this.subscriptionObserverMap.forEach((function(t){var n=t.observer;n&&!n.closed&&n.error({errors:[F({},new x.GraphQLError(e))]})})),this.subscriptionObserverMap.clear(),this.awsRealTimeSocket&&this.awsRealTimeSocket.close(),this.socketStatus=E.CLOSED},t.prototype._timeoutStartSubscriptionAck=function(e){var t=this.subscriptionObserverMap.get(e)||{},n=t.observer,r=t.query,o=t.variables;n&&(this.subscriptionObserverMap.set(e,{observer:n,query:r,variables:o,subscriptionState:w.FAILED}),n&&!n.closed&&(n.error({errors:[F({},new x.GraphQLError("Subscription timeout "+JSON.stringify({query:r,variables:o})))]}),n.complete()),K.debug("timeoutStartSubscription",JSON.stringify({query:r,variables:o})))},t.prototype._initializeWebSocketConnection=function(e){var t=this,n=e.appSyncGraphqlEndpoint,r=e.authenticationType,o=e.apiKey,i=e.region,s=e.additionalHeaders;if(this.socketStatus!==E.READY)return new Promise((function(e,a){return G(t,void 0,void 0,(function(){var t,c,u,h,f,l,p,d,y,g;return Y(this,(function(v){switch(v.label){case 0:if(this.promiseArray.push({res:e,rej:a}),this.socketStatus!==E.CLOSED)return[3,5];v.label=1;case 1:return v.trys.push([1,4,,5]),this.socketStatus=E.CONNECTING,t="{}",h=(u=JSON).stringify,[4,this._awsRealTimeHeaderBasedAuth({authenticationType:r,payload:t,canonicalUri:"/connect",apiKey:o,appSyncGraphqlEndpoint:n,region:i,additionalHeaders:s})];case 2:return c=h.apply(u,[v.sent()]),f=L.Buffer.from(c).toString("base64"),l=L.Buffer.from(t).toString("base64"),p=n,p=this.isCustomDomain(p)?p.concat("/realtime"):p.replace("appsync-api","appsync-realtime-api").replace("gogi-beta","grt-beta"),d=this.isSSLEnabled?"wss://":"ws://",p=p.replace("https://",d).replace("http://",d),y=p+"?header="+f+"&payload="+l,[4,this._initializeRetryableHandshake({awsRealTimeUrl:y})];case 3:return v.sent(),this.promiseArray.forEach((function(e){var t=e.res;K.debug("Notifying connection successful"),t()})),this.socketStatus=E.READY,this.promiseArray=[],[3,5];case 4:return g=v.sent(),this.promiseArray.forEach((function(e){return(0,e.rej)(g)})),this.promiseArray=[],this.awsRealTimeSocket&&this.awsRealTimeSocket.readyState===WebSocket.OPEN&&this.awsRealTimeSocket.close(3001),this.awsRealTimeSocket=null,this.socketStatus=E.CLOSED,[3,5];case 5:return[2]}}))}))}))},t.prototype._initializeRetryableHandshake=function(e){var t=e.awsRealTimeUrl;return G(this,void 0,void 0,(function(){return Y(this,(function(e){switch(e.label){case 0:return K.debug("Initializaling retryable Handshake"),[4,Object(i.jitteredExponentialRetry)(this._initializeHandshake.bind(this),[{awsRealTimeUrl:t}],5e3)];case 1:return e.sent(),[2]}}))}))},t.prototype._initializeHandshake=function(e){var t=e.awsRealTimeUrl;return G(this,void 0,void 0,(function(){var e,n,r,o=this;return Y(this,(function(s){switch(s.label){case 0:K.debug("Initializing handshake "+t),s.label=1;case 1:return s.trys.push([1,4,,5]),[4,new Promise((function(e,n){var r=new WebSocket(t,"graphql-ws");r.onerror=function(){K.debug("WebSocket connection error")},r.onclose=function(){n(new Error("Connection handshake error"))},r.onopen=function(){return o.awsRealTimeSocket=r,e()}}))];case 2:return s.sent(),[4,new Promise((function(e,t){var n=!1;o.awsRealTimeSocket.onerror=function(e){K.debug("WebSocket error "+JSON.stringify(e))},o.awsRealTimeSocket.onclose=function(e){K.debug("WebSocket closed "+e.reason),t(new Error(JSON.stringify(e)))},o.awsRealTimeSocket.onmessage=function(r){K.debug("subscription message from AWS AppSyncRealTime: "+r.data+" ");var i=JSON.parse(r.data),s=i.type,a=i.payload,c=(void 0===a?{}:a).connectionTimeoutMs,u=void 0===c?3e5:c;if(s===m.GQL_CONNECTION_ACK)return n=!0,o.keepAliveTimeout=u,o.awsRealTimeSocket.onmessage=o._handleIncomingSubscriptionMessage.bind(o),o.awsRealTimeSocket.onerror=function(e){K.debug(e),o._errorDisconnect(re.CONNECTION_CLOSED)},o.awsRealTimeSocket.onclose=function(e){K.debug("WebSocket closed "+e.reason),o._errorDisconnect(re.CONNECTION_CLOSED)},void e("Cool, connected to AWS AppSyncRealTime");if(s===m.GQL_CONNECTION_ERROR){var h=i.payload,f=(void 0===h?{}:h).errors,l=Q(void 0===f?[]:f,1)[0],p=void 0===l?{}:l,d=p.errorType,y=void 0===d?"":d,g=p.errorCode;t({errorType:y,errorCode:void 0===g?0:g})}};var r={type:m.GQL_CONNECTION_INIT};o.awsRealTimeSocket.send(JSON.stringify(r)),setTimeout(function(){n||t(new Error("Connection timeout: ack from AWSRealTime was not received on 15000 ms"))}.bind(o),15e3)}))];case 3:return s.sent(),[3,5];case 4:throw e=s.sent(),n=e.errorType,r=e.errorCode,J.includes(r)?new i.NonRetryableError(n):n?new Error(n):e;case 5:return[2]}}))}))},t.prototype._awsRealTimeHeaderBasedAuth=function(e){var t=e.authenticationType,n=e.payload,r=e.canonicalUri,o=e.appSyncGraphqlEndpoint,i=e.apiKey,s=e.region,a=e.additionalHeaders;return G(this,void 0,void 0,(function(){var e,c,u;return Y(this,(function(h){switch(h.label){case 0:return e={API_KEY:this._awsRealTimeApiKeyHeader.bind(this),AWS_IAM:this._awsRealTimeIAMHeader.bind(this),OPENID_CONNECT:this._awsRealTimeOPENIDHeader.bind(this),AMAZON_COGNITO_USER_POOLS:this._awsRealTimeCUPHeader.bind(this),AWS_LAMBDA:this._customAuthHeader},"function"!=typeof(c=e[t])?(K.debug("Authentication type "+t+" not supported"),[2,""]):(u=U.parse(o).host,[4,c({payload:n,canonicalUri:r,appSyncGraphqlEndpoint:o,apiKey:i,region:s,host:u,additionalHeaders:a})]);case 1:return[2,h.sent()]}}))}))},t.prototype._awsRealTimeCUPHeader=function(e){var t=e.host;return G(this,void 0,void 0,(function(){return Y(this,(function(e){switch(e.label){case 0:return[4,j.a.currentSession()];case 1:return[2,{Authorization:e.sent().getAccessToken().getJwtToken(),host:t}]}}))}))},t.prototype._awsRealTimeOPENIDHeader=function(e){var t=e.host;return G(this,void 0,void 0,(function(){var e,n,r;return Y(this,(function(o){switch(o.label){case 0:return[4,q.a.getItem("federatedInfo")];case 1:return(n=o.sent())?(e=n.token,[3,4]):[3,2];case 2:return[4,j.a.currentAuthenticatedUser()];case 3:(r=o.sent())&&(e=r.token),o.label=4;case 4:if(!e)throw new Error("No federated jwt");return[2,{Authorization:e,host:t}]}}))}))},t.prototype._awsRealTimeApiKeyHeader=function(e){var t=e.apiKey,n=e.host;return G(this,void 0,void 0,(function(){var e,r;return Y(this,(function(o){return e=new Date,r=e.toISOString().replace(/[:\-]|\.\d{3}/g,""),[2,{host:n,"x-amz-date":r,"x-api-key":t}]}))}))},t.prototype._awsRealTimeIAMHeader=function(e){var t=e.payload,n=e.canonicalUri,r=e.appSyncGraphqlEndpoint,o=e.region;return G(this,void 0,void 0,(function(){var e,s,a;return Y(this,(function(c){switch(c.label){case 0:return e={region:o,service:"appsync"},[4,this._ensureCredentials()];case 1:if(!c.sent())throw new Error("No credentials");return[4,i.Credentials.get().then((function(e){return{secret_key:e.secretAccessKey,access_key:e.accessKeyId,session_token:e.sessionToken}}))];case 2:return s=c.sent(),a={url:""+r+n,data:t,method:"POST",headers:F({},W)},[2,i.Signer.sign(a,s,e).headers]}}))}))},t.prototype._customAuthHeader=function(e){var t=e.host,n=e.additionalHeaders;if(!n.Authorization)throw new Error("No auth token specified");return{Authorization:n.Authorization,host:t}},t.prototype._ensureCredentials=function(){return i.Credentials.get().then((function(e){if(!e)return!1;var t=i.Credentials.shear(e);return K.debug("set credentials for AWSAppSyncRealTimeProvider",t),!0})).catch((function(e){return K.warn("ensure credentials error",e),!1}))},t}(h),X=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},Z=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},ee=Object(i.browserOrNode)().isNode,te=new i.ConsoleLogger("PubSub"),ne=new(function(){function e(e){this._options=e,te.debug("PubSub Options",this._options),this._pluggables=[],this.subscribe=this.subscribe.bind(this)}return Object.defineProperty(e.prototype,"awsAppSyncProvider",{get:function(){return this._awsAppSyncProvider||(this._awsAppSyncProvider=new k(this._options)),this._awsAppSyncProvider},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"awsAppSyncRealTimeProvider",{get:function(){return this._awsAppSyncRealTimeProvider||(this._awsAppSyncRealTimeProvider=new $(this._options)),this._awsAppSyncRealTimeProvider},enumerable:!0,configurable:!0}),e.prototype.getModuleName=function(){return"PubSub"},e.prototype.configure=function(e){var t=this,n=e?e.PubSub||e:{};return te.debug("configure PubSub",{opt:n}),this._options=Object.assign({},this._options,n),this._pluggables.map((function(e){return e.configure(t._options)})),this._options},e.prototype.addPluggable=function(e){return X(this,void 0,void 0,(function(){return Z(this,(function(t){return e&&"PubSub"===e.getCategory()?(this._pluggables.push(e),[2,e.configure(this._options)]):[2]}))}))},e.prototype.removePluggable=function(e){this._pluggables=this._pluggables.filter((function(t){return t.getProviderName()!==e}))},e.prototype.getProviderByName=function(e){return e===i.INTERNAL_AWS_APPSYNC_PUBSUB_PROVIDER?this.awsAppSyncProvider:e===i.INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER?this.awsAppSyncRealTimeProvider:this._pluggables.find((function(t){return t.getProviderName()===e}))},e.prototype.getProviders=function(e){void 0===e&&(e={});var t=e.provider;if(!t)return this._pluggables;var n=this.getProviderByName(t);if(!n)throw new Error("Could not find provider named "+t);return[n]},e.prototype.publish=function(e,t,n){return X(this,void 0,void 0,(function(){return Z(this,(function(r){return[2,Promise.all(this.getProviders(n).map((function(r){return r.publish(e,t,n)})))]}))}))},e.prototype.subscribe=function(e,t){if(ee&&this._options&&this._options.ssr)throw new Error("Subscriptions are not supported for Server-Side Rendering (SSR)");te.debug("subscribe options",t);var n=this.getProviders(t);return new o((function(r){var o=n.map((function(n){return{provider:n,observable:n.subscribe(e,t)}})).map((function(e){var t=e.provider;return e.observable.subscribe({start:console.error,next:function(e){return r.next({provider:t,value:e})},error:function(e){return r.error({provider:t,error:e})}})}));return function(){return o.forEach((function(e){return e.unsubscribe()}))}}))},e}())(null);i.Amplify.register(ne);var re,oe=function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ie=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},se=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},ae=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return oe(t,e),Object.defineProperty(t.prototype,"region",{get:function(){return this.options.aws_pubsub_region},enumerable:!0,configurable:!0}),t.prototype.getProviderName=function(){return"AWSIoTProvider"},Object.defineProperty(t.prototype,"endpoint",{get:function(){return ie(this,void 0,void 0,(function(){var e,t,n,r,o,s;return se(this,(function(a){switch(a.label){case 0:return e=this.options.aws_pubsub_endpoint,t={service:"iotdevicegateway",region:this.region},[4,i.Credentials.get()];case 1:return n=a.sent(),r=n.accessKeyId,o=n.secretAccessKey,s=n.sessionToken,[2,i.Signer.signUrl(e,{access_key:r,secret_key:o,session_token:s},t)]}}))}))},enumerable:!0,configurable:!0}),t}(O);!function(e){e.CONNECTION_CLOSED="Connection closed",e.CONNECTION_FAILED="Connection failed",e.REALTIME_SUBSCRIPTION_INIT_ERROR="AppSync Realtime subscription init error",e.SUBSCRIPTION_ACK="Subscription ack",e.TIMEOUT_DISCONNECT="Timeout disconnect"}(re||(re={}));t.default=ne}])}));
11
11
  //# sourceMappingURL=aws-amplify-pubsub.min.js.map