qiscus-sdk-core 2.11.0 → 2.12.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.
- package/dist/qiscus-sdk-core.min.js +6 -4
- package/dist/qiscus-sdk-core.min.js.map +1 -1
- package/lib/index.js +107 -65
- package/lib/lib/Comment.js +1 -0
- package/lib/lib/adapters/auth.js +38 -2
- package/lib/lib/adapters/http.js +68 -11
- package/lib/lib/adapters/mqtt.js +2 -1
- package/package.json +18 -19
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("QiscusSDKCore",[],t):"object"==typeof exports?exports.QiscusSDKCore=t():e.QiscusSDKCore=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("QiscusSDKCore",[],t):"object"==typeof exports?exports.QiscusSDKCore=t():e.QiscusSDKCore=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=55)}([function(e,t,n){e.exports=n(59)},function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(e,t){function n(e,t,n,r,i,o,s){try{var a=e[o](s),u=a.value}catch(e){return void n(e)}a.done?t(u):Promise.resolve(u).then(r,i)}e.exports=function(e){return function(){var t=this,r=arguments;return new Promise((function(i,o){var s=e.apply(t,r);function a(e){n(s,i,o,a,u,"next",e)}function u(e){n(s,i,o,a,u,"throw",e)}a(void 0)}))}}},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function n(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)}}e.exports=function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}},function(e,t,n){(function(r){var i,o;
|
|
2
2
|
/*!
|
|
3
3
|
* is.js 0.8.0
|
|
4
4
|
* Author: Aras Atasaygin
|
|
5
|
-
*/o=this,void 0===(i=function(){return o.is=function(){var e={VERSION:"0.8.0",not:{},all:{},any:{}},t=Object.prototype.toString,n=Array.prototype.slice,i=Object.prototype.hasOwnProperty;function o(e){return function(){return!e.apply(null,n.call(arguments))}}function s(e){return function(){for(var t=l(arguments),n=t.length,r=0;r<n;r++)if(!e.call(null,t[r]))return!1;return!0}}function a(e){return function(){for(var t=l(arguments),n=t.length,r=0;r<n;r++)if(e.call(null,t[r]))return!0;return!1}}var u={"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t}};function c(e,t){var n=t+"",r=+(n.match(/\d+/)||NaN),i=n.match(/^[<>]=?|/)[0];return u[i]?u[i](e,r):e==r||r!=r}function l(t){var r=n.call(t);return 1===r.length&&e.array(r[0])&&(r=r[0]),r}e.arguments=function(e){return"[object Arguments]"===t.call(e)||null!=e&&"object"==typeof e&&"callee"in e},e.array=Array.isArray||function(e){return"[object Array]"===t.call(e)},e.boolean=function(e){return!0===e||!1===e||"[object Boolean]"===t.call(e)},e.char=function(t){return e.string(t)&&1===t.length},e.date=function(e){return"[object Date]"===t.call(e)},e.domNode=function(t){return e.object(t)&&t.nodeType>0},e.error=function(e){return"[object Error]"===t.call(e)},e.function=function(e){return"[object Function]"===t.call(e)||"function"==typeof e},e.json=function(e){return"[object Object]"===t.call(e)},e.nan=function(e){return e!=e},e.null=function(e){return null===e},e.number=function(n){return e.not.nan(n)&&"[object Number]"===t.call(n)},e.object=function(e){return Object(e)===e},e.regexp=function(e){return"[object RegExp]"===t.call(e)},e.sameType=function(n,r){var i=t.call(n);return i===t.call(r)&&("[object Number]"!==i||!e.any.nan(n,r)||e.all.nan(n,r))},e.sameType.api=["not"],e.string=function(e){return"[object String]"===t.call(e)},e.undefined=function(e){return void 0===e},e.windowObject=function(e){return null!=e&&"object"==typeof e&&"setInterval"in e},e.empty=function(t){if(e.object(t)){var n=Object.getOwnPropertyNames(t).length;return!!(0===n||1===n&&e.array(t)||2===n&&e.arguments(t))}return""===t},e.existy=function(e){return null!=e},e.falsy=function(e){return!e},e.truthy=o(e.falsy),e.above=function(t,n){return e.all.number(t,n)&&t>n},e.above.api=["not"],e.decimal=function(t){return e.number(t)&&t%1!=0},e.equal=function(t,n){return e.all.number(t,n)?t===n&&1/t==1/n:e.all.string(t,n)||e.all.regexp(t,n)?""+t==""+n:!!e.all.boolean(t,n)&&t===n},e.equal.api=["not"],e.even=function(t){return e.number(t)&&t%2==0},e.finite=isFinite||function(t){return e.not.infinite(t)&&e.not.nan(t)},e.infinite=function(e){return e===1/0||e===-1/0},e.integer=function(t){return e.number(t)&&t%1==0},e.negative=function(t){return e.number(t)&&t<0},e.odd=function(t){return e.number(t)&&t%2==1},e.positive=function(t){return e.number(t)&&t>0},e.under=function(t,n){return e.all.number(t,n)&&t<n},e.under.api=["not"],e.within=function(t,n,r){return e.all.number(t,n,r)&&t>n&&t<r},e.within.api=["not"];var h={affirmative:/^(?:1|t(?:rue)?|y(?:es)?|ok(?:ay)?)$/,alphaNumeric:/^[A-Za-z0-9]+$/,caPostalCode:/^(?!.*[DFIOQU])[A-VXY][0-9][A-Z]\s?[0-9][A-Z][0-9]$/,creditCard:/^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/,dateString:/^(1[0-2]|0?[1-9])([\/-])(3[01]|[12][0-9]|0?[1-9])(?:\2)(?:[0-9]{2})?[0-9]{2}$/,email:/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,eppPhone:/^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$/,hexadecimal:/^(?:0x)?[0-9a-fA-F]+$/,hexColor:/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,ipv4:/^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/,ipv6:/^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i,nanpPhone:/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/,socialSecurityNumber:/^(?!000|666)[0-8][0-9]{2}-?(?!00)[0-9]{2}-?(?!0000)[0-9]{4}$/,timeString:/^(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])$/,ukPostCode:/^[A-Z]{1,2}[0-9RCHNQ][0-9A-Z]?\s?[0-9][ABD-HJLNP-UW-Z]{2}$|^[A-Z]{2}-?[0-9]{4}$/,url:/^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/i,usZipCode:/^[0-9]{5}(?:-[0-9]{4})?$/};function f(t,n){e[t]=function(e){return n[t].test(e)}}for(var d in h)h.hasOwnProperty(d)&&f(d,h);e.ip=function(t){return e.ipv4(t)||e.ipv6(t)},e.capitalized=function(t){if(e.not.string(t))return!1;for(var n=t.split(" "),r=0;r<n.length;r++){var i=n[r];if(i.length){var o=i.charAt(0);if(o!==o.toUpperCase())return!1}}return!0},e.endWith=function(t,n){if(e.not.string(t))return!1;n+="";var r=t.length-n.length;return r>=0&&t.indexOf(n,r)===r},e.endWith.api=["not"],e.include=function(e,t){return e.indexOf(t)>-1},e.include.api=["not"],e.lowerCase=function(t){return e.string(t)&&t===t.toLowerCase()},e.palindrome=function(t){if(e.not.string(t))return!1;for(var n=(t=t.replace(/[^a-zA-Z0-9]+/g,"").toLowerCase()).length-1,r=0,i=Math.floor(n/2);r<=i;r++)if(t.charAt(r)!==t.charAt(n-r))return!1;return!0},e.space=function(t){if(e.not.char(t))return!1;var n=t.charCodeAt(0);return n>8&&n<14||32===n},e.startWith=function(t,n){return e.string(t)&&0===t.indexOf(n)},e.startWith.api=["not"],e.upperCase=function(t){return e.string(t)&&t===t.toUpperCase()};var p=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],m=["january","february","march","april","may","june","july","august","september","october","november","december"];e.day=function(t,n){return e.date(t)&&n.toLowerCase()===p[t.getDay()]},e.day.api=["not"],e.dayLightSavingTime=function(e){var t=new Date(e.getFullYear(),0,1),n=new Date(e.getFullYear(),6,1),r=Math.max(t.getTimezoneOffset(),n.getTimezoneOffset());return e.getTimezoneOffset()<r},e.future=function(t){var n=new Date;return e.date(t)&&t.getTime()>n.getTime()},e.inDateRange=function(t,n,r){if(e.not.date(t)||e.not.date(n)||e.not.date(r))return!1;var i=t.getTime();return i>n.getTime()&&i<r.getTime()},e.inDateRange.api=["not"],e.inLastMonth=function(t){return e.inDateRange(t,new Date((new Date).setMonth((new Date).getMonth()-1)),new Date)},e.inLastWeek=function(t){return e.inDateRange(t,new Date((new Date).setDate((new Date).getDate()-7)),new Date)},e.inLastYear=function(t){return e.inDateRange(t,new Date((new Date).setFullYear((new Date).getFullYear()-1)),new Date)},e.inNextMonth=function(t){return e.inDateRange(t,new Date,new Date((new Date).setMonth((new Date).getMonth()+1)))},e.inNextWeek=function(t){return e.inDateRange(t,new Date,new Date((new Date).setDate((new Date).getDate()+7)))},e.inNextYear=function(t){return e.inDateRange(t,new Date,new Date((new Date).setFullYear((new Date).getFullYear()+1)))},e.leapYear=function(t){return e.number(t)&&(t%4==0&&t%100!=0||t%400==0)},e.month=function(t,n){return e.date(t)&&n.toLowerCase()===m[t.getMonth()]},e.month.api=["not"],e.past=function(t){var n=new Date;return e.date(t)&&t.getTime()<n.getTime()},e.quarterOfYear=function(t,n){return e.date(t)&&e.number(n)&&n===Math.floor((t.getMonth()+3)/3)},e.quarterOfYear.api=["not"],e.today=function(t){var n=(new Date).toDateString();return e.date(t)&&t.toDateString()===n},e.tomorrow=function(t){var n=new Date,r=new Date(n.setDate(n.getDate()+1)).toDateString();return e.date(t)&&t.toDateString()===r},e.weekend=function(t){return e.date(t)&&(6===t.getDay()||0===t.getDay())},e.weekday=o(e.weekend),e.year=function(t,n){return e.date(t)&&e.number(n)&&n===t.getFullYear()},e.year.api=["not"],e.yesterday=function(t){var n=new Date,r=new Date(n.setDate(n.getDate()-1)).toDateString();return e.date(t)&&t.toDateString()===r};var g=e.windowObject("object"==typeof r&&r)&&r,b=e.windowObject("object"==typeof self&&self)&&self,y=e.windowObject("object"==typeof this&&this)&&this,v=g||b||y||Function("return this")(),_=b&&b.document,w=v.is,k=b&&b.navigator,S=(k&&k.appVersion||"").toLowerCase(),E=(k&&k.userAgent||"").toLowerCase(),T=(k&&k.vendor||"").toLowerCase();return e.android=function(){return/android/.test(E)},e.android.api=["not"],e.androidPhone=function(){return/android/.test(E)&&/mobile/.test(E)},e.androidPhone.api=["not"],e.androidTablet=function(){return/android/.test(E)&&!/mobile/.test(E)},e.androidTablet.api=["not"],e.blackberry=function(){return/blackberry/.test(E)||/bb10/.test(E)},e.blackberry.api=["not"],e.chrome=function(e){var t=/google inc/.test(T)?E.match(/(?:chrome|crios)\/(\d+)/):null;return null!==t&&c(t[1],e)},e.chrome.api=["not"],e.desktop=function(){return e.not.mobile()&&e.not.tablet()},e.desktop.api=["not"],e.edge=function(e){var t=E.match(/edge\/(\d+)/);return null!==t&&c(t[1],e)},e.edge.api=["not"],e.firefox=function(e){var t=E.match(/(?:firefox|fxios)\/(\d+)/);return null!==t&&c(t[1],e)},e.firefox.api=["not"],e.ie=function(e){var t=E.match(/(?:msie |trident.+?; rv:)(\d+)/);return null!==t&&c(t[1],e)},e.ie.api=["not"],e.ios=function(){return e.iphone()||e.ipad()||e.ipod()},e.ios.api=["not"],e.ipad=function(e){var t=E.match(/ipad.+?os (\d+)/);return null!==t&&c(t[1],e)},e.ipad.api=["not"],e.iphone=function(e){var t=E.match(/iphone(?:.+?os (\d+))?/);return null!==t&&c(t[1]||1,e)},e.iphone.api=["not"],e.ipod=function(e){var t=E.match(/ipod.+?os (\d+)/);return null!==t&&c(t[1],e)},e.ipod.api=["not"],e.linux=function(){return/linux/.test(S)},e.linux.api=["not"],e.mac=function(){return/mac/.test(S)},e.mac.api=["not"],e.mobile=function(){return e.iphone()||e.ipod()||e.androidPhone()||e.blackberry()||e.windowsPhone()},e.mobile.api=["not"],e.offline=o(e.online),e.offline.api=["not"],e.online=function(){return!k||!0===k.onLine},e.online.api=["not"],e.opera=function(e){var t=E.match(/(?:^opera.+?version|opr)\/(\d+)/);return null!==t&&c(t[1],e)},e.opera.api=["not"],e.phantom=function(e){var t=E.match(/phantomjs\/(\d+)/);return null!==t&&c(t[1],e)},e.phantom.api=["not"],e.safari=function(e){var t=E.match(/version\/(\d+).+?safari/);return null!==t&&c(t[1],e)},e.safari.api=["not"],e.tablet=function(){return e.ipad()||e.androidTablet()||e.windowsTablet()},e.tablet.api=["not"],e.touchDevice=function(){return!!_&&("ontouchstart"in b||"DocumentTouch"in b&&_ instanceof DocumentTouch)},e.touchDevice.api=["not"],e.windows=function(){return/win/.test(S)},e.windows.api=["not"],e.windowsPhone=function(){return e.windows()&&/phone/.test(E)},e.windowsPhone.api=["not"],e.windowsTablet=function(){return e.windows()&&e.not.windowsPhone()&&/touch/.test(E)},e.windowsTablet.api=["not"],e.propertyCount=function(t,n){if(e.not.object(t)||e.not.number(n))return!1;var r=0;for(var o in t)if(i.call(t,o)&&++r>n)return!1;return r===n},e.propertyCount.api=["not"],e.propertyDefined=function(t,n){return e.object(t)&&e.string(n)&&n in t},e.propertyDefined.api=["not"],e.inArray=function(t,n){if(e.not.array(n))return!1;for(var r=0;r<n.length;r++)if(n[r]===t)return!0;return!1},e.inArray.api=["not"],e.sorted=function(t,n){if(e.not.array(t))return!1;for(var r=u[n]||u[">="],i=1;i<t.length;i++)if(!r(t[i],t[i-1]))return!1;return!0},function(){var t=e;for(var n in t)if(i.call(t,n)&&e.function(t[n]))for(var r=t[n].api||["not","all","any"],u=0;u<r.length;u++)"not"===r[u]&&(e.not[n]=o(e[n])),"all"===r[u]&&(e.all[n]=s(e[n])),"any"===r[u]&&(e.any[n]=a(e[n]))}(),e.setNamespace=function(){return v.is=w,this},e.setRegexp=function(e,t){for(var n in h)i.call(h,n)&&t===n&&(h[n]=e)},e}()}.call(t,n,t,e))||(e.exports=i)}).call(this,n(9))},function(e,t){var n,r,i=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(e){n=o}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var u,c=[],l=!1,h=-1;function f(){l&&u&&(l=!1,u.length?c=u.concat(c):h=-1,c.length&&d())}function d(){if(!l){var e=a(f);l=!0;for(var t=c.length;t;){for(u=c,c=[];++h<t;)u&&u[h].run();h=-1,t=c.length}u=null,l=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function m(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new p(e,t)),1!==c.length||l||a(d)},p.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=m,i.addListener=m,i.once=m,i.off=m,i.removeListener=m,i.removeAllListeners=m,i.emit=m,i.prependListener=m,i.prependOnceListener=m,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},function(e,t,n){"use strict";(function(e){
|
|
5
|
+
*/o=this,void 0===(i=function(){return o.is=function(){var e={VERSION:"0.8.0",not:{},all:{},any:{}},t=Object.prototype.toString,n=Array.prototype.slice,i=Object.prototype.hasOwnProperty;function o(e){return function(){return!e.apply(null,n.call(arguments))}}function s(e){return function(){for(var t=l(arguments),n=t.length,r=0;r<n;r++)if(!e.call(null,t[r]))return!1;return!0}}function a(e){return function(){for(var t=l(arguments),n=t.length,r=0;r<n;r++)if(e.call(null,t[r]))return!0;return!1}}var u={"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t}};function c(e,t){var n=t+"",r=+(n.match(/\d+/)||NaN),i=n.match(/^[<>]=?|/)[0];return u[i]?u[i](e,r):e==r||r!=r}function l(t){var r=n.call(t);return 1===r.length&&e.array(r[0])&&(r=r[0]),r}e.arguments=function(e){return"[object Arguments]"===t.call(e)||null!=e&&"object"==typeof e&&"callee"in e},e.array=Array.isArray||function(e){return"[object Array]"===t.call(e)},e.boolean=function(e){return!0===e||!1===e||"[object Boolean]"===t.call(e)},e.char=function(t){return e.string(t)&&1===t.length},e.date=function(e){return"[object Date]"===t.call(e)},e.domNode=function(t){return e.object(t)&&t.nodeType>0},e.error=function(e){return"[object Error]"===t.call(e)},e.function=function(e){return"[object Function]"===t.call(e)||"function"==typeof e},e.json=function(e){return"[object Object]"===t.call(e)},e.nan=function(e){return e!=e},e.null=function(e){return null===e},e.number=function(n){return e.not.nan(n)&&"[object Number]"===t.call(n)},e.object=function(e){return Object(e)===e},e.regexp=function(e){return"[object RegExp]"===t.call(e)},e.sameType=function(n,r){var i=t.call(n);return i===t.call(r)&&("[object Number]"!==i||!e.any.nan(n,r)||e.all.nan(n,r))},e.sameType.api=["not"],e.string=function(e){return"[object String]"===t.call(e)},e.undefined=function(e){return void 0===e},e.windowObject=function(e){return null!=e&&"object"==typeof e&&"setInterval"in e},e.empty=function(t){if(e.object(t)){var n=Object.getOwnPropertyNames(t).length;return!!(0===n||1===n&&e.array(t)||2===n&&e.arguments(t))}return""===t},e.existy=function(e){return null!=e},e.falsy=function(e){return!e},e.truthy=o(e.falsy),e.above=function(t,n){return e.all.number(t,n)&&t>n},e.above.api=["not"],e.decimal=function(t){return e.number(t)&&t%1!=0},e.equal=function(t,n){return e.all.number(t,n)?t===n&&1/t==1/n:e.all.string(t,n)||e.all.regexp(t,n)?""+t==""+n:!!e.all.boolean(t,n)&&t===n},e.equal.api=["not"],e.even=function(t){return e.number(t)&&t%2==0},e.finite=isFinite||function(t){return e.not.infinite(t)&&e.not.nan(t)},e.infinite=function(e){return e===1/0||e===-1/0},e.integer=function(t){return e.number(t)&&t%1==0},e.negative=function(t){return e.number(t)&&t<0},e.odd=function(t){return e.number(t)&&t%2==1},e.positive=function(t){return e.number(t)&&t>0},e.under=function(t,n){return e.all.number(t,n)&&t<n},e.under.api=["not"],e.within=function(t,n,r){return e.all.number(t,n,r)&&t>n&&t<r},e.within.api=["not"];var h={affirmative:/^(?:1|t(?:rue)?|y(?:es)?|ok(?:ay)?)$/,alphaNumeric:/^[A-Za-z0-9]+$/,caPostalCode:/^(?!.*[DFIOQU])[A-VXY][0-9][A-Z]\s?[0-9][A-Z][0-9]$/,creditCard:/^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/,dateString:/^(1[0-2]|0?[1-9])([\/-])(3[01]|[12][0-9]|0?[1-9])(?:\2)(?:[0-9]{2})?[0-9]{2}$/,email:/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,eppPhone:/^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$/,hexadecimal:/^(?:0x)?[0-9a-fA-F]+$/,hexColor:/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,ipv4:/^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/,ipv6:/^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i,nanpPhone:/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/,socialSecurityNumber:/^(?!000|666)[0-8][0-9]{2}-?(?!00)[0-9]{2}-?(?!0000)[0-9]{4}$/,timeString:/^(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])$/,ukPostCode:/^[A-Z]{1,2}[0-9RCHNQ][0-9A-Z]?\s?[0-9][ABD-HJLNP-UW-Z]{2}$|^[A-Z]{2}-?[0-9]{4}$/,url:/^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/i,usZipCode:/^[0-9]{5}(?:-[0-9]{4})?$/};function f(t,n){e[t]=function(e){return n[t].test(e)}}for(var p in h)h.hasOwnProperty(p)&&f(p,h);e.ip=function(t){return e.ipv4(t)||e.ipv6(t)},e.capitalized=function(t){if(e.not.string(t))return!1;for(var n=t.split(" "),r=0;r<n.length;r++){var i=n[r];if(i.length){var o=i.charAt(0);if(o!==o.toUpperCase())return!1}}return!0},e.endWith=function(t,n){if(e.not.string(t))return!1;n+="";var r=t.length-n.length;return r>=0&&t.indexOf(n,r)===r},e.endWith.api=["not"],e.include=function(e,t){return e.indexOf(t)>-1},e.include.api=["not"],e.lowerCase=function(t){return e.string(t)&&t===t.toLowerCase()},e.palindrome=function(t){if(e.not.string(t))return!1;for(var n=(t=t.replace(/[^a-zA-Z0-9]+/g,"").toLowerCase()).length-1,r=0,i=Math.floor(n/2);r<=i;r++)if(t.charAt(r)!==t.charAt(n-r))return!1;return!0},e.space=function(t){if(e.not.char(t))return!1;var n=t.charCodeAt(0);return n>8&&n<14||32===n},e.startWith=function(t,n){return e.string(t)&&0===t.indexOf(n)},e.startWith.api=["not"],e.upperCase=function(t){return e.string(t)&&t===t.toUpperCase()};var d=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],m=["january","february","march","april","may","june","july","august","september","october","november","december"];e.day=function(t,n){return e.date(t)&&n.toLowerCase()===d[t.getDay()]},e.day.api=["not"],e.dayLightSavingTime=function(e){var t=new Date(e.getFullYear(),0,1),n=new Date(e.getFullYear(),6,1),r=Math.max(t.getTimezoneOffset(),n.getTimezoneOffset());return e.getTimezoneOffset()<r},e.future=function(t){var n=new Date;return e.date(t)&&t.getTime()>n.getTime()},e.inDateRange=function(t,n,r){if(e.not.date(t)||e.not.date(n)||e.not.date(r))return!1;var i=t.getTime();return i>n.getTime()&&i<r.getTime()},e.inDateRange.api=["not"],e.inLastMonth=function(t){return e.inDateRange(t,new Date((new Date).setMonth((new Date).getMonth()-1)),new Date)},e.inLastWeek=function(t){return e.inDateRange(t,new Date((new Date).setDate((new Date).getDate()-7)),new Date)},e.inLastYear=function(t){return e.inDateRange(t,new Date((new Date).setFullYear((new Date).getFullYear()-1)),new Date)},e.inNextMonth=function(t){return e.inDateRange(t,new Date,new Date((new Date).setMonth((new Date).getMonth()+1)))},e.inNextWeek=function(t){return e.inDateRange(t,new Date,new Date((new Date).setDate((new Date).getDate()+7)))},e.inNextYear=function(t){return e.inDateRange(t,new Date,new Date((new Date).setFullYear((new Date).getFullYear()+1)))},e.leapYear=function(t){return e.number(t)&&(t%4==0&&t%100!=0||t%400==0)},e.month=function(t,n){return e.date(t)&&n.toLowerCase()===m[t.getMonth()]},e.month.api=["not"],e.past=function(t){var n=new Date;return e.date(t)&&t.getTime()<n.getTime()},e.quarterOfYear=function(t,n){return e.date(t)&&e.number(n)&&n===Math.floor((t.getMonth()+3)/3)},e.quarterOfYear.api=["not"],e.today=function(t){var n=(new Date).toDateString();return e.date(t)&&t.toDateString()===n},e.tomorrow=function(t){var n=new Date,r=new Date(n.setDate(n.getDate()+1)).toDateString();return e.date(t)&&t.toDateString()===r},e.weekend=function(t){return e.date(t)&&(6===t.getDay()||0===t.getDay())},e.weekday=o(e.weekend),e.year=function(t,n){return e.date(t)&&e.number(n)&&n===t.getFullYear()},e.year.api=["not"],e.yesterday=function(t){var n=new Date,r=new Date(n.setDate(n.getDate()-1)).toDateString();return e.date(t)&&t.toDateString()===r};var g=e.windowObject("object"==typeof r&&r)&&r,v=e.windowObject("object"==typeof self&&self)&&self,y=e.windowObject("object"==typeof this&&this)&&this,b=g||v||y||Function("return this")(),_=v&&v.document,w=b.is,k=v&&v.navigator,S=(k&&k.appVersion||"").toLowerCase(),E=(k&&k.userAgent||"").toLowerCase(),T=(k&&k.vendor||"").toLowerCase();return e.android=function(){return/android/.test(E)},e.android.api=["not"],e.androidPhone=function(){return/android/.test(E)&&/mobile/.test(E)},e.androidPhone.api=["not"],e.androidTablet=function(){return/android/.test(E)&&!/mobile/.test(E)},e.androidTablet.api=["not"],e.blackberry=function(){return/blackberry/.test(E)||/bb10/.test(E)},e.blackberry.api=["not"],e.chrome=function(e){var t=/google inc/.test(T)?E.match(/(?:chrome|crios)\/(\d+)/):null;return null!==t&&c(t[1],e)},e.chrome.api=["not"],e.desktop=function(){return e.not.mobile()&&e.not.tablet()},e.desktop.api=["not"],e.edge=function(e){var t=E.match(/edge\/(\d+)/);return null!==t&&c(t[1],e)},e.edge.api=["not"],e.firefox=function(e){var t=E.match(/(?:firefox|fxios)\/(\d+)/);return null!==t&&c(t[1],e)},e.firefox.api=["not"],e.ie=function(e){var t=E.match(/(?:msie |trident.+?; rv:)(\d+)/);return null!==t&&c(t[1],e)},e.ie.api=["not"],e.ios=function(){return e.iphone()||e.ipad()||e.ipod()},e.ios.api=["not"],e.ipad=function(e){var t=E.match(/ipad.+?os (\d+)/);return null!==t&&c(t[1],e)},e.ipad.api=["not"],e.iphone=function(e){var t=E.match(/iphone(?:.+?os (\d+))?/);return null!==t&&c(t[1]||1,e)},e.iphone.api=["not"],e.ipod=function(e){var t=E.match(/ipod.+?os (\d+)/);return null!==t&&c(t[1],e)},e.ipod.api=["not"],e.linux=function(){return/linux/.test(S)},e.linux.api=["not"],e.mac=function(){return/mac/.test(S)},e.mac.api=["not"],e.mobile=function(){return e.iphone()||e.ipod()||e.androidPhone()||e.blackberry()||e.windowsPhone()},e.mobile.api=["not"],e.offline=o(e.online),e.offline.api=["not"],e.online=function(){return!k||!0===k.onLine},e.online.api=["not"],e.opera=function(e){var t=E.match(/(?:^opera.+?version|opr)\/(\d+)/);return null!==t&&c(t[1],e)},e.opera.api=["not"],e.phantom=function(e){var t=E.match(/phantomjs\/(\d+)/);return null!==t&&c(t[1],e)},e.phantom.api=["not"],e.safari=function(e){var t=E.match(/version\/(\d+).+?safari/);return null!==t&&c(t[1],e)},e.safari.api=["not"],e.tablet=function(){return e.ipad()||e.androidTablet()||e.windowsTablet()},e.tablet.api=["not"],e.touchDevice=function(){return!!_&&("ontouchstart"in v||"DocumentTouch"in v&&_ instanceof DocumentTouch)},e.touchDevice.api=["not"],e.windows=function(){return/win/.test(S)},e.windows.api=["not"],e.windowsPhone=function(){return e.windows()&&/phone/.test(E)},e.windowsPhone.api=["not"],e.windowsTablet=function(){return e.windows()&&e.not.windowsPhone()&&/touch/.test(E)},e.windowsTablet.api=["not"],e.propertyCount=function(t,n){if(e.not.object(t)||e.not.number(n))return!1;var r=0;for(var o in t)if(i.call(t,o)&&++r>n)return!1;return r===n},e.propertyCount.api=["not"],e.propertyDefined=function(t,n){return e.object(t)&&e.string(n)&&n in t},e.propertyDefined.api=["not"],e.inArray=function(t,n){if(e.not.array(n))return!1;for(var r=0;r<n.length;r++)if(n[r]===t)return!0;return!1},e.inArray.api=["not"],e.sorted=function(t,n){if(e.not.array(t))return!1;for(var r=u[n]||u[">="],i=1;i<t.length;i++)if(!r(t[i],t[i-1]))return!1;return!0},function(){var t=e;for(var n in t)if(i.call(t,n)&&e.function(t[n]))for(var r=t[n].api||["not","all","any"],u=0;u<r.length;u++)"not"===r[u]&&(e.not[n]=o(e[n])),"all"===r[u]&&(e.all[n]=s(e[n])),"any"===r[u]&&(e.any[n]=a(e[n]))}(),e.setNamespace=function(){return b.is=w,this},e.setRegexp=function(e,t){for(var n in h)i.call(h,n)&&t===n&&(h[n]=e)},e}()}.call(t,n,t,e))||(e.exports=i)}).call(this,n(10))},function(e,t,n){var r;"undefined"!=typeof window?r=window:"undefined"!=typeof self?r=self:(console.warn("Using browser-only version of superagent in non-browser environment"),r=this);var i=n(60),o=n(61),s=n(29),a=n(62),u=n(64);function c(){}var l=t=e.exports=function(e,n){return"function"==typeof n?new t.Request("GET",e).end(n):1==arguments.length?new t.Request("GET",e):new t.Request(e,n)};t.Request=v,l.getXHR=function(){if(!(!r.XMLHttpRequest||r.location&&"file:"==r.location.protocol&&r.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}throw Error("Browser-only version of superagent could not find XHR")};var h="".trim?function(e){return e.trim()}:function(e){return e.replace(/(^\s*|\s*$)/g,"")};function f(e){if(!s(e))return e;var t=[];for(var n in e)p(t,n,e[n]);return t.join("&")}function p(e,t,n){if(null!=n)if(Array.isArray(n))n.forEach((function(n){p(e,t,n)}));else if(s(n))for(var r in n)p(e,t+"["+r+"]",n[r]);else e.push(encodeURIComponent(t)+"="+encodeURIComponent(n));else null===n&&e.push(encodeURIComponent(t))}function d(e){for(var t,n,r={},i=e.split("&"),o=0,s=i.length;o<s;++o)-1==(n=(t=i[o]).indexOf("="))?r[decodeURIComponent(t)]="":r[decodeURIComponent(t.slice(0,n))]=decodeURIComponent(t.slice(n+1));return r}function m(e){return/[\/+]json($|[^-\w])/.test(e)}function g(e){this.req=e,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||void 0===this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText;var t=this.xhr.status;1223===t&&(t=204),this._setStatusProperties(t),this.header=this.headers=function(e){for(var t,n,r,i,o=e.split(/\r?\n/),s={},a=0,u=o.length;a<u;++a)-1!==(t=(n=o[a]).indexOf(":"))&&(r=n.slice(0,t).toLowerCase(),i=h(n.slice(t+1)),s[r]=i);return s}(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this._setHeaderProperties(this.header),null===this.text&&e._responseType?this.body=this.xhr.response:this.body="HEAD"!=this.req.method?this._parseBody(this.text?this.text:this.xhr.response):null}function v(e,t){var n=this;this._query=this._query||[],this.method=e,this.url=t,this.header={},this._header={},this.on("end",(function(){var e,t=null,r=null;try{r=new g(n)}catch(e){return(t=new Error("Parser is unable to parse the response")).parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=r.status,n.callback(e,r)):n.callback(null,r)}))}function y(e,t,n){var r=l("DELETE",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}l.serializeObject=f,l.parseString=d,l.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},l.serialize={"application/x-www-form-urlencoded":f,"application/json":JSON.stringify},l.parse={"application/x-www-form-urlencoded":d,"application/json":JSON.parse},a(g.prototype),g.prototype._parseBody=function(e){var t=l.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&m(this.type)&&(t=l.parse["application/json"]),t&&e&&(e.length||e instanceof Object)?t(e):null)},g.prototype.toError=function(){var e=this.req,t=e.method,n=e.url,r="cannot "+t+" "+n+" ("+this.status+")",i=new Error(r);return i.status=this.status,i.method=t,i.url=n,i},l.Response=g,i(v.prototype),o(v.prototype),v.prototype.type=function(e){return this.set("Content-Type",l.types[e]||e),this},v.prototype.accept=function(e){return this.set("Accept",l.types[e]||e),this},v.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});var r=function(e){if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},v.prototype.query=function(e){return"string"!=typeof e&&(e=f(e)),e&&this._query.push(e),this},v.prototype.attach=function(e,t,n){if(t){if(this._data)throw Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},v.prototype._getFormData=function(){return this._formData||(this._formData=new r.FormData),this._formData},v.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();var n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},v.prototype.crossDomainError=function(){var e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},v.prototype.buffer=v.prototype.ca=v.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},v.prototype.pipe=v.prototype.write=function(){throw Error("Streaming is not supported in browser version of superagent")},v.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},v.prototype.end=function(e){return this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||c,this._finalizeQueryString(),this._end()},v.prototype._end=function(){var e=this,t=this.xhr=l.getXHR(),n=this._formData||this._data;this._setTimeouts(),t.onreadystatechange=function(){var n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4==n){var r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}};var r=function(t,n){n.total>0&&(n.percent=n.loaded/n.total*100),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.onprogress=r.bind(null,"download"),t.upload&&(t.upload.onprogress=r.bind(null,"upload"))}catch(e){}try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof n&&!this._isHost(n)){var i=this._header["content-type"],o=this._serializer||l.serialize[i?i.split(";")[0]:""];!o&&m(i)&&(o=l.serialize["application/json"]),o&&(n=o(n))}for(var s in this.header)null!=this.header[s]&&this.header.hasOwnProperty(s)&&t.setRequestHeader(s,this.header[s]);return this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0!==n?n:null),this},l.agent=function(){return new u},["GET","POST","OPTIONS","PATCH","PUT","DELETE"].forEach((function(e){u.prototype[e.toLowerCase()]=function(t,n){var r=new l.Request(e,t);return this._setDefaults(r),n&&r.end(n),r}})),u.prototype.del=u.prototype.delete,l.get=function(e,t,n){var r=l("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},l.head=function(e,t,n){var r=l("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},l.options=function(e,t,n){var r=l("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},l.del=y,l.delete=y,l.patch=function(e,t,n){var r=l("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},l.post=function(e,t,n){var r=l("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},l.put=function(e,t,n){var r=l("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}},function(e,t,n){var r=n(66),i=n(30),o=36e5,s=6e4,a=2,u=/[T ]/,c=/:/,l=/^(\d{2})$/,h=[/^([+-]\d{2})$/,/^([+-]\d{3})$/,/^([+-]\d{4})$/],f=/^(\d{4})/,p=[/^([+-]\d{4})/,/^([+-]\d{5})/,/^([+-]\d{6})/],d=/^-(\d{2})$/,m=/^-?(\d{3})$/,g=/^-?(\d{2})-?(\d{2})$/,v=/^-?W(\d{2})$/,y=/^-?W(\d{2})-?(\d{1})$/,b=/^(\d{2}([.,]\d*)?)$/,_=/^(\d{2}):?(\d{2}([.,]\d*)?)$/,w=/^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,k=/([Z+-].*)$/,S=/^(Z)$/,E=/^([+-])(\d{2})$/,T=/^([+-])(\d{2}):?(\d{2})$/;function C(e,t,n){t=t||0,n=n||0;var r=new Date(0);r.setUTCFullYear(e,0,4);var i=7*t+n+1-(r.getUTCDay()||7);return r.setUTCDate(r.getUTCDate()+i),r}e.exports=function(e,t){if(i(e))return new Date(e.getTime());if("string"!=typeof e)return new Date(e);var n=(t||{}).additionalDigits;n=null==n?a:Number(n);var A=function(e){var t,n={},r=e.split(u);c.test(r[0])?(n.date=null,t=r[0]):(n.date=r[0],t=r[1]);if(t){var i=k.exec(t);i?(n.time=t.replace(i[1],""),n.timezone=i[1]):n.time=t}return n}(e),x=function(e,t){var n,r=h[t],i=p[t];if(n=f.exec(e)||i.exec(e)){var o=n[1];return{year:parseInt(o,10),restDateString:e.slice(o.length)}}if(n=l.exec(e)||r.exec(e)){var s=n[1];return{year:100*parseInt(s,10),restDateString:e.slice(s.length)}}return{year:null}}(A.date,n),I=x.year,R=function(e,t){if(null===t)return null;var n,r,i,o;if(0===e.length)return(r=new Date(0)).setUTCFullYear(t),r;if(n=d.exec(e))return r=new Date(0),i=parseInt(n[1],10)-1,r.setUTCFullYear(t,i),r;if(n=m.exec(e)){r=new Date(0);var s=parseInt(n[1],10);return r.setUTCFullYear(t,0,s),r}if(n=g.exec(e)){r=new Date(0),i=parseInt(n[1],10)-1;var a=parseInt(n[2],10);return r.setUTCFullYear(t,i,a),r}if(n=v.exec(e))return o=parseInt(n[1],10)-1,C(t,o);if(n=y.exec(e)){o=parseInt(n[1],10)-1;var u=parseInt(n[2],10)-1;return C(t,o,u)}return null}(x.restDateString,I);if(R){var P,O=R.getTime(),M=0;if(A.time&&(M=function(e){var t,n,r;if(t=b.exec(e))return(n=parseFloat(t[1].replace(",",".")))%24*o;if(t=_.exec(e))return n=parseInt(t[1],10),r=parseFloat(t[2].replace(",",".")),n%24*o+r*s;if(t=w.exec(e)){n=parseInt(t[1],10),r=parseInt(t[2],10);var i=parseFloat(t[3].replace(",","."));return n%24*o+r*s+1e3*i}return null}(A.time)),A.timezone)P=function(e){var t,n;if(t=S.exec(e))return 0;if(t=E.exec(e))return n=60*parseInt(t[2],10),"+"===t[1]?-n:n;if(t=T.exec(e))return n=60*parseInt(t[2],10)+parseInt(t[3],10),"+"===t[1]?-n:n;return 0}(A.timezone)*s;else{var L=O+M,D=new Date(L);P=r(D);var U=new Date(L);U.setDate(D.getDate()+1);var j=r(U)-r(D);j>0&&(P+=j)}return new Date(O+M+P)}return new Date(e)}},function(e,t,n){"use strict";(function(e){
|
|
6
6
|
/*!
|
|
7
7
|
* The buffer module from node.js, for the browser.
|
|
8
8
|
*
|
|
9
9
|
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
|
10
10
|
* @license MIT
|
|
11
11
|
*/
|
|
12
|
-
var r=n(99),i=n(100),o=n(41);function s(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(s()<t)throw new RangeError("Invalid typed array length");return u.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=u.prototype:(null===e&&(e=new u(t)),e.length=t),e}function u(e,t,n){if(!(u.TYPED_ARRAY_SUPPORT||this instanceof u))return new u(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 h(this,e)}return c(this,e,t,n)}function c(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);u.TYPED_ARRAY_SUPPORT?(e=t).__proto__=u.prototype:e=f(e,t);return e}(e,t,n,r):"string"==typeof t?function(e,t,n){"string"==typeof n&&""!==n||(n="utf8");if(!u.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|p(t,n),i=(e=a(e,r)).write(t,n);i!==r&&(e=e.slice(0,i));return e}(e,t,n):function(e,t){if(u.isBuffer(t)){var n=0|d(t.length);return 0===(e=a(e,n)).length?e:(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):f(e,t);if("Buffer"===t.type&&o(t.data))return f(e,t.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function l(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 h(e,t){if(l(t),e=a(e,t<0?0:0|d(t)),!u.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)e[n]=0;return e}function f(e,t){var n=t.length<0?0:0|d(t.length);e=a(e,n);for(var r=0;r<n;r+=1)e[r]=255&t[r];return e}function d(e){if(e>=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|e}function p(e,t){if(u.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 B(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return H(e).length;default:if(r)return B(e).length;t=(""+t).toLowerCase(),r=!0}}function m(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 I(this,t,n);case"utf8":case"utf-8":return C(this,t,n);case"ascii":return R(this,t,n);case"latin1":case"binary":return A(this,t,n);case"base64":return T(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(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 b(e,t,n,r,i){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=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof t&&(t=u.from(t,r)),u.isBuffer(t))return 0===t.length?-1:y(e,t,n,r,i);if("number"==typeof t)return t&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):y(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function y(e,t,n,r,i){var o,s=1,a=e.length,u=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,u/=2,n/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var l=-1;for(o=n;o<a;o++)if(c(e,o)===c(t,-1===l?0:o-l)){if(-1===l&&(l=o),o-l+1===u)return l*s}else-1!==l&&(o-=o-l),l=-1}else for(n+u>a&&(n=a-u),o=n;o>=0;o--){for(var h=!0,f=0;f<u;f++)if(c(e,o+f)!==c(t,f)){h=!1;break}if(h)return o}return-1}function v(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r))>i&&(r=i):r=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/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 _(e,t,n,r){return W(B(t,e.length-n),e,n,r)}function w(e,t,n,r){return W(function(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function k(e,t,n,r){return w(e,t,n,r)}function S(e,t,n,r){return W(H(t),e,n,r)}function E(e,t,n,r){return W(function(e,t){for(var n,r,i,o=[],s=0;s<e.length&&!((t-=2)<0);++s)n=e.charCodeAt(s),r=n>>8,i=n%256,o.push(i),o.push(r);return o}(t,e.length-n),e,n,r)}function T(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function C(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i<n;){var o,s,a,u,c=e[i],l=null,h=c>239?4:c>223?3:c>191?2:1;if(i+h<=n)switch(h){case 1:c<128&&(l=c);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&c)<<6|63&o)>127&&(l=u);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(u=(15&c)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,h=1):l>65535&&(l-=65536,r.push(l>>>10&1023|55296),l=56320|1023&l),r.push(l),i+=h}return function(e){var t=e.length;if(t<=x)return String.fromCharCode.apply(String,e);var n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=x));return n}(r)}t.Buffer=u,t.SlowBuffer=function(e){+e!=e&&(e=0);return u.alloc(+e)},t.INSPECT_MAX_BYTES=50,u.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(),u.poolSize=8192,u._augment=function(e){return e.__proto__=u.prototype,e},u.from=function(e,t,n){return c(null,e,t,n)},u.TYPED_ARRAY_SUPPORT&&(u.prototype.__proto__=Uint8Array.prototype,u.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&u[Symbol.species]===u&&Object.defineProperty(u,Symbol.species,{value:null,configurable:!0})),u.alloc=function(e,t,n){return function(e,t,n,r){return l(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)},u.allocUnsafe=function(e){return h(null,e)},u.allocUnsafeSlow=function(e){return h(null,e)},u.isBuffer=function(e){return!(null==e||!e._isBuffer)},u.compare=function(e,t){if(!u.isBuffer(e)||!u.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,i=0,o=Math.min(n,r);i<o;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:r<n?1:0},u.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}},u.concat=function(e,t){if(!o(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return u.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=u.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){var s=e[n];if(!u.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(r,i),i+=s.length}return r},u.byteLength=p,u.prototype._isBuffer=!0,u.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},u.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},u.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},u.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?C(this,0,e):m.apply(this,arguments)},u.prototype.equals=function(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===u.compare(this,e)},u.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+">"},u.prototype.compare=function(e,t,n,r,i){if(!u.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===i&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(r>>>=0),s=(n>>>=0)-(t>>>=0),a=Math.min(o,s),c=this.slice(r,i),l=e.slice(t,n),h=0;h<a;++h)if(c[h]!==l[h]){o=c[h],s=l[h];break}return o<s?-1:s<o?1:0},u.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},u.prototype.indexOf=function(e,t,n){return b(this,e,t,n,!0)},u.prototype.lastIndexOf=function(e,t,n){return b(this,e,t,n,!1)},u.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 i=this.length-t;if((void 0===n||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return v(this,e,t,n);case"utf8":case"utf-8":return _(this,e,t,n);case"ascii":return w(this,e,t,n);case"latin1":case"binary":return k(this,e,t,n);case"base64":return S(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return E(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var x=4096;function R(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(127&e[i]);return r}function A(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function I(e,t,n){var r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);for(var i="",o=t;o<n;++o)i+=N(e[o]);return i}function P(e,t,n){for(var r=e.slice(t,n),i="",o=0;o<r.length;o+=2)i+=String.fromCharCode(r[o]+256*r[o+1]);return i}function O(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 M(e,t,n,r,i,o){if(!u.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function L(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-n,2);i<o;++i)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function D(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-n,4);i<o;++i)e[n+i]=t>>>8*(r?i:3-i)&255}function j(e,t,n,r,i,o){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function U(e,t,n,r,o){return o||j(e,0,n,4),i.write(e,t,n,r,23,4),n+4}function q(e,t,n,r,o){return o||j(e,0,n,8),i.write(e,t,n,r,52,8),n+8}u.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),u.TYPED_ARRAY_SUPPORT)(n=this.subarray(e,t)).__proto__=u.prototype;else{var i=t-e;n=new u(i,void 0);for(var o=0;o<i;++o)n[o]=this[o+e]}return n},u.prototype.readUIntLE=function(e,t,n){e|=0,t|=0,n||O(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r},u.prototype.readUIntBE=function(e,t,n){e|=0,t|=0,n||O(e,t,this.length);for(var r=this[e+--t],i=1;t>0&&(i*=256);)r+=this[e+--t]*i;return r},u.prototype.readUInt8=function(e,t){return t||O(e,1,this.length),this[e]},u.prototype.readUInt16LE=function(e,t){return t||O(e,2,this.length),this[e]|this[e+1]<<8},u.prototype.readUInt16BE=function(e,t){return t||O(e,2,this.length),this[e]<<8|this[e+1]},u.prototype.readUInt32LE=function(e,t){return t||O(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},u.prototype.readUInt32BE=function(e,t){return t||O(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},u.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||O(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r>=(i*=128)&&(r-=Math.pow(2,8*t)),r},u.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||O(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},u.prototype.readInt8=function(e,t){return t||O(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},u.prototype.readInt16LE=function(e,t){t||O(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt16BE=function(e,t){t||O(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt32LE=function(e,t){return t||O(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},u.prototype.readInt32BE=function(e,t){return t||O(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},u.prototype.readFloatLE=function(e,t){return t||O(e,4,this.length),i.read(this,e,!0,23,4)},u.prototype.readFloatBE=function(e,t){return t||O(e,4,this.length),i.read(this,e,!1,23,4)},u.prototype.readDoubleLE=function(e,t){return t||O(e,8,this.length),i.read(this,e,!0,52,8)},u.prototype.readDoubleBE=function(e,t){return t||O(e,8,this.length),i.read(this,e,!1,52,8)},u.prototype.writeUIntLE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||M(this,e,t,n,Math.pow(2,8*n)-1,0);var i=1,o=0;for(this[t]=255&e;++o<n&&(i*=256);)this[t+o]=e/i&255;return t+n},u.prototype.writeUIntBE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||M(this,e,t,n,Math.pow(2,8*n)-1,0);var i=n-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+n},u.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,1,255,0),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},u.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},u.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},u.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):D(this,e,t,!0),t+4},u.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):D(this,e,t,!1),t+4},u.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);M(this,e,t,n,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o<n&&(s*=256);)e<0&&0===a&&0!==this[t+o-1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n},u.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);M(this,e,t,n,i-1,-i)}var o=n-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n},u.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,1,127,-128),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},u.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},u.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},u.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):D(this,e,t,!0),t+4},u.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):D(this,e,t,!1),t+4},u.prototype.writeFloatLE=function(e,t,n){return U(this,e,t,!0,n)},u.prototype.writeFloatBE=function(e,t,n){return U(this,e,t,!1,n)},u.prototype.writeDoubleLE=function(e,t,n){return q(this,e,t,!0,n)},u.prototype.writeDoubleBE=function(e,t,n){return q(this,e,t,!1,n)},u.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 i,o=r-n;if(this===e&&n<t&&t<r)for(i=o-1;i>=0;--i)e[i+t]=this[i+n];else if(o<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)e[i+t]=this[i+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+o),t);return o},u.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 i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!u.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 o;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(o=t;o<n;++o)this[o]=e;else{var s=u.isBuffer(e)?e:B(new u(e,r).toString()),a=s.length;for(o=0;o<n-t;++o)this[o+t]=s[o%a]}return this};var F=/[^+\/0-9A-Za-z-_]/g;function N(e){return e<16?"0"+e.toString(16):e.toString(16)}function B(e,t){var n;t=t||1/0;for(var r=e.length,i=null,o=[],s=0;s<r;++s){if((n=e.charCodeAt(s))>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;o.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;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function H(e){return r.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(F,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function W(e,t,n,r){for(var i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}}).call(this,n(9))},function(e,t,n){var r;"undefined"!=typeof window?r=window:"undefined"!=typeof self?r=self:(console.warn("Using browser-only version of superagent in non-browser environment"),r=this);var i=n(71),o=n(72),s=n(34),a=n(73),u=n(75);function c(){}var l=t=e.exports=function(e,n){return"function"==typeof n?new t.Request("GET",e).end(n):1==arguments.length?new t.Request("GET",e):new t.Request(e,n)};t.Request=b,l.getXHR=function(){if(!(!r.XMLHttpRequest||r.location&&"file:"==r.location.protocol&&r.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}throw Error("Browser-only version of superagent could not find XHR")};var h="".trim?function(e){return e.trim()}:function(e){return e.replace(/(^\s*|\s*$)/g,"")};function f(e){if(!s(e))return e;var t=[];for(var n in e)d(t,n,e[n]);return t.join("&")}function d(e,t,n){if(null!=n)if(Array.isArray(n))n.forEach((function(n){d(e,t,n)}));else if(s(n))for(var r in n)d(e,t+"["+r+"]",n[r]);else e.push(encodeURIComponent(t)+"="+encodeURIComponent(n));else null===n&&e.push(encodeURIComponent(t))}function p(e){for(var t,n,r={},i=e.split("&"),o=0,s=i.length;o<s;++o)-1==(n=(t=i[o]).indexOf("="))?r[decodeURIComponent(t)]="":r[decodeURIComponent(t.slice(0,n))]=decodeURIComponent(t.slice(n+1));return r}function m(e){return/[\/+]json($|[^-\w])/.test(e)}function g(e){this.req=e,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||void 0===this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText;var t=this.xhr.status;1223===t&&(t=204),this._setStatusProperties(t),this.header=this.headers=function(e){for(var t,n,r,i,o=e.split(/\r?\n/),s={},a=0,u=o.length;a<u;++a)-1!==(t=(n=o[a]).indexOf(":"))&&(r=n.slice(0,t).toLowerCase(),i=h(n.slice(t+1)),s[r]=i);return s}(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this._setHeaderProperties(this.header),null===this.text&&e._responseType?this.body=this.xhr.response:this.body="HEAD"!=this.req.method?this._parseBody(this.text?this.text:this.xhr.response):null}function b(e,t){var n=this;this._query=this._query||[],this.method=e,this.url=t,this.header={},this._header={},this.on("end",(function(){var e,t=null,r=null;try{r=new g(n)}catch(e){return(t=new Error("Parser is unable to parse the response")).parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=r.status,n.callback(e,r)):n.callback(null,r)}))}function y(e,t,n){var r=l("DELETE",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}l.serializeObject=f,l.parseString=p,l.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},l.serialize={"application/x-www-form-urlencoded":f,"application/json":JSON.stringify},l.parse={"application/x-www-form-urlencoded":p,"application/json":JSON.parse},a(g.prototype),g.prototype._parseBody=function(e){var t=l.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&m(this.type)&&(t=l.parse["application/json"]),t&&e&&(e.length||e instanceof Object)?t(e):null)},g.prototype.toError=function(){var e=this.req,t=e.method,n=e.url,r="cannot "+t+" "+n+" ("+this.status+")",i=new Error(r);return i.status=this.status,i.method=t,i.url=n,i},l.Response=g,i(b.prototype),o(b.prototype),b.prototype.type=function(e){return this.set("Content-Type",l.types[e]||e),this},b.prototype.accept=function(e){return this.set("Accept",l.types[e]||e),this},b.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});var r=function(e){if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},b.prototype.query=function(e){return"string"!=typeof e&&(e=f(e)),e&&this._query.push(e),this},b.prototype.attach=function(e,t,n){if(t){if(this._data)throw Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},b.prototype._getFormData=function(){return this._formData||(this._formData=new r.FormData),this._formData},b.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();var n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},b.prototype.crossDomainError=function(){var e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},b.prototype.buffer=b.prototype.ca=b.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},b.prototype.pipe=b.prototype.write=function(){throw Error("Streaming is not supported in browser version of superagent")},b.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},b.prototype.end=function(e){return this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||c,this._finalizeQueryString(),this._end()},b.prototype._end=function(){var e=this,t=this.xhr=l.getXHR(),n=this._formData||this._data;this._setTimeouts(),t.onreadystatechange=function(){var n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4==n){var r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}};var r=function(t,n){n.total>0&&(n.percent=n.loaded/n.total*100),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.onprogress=r.bind(null,"download"),t.upload&&(t.upload.onprogress=r.bind(null,"upload"))}catch(e){}try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof n&&!this._isHost(n)){var i=this._header["content-type"],o=this._serializer||l.serialize[i?i.split(";")[0]:""];!o&&m(i)&&(o=l.serialize["application/json"]),o&&(n=o(n))}for(var s in this.header)null!=this.header[s]&&this.header.hasOwnProperty(s)&&t.setRequestHeader(s,this.header[s]);return this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0!==n?n:null),this},l.agent=function(){return new u},["GET","POST","OPTIONS","PATCH","PUT","DELETE"].forEach((function(e){u.prototype[e.toLowerCase()]=function(t,n){var r=new l.Request(e,t);return this._setDefaults(r),n&&r.end(n),r}})),u.prototype.del=u.prototype.delete,l.get=function(e,t,n){var r=l("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},l.head=function(e,t,n){var r=l("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},l.options=function(e,t,n){var r=l("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},l.del=y,l.delete=y,l.patch=function(e,t,n){var r=l("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},l.post=function(e,t,n){var r=l("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},l.put=function(e,t,n){var r=l("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){var r=n(77),i=n(35),o=36e5,s=6e4,a=2,u=/[T ]/,c=/:/,l=/^(\d{2})$/,h=[/^([+-]\d{2})$/,/^([+-]\d{3})$/,/^([+-]\d{4})$/],f=/^(\d{4})/,d=[/^([+-]\d{4})/,/^([+-]\d{5})/,/^([+-]\d{6})/],p=/^-(\d{2})$/,m=/^-?(\d{3})$/,g=/^-?(\d{2})-?(\d{2})$/,b=/^-?W(\d{2})$/,y=/^-?W(\d{2})-?(\d{1})$/,v=/^(\d{2}([.,]\d*)?)$/,_=/^(\d{2}):?(\d{2}([.,]\d*)?)$/,w=/^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,k=/([Z+-].*)$/,S=/^(Z)$/,E=/^([+-])(\d{2})$/,T=/^([+-])(\d{2}):?(\d{2})$/;function C(e,t,n){t=t||0,n=n||0;var r=new Date(0);r.setUTCFullYear(e,0,4);var i=7*t+n+1-(r.getUTCDay()||7);return r.setUTCDate(r.getUTCDate()+i),r}e.exports=function(e,t){if(i(e))return new Date(e.getTime());if("string"!=typeof e)return new Date(e);var n=(t||{}).additionalDigits;n=null==n?a:Number(n);var x=function(e){var t,n={},r=e.split(u);c.test(r[0])?(n.date=null,t=r[0]):(n.date=r[0],t=r[1]);if(t){var i=k.exec(t);i?(n.time=t.replace(i[1],""),n.timezone=i[1]):n.time=t}return n}(e),R=function(e,t){var n,r=h[t],i=d[t];if(n=f.exec(e)||i.exec(e)){var o=n[1];return{year:parseInt(o,10),restDateString:e.slice(o.length)}}if(n=l.exec(e)||r.exec(e)){var s=n[1];return{year:100*parseInt(s,10),restDateString:e.slice(s.length)}}return{year:null}}(x.date,n),A=R.year,I=function(e,t){if(null===t)return null;var n,r,i,o;if(0===e.length)return(r=new Date(0)).setUTCFullYear(t),r;if(n=p.exec(e))return r=new Date(0),i=parseInt(n[1],10)-1,r.setUTCFullYear(t,i),r;if(n=m.exec(e)){r=new Date(0);var s=parseInt(n[1],10);return r.setUTCFullYear(t,0,s),r}if(n=g.exec(e)){r=new Date(0),i=parseInt(n[1],10)-1;var a=parseInt(n[2],10);return r.setUTCFullYear(t,i,a),r}if(n=b.exec(e))return o=parseInt(n[1],10)-1,C(t,o);if(n=y.exec(e)){o=parseInt(n[1],10)-1;var u=parseInt(n[2],10)-1;return C(t,o,u)}return null}(R.restDateString,A);if(I){var P,O=I.getTime(),M=0;if(x.time&&(M=function(e){var t,n,r;if(t=v.exec(e))return(n=parseFloat(t[1].replace(",",".")))%24*o;if(t=_.exec(e))return n=parseInt(t[1],10),r=parseFloat(t[2].replace(",",".")),n%24*o+r*s;if(t=w.exec(e)){n=parseInt(t[1],10),r=parseInt(t[2],10);var i=parseFloat(t[3].replace(",","."));return n%24*o+r*s+1e3*i}return null}(x.time)),x.timezone)P=function(e){var t,n;if(t=S.exec(e))return 0;if(t=E.exec(e))return n=60*parseInt(t[2],10),"+"===t[1]?-n:n;if(t=T.exec(e))return n=60*parseInt(t[2],10)+parseInt(t[3],10),"+"===t[1]?-n:n;return 0}(x.timezone)*s;else{var L=O+M,D=new Date(L);P=r(D);var j=new Date(L);j.setDate(D.getDate()+1);var U=r(j)-r(D);U>0&&(P+=U)}return new Date(O+M+P)}return new Date(e)}},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}},function(e,t,n){"use strict";var r,i="object"==typeof Reflect?Reflect:null,o=i&&"function"==typeof i.apply?i.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};r=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var s=Number.isNaN||function(e){return e!=e};function a(){a.init.call(this)}e.exports=a,a.EventEmitter=a,a.prototype._events=void 0,a.prototype._eventsCount=0,a.prototype._maxListeners=void 0;var u=10;function c(e){return void 0===e._maxListeners?a.defaultMaxListeners:e._maxListeners}function l(e,t,n,r){var i,o,s,a;if("function"!=typeof n)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n);if(void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),s=o[t]),void 0===s)s=o[t]=n,++e._eventsCount;else if("function"==typeof s?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(i=c(e))>0&&s.length>i&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,a=u,console&&console.warn&&console.warn(a)}return e}function h(){for(var e=[],t=0;t<arguments.length;t++)e.push(arguments[t]);this.fired||(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,o(this.listener,this.target,e))}function f(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=h.bind(r);return i.listener=n,r.wrapFn=i,i}function d(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):m(i,i.length)}function p(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function m(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return u},set:function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");u=e}}),a.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},a.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},a.prototype.getMaxListeners=function(){return c(this)},a.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r="error"===e,i=this._events;if(void 0!==i)r=r&&void 0===i.error;else if(!r)return!1;if(r){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var u=i[e];if(void 0===u)return!1;if("function"==typeof u)o(u,this,t);else{var c=u.length,l=m(u,c);for(n=0;n<c;++n)o(l[n],this,t)}return!0},a.prototype.addListener=function(e,t){return l(this,e,t,!1)},a.prototype.on=a.prototype.addListener,a.prototype.prependListener=function(e,t){return l(this,e,t,!0)},a.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);return this.on(e,f(this,e,t)),this},a.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);return this.prependListener(e,f(this,e,t)),this},a.prototype.removeListener=function(e,t){var n,r,i,o,s;if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);if(void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===t||n[o].listener===t){s=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},a.prototype.off=a.prototype.removeListener,a.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,o=Object.keys(n);for(r=0;r<o.length;++r)"removeListener"!==(i=o[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},a.prototype.listeners=function(e){return d(this,e,!0)},a.prototype.rawListeners=function(e){return d(this,e,!1)},a.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},a.prototype.listenerCount=p,a.prototype.eventNames=function(){return this._eventsCount>0?r(this._events):[]}},function(e,t,n){(function(r){t.log=function(...e){return"object"==typeof console&&console.log&&console.log(...e)},t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,i=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(i=r))}),t.splice(i,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.exports=n(114)(t);const{formatters:i}=e.exports;i.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}).call(this,n(6))},function(e,t,n){(t=e.exports=n(39)).Stream=t,t.Readable=t,t.Writable=n(44),t.Duplex=n(16),t.Transform=n(46),t.PassThrough=n(107),t.finished=n(25),t.pipeline=n(108)},function(e,t,n){"use strict";var r={};function i(e,t,n){n||(n=Error);var i=function(e){var n,r;function i(n,r,i){return e.call(this,function(e,n,r){return"string"==typeof t?t:t(e,n,r)}(n,r,i))||this}return r=e,(n=i).prototype=Object.create(r.prototype),n.prototype.constructor=n,n.__proto__=r,i}(n);i.prototype.name=n.name,i.prototype.code=e,r[e]=i}function o(e,t){if(Array.isArray(e)){var n=e.length;return e=e.map((function(e){return String(e)})),n>2?"one of ".concat(t," ").concat(e.slice(0,n-1).join(", "),", or ")+e[n-1]:2===n?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}return"of ".concat(t," ").concat(String(e))}i("ERR_INVALID_OPT_VALUE",(function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),i("ERR_INVALID_ARG_TYPE",(function(e,t,n){var r,i,s,a;if("string"==typeof t&&(i="not ",t.substr(!s||s<0?0:+s,i.length)===i)?(r="must not be",t=t.replace(/^not /,"")):r="must be",function(e,t,n){return(void 0===n||n>e.length)&&(n=e.length),e.substring(n-t.length,n)===t}(e," argument"))a="The ".concat(e," ").concat(r," ").concat(o(t,"type"));else{var u=function(e,t,n){return"number"!=typeof n&&(n=0),!(n+t.length>e.length)&&-1!==e.indexOf(t,n)}(e,".")?"property":"argument";a='The "'.concat(e,'" ').concat(u," ").concat(r," ").concat(o(t,"type"))}return a+=". Received type ".concat(typeof n)}),TypeError),i("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),i("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return"The "+e+" method is not implemented"})),i("ERR_STREAM_PREMATURE_CLOSE","Premature close"),i("ERR_STREAM_DESTROYED",(function(e){return"Cannot call "+e+" after a stream was destroyed"})),i("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),i("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),i("ERR_STREAM_WRITE_AFTER_END","write after end"),i("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),i("ERR_UNKNOWN_ENCODING",(function(e){return"Unknown encoding: "+e}),TypeError),i("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),e.exports.codes=r},function(e,t,n){"use strict";(function(t){var r=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};e.exports=c;var i=n(39),o=n(44);n(11)(c,i);for(var s=r(o.prototype),a=0;a<s.length;a++){var u=s[a];c.prototype[u]||(c.prototype[u]=o.prototype[u])}function c(e){if(!(this instanceof c))return new c(e);i.call(this,e),o.call(this,e),this.allowHalfOpen=!0,e&&(!1===e.readable&&(this.readable=!1),!1===e.writable&&(this.writable=!1),!1===e.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",l)))}function l(){this._writableState.ended||t.nextTick(h,this)}function h(e){e.end()}Object.defineProperty(c.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(c.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(c.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(c.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed&&this._writableState.destroyed)},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}})}).call(this,n(6))},function(e,t,n){"use strict";var r=n(18),i=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};e.exports=h;var o=Object.create(n(19));o.inherits=n(11);var s=n(51),a=n(54);o.inherits(h,s);for(var u=i(a.prototype),c=0;c<u.length;c++){var l=u[c];h.prototype[l]||(h.prototype[l]=a.prototype[l])}function h(e){if(!(this instanceof h))return new h(e);s.call(this,e),a.call(this,e),e&&!1===e.readable&&(this.readable=!1),e&&!1===e.writable&&(this.writable=!1),this.allowHalfOpen=!0,e&&!1===e.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",f)}function f(){this.allowHalfOpen||this._writableState.ended||r.nextTick(d,this)}function d(e){e.end()}Object.defineProperty(h.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(h.prototype,"destroyed",{get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed&&this._writableState.destroyed)},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}}),h.prototype._destroy=function(e,t){this.push(null),this.end(),r.nextTick(t,e)}},function(e,t,n){"use strict";(function(t){void 0===t||!t.version||0===t.version.indexOf("v0.")||0===t.version.indexOf("v1.")&&0!==t.version.indexOf("v1.8.")?e.exports={nextTick:function(e,n,r,i){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return t.nextTick(e);case 2:return t.nextTick((function(){e.call(null,n)}));case 3:return t.nextTick((function(){e.call(null,n,r)}));case 4:return t.nextTick((function(){e.call(null,n,r,i)}));default:for(o=new Array(a-1),s=0;s<o.length;)o[s++]=arguments[s];return t.nextTick((function(){e.apply(null,o)}))}}}:e.exports=t}).call(this,n(6))},function(e,t,n){(function(e){function n(e){return Object.prototype.toString.call(e)}t.isArray=function(e){return Array.isArray?Array.isArray(e):"[object Array]"===n(e)},t.isBoolean=function(e){return"boolean"==typeof e},t.isNull=function(e){return null===e},t.isNullOrUndefined=function(e){return null==e},t.isNumber=function(e){return"number"==typeof e},t.isString=function(e){return"string"==typeof e},t.isSymbol=function(e){return"symbol"==typeof e},t.isUndefined=function(e){return void 0===e},t.isRegExp=function(e){return"[object RegExp]"===n(e)},t.isObject=function(e){return"object"==typeof e&&null!==e},t.isDate=function(e){return"[object Date]"===n(e)},t.isError=function(e){return"[object Error]"===n(e)||e instanceof Error},t.isFunction=function(e){return"function"==typeof e},t.isPrimitive=function(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||void 0===e},t.isBuffer=e.isBuffer}).call(this,n(7).Buffer)},function(e,t,n){var r=n(67),i=n(68),o=n(33),s=n(69);e.exports=function(e){return r(e)||i(e)||o(e)||s()}},function(e,t,n){var r=n(76),i=n(81),o=n(36),s=n(10),a=n(84),u=n(37);var c={M:function(e){return e.getMonth()+1},MM:function(e){return f(e.getMonth()+1,2)},Q:function(e){return Math.ceil((e.getMonth()+1)/3)},D:function(e){return e.getDate()},DD:function(e){return f(e.getDate(),2)},DDD:function(e){return r(e)},DDDD:function(e){return f(r(e),3)},d:function(e){return e.getDay()},E:function(e){return e.getDay()||7},W:function(e){return i(e)},WW:function(e){return f(i(e),2)},YY:function(e){return f(e.getFullYear(),4).substr(2)},YYYY:function(e){return f(e.getFullYear(),4)},GG:function(e){return String(o(e)).substr(2)},GGGG:function(e){return o(e)},H:function(e){return e.getHours()},HH:function(e){return f(e.getHours(),2)},h:function(e){var t=e.getHours();return 0===t?12:t>12?t%12:t},hh:function(e){return f(c.h(e),2)},m:function(e){return e.getMinutes()},mm:function(e){return f(e.getMinutes(),2)},s:function(e){return e.getSeconds()},ss:function(e){return f(e.getSeconds(),2)},S:function(e){return Math.floor(e.getMilliseconds()/100)},SS:function(e){return f(Math.floor(e.getMilliseconds()/10),2)},SSS:function(e){return f(e.getMilliseconds(),3)},Z:function(e){return h(e.getTimezoneOffset(),":")},ZZ:function(e){return h(e.getTimezoneOffset())},X:function(e){return Math.floor(e.getTime()/1e3)},x:function(e){return e.getTime()}};function l(e){return e.match(/\[[\s\S]/)?e.replace(/^\[|]$/g,""):e.replace(/\\/g,"")}function h(e,t){t=t||"";var n=e>0?"-":"+",r=Math.abs(e),i=r%60;return n+f(Math.floor(r/60),2)+t+f(i,2)}function f(e,t){for(var n=Math.abs(e).toString();n.length<t;)n="0"+n;return n}e.exports=function(e,t,n){var r=t?String(t):"YYYY-MM-DDTHH:mm:ss.SSSZ",i=(n||{}).locale,o=u.format.formatters,h=u.format.formattingTokensRegExp;i&&i.format&&i.format.formatters&&(o=i.format.formatters,i.format.formattingTokensRegExp&&(h=i.format.formattingTokensRegExp));var f=s(e);return a(f)?function(e,t,n){var r,i,o=e.match(n),s=o.length;for(r=0;r<s;r++)i=t[o[r]]||c[o[r]],o[r]=i||l(o[r]);return function(e){for(var t="",n=0;n<s;n++)o[n]instanceof Function?t+=o[n](e,c):t+=o[n];return t}}(r,o,h)(f):"Invalid Date"}},function(e,t,n){"use strict";var r=n(104).Buffer,i=r.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function o(e){var t;switch(this.encoding=function(e){var t=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof t&&(r.isEncoding===i||!i(e)))throw new Error("Unknown encoding: "+e);return t||e}(e),this.encoding){case"utf16le":this.text=u,this.end=c,t=4;break;case"utf8":this.fillLast=a,t=4;break;case"base64":this.text=l,this.end=h,t=3;break;default:return this.write=f,void(this.end=d)}this.lastNeed=0,this.lastTotal=0,this.lastChar=r.allocUnsafe(t)}function s(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function a(e){var t=this.lastTotal-this.lastNeed,n=function(e,t,n){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}(this,e);return void 0!==n?n:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function u(e,t){if((e.length-t)%2==0){var n=e.toString("utf16le",t);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function c(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,n)}return t}function l(e,t){var n=(e.length-t)%3;return 0===n?e.toString("base64",t):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-n))}function h(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function f(e){return e.toString(this.encoding)}function d(e){return e&&e.length?this.write(e):""}t.StringDecoder=o,o.prototype.write=function(e){if(0===e.length)return"";var t,n;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n<e.length?t?t+this.text(e,n):this.text(e,n):t||""},o.prototype.end=function(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t},o.prototype.text=function(e,t){var n=function(e,t,n){var r=t.length-1;if(r<n)return 0;var i=s(t[r]);if(i>=0)return i>0&&(e.lastNeed=i-1),i;if(--r<n||-2===i)return 0;if((i=s(t[r]))>=0)return i>0&&(e.lastNeed=i-2),i;if(--r<n||-2===i)return 0;if((i=s(t[r]))>=0)return i>0&&(2===i?i=0:e.lastNeed=i-3),i;return 0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=n;var r=e.length-(n-this.lastNeed);return e.copy(this.lastChar,0,r),e.toString("utf8",t,r)},o.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}},function(e,t,n){var r=n(82);e.exports=function(e){return r(e,{weekStartsOn:1})}},function(e,t){e.exports=function(){for(var e={},t=0;t<arguments.length;t++){var r=arguments[t];for(var i in r)n.call(r,i)&&(e[i]=r[i])}return e};var n=Object.prototype.hasOwnProperty},function(e,t,n){"use strict";var r=n(15).codes.ERR_STREAM_PREMATURE_CLOSE;function i(){}e.exports=function e(t,n,o){if("function"==typeof n)return e(t,null,n);n||(n={}),o=function(e){var t=!1;return function(){if(!t){t=!0;for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];e.apply(this,r)}}}(o||i);var s=n.readable||!1!==n.readable&&t.readable,a=n.writable||!1!==n.writable&&t.writable,u=function(){t.writable||l()},c=t._writableState&&t._writableState.finished,l=function(){a=!1,c=!0,s||o.call(t)},h=t._readableState&&t._readableState.endEmitted,f=function(){s=!1,h=!0,a||o.call(t)},d=function(e){o.call(t,e)},p=function(){var e;return s&&!h?(t._readableState&&t._readableState.ended||(e=new r),o.call(t,e)):a&&!c?(t._writableState&&t._writableState.ended||(e=new r),o.call(t,e)):void 0},m=function(){t.req.on("finish",l)};return!function(e){return e.setHeader&&"function"==typeof e.abort}(t)?a&&!t._writableState&&(t.on("end",u),t.on("close",u)):(t.on("complete",l),t.on("abort",p),t.req?m():t.on("request",m)),t.on("end",f),t.on("finish",l),!1!==n.error&&t.on("error",d),t.on("close",p),function(){t.removeListener("complete",l),t.removeListener("abort",p),t.removeListener("request",m),t.req&&t.req.removeListener("finish",l),t.removeListener("end",u),t.removeListener("close",u),t.removeListener("finish",l),t.removeListener("end",f),t.removeListener("error",d),t.removeListener("close",p)}}},function(e,t,n){"use strict";var r=n(128),i=n(13)("mqttjs:tls");e.exports=function(e,t){var n;function o(r){t.rejectUnauthorized&&e.emit("error",r),n.end()}return t.port=t.port||8883,t.host=t.hostname||t.host||"localhost",t.servername=t.host,t.rejectUnauthorized=!1!==t.rejectUnauthorized,delete t.path,i("port %d host %s rejectUnauthorized %b",t.port,t.host,t.rejectUnauthorized),(n=r.connect(t)).on("secureConnect",(function(){t.rejectUnauthorized&&!n.authorized?n.emit("error",new Error("TLS not authorized")):n.removeListener("error",o)})),n.on("error",o),n}},function(e,t,n){(function(t,r){var i=n(129),o=n(136),s=n(11),a=n(139),u=t.from&&t.from!==Uint8Array.from?t.from([0]):new t([0]),c=function(e,t){e._corked?e.once("uncork",t):t()},l=function(e,t){return function(n){n?function(e,t){e._autoDestroy&&e.destroy(t)}(e,"premature close"===n.message?null:n):t&&!e._ended&&e.end()}},h=function(e,t,n){if(!(this instanceof h))return new h(e,t,n);i.Duplex.call(this,n),this._writable=null,this._readable=null,this._readable2=null,this._autoDestroy=!n||!1!==n.autoDestroy,this._forwardDestroy=!n||!1!==n.destroy,this._forwardEnd=!n||!1!==n.end,this._corked=1,this._ondrain=null,this._drained=!1,this._forwarding=!1,this._unwrite=null,this._unread=null,this._ended=!1,this.destroyed=!1,e&&this.setWritable(e),t&&this.setReadable(t)};s(h,i.Duplex),h.obj=function(e,t,n){return n||(n={}),n.objectMode=!0,n.highWaterMark=16,new h(e,t,n)},h.prototype.cork=function(){1==++this._corked&&this.emit("cork")},h.prototype.uncork=function(){this._corked&&0==--this._corked&&this.emit("uncork")},h.prototype.setWritable=function(e){if(this._unwrite&&this._unwrite(),this.destroyed)e&&e.destroy&&e.destroy();else if(null!==e&&!1!==e){var t=this,n=o(e,{writable:!0,readable:!1},l(this,this._forwardEnd)),i=function(){var e=t._ondrain;t._ondrain=null,e&&e()};this._unwrite&&r.nextTick(i),this._writable=e,this._writable.on("drain",i),this._unwrite=function(){t._writable.removeListener("drain",i),n()},this.uncork()}else this.end()},h.prototype.setReadable=function(e){if(this._unread&&this._unread(),this.destroyed)e&&e.destroy&&e.destroy();else{if(null===e||!1===e)return this.push(null),void this.resume();var t,n=this,r=o(e,{writable:!1,readable:!0},l(this)),s=function(){n._forward()},a=function(){n.push(null)};this._drained=!0,this._readable=e,this._readable2=e._readableState?e:(t=e,new i.Readable({objectMode:!0,highWaterMark:16}).wrap(t)),this._readable2.on("readable",s),this._readable2.on("end",a),this._unread=function(){n._readable2.removeListener("readable",s),n._readable2.removeListener("end",a),r()},this._forward()}},h.prototype._read=function(){this._drained=!0,this._forward()},h.prototype._forward=function(){if(!this._forwarding&&this._readable2&&this._drained){var e;for(this._forwarding=!0;this._drained&&null!==(e=a(this._readable2));)this.destroyed||(this._drained=this.push(e));this._forwarding=!1}},h.prototype.destroy=function(e){if(!this.destroyed){this.destroyed=!0;var t=this;r.nextTick((function(){t._destroy(e)}))}},h.prototype._destroy=function(e){if(e){var t=this._ondrain;this._ondrain=null,t?t(e):this.emit("error",e)}this._forwardDestroy&&(this._readable&&this._readable.destroy&&this._readable.destroy(),this._writable&&this._writable.destroy&&this._writable.destroy()),this.emit("close")},h.prototype._write=function(e,t,n){return this.destroyed?n():this._corked?c(this,this._write.bind(this,e,t,n)):e===u?this._finish(n):this._writable?void(!1===this._writable.write(e)?this._ondrain=n:n()):n()},h.prototype._finish=function(e){var t=this;this.emit("preend"),c(this,(function(){var n,r;n=t._forwardEnd&&t._writable,r=function(){!1===t._writableState.prefinished&&(t._writableState.prefinished=!0),t.emit("prefinish"),c(t,e)},n?n._writableState&&n._writableState.finished?r():n._writableState?n.end(r):(n.end(),r()):r()}))},h.prototype.end=function(e,t,n){return"function"==typeof e?this.end(null,null,e):"function"==typeof t?this.end(e,null,t):(this._ended=!0,e&&this.write(e),this._writableState.ending||this.write(u),i.Writable.prototype.end.call(this,n))},e.exports=h}).call(this,n(7).Buffer,n(6))},function(e,t,n){var r=n(7),i=r.Buffer;function o(e,t){for(var n in e)t[n]=e[n]}function s(e,t,n){return i(e,t,n)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?e.exports=r:(o(r,t),t.Buffer=s),o(i,s),s.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return i(e,t,n)},s.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var r=i(e);return void 0!==t?"string"==typeof n?r.fill(t,n):r.fill(t):r.fill(0),r},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i(e)},s.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}},function(e,t){e.exports=function(e){var t;if("undefined"!=typeof Symbol){if(Symbol.asyncIterator&&null!=(t=e[Symbol.asyncIterator]))return t.call(e);if(Symbol.iterator&&null!=(t=e[Symbol.iterator]))return t.call(e)}throw new TypeError("Object is not async iterable")}},function(e,t,n){var r=n(58);e.exports=function(e){return new r(e)}},function(e,t,n){var r=n(141);e.exports=function(e){return function(){return new r(e.apply(this,arguments))}}},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}},function(e,t,n){var r=n(32);e.exports=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}},function(e,t,n){"use strict";e.exports=function(e){return null!==e&&"object"==typeof e}},function(e,t){e.exports=function(e){return e instanceof Date}},function(e,t,n){var r=n(10),i=n(23);e.exports=function(e){var t=r(e),n=t.getFullYear(),o=new Date(0);o.setFullYear(n+1,0,4),o.setHours(0,0,0,0);var s=i(o),a=new Date(0);a.setFullYear(n,0,4),a.setHours(0,0,0,0);var u=i(a);return t.getTime()>=s.getTime()?n+1:t.getTime()>=u.getTime()?n:n-1}},function(e,t,n){var r=n(85),i=n(86);e.exports={distanceInWords:r(),format:i()}},function(e,t,n){"use strict";var r=n(24),i=n(14).Readable,o={objectMode:!0},s={clean:!0};function a(e){if(!(this instanceof a))return new a(e);this.options=e||{},this.options=r(s,e),this._inflights=new Map}a.prototype.put=function(e,t){return this._inflights.set(e.messageId,e),t&&t(),this},a.prototype.createStream=function(){var e=new i(o),t=!1,n=[],r=0;return this._inflights.forEach((function(e,t){n.push(e)})),e._read=function(){!t&&r<n.length?this.push(n[r++]):this.push(null)},e.destroy=function(){if(!t){var e=this;t=!0,setTimeout((function(){e.emit("close")}),0)}},e},a.prototype.del=function(e,t){return(e=this._inflights.get(e.messageId))?(this._inflights.delete(e.messageId),t(null,e)):t&&t(new Error("missing packet")),this},a.prototype.get=function(e,t){return(e=this._inflights.get(e.messageId))?t(null,e):t&&t(new Error("missing packet")),this},a.prototype.close=function(e){this.options.clean&&(this._inflights=null),e&&e()},e.exports=a},function(e,t,n){"use strict";(function(t,r){var i;e.exports=T,T.ReadableState=E;n(12).EventEmitter;var o=function(e,t){return e.listeners(t).length},s=n(40),a=n(7).Buffer,u=t.Uint8Array||function(){};var c,l=n(101);c=l&&l.debuglog?l.debuglog("stream"):function(){};var h,f,d,p=n(102),m=n(42),g=n(43).getHighWaterMark,b=n(15).codes,y=b.ERR_INVALID_ARG_TYPE,v=b.ERR_STREAM_PUSH_AFTER_EOF,_=b.ERR_METHOD_NOT_IMPLEMENTED,w=b.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;n(11)(T,s);var k=m.errorOrDestroy,S=["error","close","destroy","pause","resume"];function E(e,t,r){i=i||n(16),e=e||{},"boolean"!=typeof r&&(r=t instanceof i),this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.readableObjectMode),this.highWaterMark=g(this,e,"readableHighWaterMark",r),this.buffer=new p,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(h||(h=n(22).StringDecoder),this.decoder=new h(e.encoding),this.encoding=e.encoding)}function T(e){if(i=i||n(16),!(this instanceof T))return new T(e);var t=this instanceof i;this._readableState=new E(e,this,t),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),s.call(this)}function C(e,t,n,r,i){c("readableAddChunk",t);var o,s=e._readableState;if(null===t)s.reading=!1,function(e,t){if(c("onEofChunk"),t.ended)return;if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,t.sync?I(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,P(e)))}(e,s);else if(i||(o=function(e,t){var n;r=t,a.isBuffer(r)||r instanceof u||"string"==typeof t||void 0===t||e.objectMode||(n=new y("chunk",["string","Buffer","Uint8Array"],t));var r;return n}(s,t)),o)k(e,o);else if(s.objectMode||t&&t.length>0)if("string"==typeof t||s.objectMode||Object.getPrototypeOf(t)===a.prototype||(t=function(e){return a.from(e)}(t)),r)s.endEmitted?k(e,new w):x(e,s,t,!0);else if(s.ended)k(e,new v);else{if(s.destroyed)return!1;s.reading=!1,s.decoder&&!n?(t=s.decoder.write(t),s.objectMode||0!==t.length?x(e,s,t,!1):O(e,s)):x(e,s,t,!1)}else r||(s.reading=!1,O(e,s));return!s.ended&&(s.length<s.highWaterMark||0===s.length)}function x(e,t,n,r){t.flowing&&0===t.length&&!t.sync?(t.awaitDrain=0,e.emit("data",n)):(t.length+=t.objectMode?1:n.length,r?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&I(e)),O(e,t)}Object.defineProperty(T.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),T.prototype.destroy=m.destroy,T.prototype._undestroy=m.undestroy,T.prototype._destroy=function(e,t){t(e)},T.prototype.push=function(e,t){var n,r=this._readableState;return r.objectMode?n=!0:"string"==typeof e&&((t=t||r.defaultEncoding)!==r.encoding&&(e=a.from(e,t),t=""),n=!0),C(this,e,t,!1,n)},T.prototype.unshift=function(e){return C(this,e,null,!0,!1)},T.prototype.isPaused=function(){return!1===this._readableState.flowing},T.prototype.setEncoding=function(e){h||(h=n(22).StringDecoder);var t=new h(e);this._readableState.decoder=t,this._readableState.encoding=this._readableState.decoder.encoding;for(var r=this._readableState.buffer.head,i="";null!==r;)i+=t.write(r.data),r=r.next;return this._readableState.buffer.clear(),""!==i&&this._readableState.buffer.push(i),this._readableState.length=i.length,this};var R=1073741824;function A(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!=e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=function(e){return e>=R?e=R:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function I(e){var t=e._readableState;c("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(c("emitReadable",t.flowing),t.emittedReadable=!0,r.nextTick(P,e))}function P(e){var t=e._readableState;c("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,U(e)}function O(e,t){t.readingMore||(t.readingMore=!0,r.nextTick(M,e,t))}function M(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&0===t.length);){var n=t.length;if(c("maybeReadMore read 0"),e.read(0),n===t.length)break}t.readingMore=!1}function L(e){var t=e._readableState;t.readableListening=e.listenerCount("readable")>0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume()}function D(e){c("readable nexttick read 0"),e.read(0)}function j(e,t){c("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),U(e),t.flowing&&!t.reading&&e.read(0)}function U(e){var t=e._readableState;for(c("flow",t.flowing);t.flowing&&null!==e.read(););}function q(e,t){return 0===t.length?null:(t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n);var n}function F(e){var t=e._readableState;c("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,r.nextTick(N,t,e))}function N(e,t){if(c("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy()}}function B(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}T.prototype.read=function(e){c("read",e),e=parseInt(e,10);var t=this._readableState,n=e;if(0!==e&&(t.emittedReadable=!1),0===e&&t.needReadable&&((0!==t.highWaterMark?t.length>=t.highWaterMark:t.length>0)||t.ended))return c("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?F(this):I(this),null;if(0===(e=A(e,t))&&t.ended)return 0===t.length&&F(this),null;var r,i=t.needReadable;return c("need readable",i),(0===t.length||t.length-e<t.highWaterMark)&&c("length less than watermark",i=!0),t.ended||t.reading?c("reading or ended",i=!1):i&&(c("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=A(n,t))),null===(r=e>0?q(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&F(this)),null!==r&&this.emit("data",r),r},T.prototype._read=function(e){k(this,new _("_read()"))},T.prototype.pipe=function(e,t){var n=this,i=this._readableState;switch(i.pipesCount){case 0:i.pipes=e;break;case 1:i.pipes=[i.pipes,e];break;default:i.pipes.push(e)}i.pipesCount+=1,c("pipe count=%d opts=%j",i.pipesCount,t);var s=(!t||!1!==t.end)&&e!==r.stdout&&e!==r.stderr?u:g;function a(t,r){c("onunpipe"),t===n&&r&&!1===r.hasUnpiped&&(r.hasUnpiped=!0,c("cleanup"),e.removeListener("close",p),e.removeListener("finish",m),e.removeListener("drain",l),e.removeListener("error",d),e.removeListener("unpipe",a),n.removeListener("end",u),n.removeListener("end",g),n.removeListener("data",f),h=!0,!i.awaitDrain||e._writableState&&!e._writableState.needDrain||l())}function u(){c("onend"),e.end()}i.endEmitted?r.nextTick(s):n.once("end",s),e.on("unpipe",a);var l=function(e){return function(){var t=e._readableState;c("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&o(e,"data")&&(t.flowing=!0,U(e))}}(n);e.on("drain",l);var h=!1;function f(t){c("ondata");var r=e.write(t);c("dest.write",r),!1===r&&((1===i.pipesCount&&i.pipes===e||i.pipesCount>1&&-1!==B(i.pipes,e))&&!h&&(c("false write response, pause",i.awaitDrain),i.awaitDrain++),n.pause())}function d(t){c("onerror",t),g(),e.removeListener("error",d),0===o(e,"error")&&k(e,t)}function p(){e.removeListener("finish",m),g()}function m(){c("onfinish"),e.removeListener("close",p),g()}function g(){c("unpipe"),n.unpipe(e)}return n.on("data",f),function(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n)}(e,"error",d),e.once("close",p),e.once("finish",m),e.emit("pipe",n),i.flowing||(c("pipe resume"),n.resume()),e},T.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n),this);if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o<i;o++)r[o].emit("unpipe",this,{hasUnpiped:!1});return this}var s=B(t.pipes,e);return-1===s?this:(t.pipes.splice(s,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,n),this)},T.prototype.on=function(e,t){var n=s.prototype.on.call(this,e,t),i=this._readableState;return"data"===e?(i.readableListening=this.listenerCount("readable")>0,!1!==i.flowing&&this.resume()):"readable"===e&&(i.endEmitted||i.readableListening||(i.readableListening=i.needReadable=!0,i.flowing=!1,i.emittedReadable=!1,c("on readable",i.length,i.reading),i.length?I(this):i.reading||r.nextTick(D,this))),n},T.prototype.addListener=T.prototype.on,T.prototype.removeListener=function(e,t){var n=s.prototype.removeListener.call(this,e,t);return"readable"===e&&r.nextTick(L,this),n},T.prototype.removeAllListeners=function(e){var t=s.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||r.nextTick(L,this),t},T.prototype.resume=function(){var e=this._readableState;return e.flowing||(c("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,r.nextTick(j,e,t))}(this,e)),e.paused=!1,this},T.prototype.pause=function(){return c("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(c("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},T.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on("end",(function(){if(c("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e)}t.push(null)})),e.on("data",(function(i){(c("wrapped data"),n.decoder&&(i=n.decoder.write(i)),n.objectMode&&null==i)||(n.objectMode||i&&i.length)&&(t.push(i)||(r=!0,e.pause()))})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var o=0;o<S.length;o++)e.on(S[o],this.emit.bind(this,S[o]));return this._read=function(t){c("wrapped _read",t),r&&(r=!1,e.resume())},this},"function"==typeof Symbol&&(T.prototype[Symbol.asyncIterator]=function(){return void 0===f&&(f=n(105)),f(this)}),Object.defineProperty(T.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(T.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(T.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),T._fromList=q,Object.defineProperty(T.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(T.from=function(e,t){return void 0===d&&(d=n(106)),d(T,e,t)})}).call(this,n(9),n(6))},function(e,t,n){e.exports=n(12).EventEmitter},function(e,t){var n={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},function(e,t,n){"use strict";(function(t){function n(e,t){i(e,t),r(e)}function r(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function i(e,t){e.emit("error",t)}e.exports={destroy:function(e,o){var s=this,a=this._readableState&&this._readableState.destroyed,u=this._writableState&&this._writableState.destroyed;return a||u?(o?o(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,t.nextTick(i,this,e)):t.nextTick(i,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,(function(e){!o&&e?s._writableState?s._writableState.errorEmitted?t.nextTick(r,s):(s._writableState.errorEmitted=!0,t.nextTick(n,s,e)):t.nextTick(n,s,e):o?(t.nextTick(r,s),o(e)):t.nextTick(r,s)})),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(e,t){var n=e._readableState,r=e._writableState;n&&n.autoDestroy||r&&r.autoDestroy?e.destroy(t):e.emit("error",t)}}}).call(this,n(6))},function(e,t,n){"use strict";var r=n(15).codes.ERR_INVALID_OPT_VALUE;e.exports={getHighWaterMark:function(e,t,n,i){var o=function(e,t,n){return null!=e.highWaterMark?e.highWaterMark:t?e[n]:null}(t,i,n);if(null!=o){if(!isFinite(o)||Math.floor(o)!==o||o<0)throw new r(i?n:"highWaterMark",o);return Math.floor(o)}return e.objectMode?16:16384}}},function(e,t,n){"use strict";(function(t,r){function i(e){var t=this;this.next=null,this.entry=null,this.finish=function(){!function(e,t,n){var r=e.entry;e.entry=null;for(;r;){var i=r.callback;t.pendingcb--,i(n),r=r.next}t.corkedRequestsFree.next=e}(t,e)}}var o;e.exports=T,T.WritableState=E;var s={deprecate:n(45)},a=n(40),u=n(7).Buffer,c=t.Uint8Array||function(){};var l,h=n(42),f=n(43).getHighWaterMark,d=n(15).codes,p=d.ERR_INVALID_ARG_TYPE,m=d.ERR_METHOD_NOT_IMPLEMENTED,g=d.ERR_MULTIPLE_CALLBACK,b=d.ERR_STREAM_CANNOT_PIPE,y=d.ERR_STREAM_DESTROYED,v=d.ERR_STREAM_NULL_VALUES,_=d.ERR_STREAM_WRITE_AFTER_END,w=d.ERR_UNKNOWN_ENCODING,k=h.errorOrDestroy;function S(){}function E(e,t,s){o=o||n(16),e=e||{},"boolean"!=typeof s&&(s=t instanceof o),this.objectMode=!!e.objectMode,s&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=f(this,e,"writableHighWaterMark",s),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var a=!1===e.decodeStrings;this.decodeStrings=!a,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){!function(e,t){var n=e._writableState,i=n.sync,o=n.writecb;if("function"!=typeof o)throw new g;if(function(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}(n),t)!function(e,t,n,i,o){--t.pendingcb,n?(r.nextTick(o,i),r.nextTick(P,e,t),e._writableState.errorEmitted=!0,k(e,i)):(o(i),e._writableState.errorEmitted=!0,k(e,i),P(e,t))}(e,n,i,t,o);else{var s=A(n)||e.destroyed;s||n.corked||n.bufferProcessing||!n.bufferedRequest||R(e,n),i?r.nextTick(x,e,n,s,o):x(e,n,s,o)}}(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new i(this)}function T(e){var t=this instanceof(o=o||n(16));if(!t&&!l.call(T,this))return new T(e);this._writableState=new E(e,this,t),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),a.call(this)}function C(e,t,n,r,i,o,s){t.writelen=r,t.writecb=s,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new y("write")):n?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function x(e,t,n,r){n||function(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}(e,t),t.pendingcb--,r(),P(e,t)}function R(e,t){t.bufferProcessing=!0;var n=t.bufferedRequest;if(e._writev&&n&&n.next){var r=t.bufferedRequestCount,o=new Array(r),s=t.corkedRequestsFree;s.entry=n;for(var a=0,u=!0;n;)o[a]=n,n.isBuf||(u=!1),n=n.next,a+=1;o.allBuffers=u,C(e,t,!0,t.length,o,"",s.finish),t.pendingcb++,t.lastBufferedRequest=null,s.next?(t.corkedRequestsFree=s.next,s.next=null):t.corkedRequestsFree=new i(t),t.bufferedRequestCount=0}else{for(;n;){var c=n.chunk,l=n.encoding,h=n.callback;if(C(e,t,!1,t.objectMode?1:c.length,c,l,h),n=n.next,t.bufferedRequestCount--,t.writing)break}null===n&&(t.lastBufferedRequest=null)}t.bufferedRequest=n,t.bufferProcessing=!1}function A(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function I(e,t){e._final((function(n){t.pendingcb--,n&&k(e,n),t.prefinished=!0,e.emit("prefinish"),P(e,t)}))}function P(e,t){var n=A(t);if(n&&(function(e,t){t.prefinished||t.finalCalled||("function"!=typeof e._final||t.destroyed?(t.prefinished=!0,e.emit("prefinish")):(t.pendingcb++,t.finalCalled=!0,r.nextTick(I,e,t)))}(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"),t.autoDestroy))){var i=e._readableState;(!i||i.autoDestroy&&i.endEmitted)&&e.destroy()}return n}n(11)(T,a),E.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(E.prototype,"buffer",{get:s.deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(l=Function.prototype[Symbol.hasInstance],Object.defineProperty(T,Symbol.hasInstance,{value:function(e){return!!l.call(this,e)||this===T&&(e&&e._writableState instanceof E)}})):l=function(e){return e instanceof this},T.prototype.pipe=function(){k(this,new b)},T.prototype.write=function(e,t,n){var i,o=this._writableState,s=!1,a=!o.objectMode&&(i=e,u.isBuffer(i)||i instanceof c);return a&&!u.isBuffer(e)&&(e=function(e){return u.from(e)}(e)),"function"==typeof t&&(n=t,t=null),a?t="buffer":t||(t=o.defaultEncoding),"function"!=typeof n&&(n=S),o.ending?function(e,t){var n=new _;k(e,n),r.nextTick(t,n)}(this,n):(a||function(e,t,n,i){var o;return null===n?o=new v:"string"==typeof n||t.objectMode||(o=new p("chunk",["string","Buffer"],n)),!o||(k(e,o),r.nextTick(i,o),!1)}(this,o,e,n))&&(o.pendingcb++,s=function(e,t,n,r,i,o){if(!n){var s=function(e,t,n){e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=u.from(t,n));return t}(t,r,i);r!==s&&(n=!0,i="buffer",r=s)}var a=t.objectMode?1:r.length;t.length+=a;var c=t.length<t.highWaterMark;c||(t.needDrain=!0);if(t.writing||t.corked){var l=t.lastBufferedRequest;t.lastBufferedRequest={chunk:r,encoding:i,isBuf:n,callback:o,next:null},l?l.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else C(e,t,!1,a,r,i,o);return c}(this,o,a,e,t,n)),s},T.prototype.cork=function(){this._writableState.corked++},T.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.bufferProcessing||!e.bufferedRequest||R(this,e))},T.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new w(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(T.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(T.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),T.prototype._write=function(e,t,n){n(new m("_write()"))},T.prototype._writev=null,T.prototype.end=function(e,t,n){var i=this._writableState;return"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||function(e,t,n){t.ending=!0,P(e,t),n&&(t.finished?r.nextTick(n):e.once("finish",n));t.ended=!0,e.writable=!1}(this,i,n),this},Object.defineProperty(T.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(T.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),T.prototype.destroy=h.destroy,T.prototype._undestroy=h.undestroy,T.prototype._destroy=function(e,t){t(e)}}).call(this,n(9),n(6))},function(e,t,n){(function(t){function n(e){try{if(!t.localStorage)return!1}catch(e){return!1}var n=t.localStorage[e];return null!=n&&"true"===String(n).toLowerCase()}e.exports=function(e,t){if(n("noDeprecation"))return e;var r=!1;return function(){if(!r){if(n("throwDeprecation"))throw new Error(t);n("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}}}).call(this,n(9))},function(e,t,n){"use strict";e.exports=l;var r=n(15).codes,i=r.ERR_METHOD_NOT_IMPLEMENTED,o=r.ERR_MULTIPLE_CALLBACK,s=r.ERR_TRANSFORM_ALREADY_TRANSFORMING,a=r.ERR_TRANSFORM_WITH_LENGTH_0,u=n(16);function c(e,t){var n=this._transformState;n.transforming=!1;var r=n.writecb;if(null===r)return this.emit("error",new o);n.writechunk=null,n.writecb=null,null!=t&&this.push(t),r(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function l(e){if(!(this instanceof l))return new l(e);u.call(this,e),this._transformState={afterTransform:c.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.on("prefinish",h)}function h(){var e=this;"function"!=typeof this._flush||this._readableState.destroyed?f(this,null,null):this._flush((function(t,n){f(e,t,n)}))}function f(e,t,n){if(t)return e.emit("error",t);if(null!=n&&e.push(n),e._writableState.length)throw new a;if(e._transformState.transforming)throw new s;return e.push(null)}n(11)(l,u),l.prototype.push=function(e,t){return this._transformState.needTransform=!1,u.prototype.push.call(this,e,t)},l.prototype._transform=function(e,t,n){n(new i("_transform()"))},l.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var i=this._readableState;(r.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},l.prototype._read=function(e){var t=this._transformState;null===t.writechunk||t.transforming?t.needTransform=!0:(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform))},l.prototype._destroy=function(e,t){u.prototype._destroy.call(this,e,(function(e){t(e)}))}},function(e,t,n){(function(t){const n=e.exports;n.types={0:"reserved",1:"connect",2:"connack",3:"publish",4:"puback",5:"pubrec",6:"pubrel",7:"pubcomp",8:"subscribe",9:"suback",10:"unsubscribe",11:"unsuback",12:"pingreq",13:"pingresp",14:"disconnect",15:"auth"},n.codes={};for(const e in n.types){const t=n.types[e];n.codes[t]=e}n.CMD_SHIFT=4,n.CMD_MASK=240,n.DUP_MASK=8,n.QOS_MASK=3,n.QOS_SHIFT=1,n.RETAIN_MASK=1,n.VARBYTEINT_MASK=127,n.VARBYTEINT_FIN_MASK=128,n.VARBYTEINT_MAX=268435455,n.SESSIONPRESENT_MASK=1,n.SESSIONPRESENT_HEADER=t.from([n.SESSIONPRESENT_MASK]),n.CONNACK_HEADER=t.from([n.codes.connack<<n.CMD_SHIFT]),n.USERNAME_MASK=128,n.PASSWORD_MASK=64,n.WILL_RETAIN_MASK=32,n.WILL_QOS_MASK=24,n.WILL_QOS_SHIFT=3,n.WILL_FLAG_MASK=4,n.CLEAN_SESSION_MASK=2,n.CONNECT_HEADER=t.from([n.codes.connect<<n.CMD_SHIFT]),n.properties={sessionExpiryInterval:17,willDelayInterval:24,receiveMaximum:33,maximumPacketSize:39,topicAliasMaximum:34,requestResponseInformation:25,requestProblemInformation:23,userProperties:38,authenticationMethod:21,authenticationData:22,payloadFormatIndicator:1,messageExpiryInterval:2,contentType:3,responseTopic:8,correlationData:9,maximumQoS:36,retainAvailable:37,assignedClientIdentifier:18,reasonString:31,wildcardSubscriptionAvailable:40,subscriptionIdentifiersAvailable:41,sharedSubscriptionAvailable:42,serverKeepAlive:19,responseInformation:26,serverReference:28,topicAlias:35,subscriptionIdentifier:11},n.propertiesCodes={};for(const e in n.properties){const t=n.properties[e];n.propertiesCodes[t]=e}function r(e){return[0,1,2].map(r=>[0,1].map(i=>[0,1].map(o=>{const s=t.alloc(1);return s.writeUInt8(n.codes[e]<<n.CMD_SHIFT|(i?n.DUP_MASK:0)|r<<n.QOS_SHIFT|o,0,!0),s})))}n.propertiesTypes={sessionExpiryInterval:"int32",willDelayInterval:"int32",receiveMaximum:"int16",maximumPacketSize:"int32",topicAliasMaximum:"int16",requestResponseInformation:"byte",requestProblemInformation:"byte",userProperties:"pair",authenticationMethod:"string",authenticationData:"binary",payloadFormatIndicator:"byte",messageExpiryInterval:"int32",contentType:"string",responseTopic:"string",correlationData:"binary",maximumQoS:"int8",retainAvailable:"byte",assignedClientIdentifier:"string",reasonString:"string",wildcardSubscriptionAvailable:"byte",subscriptionIdentifiersAvailable:"byte",sharedSubscriptionAvailable:"byte",serverKeepAlive:"int16",responseInformation:"string",serverReference:"string",topicAlias:"int16",subscriptionIdentifier:"var"},n.PUBLISH_HEADER=r("publish"),n.SUBSCRIBE_HEADER=r("subscribe"),n.SUBSCRIBE_OPTIONS_QOS_MASK=3,n.SUBSCRIBE_OPTIONS_NL_MASK=1,n.SUBSCRIBE_OPTIONS_NL_SHIFT=2,n.SUBSCRIBE_OPTIONS_RAP_MASK=1,n.SUBSCRIBE_OPTIONS_RAP_SHIFT=3,n.SUBSCRIBE_OPTIONS_RH_MASK=3,n.SUBSCRIBE_OPTIONS_RH_SHIFT=4,n.SUBSCRIBE_OPTIONS_RH=[0,16,32],n.SUBSCRIBE_OPTIONS_NL=4,n.SUBSCRIBE_OPTIONS_RAP=8,n.SUBSCRIBE_OPTIONS_QOS=[0,1,2],n.UNSUBSCRIBE_HEADER=r("unsubscribe"),n.ACKS={unsuback:r("unsuback"),puback:r("puback"),pubcomp:r("pubcomp"),pubrel:r("pubrel"),pubrec:r("pubrec")},n.SUBACK_HEADER=t.from([n.codes.suback<<n.CMD_SHIFT]),n.VERSION3=t.from([3]),n.VERSION4=t.from([4]),n.VERSION5=t.from([5]),n.VERSION131=t.from([131]),n.VERSION132=t.from([132]),n.QOS=[0,1,2].map(e=>t.from([e])),n.EMPTY={pingreq:t.from([n.codes.pingreq<<4,0]),pingresp:t.from([n.codes.pingresp<<4,0]),disconnect:t.from([n.codes.disconnect<<4,0])}}).call(this,n(7).Buffer)},function(e,t,n){(function(t){const r=n(47),i=t.allocUnsafe(0),o=t.from([0]),s=n(117),a=n(18).nextTick,u=n(13)("mqtt-packet:writeToStream"),c=s.cache,l=s.generateNumber,h=s.generateCache,f=s.genBufVariableByteInt,d=s.generate4ByteBuffer;let p=k,m=!0;function g(e,n,s){switch(u("generate called"),n.cork&&(n.cork(),a(b,n)),m&&(m=!1,h()),u("generate: packet.cmd: %s",e.cmd),e.cmd){case"connect":return function(e,n,i){const o=e||{},s=o.protocolId||"MQTT";let a=o.protocolVersion||4;const u=o.will;let c=o.clean;const l=o.keepalive||0,h=o.clientId||"",f=o.username,d=o.password,m=o.properties;void 0===c&&(c=!0);let g=0;if(!s||"string"!=typeof s&&!t.isBuffer(s))return n.emit("error",new Error("Invalid protocolId")),!1;g+=s.length+2;if(3!==a&&4!==a&&5!==a)return n.emit("error",new Error("Invalid protocol version")),!1;g+=1;if(("string"==typeof h||t.isBuffer(h))&&(h||a>=4)&&(h||c))g+=t.byteLength(h)+2;else{if(a<4)return n.emit("error",new Error("clientId must be supplied before 3.1.1")),!1;if(1*c==0)return n.emit("error",new Error("clientId must be given if cleanSession set to 0")),!1}if("number"!=typeof l||l<0||l>65535||l%1!=0)return n.emit("error",new Error("Invalid keepalive")),!1;g+=2;if(g+=1,5===a){var b=T(n,m);if(!b)return!1;g+=b.length}if(u){if("object"!=typeof u)return n.emit("error",new Error("Invalid will")),!1;if(!u.topic||"string"!=typeof u.topic)return n.emit("error",new Error("Invalid will topic")),!1;if(g+=t.byteLength(u.topic)+2,g+=2,u.payload){if(!(u.payload.length>=0))return n.emit("error",new Error("Invalid will payload")),!1;"string"==typeof u.payload?g+=t.byteLength(u.payload):g+=u.payload.length}var y={};if(5===a){if(!(y=T(n,u.properties)))return!1;g+=y.length}}let w=!1;if(null!=f){if(!I(f))return n.emit("error",new Error("Invalid username")),!1;w=!0,g+=t.byteLength(f)+2}if(null!=d){if(!w)return n.emit("error",new Error("Username is required to use password")),!1;if(!I(d))return n.emit("error",new Error("Invalid password")),!1;g+=A(d)+2}n.write(r.CONNECT_HEADER),v(n,g),E(n,s),o.bridgeMode&&(a+=128);n.write(131===a?r.VERSION131:132===a?r.VERSION132:4===a?r.VERSION4:5===a?r.VERSION5:r.VERSION3);let k=0;k|=null!=f?r.USERNAME_MASK:0,k|=null!=d?r.PASSWORD_MASK:0,k|=u&&u.retain?r.WILL_RETAIN_MASK:0,k|=u&&u.qos?u.qos<<r.WILL_QOS_SHIFT:0,k|=u?r.WILL_FLAG_MASK:0,k|=c?r.CLEAN_SESSION_MASK:0,n.write(t.from([k])),p(n,l),5===a&&b.write();E(n,h),u&&(5===a&&y.write(),_(n,u.topic),E(n,u.payload));null!=f&&E(n,f);null!=d&&E(n,d);return!0}(e,n);case"connack":return function(e,n,i){const s=i?i.protocolVersion:4,a=e||{},u=5===s?a.reasonCode:a.returnCode,c=a.properties;let l=2;if("number"!=typeof u)return n.emit("error",new Error("Invalid return code")),!1;let h=null;if(5===s){if(!(h=T(n,c)))return!1;l+=h.length}n.write(r.CONNACK_HEADER),v(n,l),n.write(a.sessionPresent?r.SESSIONPRESENT_HEADER:o),n.write(t.from([u])),null!=h&&h.write();return!0}(e,n,s);case"publish":return function(e,n,o){u("publish: packet: %o",e);const s=o?o.protocolVersion:4,a=e||{},c=a.qos||0,l=a.retain?r.RETAIN_MASK:0,h=a.topic,f=a.payload||i,d=a.messageId,m=a.properties;let g=0;if("string"==typeof h)g+=t.byteLength(h)+2;else{if(!t.isBuffer(h))return n.emit("error",new Error("Invalid topic")),!1;g+=h.length+2}t.isBuffer(f)?g+=f.length:g+=t.byteLength(f);if(c&&"number"!=typeof d)return n.emit("error",new Error("Invalid messageId")),!1;c&&(g+=2);let b=null;if(5===s){if(!(b=T(n,m)))return!1;g+=b.length}n.write(r.PUBLISH_HEADER[c][a.dup?1:0][l?1:0]),v(n,g),p(n,A(h)),n.write(h),c>0&&p(n,d);null!=b&&b.write();return u("publish: payload: %o",f),n.write(f)}(e,n,s);case"puback":case"pubrec":case"pubrel":case"pubcomp":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.cmd||"puback",u=s.messageId,c=s.dup&&"pubrel"===a?r.DUP_MASK:0;let l=0;const h=s.reasonCode,f=s.properties;let d=5===o?3:2;"pubrel"===a&&(l=1);if("number"!=typeof u)return n.emit("error",new Error("Invalid messageId")),!1;let m=null;if(5===o&&"object"==typeof f){if(!(m=C(n,f,i,d)))return!1;d+=m.length}n.write(r.ACKS[a][l][c][0]),v(n,d),p(n,u),5===o&&n.write(t.from([h]));null!==m&&m.write();return!0}(e,n,s);case"subscribe":return function(e,n,i){u("subscribe: packet: ");const o=i?i.protocolVersion:4,s=e||{},a=s.dup?r.DUP_MASK:0,c=s.messageId,l=s.subscriptions,h=s.properties;let f=0;if("number"!=typeof c)return n.emit("error",new Error("Invalid messageId")),!1;f+=2;let d=null;if(5===o){if(!(d=T(n,h)))return!1;f+=d.length}if("object"!=typeof l||!l.length)return n.emit("error",new Error("Invalid subscriptions")),!1;for(let e=0;e<l.length;e+=1){const r=l[e].topic,i=l[e].qos;if("string"!=typeof r)return n.emit("error",new Error("Invalid subscriptions - invalid topic")),!1;if("number"!=typeof i)return n.emit("error",new Error("Invalid subscriptions - invalid qos")),!1;if(5===o){if("boolean"!=typeof(l[e].nl||!1))return n.emit("error",new Error("Invalid subscriptions - invalid No Local")),!1;if("boolean"!=typeof(l[e].rap||!1))return n.emit("error",new Error("Invalid subscriptions - invalid Retain as Published")),!1;const t=l[e].rh||0;if("number"!=typeof t||t>2)return n.emit("error",new Error("Invalid subscriptions - invalid Retain Handling")),!1}f+=t.byteLength(r)+2+1}u("subscribe: writing to stream: %o",r.SUBSCRIBE_HEADER),n.write(r.SUBSCRIBE_HEADER[1][a?1:0][0]),v(n,f),p(n,c),null!==d&&d.write();let m=!0;for(const e of l){const i=e.topic,s=e.qos,a=+e.nl,u=+e.rap,c=e.rh;let l;_(n,i),l=r.SUBSCRIBE_OPTIONS_QOS[s],5===o&&(l|=a?r.SUBSCRIBE_OPTIONS_NL:0,l|=u?r.SUBSCRIBE_OPTIONS_RAP:0,l|=c?r.SUBSCRIBE_OPTIONS_RH[c]:0),m=n.write(t.from([l]))}return m}(e,n,s);case"suback":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.messageId,u=s.granted,c=s.properties;let l=0;if("number"!=typeof a)return n.emit("error",new Error("Invalid messageId")),!1;l+=2;if("object"!=typeof u||!u.length)return n.emit("error",new Error("Invalid qos vector")),!1;for(let e=0;e<u.length;e+=1){if("number"!=typeof u[e])return n.emit("error",new Error("Invalid qos vector")),!1;l+=1}let h=null;if(5===o){if(!(h=C(n,c,i,l)))return!1;l+=h.length}n.write(r.SUBACK_HEADER),v(n,l),p(n,a),null!==h&&h.write();return n.write(t.from(u))}(e,n,s);case"unsubscribe":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.messageId,u=s.dup?r.DUP_MASK:0,c=s.unsubscriptions,l=s.properties;let h=0;if("number"!=typeof a)return n.emit("error",new Error("Invalid messageId")),!1;h+=2;if("object"!=typeof c||!c.length)return n.emit("error",new Error("Invalid unsubscriptions")),!1;for(let e=0;e<c.length;e+=1){if("string"!=typeof c[e])return n.emit("error",new Error("Invalid unsubscriptions")),!1;h+=t.byteLength(c[e])+2}let f=null;if(5===o){if(!(f=T(n,l)))return!1;h+=f.length}n.write(r.UNSUBSCRIBE_HEADER[1][u?1:0][0]),v(n,h),p(n,a),null!==f&&f.write();let d=!0;for(let e=0;e<c.length;e++)d=_(n,c[e]);return d}(e,n,s);case"unsuback":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.messageId,u=s.dup?r.DUP_MASK:0,c=s.granted,l=s.properties,h=s.cmd;let f=2;if("number"!=typeof a)return n.emit("error",new Error("Invalid messageId")),!1;if(5===o){if("object"!=typeof c||!c.length)return n.emit("error",new Error("Invalid qos vector")),!1;for(let e=0;e<c.length;e+=1){if("number"!=typeof c[e])return n.emit("error",new Error("Invalid qos vector")),!1;f+=1}}let d=null;if(5===o){if(!(d=C(n,l,i,f)))return!1;f+=d.length}n.write(r.ACKS[h][0][u][0]),v(n,f),p(n,a),null!==d&&d.write();5===o&&n.write(t.from(c));return!0}(e,n,s);case"pingreq":case"pingresp":return function(e,t,n){return t.write(r.EMPTY[e.cmd])}(e,n);case"disconnect":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.reasonCode,u=s.properties;let c=5===o?1:0,l=null;if(5===o){if(!(l=C(n,u,i,c)))return!1;c+=l.length}n.write(t.from([r.codes.disconnect<<4])),v(n,c),5===o&&n.write(t.from([a]));null!==l&&l.write();return!0}(e,n,s);case"auth":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.reasonCode,u=s.properties;let c=5===o?1:0;5!==o&&n.emit("error",new Error("Invalid mqtt version for auth packet"));const l=C(n,u,i,c);if(!l)return!1;c+=l.length,n.write(t.from([r.codes.auth<<4])),v(n,c),n.write(t.from([a])),null!==l&&l.write();return!0}(e,n,s);default:return n.emit("error",new Error("Unknown command")),!1}}function b(e){e.uncork()}Object.defineProperty(g,"cacheNumbers",{get:()=>p===k,set(e){e?(c&&0!==Object.keys(c).length||(m=!0),p=k):(m=!1,p=S)}});const y={};function v(e,t){if(t>r.VARBYTEINT_MAX)return e.emit("error",new Error(`Invalid variable byte integer: ${t}`)),!1;let n=y[t];return n||(n=f(t),t<16384&&(y[t]=n)),u("writeVarByteInt: writing to stream: %o",n),e.write(n)}function _(e,n){const r=t.byteLength(n);return p(e,r),u("writeString: %s",n),e.write(n,"utf8")}function w(e,t,n){_(e,t),_(e,n)}function k(e,t){return u("writeNumberCached: number: %d",t),u("writeNumberCached: %o",c[t]),e.write(c[t])}function S(e,t){const n=l(t);return u("writeNumberGenerated: %o",n),e.write(n)}function E(e,t){"string"==typeof t?_(e,t):t?(p(e,t.length),e.write(t)):p(e,0)}function T(e,n){if("object"!=typeof n||null!=n.length)return{length:1,write(){R(e,{},0)}};let i=0;function o(n,i){let o=0;switch(r.propertiesTypes[n]){case"byte":if("boolean"!=typeof i)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=2;break;case"int8":if("number"!=typeof i||i<0||i>255)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=2;break;case"binary":if(i&&null===i)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=1+t.byteLength(i)+2;break;case"int16":if("number"!=typeof i||i<0||i>65535)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=3;break;case"int32":if("number"!=typeof i||i<0||i>4294967295)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=5;break;case"var":if("number"!=typeof i||i<0||i>268435455)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=1+t.byteLength(f(i));break;case"string":if("string"!=typeof i)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=3+t.byteLength(i.toString());break;case"pair":if("object"!=typeof i)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=Object.getOwnPropertyNames(i).reduce((e,n)=>{const r=i[n];return Array.isArray(r)?e+=r.reduce((e,r)=>e+=3+t.byteLength(n.toString())+2+t.byteLength(r.toString()),0):e+=3+t.byteLength(n.toString())+2+t.byteLength(i[n].toString()),e},0);break;default:return e.emit("error",new Error(`Invalid property ${n}: ${i}`)),!1}return o}if(n)for(const e in n){let t=0,r=0;const s=n[e];if(Array.isArray(s))for(let n=0;n<s.length;n++){if(!(r=o(e,s[n])))return!1;t+=r}else{if(!(r=o(e,s)))return!1;t=r}if(!t)return!1;i+=t}return{length:t.byteLength(f(i))+i,write(){R(e,n,i)}}}function C(e,t,n,r){const i=["reasonString","userProperties"],o=n&&n.properties&&n.properties.maximumPacketSize?n.properties.maximumPacketSize:0;let s=T(e,t);if(o)for(;r+s.length>o;){const n=i.shift();if(!n||!t[n])return!1;delete t[n],s=T(e,t)}return s}function x(e,n,i){switch(r.propertiesTypes[n]){case"byte":e.write(t.from([r.properties[n]])),e.write(t.from([+i]));break;case"int8":e.write(t.from([r.properties[n]])),e.write(t.from([i]));break;case"binary":e.write(t.from([r.properties[n]])),E(e,i);break;case"int16":e.write(t.from([r.properties[n]])),p(e,i);break;case"int32":e.write(t.from([r.properties[n]])),function(e,t){const n=d(t);u("write4ByteNumber: %o",n),e.write(n)}(e,i);break;case"var":e.write(t.from([r.properties[n]])),v(e,i);break;case"string":e.write(t.from([r.properties[n]])),_(e,i);break;case"pair":Object.getOwnPropertyNames(i).forEach(o=>{const s=i[o];Array.isArray(s)?s.forEach(i=>{e.write(t.from([r.properties[n]])),w(e,o.toString(),i.toString())}):(e.write(t.from([r.properties[n]])),w(e,o.toString(),s.toString()))});break;default:return e.emit("error",new Error(`Invalid property ${n} value: ${i}`)),!1}}function R(e,t,n){v(e,n);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&null!==t[n]){const r=t[n];if(Array.isArray(r))for(let t=0;t<r.length;t++)x(e,n,r[t]);else x(e,n,r)}}function A(e){return e?e instanceof t?e.length:t.byteLength(e):0}function I(e){return"string"==typeof e||e instanceof t}e.exports=g}).call(this,n(7).Buffer)},function(e,t,n){"use strict";var r=n(127),i=n(13)("mqttjs:tcp");e.exports=function(e,t){var n,o;return t.port=t.port||1883,t.hostname=t.hostname||t.host||"localhost",n=t.port,o=t.hostname,i("port %d and host %s",n,o),r.createConnection(n,o)}},function(e,t,n){"use strict";(function(t){var r,i,o,s=n(14).Transform,a=n(27);e.exports=function(e,n){if(n.hostname=n.hostname||n.host,!n.hostname)throw new Error("Could not determine host. Specify host manually.");var u="MQIsdp"===n.protocolId&&3===n.protocolVersion?"mqttv3.1":"mqtt";!function(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}(n);var c=function(e,t){var n="wxs"===e.protocol?"wss":"ws",r=n+"://"+e.hostname+e.path;return e.port&&80!==e.port&&443!==e.port&&(r=n+"://"+e.hostname+":"+e.port+e.path),"function"==typeof e.transformWsUrl&&(r=e.transformWsUrl(r,e,t)),r}(n,e);r=wx.connectSocket({url:c,protocols:[u]}),i=function(){var e=new s;return e._write=function(e,t,n){r.send({data:e.buffer,success:function(){n()},fail:function(e){n(new Error(e))}})},e._flush=function(e){r.close({success:function(){e()}})},e}(),(o=a.obj())._destroy=function(e,t){r.close({success:function(){t&&t(e)}})};var l=o.destroy;return o.destroy=function(){o.destroy=l;var e=this;setTimeout((function(){r.close({fail:function(){e._destroy(new Error)}})}),0)}.bind(o),r.onOpen((function(){o.setReadable(i),o.setWritable(i),o.emit("connect")})),r.onMessage((function(e){var n=e.data;n=n instanceof ArrayBuffer?t.from(n):t.from(n,"utf8"),i.push(n)})),r.onClose((function(){o.end(),o.destroy()})),r.onError((function(e){o.destroy(new Error(e.errMsg))})),o}}).call(this,n(7).Buffer)},function(e,t,n){"use strict";(function(t,r){var i=n(18);e.exports=v;var o,s=n(41);v.ReadableState=y;n(12).EventEmitter;var a=function(e,t){return e.listeners(t).length},u=n(52),c=n(28).Buffer,l=t.Uint8Array||function(){};var h=Object.create(n(19));h.inherits=n(11);var f=n(130),d=void 0;d=f&&f.debuglog?f.debuglog("stream"):function(){};var p,m=n(131),g=n(53);h.inherits(v,u);var b=["error","close","destroy","pause","resume"];function y(e,t){e=e||{};var r=t instanceof(o=o||n(17));this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var i=e.highWaterMark,s=e.readableHighWaterMark,a=this.objectMode?16:16384;this.highWaterMark=i||0===i?i:r&&(s||0===s)?s:a,this.highWaterMark=Math.floor(this.highWaterMark),this.buffer=new m,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(p||(p=n(22).StringDecoder),this.decoder=new p(e.encoding),this.encoding=e.encoding)}function v(e){if(o=o||n(17),!(this instanceof v))return new v(e);this._readableState=new y(e,this),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),u.call(this)}function _(e,t,n,r,i){var o,s=e._readableState;null===t?(s.reading=!1,function(e,t){if(t.ended)return;if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,E(e)}(e,s)):(i||(o=function(e,t){var n;r=t,c.isBuffer(r)||r instanceof l||"string"==typeof t||void 0===t||e.objectMode||(n=new TypeError("Invalid non-string/buffer chunk"));var r;return n}(s,t)),o?e.emit("error",o):s.objectMode||t&&t.length>0?("string"==typeof t||s.objectMode||Object.getPrototypeOf(t)===c.prototype||(t=function(e){return c.from(e)}(t)),r?s.endEmitted?e.emit("error",new Error("stream.unshift() after end event")):w(e,s,t,!0):s.ended?e.emit("error",new Error("stream.push() after EOF")):(s.reading=!1,s.decoder&&!n?(t=s.decoder.write(t),s.objectMode||0!==t.length?w(e,s,t,!1):C(e,s)):w(e,s,t,!1))):r||(s.reading=!1));return function(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||0===e.length)}(s)}function w(e,t,n,r){t.flowing&&0===t.length&&!t.sync?(e.emit("data",n),e.read(0)):(t.length+=t.objectMode?1:n.length,r?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&E(e)),C(e,t)}Object.defineProperty(v.prototype,"destroyed",{get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),v.prototype.destroy=g.destroy,v.prototype._undestroy=g.undestroy,v.prototype._destroy=function(e,t){this.push(null),t(e)},v.prototype.push=function(e,t){var n,r=this._readableState;return r.objectMode?n=!0:"string"==typeof e&&((t=t||r.defaultEncoding)!==r.encoding&&(e=c.from(e,t),t=""),n=!0),_(this,e,t,!1,n)},v.prototype.unshift=function(e){return _(this,e,null,!0,!1)},v.prototype.isPaused=function(){return!1===this._readableState.flowing},v.prototype.setEncoding=function(e){return p||(p=n(22).StringDecoder),this._readableState.decoder=new p(e),this._readableState.encoding=e,this};var k=8388608;function S(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!=e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=function(e){return e>=k?e=k:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function E(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(d("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?i.nextTick(T,e):T(e))}function T(e){d("emit readable"),e.emit("readable"),I(e)}function C(e,t){t.readingMore||(t.readingMore=!0,i.nextTick(x,e,t))}function x(e,t){for(var n=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(d("maybeReadMore read 0"),e.read(0),n!==t.length);)n=t.length;t.readingMore=!1}function R(e){d("readable nexttick read 0"),e.read(0)}function A(e,t){t.reading||(d("resume read 0"),e.read(0)),t.resumeScheduled=!1,t.awaitDrain=0,e.emit("resume"),I(e),t.flowing&&!t.reading&&e.read(0)}function I(e){var t=e._readableState;for(d("flow",t.flowing);t.flowing&&null!==e.read(););}function P(e,t){return 0===t.length?null:(t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):n=function(e,t,n){var r;e<t.head.data.length?(r=t.head.data.slice(0,e),t.head.data=t.head.data.slice(e)):r=e===t.head.data.length?t.shift():n?function(e,t){var n=t.head,r=1,i=n.data;e-=i.length;for(;n=n.next;){var o=n.data,s=e>o.length?o.length:e;if(s===o.length?i+=o:i+=o.slice(0,e),0===(e-=s)){s===o.length?(++r,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=o.slice(s));break}++r}return t.length-=r,i}(e,t):function(e,t){var n=c.allocUnsafe(e),r=t.head,i=1;r.data.copy(n),e-=r.data.length;for(;r=r.next;){var o=r.data,s=e>o.length?o.length:e;if(o.copy(n,n.length-e,0,s),0===(e-=s)){s===o.length?(++i,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=o.slice(s));break}++i}return t.length-=i,n}(e,t);return r}(e,t.buffer,t.decoder),n);var n}function O(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,i.nextTick(M,t,e))}function M(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function L(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}v.prototype.read=function(e){d("read",e),e=parseInt(e,10);var t=this._readableState,n=e;if(0!==e&&(t.emittedReadable=!1),0===e&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return d("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?O(this):E(this),null;if(0===(e=S(e,t))&&t.ended)return 0===t.length&&O(this),null;var r,i=t.needReadable;return d("need readable",i),(0===t.length||t.length-e<t.highWaterMark)&&d("length less than watermark",i=!0),t.ended||t.reading?d("reading or ended",i=!1):i&&(d("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=S(n,t))),null===(r=e>0?P(e,t):null)?(t.needReadable=!0,e=0):t.length-=e,0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&O(this)),null!==r&&this.emit("data",r),r},v.prototype._read=function(e){this.emit("error",new Error("_read() is not implemented"))},v.prototype.pipe=function(e,t){var n=this,o=this._readableState;switch(o.pipesCount){case 0:o.pipes=e;break;case 1:o.pipes=[o.pipes,e];break;default:o.pipes.push(e)}o.pipesCount+=1,d("pipe count=%d opts=%j",o.pipesCount,t);var u=(!t||!1!==t.end)&&e!==r.stdout&&e!==r.stderr?l:v;function c(t,r){d("onunpipe"),t===n&&r&&!1===r.hasUnpiped&&(r.hasUnpiped=!0,d("cleanup"),e.removeListener("close",b),e.removeListener("finish",y),e.removeListener("drain",h),e.removeListener("error",g),e.removeListener("unpipe",c),n.removeListener("end",l),n.removeListener("end",v),n.removeListener("data",m),f=!0,!o.awaitDrain||e._writableState&&!e._writableState.needDrain||h())}function l(){d("onend"),e.end()}o.endEmitted?i.nextTick(u):n.once("end",u),e.on("unpipe",c);var h=function(e){return function(){var t=e._readableState;d("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&a(e,"data")&&(t.flowing=!0,I(e))}}(n);e.on("drain",h);var f=!1;var p=!1;function m(t){d("ondata"),p=!1,!1!==e.write(t)||p||((1===o.pipesCount&&o.pipes===e||o.pipesCount>1&&-1!==L(o.pipes,e))&&!f&&(d("false write response, pause",n._readableState.awaitDrain),n._readableState.awaitDrain++,p=!0),n.pause())}function g(t){d("onerror",t),v(),e.removeListener("error",g),0===a(e,"error")&&e.emit("error",t)}function b(){e.removeListener("finish",y),v()}function y(){d("onfinish"),e.removeListener("close",b),v()}function v(){d("unpipe"),n.unpipe(e)}return n.on("data",m),function(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?s(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n)}(e,"error",g),e.once("close",b),e.once("finish",y),e.emit("pipe",n),o.flowing||(d("pipe resume"),n.resume()),e},v.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n),this);if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o<i;o++)r[o].emit("unpipe",this,n);return this}var s=L(t.pipes,e);return-1===s?this:(t.pipes.splice(s,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,n),this)},v.prototype.on=function(e,t){var n=u.prototype.on.call(this,e,t);if("data"===e)!1!==this._readableState.flowing&&this.resume();else if("readable"===e){var r=this._readableState;r.endEmitted||r.readableListening||(r.readableListening=r.needReadable=!0,r.emittedReadable=!1,r.reading?r.length&&E(this):i.nextTick(R,this))}return n},v.prototype.addListener=v.prototype.on,v.prototype.resume=function(){var e=this._readableState;return e.flowing||(d("resume"),e.flowing=!0,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,i.nextTick(A,e,t))}(this,e)),this},v.prototype.pause=function(){return d("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(d("pause"),this._readableState.flowing=!1,this.emit("pause")),this},v.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on("end",(function(){if(d("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e)}t.push(null)})),e.on("data",(function(i){(d("wrapped data"),n.decoder&&(i=n.decoder.write(i)),n.objectMode&&null==i)||(n.objectMode||i&&i.length)&&(t.push(i)||(r=!0,e.pause()))})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var o=0;o<b.length;o++)e.on(b[o],this.emit.bind(this,b[o]));return this._read=function(t){d("wrapped _read",t),r&&(r=!1,e.resume())},this},Object.defineProperty(v.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),v._fromList=P}).call(this,n(9),n(6))},function(e,t,n){e.exports=n(12).EventEmitter},function(e,t,n){"use strict";var r=n(18);function i(e,t){e.emit("error",t)}e.exports={destroy:function(e,t){var n=this,o=this._readableState&&this._readableState.destroyed,s=this._writableState&&this._writableState.destroyed;return o||s?(t?t(e):!e||this._writableState&&this._writableState.errorEmitted||r.nextTick(i,this,e),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,(function(e){!t&&e?(r.nextTick(i,n,e),n._writableState&&(n._writableState.errorEmitted=!0)):t&&t(e)})),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}}},function(e,t,n){"use strict";(function(t,r,i){var o=n(18);function s(e){var t=this;this.next=null,this.entry=null,this.finish=function(){!function(e,t,n){var r=e.entry;e.entry=null;for(;r;){var i=r.callback;t.pendingcb--,i(n),r=r.next}t.corkedRequestsFree?t.corkedRequestsFree.next=e:t.corkedRequestsFree=e}(t,e)}}e.exports=y;var a,u=!t.browser&&["v0.10","v0.9."].indexOf(t.version.slice(0,5))>-1?r:o.nextTick;y.WritableState=b;var c=Object.create(n(19));c.inherits=n(11);var l={deprecate:n(45)},h=n(52),f=n(28).Buffer,d=i.Uint8Array||function(){};var p,m=n(53);function g(){}function b(e,t){a=a||n(17),e=e||{};var r=t instanceof a;this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.writableObjectMode);var i=e.highWaterMark,c=e.writableHighWaterMark,l=this.objectMode?16:16384;this.highWaterMark=i||0===i?i:r&&(c||0===c)?c:l,this.highWaterMark=Math.floor(this.highWaterMark),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var h=!1===e.decodeStrings;this.decodeStrings=!h,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){!function(e,t){var n=e._writableState,r=n.sync,i=n.writecb;if(function(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}(n),t)!function(e,t,n,r,i){--t.pendingcb,n?(o.nextTick(i,r),o.nextTick(E,e,t),e._writableState.errorEmitted=!0,e.emit("error",r)):(i(r),e._writableState.errorEmitted=!0,e.emit("error",r),E(e,t))}(e,n,r,t,i);else{var s=k(n);s||n.corked||n.bufferProcessing||!n.bufferedRequest||w(e,n),r?u(_,e,n,s,i):_(e,n,s,i)}}(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new s(this)}function y(e){if(a=a||n(17),!(p.call(y,this)||this instanceof a))return new y(e);this._writableState=new b(e,this),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),h.call(this)}function v(e,t,n,r,i,o,s){t.writelen=r,t.writecb=s,t.writing=!0,t.sync=!0,n?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function _(e,t,n,r){n||function(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}(e,t),t.pendingcb--,r(),E(e,t)}function w(e,t){t.bufferProcessing=!0;var n=t.bufferedRequest;if(e._writev&&n&&n.next){var r=t.bufferedRequestCount,i=new Array(r),o=t.corkedRequestsFree;o.entry=n;for(var a=0,u=!0;n;)i[a]=n,n.isBuf||(u=!1),n=n.next,a+=1;i.allBuffers=u,v(e,t,!0,t.length,i,"",o.finish),t.pendingcb++,t.lastBufferedRequest=null,o.next?(t.corkedRequestsFree=o.next,o.next=null):t.corkedRequestsFree=new s(t),t.bufferedRequestCount=0}else{for(;n;){var c=n.chunk,l=n.encoding,h=n.callback;if(v(e,t,!1,t.objectMode?1:c.length,c,l,h),n=n.next,t.bufferedRequestCount--,t.writing)break}null===n&&(t.lastBufferedRequest=null)}t.bufferedRequest=n,t.bufferProcessing=!1}function k(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function S(e,t){e._final((function(n){t.pendingcb--,n&&e.emit("error",n),t.prefinished=!0,e.emit("prefinish"),E(e,t)}))}function E(e,t){var n=k(t);return n&&(!function(e,t){t.prefinished||t.finalCalled||("function"==typeof e._final?(t.pendingcb++,t.finalCalled=!0,o.nextTick(S,e,t)):(t.prefinished=!0,e.emit("prefinish")))}(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"))),n}c.inherits(y,h),b.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(b.prototype,"buffer",{get:l.deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(p=Function.prototype[Symbol.hasInstance],Object.defineProperty(y,Symbol.hasInstance,{value:function(e){return!!p.call(this,e)||this===y&&(e&&e._writableState instanceof b)}})):p=function(e){return e instanceof this},y.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},y.prototype.write=function(e,t,n){var r,i=this._writableState,s=!1,a=!i.objectMode&&(r=e,f.isBuffer(r)||r instanceof d);return a&&!f.isBuffer(e)&&(e=function(e){return f.from(e)}(e)),"function"==typeof t&&(n=t,t=null),a?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof n&&(n=g),i.ended?function(e,t){var n=new Error("write after end");e.emit("error",n),o.nextTick(t,n)}(this,n):(a||function(e,t,n,r){var i=!0,s=!1;return null===n?s=new TypeError("May not write null values to stream"):"string"==typeof n||void 0===n||t.objectMode||(s=new TypeError("Invalid non-string/buffer chunk")),s&&(e.emit("error",s),o.nextTick(r,s),i=!1),i}(this,i,e,n))&&(i.pendingcb++,s=function(e,t,n,r,i,o){if(!n){var s=function(e,t,n){e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=f.from(t,n));return t}(t,r,i);r!==s&&(n=!0,i="buffer",r=s)}var a=t.objectMode?1:r.length;t.length+=a;var u=t.length<t.highWaterMark;u||(t.needDrain=!0);if(t.writing||t.corked){var c=t.lastBufferedRequest;t.lastBufferedRequest={chunk:r,encoding:i,isBuf:n,callback:o,next:null},c?c.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else v(e,t,!1,a,r,i,o);return u}(this,i,a,e,t,n)),s},y.prototype.cork=function(){this._writableState.corked++},y.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||w(this,e))},y.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(y.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),y.prototype._write=function(e,t,n){n(new Error("_write() is not implemented"))},y.prototype._writev=null,y.prototype.end=function(e,t,n){var r=this._writableState;"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||r.finished||function(e,t,n){t.ending=!0,E(e,t),n&&(t.finished?o.nextTick(n):e.once("finish",n));t.ended=!0,e.writable=!1}(this,r,n)},Object.defineProperty(y.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),y.prototype.destroy=m.destroy,y.prototype._undestroy=m.undestroy,y.prototype._destroy=function(e,t){this.end(),t(e)}}).call(this,n(6),n(133).setImmediate,n(9))},function(e,t,n){"use strict";e.exports=s;var r=n(17),i=Object.create(n(19));function o(e,t){var n=this._transformState;n.transforming=!1;var r=n.writecb;if(!r)return this.emit("error",new Error("write callback called multiple times"));n.writechunk=null,n.writecb=null,null!=t&&this.push(t),r(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function s(e){if(!(this instanceof s))return new s(e);r.call(this,e),this._transformState={afterTransform:o.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.on("prefinish",a)}function a(){var e=this;"function"==typeof this._flush?this._flush((function(t,n){u(e,t,n)})):u(this,null,null)}function u(e,t,n){if(t)return e.emit("error",t);if(null!=n&&e.push(n),e._writableState.length)throw new Error("Calling transform done when ws.length != 0");if(e._transformState.transforming)throw new Error("Calling transform done when still transforming");return e.push(null)}i.inherits=n(11),i.inherits(s,r),s.prototype.push=function(e,t){return this._transformState.needTransform=!1,r.prototype.push.call(this,e,t)},s.prototype._transform=function(e,t,n){throw new Error("_transform() is not implemented")},s.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var i=this._readableState;(r.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},s.prototype._read=function(e){var t=this._transformState;null!==t.writechunk&&t.writecb&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0},s.prototype._destroy=function(e,t){var n=this;r.prototype._destroy.call(this,e,(function(e){t(e),n.emit("close")}))}},function(e,t,n){"use strict";(function(t){var r,i,o,s=n(14).Transform,a=n(27),u=!1;e.exports=function(e,n){if(n.hostname=n.hostname||n.host,!n.hostname)throw new Error("Could not determine host. Specify host manually.");var c="MQIsdp"===n.protocolId&&3===n.protocolVersion?"mqttv3.1":"mqtt";!function(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}(n);var l=function(e,t){var n="alis"===e.protocol?"wss":"ws",r=n+"://"+e.hostname+e.path;return e.port&&80!==e.port&&443!==e.port&&(r=n+"://"+e.hostname+":"+e.port+e.path),"function"==typeof e.transformWsUrl&&(r=e.transformWsUrl(r,e,t)),r}(n,e);return(r=n.my).connectSocket({url:l,protocols:c}),i=function(){var e=new s;return e._write=function(e,t,n){r.sendSocketMessage({data:e.buffer,success:function(){n()},fail:function(){n(new Error)}})},e._flush=function(e){r.closeSocket({success:function(){e()}})},e}(),o=a.obj(),u||(u=!0,r.onSocketOpen((function(){o.setReadable(i),o.setWritable(i),o.emit("connect")})),r.onSocketMessage((function(e){if("string"==typeof e.data){var n=t.from(e.data,"base64");i.push(n)}else{var r=new FileReader;r.addEventListener("load",(function(){var e=r.result;e=e instanceof ArrayBuffer?t.from(e):t.from(e,"utf8"),i.push(e)})),r.readAsArrayBuffer(e.data)}})),r.onSocketClose((function(){o.end(),o.destroy()})),r.onSocketError((function(e){o.destroy(e)}))),o}}).call(this,n(7).Buffer)},function(e,t,n){"use strict";(function(t,r){const i=n(140),o=n(13)("mqttjs:ws"),s=n(27),a=n(14).Transform;let u=["rejectUnauthorized","ca","cert","key","pfx","passphrase"];const c=void 0!==t&&"browser"===t.title||"function"==typeof n;function l(e,t){let n=e.protocol+"://"+e.hostname+":"+e.port+e.path;return"function"==typeof e.transformWsUrl&&(n=e.transformWsUrl(n,e,t)),n}function h(e){let t=e;return e.hostname||(t.hostname="localhost"),e.port||("wss"===e.protocol?t.port=443:t.port=80),e.path||(t.path="/"),e.wsOptions||(t.wsOptions={}),c||"wss"!==e.protocol||u.forEach((function(n){e.hasOwnProperty(n)&&!e.wsOptions.hasOwnProperty(n)&&(t.wsOptions[n]=e[n])})),t}e.exports=c?function(e,t){let n;o("browserStreamBuilder");const i=function(e){let t=h(e);if(t.hostname||(t.hostname=t.host),!t.hostname){if("undefined"==typeof document)throw new Error("Could not determine host. Specify host manually.");const e=new URL(document.URL);t.hostname=e.hostname,t.port||(t.port=e.port)}return void 0===t.objectMode&&(t.objectMode=!(!0===t.binary||void 0===t.binary)),t}(t).browserBufferSize||524288,u=t.browserBufferTimeout||1e3,c=!t.objectMode;let f=function(e,t){const n="MQIsdp"===t.protocolId&&3===t.protocolVersion?"mqttv3.1":"mqtt";let r=l(t,e),i=new WebSocket(r,[n]);return i.binaryType="arraybuffer",i}(e,t),d=function(e,t,n){let r=new a({objectModeMode:e.objectMode});return r._write=t,r._flush=n,r}(t,(function e(t,n,o){f.bufferedAmount>i&&setTimeout(e,u,t,n,o);c&&"string"==typeof t&&(t=r.from(t,"utf8"));try{f.send(t)}catch(e){return o(e)}o()}),(function(e){f.close(),e()}));t.objectMode||(d._writev=v),d.on("close",()=>{f.close()});const p=void 0===f.addEventListener;function m(){n.setReadable(d),n.setWritable(d),n.emit("connect")}function g(){n.end(),n.destroy()}function b(e){n.destroy(e)}function y(e){let t=e.data;t=t instanceof ArrayBuffer?r.from(t):r.from(t,"utf8"),d.push(t)}function v(e,t){const n=new Array(e.length);for(let t=0;t<e.length;t++)"string"==typeof e[t].chunk?n[t]=r.from(e[t],"utf8"):n[t]=e[t].chunk;this._write(r.concat(n),"binary",t)}return(f.readyState===f.OPEN?n=d:(n=n=s(void 0,void 0,t),t.objectMode||(n._writev=v),p?f.addEventListener("open",m):f.onopen=m),n.socket=f,p?(f.addEventListener("close",g),f.addEventListener("error",b),f.addEventListener("message",y)):(f.onclose=g,f.onerror=b,f.onmessage=y),n)}:function(e,t){o("streamBuilder");let n=h(t);const r=l(n,e);let s=function(e,t,n){o("createWebSocket"),o("protocol: "+n.protocolId+" "+n.protocolVersion);const r="MQIsdp"===n.protocolId&&3===n.protocolVersion?"mqttv3.1":"mqtt";return o("creating new Websocket for url: "+t+" and protocol: "+r),new i(t,[r],n.wsOptions)}(0,r,n),a=i.createWebSocketStream(s,n.wsOptions);return a.url=r,a}}).call(this,n(6),n(7).Buffer)},function(e,t){e.exports=function(e){this.wrapped=e}},function(e,t,n){var r=n(88);e.exports=function(e,t){return r(Date.now(),e,t)}},function(e,t,n){(function(t){var n="Expected a function",r=NaN,i="[object Symbol]",o=/^\s+|\s+$/g,s=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,u=/^0o[0-7]+$/i,c=parseInt,l="object"==typeof t&&t&&t.Object===Object&&t,h="object"==typeof self&&self&&self.Object===Object&&self,f=l||h||Function("return this")(),d=Object.prototype.toString,p=Math.max,m=Math.min,g=function(){return f.Date.now()};function b(e,t,r){var i,o,s,a,u,c,l=0,h=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError(n);function b(t){var n=i,r=o;return i=o=void 0,l=t,a=e.apply(r,n)}function _(e){var n=e-c;return void 0===c||n>=t||n<0||f&&e-l>=s}function w(){var e=g();if(_(e))return k(e);u=setTimeout(w,function(e){var n=t-(e-c);return f?m(n,s-(e-l)):n}(e))}function k(e){return u=void 0,d&&i?b(e):(i=o=void 0,a)}function S(){var e=g(),n=_(e);if(i=arguments,o=this,c=e,n){if(void 0===u)return function(e){return l=e,u=setTimeout(w,t),h?b(e):a}(c);if(f)return u=setTimeout(w,t),b(c)}return void 0===u&&(u=setTimeout(w,t)),a}return t=v(t)||0,y(r)&&(h=!!r.leading,s=(f="maxWait"in r)?p(v(r.maxWait)||0,t):s,d="trailing"in r?!!r.trailing:d),S.cancel=function(){void 0!==u&&clearTimeout(u),l=0,i=c=o=u=void 0},S.flush=function(){return void 0===u?a:k(g())},S}function y(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function v(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&d.call(e)==i}(e))return r;if(y(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=y(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(o,"");var n=a.test(e);return n||u.test(e)?c(e.slice(2),n?2:8):s.test(e)?r:+e}e.exports=function(e,t,r){var i=!0,o=!0;if("function"!=typeof e)throw new TypeError(n);return y(r)&&(i="leading"in r?!!r.leading:i,o="trailing"in r?!!r.trailing:o),b(e,t,{leading:i,maxWait:t,trailing:o})}}).call(this,n(9))},function(e,t,n){var r=n(95),i=n(96),o=n(33),s=n(97);e.exports=function(e,t){return r(e)||i(e,t)||o(e,t)||s()}},function(e,t){function n(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?e.exports=n=function(e){return typeof e}:e.exports=n=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(t)}e.exports=n},function(e,t,n){"use strict";(function(t){var r=n(98),i=n(38),o=n(120),s=n(24),a=n(13)("mqttjs"),u={};function c(e,t){if(a("connecting to an MQTT broker..."),"object"!=typeof e||t||(t=e,e=null),t=t||{},e){var n=o.parse(e,!0);if(null!=n.port&&(n.port=Number(n.port)),null===(t=s(n,t)).protocol)throw new Error("Missing protocol");t.protocol=t.protocol.replace(/:$/,"")}if(function(e){var t;e.auth&&((t=e.auth.match(/^(.+):(.+)$/))?(e.username=t[1],e.password=t[2]):e.username=e.auth)}(t),t.query&&"string"==typeof t.query.clientId&&(t.clientId=t.query.clientId),t.cert&&t.key){if(!t.protocol)throw new Error("Missing secure protocol key");if(-1===["mqtts","wss","wxs","alis"].indexOf(t.protocol))switch(t.protocol){case"mqtt":t.protocol="mqtts";break;case"ws":t.protocol="wss";break;case"wx":t.protocol="wxs";break;case"ali":t.protocol="alis";break;default:throw new Error('Unknown protocol for secure connection: "'+t.protocol+'"!')}}if(!u[t.protocol]){var i=-1!==["mqtts","wss"].indexOf(t.protocol);t.protocol=["mqtt","mqtts","ws","wss","wx","wxs","ali","alis"].filter((function(e,t){return(!i||t%2!=0)&&"function"==typeof u[e]}))[0]}if(!1===t.clean&&!t.clientId)throw new Error("Missing clientId for unclean clients");t.protocol&&(t.defaultProtocol=t.protocol);var c=new r((function(e){return t.servers&&(e._reconnectCount&&e._reconnectCount!==t.servers.length||(e._reconnectCount=0),t.host=t.servers[e._reconnectCount].host,t.port=t.servers[e._reconnectCount].port,t.protocol=t.servers[e._reconnectCount].protocol?t.servers[e._reconnectCount].protocol:t.defaultProtocol,t.hostname=t.host,e._reconnectCount++),a("calling streambuilder for",t.protocol),u[t.protocol](e,t)}),t);return c.on("error",(function(){})),c}void 0!==t&&"browser"!==t.title||"function"!=typeof n?(u.mqtt=n(49),u.tcp=n(49),u.ssl=n(26),u.tls=n(26),u.mqtts=n(26)):(u.wx=n(50),u.wxs=n(50),u.ali=n(56),u.alis=n(56)),u.ws=n(57),u.wss=n(57),e.exports=c,e.exports.connect=c,e.exports.MqttClient=r,e.exports.Store=i}).call(this,n(6))},function(e,t,n){(function(t){var n="Expected a function",r=NaN,i="[object Symbol]",o=/^\s+|\s+$/g,s=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,u=/^0o[0-7]+$/i,c=parseInt,l="object"==typeof t&&t&&t.Object===Object&&t,h="object"==typeof self&&self&&self.Object===Object&&self,f=l||h||Function("return this")(),d=Object.prototype.toString,p=Math.max,m=Math.min,g=function(){return f.Date.now()};function b(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function y(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&d.call(e)==i}(e))return r;if(b(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=b(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(o,"");var n=a.test(e);return n||u.test(e)?c(e.slice(2),n?2:8):s.test(e)?r:+e}e.exports=function(e,t,r){var i,o,s,a,u,c,l=0,h=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError(n);function v(t){var n=i,r=o;return i=o=void 0,l=t,a=e.apply(r,n)}function _(e){var n=e-c;return void 0===c||n>=t||n<0||f&&e-l>=s}function w(){var e=g();if(_(e))return k(e);u=setTimeout(w,function(e){var n=t-(e-c);return f?m(n,s-(e-l)):n}(e))}function k(e){return u=void 0,d&&i?v(e):(i=o=void 0,a)}function S(){var e=g(),n=_(e);if(i=arguments,o=this,c=e,n){if(void 0===u)return function(e){return l=e,u=setTimeout(w,t),h?v(e):a}(c);if(f)return u=setTimeout(w,t),v(c)}return void 0===u&&(u=setTimeout(w,t)),a}return t=y(t)||0,b(r)&&(h=!!r.leading,s=(f="maxWait"in r)?p(y(r.maxWait)||0,t):s,d="trailing"in r?!!r.trailing:d),S.cancel=function(){void 0!==u&&clearTimeout(u),l=0,i=c=o=u=void 0},S.flush=function(){return void 0===u?a:k(g())},S}}).call(this,n(9))},function(e){e.exports=JSON.parse('{"name":"qiscus-sdk-core","version":"2.11.0","description":"Qiscus Web SDK Core","license":"MIT","main":"lib/index.js","browser":"dist/qiscus-sdk-core.min.js","files":["lib","dist"],"scripts":{"build":"npm-run-all --parallel build:node build:web","build:dev":"npm-run-all --parallel build:node build:web:dev build:dev:watch","build:dev:watch":"npm-run-all --parallel build:web:watch serve","build:node":"babel -d lib src","build:node:watch":"babel -w -d lib src","build:web":"webpack --env.production --env.target=web","build:web:dev":"webpack --env.development --env.target=web","build:web:watch":"webpack --env.development --env.target=web --watch","dev":"webpack --env.development --progress --colors --watch","watch":"npm-run-all build:web:watch build:node:watch","test":"mocha --require @babel/register --colors \'test/**/*test.js\'","test:watch":"npm run test -- -w","clean":"rimraf dist lib","preversion":"npm-run-all clean build","prepublishOnly":"npm-run-all clean build","serve":"http-server -p 1234 -c-1 dist"},"devDependencies":{"@babel/cli":"^7.8.4","@babel/core":"^7.8.6","@babel/plugin-proposal-class-properties":"^7.8.3","@babel/plugin-transform-runtime":"^7.8.3","@babel/polyfill":"^7.8.3","@babel/preset-env":"^7.8.6","@babel/register":"^7.8.6","@commitlint/cli":"^8.3.5","@commitlint/config-conventional":"^8.3.4","babel-eslint":"^8.0.0","babel-loader":"^8.0.6","babel-minify-webpack-plugin":"^0.2.0","babel-plugin-add-module-exports":"^1.0.2","babel-plugin-date-fns":"^0.1.0","chai":"^4.1.2","chai-spies":"^1.0.0","eslint":"^4.19.1","eslint-config-standard":"^12.0.0","eslint-loader":"^1.9.0","eslint-plugin-import":"^2.20.1","eslint-plugin-node":"^8.0.1","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","http-server":"^0.12.3","mocha":"^5.2.0","npm-run-all":"^4.1.5","rimraf":"^2.7.1","serve":"^12.0.0","webpack":"^4.41.6","webpack-cli":"^3.3.11"},"dependencies":{"@babel/runtime":"^7.8.4","date-fns":"^1.30.1","is_js":"^0.9.0","lodash.debounce":"^4.0.8","lodash.throttle":"^4.1.1","mitt":"^1.2.0","mqtt":"^4.2.6","store":"^2.0.12","superagent":"^3.6.3"},"babel":{"presets":[["@babel/preset-env",{"modules":"auto"}]],"plugins":["@babel/plugin-transform-runtime","@babel/plugin-proposal-class-properties","babel-plugin-add-module-exports","date-fns"]},"prettier":{"semi":false,"singleQuote":true,"trailingComma":"es5"}}')},function(e,t,n){e.exports=n(142)},function(e,t,n){var r=n(32);e.exports=function(e){if(Array.isArray(e))return r(e)}},function(e,t){e.exports=function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}},function(e,t,n){var r=function(e){"use strict";var t,n=Object.prototype,r=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",a=i.toStringTag||"@@toStringTag";function u(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=t&&t.prototype instanceof g?t:g,o=Object.create(i.prototype),s=new R(r||[]);return o._invoke=function(e,t,n){var r=h;return function(i,o){if(r===d)throw new Error("Generator is already running");if(r===p){if("throw"===i)throw o;return I()}for(n.method=i,n.arg=o;;){var s=n.delegate;if(s){var a=T(s,n);if(a){if(a===m)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===h)throw r=p,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=d;var u=l(e,t,n);if("normal"===u.type){if(r=n.done?p:f,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=p,n.method="throw",n.arg=u.arg)}}}(e,n,s),o}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var h="suspendedStart",f="suspendedYield",d="executing",p="completed",m={};function g(){}function b(){}function y(){}var v={};v[o]=function(){return this};var _=Object.getPrototypeOf,w=_&&_(_(A([])));w&&w!==n&&r.call(w,o)&&(v=w);var k=y.prototype=g.prototype=Object.create(v);function S(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function E(e,t){var n;this._invoke=function(i,o){function s(){return new t((function(n,s){!function n(i,o,s,a){var u=l(e[i],e,o);if("throw"!==u.type){var c=u.arg,h=c.value;return h&&"object"==typeof h&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){n("next",e,s,a)}),(function(e){n("throw",e,s,a)})):t.resolve(h).then((function(e){c.value=e,s(c)}),(function(e){return n("throw",e,s,a)}))}a(u.arg)}(i,o,n,s)}))}return n=n?n.then(s,s):s()}}function T(e,n){var r=e.iterator[n.method];if(r===t){if(n.delegate=null,"throw"===n.method){if(e.iterator.return&&(n.method="return",n.arg=t,T(e,n),"throw"===n.method))return m;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var i=l(r,e.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,m;var o=i.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,m):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,m)}function C(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function R(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(C,this),this.reset(!0)}function A(e){if(e){var n=e[o];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,s=function n(){for(;++i<e.length;)if(r.call(e,i))return n.value=e[i],n.done=!1,n;return n.value=t,n.done=!0,n};return s.next=s}}return{next:I}}function I(){return{value:t,done:!0}}return b.prototype=k.constructor=y,y.constructor=b,b.displayName=u(y,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===b||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,u(e,a,"GeneratorFunction")),e.prototype=Object.create(k),e},e.awrap=function(e){return{__await:e}},S(E.prototype),E.prototype[s]=function(){return this},e.AsyncIterator=E,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var s=new E(c(t,n,r,i),o);return e.isGeneratorFunction(n)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},S(k),u(k,a,"Generator"),k[o]=function(){return this},k.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=A,R.prototype={constructor:R,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(x),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function i(r,i){return a.type="throw",a.arg=e,n.next=r,i&&(n.method="next",n.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var s=this.tryEntries[o],a=s.completion;if("root"===s.tryLoc)return i("end");if(s.tryLoc<=this.prev){var u=r.call(s,"catchLoc"),c=r.call(s,"finallyLoc");if(u&&c){if(this.prev<s.catchLoc)return i(s.catchLoc,!0);if(this.prev<s.finallyLoc)return i(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return i(s.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return i(s.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=e,s.arg=t,o?(this.method="next",this.next=o.finallyLoc,m):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),m},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),x(n),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;x(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:A(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),m}},e}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}},function(e,t,n){function r(e){if(e)return function(e){for(var t in r.prototype)e[t]=r.prototype[t];return e}(e)}e.exports=r,r.prototype.on=r.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},r.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},r.prototype.off=r.prototype.removeListener=r.prototype.removeAllListeners=r.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var i=0;i<r.length;i++)if((n=r[i])===t||n.fn===t){r.splice(i,1);break}return 0===r.length&&delete this._callbacks["$"+e],this},r.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),n=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){r=0;for(var i=(n=n.slice(0)).length;r<i;++r)n[r].apply(this,t)}return this},r.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},r.prototype.hasListeners=function(e){return!!this.listeners(e).length}},function(e,t,n){"use strict";var r=n(34);function i(e){if(e)return function(e){for(var t in i.prototype)e[t]=i.prototype[t];return e}(e)}e.exports=i,i.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,this},i.prototype.parse=function(e){return this._parser=e,this},i.prototype.responseType=function(e){return this._responseType=e,this},i.prototype.serialize=function(e){return this._serializer=e,this},i.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this;for(var t in e)switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;default:console.warn("Unknown timeout option",t)}return this},i.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};var o=["ECONNRESET","ETIMEDOUT","EADDRINFO","ESOCKETTIMEDOUT"];i.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{var n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&t.status>=500&&501!=t.status)return!0;if(e){if(e.code&&~o.indexOf(e.code))return!0;if(e.timeout&&"ECONNABORTED"==e.code)return!0;if(e.crossDomain)return!0}return!1},i.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this._end()},i.prototype.then=function(e,t){if(!this._fullfilledPromise){var n=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise((function(e,t){n.end((function(n,r){n?t(n):e(r)}))}))}return this._fullfilledPromise.then(e,t)},i.prototype.catch=function(e){return this.then(void 0,e)},i.prototype.use=function(e){return e(this),this},i.prototype.ok=function(e){if("function"!=typeof e)throw Error("Callback required");return this._okCallback=e,this},i.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},i.prototype.get=function(e){return this._header[e.toLowerCase()]},i.prototype.getHeader=i.prototype.get,i.prototype.set=function(e,t){if(r(e)){for(var n in e)this.set(n,e[n]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},i.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},i.prototype.field=function(e,t){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data&&console.error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()"),r(e)){for(var n in e)this.field(n,e[n]);return this}if(Array.isArray(t)){for(var i in t)this.field(e,t[i]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=""+t),this._getFormData().append(e,t),this},i.prototype.abort=function(){return this._aborted?this:(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req&&this.req.abort(),this.clearTimeout(),this.emit("abort"),this)},i.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization","Basic "+r(e+":"+t));break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization","Bearer "+e)}return this},i.prototype.withCredentials=function(e){return null==e&&(e=!0),this._withCredentials=e,this},i.prototype.redirects=function(e){return this._maxRedirects=e,this},i.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw TypeError("Invalid argument");return this._maxResponseSize=e,this},i.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},i.prototype.send=function(e){var t=r(e),n=this._header["content-type"];if(this._formData&&console.error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()"),t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw Error("Can't merge these send calls");if(t&&r(this._data))for(var i in e)this._data[i]=e[i];else"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],this._data="application/x-www-form-urlencoded"==n?this._data?this._data+"&"+e:e:(this._data||"")+e):this._data=e;return!t||this._isHost(e)?this:(n||this.type("json"),this)},i.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},i.prototype._finalizeQueryString=function(){var e=this._query.join("&");if(e&&(this.url+=(this.url.indexOf("?")>=0?"&":"?")+e),this._query.length=0,this._sort){var t=this.url.indexOf("?");if(t>=0){var n=this.url.substring(t+1).split("&");"function"==typeof this._sort?n.sort(this._sort):n.sort(),this.url=this.url.substring(0,t)+"?"+n.join("&")}}},i.prototype._appendQueryString=function(){console.trace("Unsupported")},i.prototype._timeoutError=function(e,t,n){if(!this._aborted){var r=new Error(e+t+"ms exceeded");r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.abort(),this.callback(r)}},i.prototype._setTimeouts=function(){var e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((function(){e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((function(){e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))}},function(e,t,n){"use strict";var r=n(74);function i(e){if(e)return function(e){for(var t in i.prototype)e[t]=i.prototype[t];return e}(e)}e.exports=i,i.prototype.get=function(e){return this.header[e.toLowerCase()]},i.prototype._setHeaderProperties=function(e){var t=e["content-type"]||"";this.type=r.type(t);var n=r.params(t);for(var i in n)this[i]=n[i];this.links={};try{e.link&&(this.links=r.parseLinks(e.link))}catch(e){}},i.prototype._setStatusProperties=function(e){var t=e/100|0;this.status=this.statusCode=e,this.statusType=t,this.info=1==t,this.ok=2==t,this.redirect=3==t,this.clientError=4==t,this.serverError=5==t,this.error=(4==t||5==t)&&this.toError(),this.created=201==e,this.accepted=202==e,this.noContent=204==e,this.badRequest=400==e,this.unauthorized=401==e,this.notAcceptable=406==e,this.forbidden=403==e,this.notFound=404==e,this.unprocessableEntity=422==e}},function(e,t,n){"use strict";t.type=function(e){return e.split(/ *; */).shift()},t.params=function(e){return e.split(/ *; */).reduce((function(e,t){var n=t.split(/ *= */),r=n.shift(),i=n.shift();return r&&i&&(e[r]=i),e}),{})},t.parseLinks=function(e){return e.split(/ *, */).reduce((function(e,t){var n=t.split(/ *; */),r=n[0].slice(1,-1);return e[n[1].split(/ *= */)[1].slice(1,-1)]=r,e}),{})},t.cleanHeader=function(e,t){return delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e}},function(e,t){function n(){this._defaults=[]}["use","on","once","set","query","type","accept","auth","withCredentials","sortQuery","retry","ok","redirects","timeout","buffer","serialize","parse","ca","key","pfx","cert"].forEach((function(e){n.prototype[e]=function(){return this._defaults.push({fn:e,arguments:arguments}),this}})),n.prototype._setDefaults=function(e){this._defaults.forEach((function(t){e[t.fn].apply(e,t.arguments)}))},e.exports=n},function(e,t,n){var r=n(10),i=n(78),o=n(79);e.exports=function(e){var t=r(e);return o(t,i(t))+1}},function(e,t){e.exports=function(e){var t=new Date(e.getTime()),n=t.getTimezoneOffset();return t.setSeconds(0,0),6e4*n+t.getTime()%6e4}},function(e,t,n){var r=n(10);e.exports=function(e){var t=r(e),n=new Date(0);return n.setFullYear(t.getFullYear(),0,1),n.setHours(0,0,0,0),n}},function(e,t,n){var r=n(80),i=6e4,o=864e5;e.exports=function(e,t){var n=r(e),s=r(t),a=n.getTime()-n.getTimezoneOffset()*i,u=s.getTime()-s.getTimezoneOffset()*i;return Math.round((a-u)/o)}},function(e,t,n){var r=n(10);e.exports=function(e){var t=r(e);return t.setHours(0,0,0,0),t}},function(e,t,n){var r=n(10),i=n(23),o=n(83),s=6048e5;e.exports=function(e){var t=r(e),n=i(t).getTime()-o(t).getTime();return Math.round(n/s)+1}},function(e,t,n){var r=n(10);e.exports=function(e,t){var n=t&&Number(t.weekStartsOn)||0,i=r(e),o=i.getDay(),s=(o<n?7:0)+o-n;return i.setDate(i.getDate()-s),i.setHours(0,0,0,0),i}},function(e,t,n){var r=n(36),i=n(23);e.exports=function(e){var t=r(e),n=new Date(0);return n.setFullYear(t,0,4),n.setHours(0,0,0,0),i(n)}},function(e,t,n){var r=n(35);e.exports=function(e){if(r(e))return!isNaN(e);throw new TypeError(toString.call(e)+" is not an instance of Date")}},function(e,t){e.exports=function(){var e={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};return{localize:function(t,n,r){var i;return r=r||{},i="string"==typeof e[t]?e[t]:1===n?e[t].one:e[t].other.replace("{{count}}",n),r.addSuffix?r.comparison>0?"in "+i:i+" ago":i}}}},function(e,t,n){var r=n(87);e.exports=function(){var e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],t=["January","February","March","April","May","June","July","August","September","October","November","December"],n=["Su","Mo","Tu","We","Th","Fr","Sa"],i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],o=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],s=["AM","PM"],a=["am","pm"],u=["a.m.","p.m."],c={MMM:function(t){return e[t.getMonth()]},MMMM:function(e){return t[e.getMonth()]},dd:function(e){return n[e.getDay()]},ddd:function(e){return i[e.getDay()]},dddd:function(e){return o[e.getDay()]},A:function(e){return e.getHours()/12>=1?s[1]:s[0]},a:function(e){return e.getHours()/12>=1?a[1]:a[0]},aa:function(e){return e.getHours()/12>=1?u[1]:u[0]}};return["M","D","DDD","d","Q","W"].forEach((function(e){c[e+"o"]=function(t,n){return function(e){var t=e%100;if(t>20||t<10)switch(t%10){case 1:return e+"st";case 2:return e+"nd";case 3:return e+"rd"}return e+"th"}(n[e](t))}})),{formatters:c,formattingTokensRegExp:r(c)}}},function(e,t){var n=["M","MM","Q","D","DD","DDD","DDDD","d","E","W","WW","YY","YYYY","GG","GGGG","H","HH","h","hh","m","mm","s","ss","S","SS","SSS","Z","ZZ","X","x"];e.exports=function(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(r);var i=n.concat(t).sort().reverse();return new RegExp("(\\[[^\\[]*\\])|(\\\\)?("+i.join("|")+"|.)","g")}},function(e,t,n){var r=n(89),i=n(10),o=n(90),s=n(92),a=n(37),u=1440,c=2520,l=43200,h=86400;e.exports=function(e,t,n){var f=n||{},d=r(e,t),p=f.locale,m=a.distanceInWords.localize;p&&p.distanceInWords&&p.distanceInWords.localize&&(m=p.distanceInWords.localize);var g,b,y={addSuffix:Boolean(f.addSuffix),comparison:d};d>0?(g=i(e),b=i(t)):(g=i(t),b=i(e));var v,_=o(b,g),w=b.getTimezoneOffset()-g.getTimezoneOffset(),k=Math.round(_/60)-w;if(k<2)return f.includeSeconds?_<5?m("lessThanXSeconds",5,y):_<10?m("lessThanXSeconds",10,y):_<20?m("lessThanXSeconds",20,y):_<40?m("halfAMinute",null,y):m(_<60?"lessThanXMinutes":"xMinutes",1,y):0===k?m("lessThanXMinutes",1,y):m("xMinutes",k,y);if(k<45)return m("xMinutes",k,y);if(k<90)return m("aboutXHours",1,y);if(k<u)return m("aboutXHours",Math.round(k/60),y);if(k<c)return m("xDays",1,y);if(k<l)return m("xDays",Math.round(k/u),y);if(k<h)return m("aboutXMonths",v=Math.round(k/l),y);if((v=s(b,g))<12)return m("xMonths",Math.round(k/l),y);var S=v%12,E=Math.floor(v/12);return S<3?m("aboutXYears",E,y):S<9?m("overXYears",E,y):m("almostXYears",E+1,y)}},function(e,t,n){var r=n(10);e.exports=function(e,t){var n=r(e).getTime(),i=r(t).getTime();return n>i?-1:n<i?1:0}},function(e,t,n){var r=n(91);e.exports=function(e,t){var n=r(e,t)/1e3;return n>0?Math.floor(n):Math.ceil(n)}},function(e,t,n){var r=n(10);e.exports=function(e,t){var n=r(e),i=r(t);return n.getTime()-i.getTime()}},function(e,t,n){var r=n(10),i=n(93),o=n(94);e.exports=function(e,t){var n=r(e),s=r(t),a=o(n,s),u=Math.abs(i(n,s));return n.setMonth(n.getMonth()-a*u),a*(u-(o(n,s)===-a))}},function(e,t,n){var r=n(10);e.exports=function(e,t){var n=r(e),i=r(t);return 12*(n.getFullYear()-i.getFullYear())+(n.getMonth()-i.getMonth())}},function(e,t,n){var r=n(10);e.exports=function(e,t){var n=r(e).getTime(),i=r(t).getTime();return n<i?-1:n>i?1:0}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var n=[],r=!0,i=!1,o=void 0;try{for(var s,a=e[Symbol.iterator]();!(r=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==a.return||a.return()}finally{if(i)throw o}}return n}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}},function(e,t,n){"use strict";(function(t,r){var i=n(12).EventEmitter,o=n(38),s=n(109),a=n(14).Writable,u=n(11),c=n(118),l=n(119),h=n(24),f=n(13)("mqttjs:client"),d=t?t.nextTick:function(e){setTimeout(e,0)},p=r.setImmediate||function(e){d(e)},m={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:3e4,clean:!0,resubscribe:!0},g=["ECONNREFUSED","EADDRINUSE","ECONNRESET","ENOTFOUND"],b={0:"",1:"Unacceptable protocol version",2:"Identifier rejected",3:"Server unavailable",4:"Bad username or password",5:"Not authorized",16:"No matching subscribers",17:"No subscription existed",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",132:"Unsupported Protocol Version",133:"Client Identifier not valid",134:"Bad User Name or Password",135:"Not authorized",136:"Server unavailable",137:"Server busy",138:"Banned",139:"Server shutting down",140:"Bad authentication method",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",145:"Packet identifier in use",146:"Packet Identifier not found",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"};function y(e,t,n){f("sendPacket :: packet: %O",t),f("sendPacket :: emitting `packetsend`"),e.emit("packetsend",t),f("sendPacket :: writing to stream");var r=s.writeToStream(t,e.stream,e.options);f("sendPacket :: writeToStream result %s",r),!r&&n?(f("sendPacket :: handle events on `drain` once through callback."),e.stream.once("drain",n)):n&&(f("sendPacket :: invoking cb"),n())}function v(e){e&&(f("flush: queue exists? %b",!!e),Object.keys(e).forEach((function(t){"function"==typeof e[t].cb&&(e[t].cb(new Error("Connection closed")),delete e[t])})))}function _(e,t,n,r){f("storeAndSend :: store packet with cmd %s to outgoingStore",t.cmd),e.outgoingStore.put(t,(function(i){if(i)return n&&n(i);r(),y(e,t,n)}))}function w(e){f("nop ::",e)}function k(e,t){var n,r=this;if(!(this instanceof k))return new k(e,t);for(n in this.options=t||{},m)void 0===this.options[n]?this.options[n]=m[n]:this.options[n]=t[n];f("MqttClient :: options.protocol",t.protocol),f("MqttClient :: options.protocolVersion",t.protocolVersion),f("MqttClient :: options.username",t.username),f("MqttClient :: options.keepalive",t.keepalive),f("MqttClient :: options.reconnectPeriod",t.reconnectPeriod),f("MqttClient :: options.rejectUnauthorized",t.rejectUnauthorized),this.options.clientId="string"==typeof t.clientId?t.clientId:"mqttjs_"+Math.random().toString(16).substr(2,8),f("MqttClient :: clientId",this.options.clientId),this.options.customHandleAcks=5===t.protocolVersion&&t.customHandleAcks?t.customHandleAcks:function(){arguments[3](0)},this.streamBuilder=e,this.outgoingStore=t.outgoingStore||new o,this.incomingStore=t.incomingStore||new o,this.queueQoSZero=void 0===t.queueQoSZero||t.queueQoSZero,this._resubscribeTopics={},this.messageIdToTopic={},this.pingTimer=null,this.connected=!1,this.disconnecting=!1,this.queue=[],this.connackTimer=null,this.reconnectTimer=null,this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={},this.nextId=Math.max(1,Math.floor(65535*Math.random())),this.outgoing={},this._firstConnection=!0,this.on("connect",(function(){var e=this.queue;f("connect :: sending queued packets"),function t(){var n=e.shift();f("deliver :: entry %o",n);var i;n&&(i=n.packet,f("deliver :: call _sendPacket for %o",i),r._sendPacket(i,(function(e){n.cb&&n.cb(e),t()})))}()})),this.on("close",(function(){f("close :: connected set to `false`"),this.connected=!1,f("close :: clearing connackTimer"),clearTimeout(this.connackTimer),f("close :: clearing ping timer"),null!==r.pingTimer&&(r.pingTimer.clear(),r.pingTimer=null),f("close :: calling _setupReconnect"),this._setupReconnect()})),i.call(this),f("MqttClient :: setting up stream"),this._setupStream()}u(k,i),k.prototype._setupStream=function(){var e,t=this,n=new a,r=s.parser(this.options),i=null,o=[];function u(){if(o.length)d(c);else{var e=i;i=null,e()}}function c(){f("work :: getting next packet in queue");var e=o.shift();if(e)f("work :: packet pulled from queue"),t._handlePacket(e,u);else{f("work :: no packets in queue");var n=i;i=null,f("work :: done flag is %s",!!n),n&&n()}}if(f("_setupStream :: calling method to clear reconnect"),this._clearReconnect(),f("_setupStream :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),r.on("packet",(function(e){f("parser :: on packet push to packets array."),o.push(e)})),n._write=function(e,t,n){i=n,f("writable stream :: parsing buffer"),r.parse(e),c()},f("_setupStream :: pipe stream to writable stream"),this.stream.pipe(n),this.stream.on("error",(function(e){f("streamErrorHandler :: error",e.message),g.includes(e.code)?(f("streamErrorHandler :: emitting error"),t.emit("error",e)):w(e)})),this.stream.on("close",(function(){var e;f("(%s)stream :: on close",t.options.clientId),(e=t.outgoing)&&(f("flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(e).forEach((function(t){e[t].volatile&&"function"==typeof e[t].cb&&(e[t].cb(new Error("Connection closed")),delete e[t])}))),f("stream: emit close to MqttClient"),t.emit("close")})),f("_setupStream: sending packet `connect`"),(e=Object.create(this.options)).cmd="connect",y(this,e),r.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return t.end(()=>this.emit("error",new Error("Packet has no Authentication Method"))),this;if(this.options.properties.authenticationMethod&&this.options.authPacket&&"object"==typeof this.options.authPacket)y(this,h({cmd:"auth",reasonCode:0},this.options.authPacket))}this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout((function(){f("!!connectTimeout hit!! Calling _cleanUp with force `true`"),t._cleanUp(!0)}),this.options.connectTimeout)},k.prototype._handlePacket=function(e,t){var n=this.options;if(5===n.protocolVersion&&n.properties&&n.properties.maximumPacketSize&&n.properties.maximumPacketSize<e.length)return this.emit("error",new Error("exceeding packets size "+e.cmd)),this.end({reasonCode:149,properties:{reasonString:"Maximum packet size was exceeded"}}),this;switch(f("_handlePacket :: emitting packetreceive"),this.emit("packetreceive",e),e.cmd){case"publish":this._handlePublish(e,t);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(e),t();break;case"pubrel":this._handlePubrel(e,t);break;case"connack":this._handleConnack(e),t();break;case"pingresp":this._handlePingresp(e),t();break;case"disconnect":this._handleDisconnect(e),t()}},k.prototype._checkDisconnecting=function(e){return this.disconnecting&&(e?e(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting},k.prototype.publish=function(e,t,n,r){var i;f("publish :: message `%s` to topic `%s`",t,e);var o=this.options;"function"==typeof n&&(r=n,n=null);if(n=h({qos:0,retain:!1,dup:!1},n),this._checkDisconnecting(r))return this;switch(i={cmd:"publish",topic:e,payload:t,qos:n.qos,retain:n.retain,messageId:this._nextId(),dup:n.dup},5===o.protocolVersion&&(i.properties=n.properties,(!o.properties&&i.properties&&i.properties.topicAlias||n.properties&&o.properties&&(n.properties.topicAlias&&o.properties.topicAliasMaximum&&n.properties.topicAlias>o.properties.topicAliasMaximum||!o.properties.topicAliasMaximum&&n.properties.topicAlias))&&delete i.properties.topicAlias),f("publish :: qos",n.qos),n.qos){case 1:case 2:this.outgoing[i.messageId]={volatile:!1,cb:r||w},this._storeProcessing?(f("_storeProcessing enabled"),this._packetIdsDuringStoreProcessing[i.messageId]=!1,this._storePacket(i,void 0,n.cbStorePut)):(f("MqttClient:publish: packet cmd: %s",i.cmd),this._sendPacket(i,void 0,n.cbStorePut));break;default:this._storeProcessing?(f("_storeProcessing enabled"),this._storePacket(i,r,n.cbStorePut)):(f("MqttClient:publish: packet cmd: %s",i.cmd),this._sendPacket(i,r,n.cbStorePut))}return this},k.prototype.subscribe=function(){for(var e,t=new Array(arguments.length),n=0;n<arguments.length;n++)t[n]=arguments[n];var r,i=[],o=t.shift(),s=o.resubscribe,a=t.pop()||w,u=t.pop(),c=this,d=this.options.protocolVersion;if(delete o.resubscribe,"string"==typeof o&&(o=[o]),"function"!=typeof a&&(u=a,a=w),null!==(r=l.validateTopics(o)))return p(a,new Error("Invalid topic "+r)),this;if(this._checkDisconnecting(a))return f("subscribe: discconecting true"),this;var m={qos:0};if(5===d&&(m.nl=!1,m.rap=!1,m.rh=0),u=h(m,u),Array.isArray(o)?o.forEach((function(e){if(f("subscribe: array topic %s",e),!c._resubscribeTopics.hasOwnProperty(e)||c._resubscribeTopics[e].qos<u.qos||s){var t={topic:e,qos:u.qos};5===d&&(t.nl=u.nl,t.rap=u.rap,t.rh=u.rh,t.properties=u.properties),f("subscribe: pushing topic `%s` and qos `%s` to subs list",t.topic,t.qos),i.push(t)}})):Object.keys(o).forEach((function(e){if(f("subscribe: object topic %s",e),!c._resubscribeTopics.hasOwnProperty(e)||c._resubscribeTopics[e].qos<o[e].qos||s){var t={topic:e,qos:o[e].qos};5===d&&(t.nl=o[e].nl,t.rap=o[e].rap,t.rh=o[e].rh,t.properties=u.properties),f("subscribe: pushing `%s` to subs list",t),i.push(t)}})),e={cmd:"subscribe",subscriptions:i,qos:1,retain:!1,dup:!1,messageId:this._nextId()},u.properties&&(e.properties=u.properties),i.length){if(this.options.resubscribe){f("subscribe :: resubscribe true");var g=[];i.forEach((function(e){if(c.options.reconnectPeriod>0){var t={qos:e.qos};5===d&&(t.nl=e.nl||!1,t.rap=e.rap||!1,t.rh=e.rh||0,t.properties=e.properties),c._resubscribeTopics[e.topic]=t,g.push(e.topic)}})),c.messageIdToTopic[e.messageId]=g}return this.outgoing[e.messageId]={volatile:!0,cb:function(e,t){if(!e)for(var n=t.granted,r=0;r<n.length;r+=1)i[r].qos=n[r];a(e,i)}},f("subscribe :: call _sendPacket"),this._sendPacket(e),this}a(null,[])},k.prototype.unsubscribe=function(){for(var e={cmd:"unsubscribe",qos:1,messageId:this._nextId()},t=this,n=new Array(arguments.length),r=0;r<arguments.length;r++)n[r]=arguments[r];var i=n.shift(),o=n.pop()||w,s=n.pop();return"string"==typeof i&&(i=[i]),"function"!=typeof o&&(s=o,o=w),this._checkDisconnecting(o)?this:("string"==typeof i?e.unsubscriptions=[i]:Array.isArray(i)&&(e.unsubscriptions=i),this.options.resubscribe&&e.unsubscriptions.forEach((function(e){delete t._resubscribeTopics[e]})),"object"==typeof s&&s.properties&&(e.properties=s.properties),this.outgoing[e.messageId]={volatile:!0,cb:o},f("unsubscribe: call _sendPacket"),this._sendPacket(e),this)},k.prototype.end=function(e,t,n){var r=this;function i(){f("end :: closeStores: closing incoming and outgoing stores"),r.disconnected=!0,r.incomingStore.close((function(e){r.outgoingStore.close((function(t){if(f("end :: closeStores: emitting end"),r.emit("end"),n){let r=e||t;f("end :: closeStores: invoking callback with args"),n(r)}}))})),r._deferredReconnect&&r._deferredReconnect()}function o(){f("end :: (%s) :: finish :: calling _cleanUp with force %s",r.options.clientId,e),r._cleanUp(e,()=>{f("end :: finish :: calling process.nextTick on closeStores"),d(i.bind(r))},t)}return f("end :: (%s)",this.options.clientId),null!=e&&"boolean"==typeof e||(n=t||w,t=e,e=!1,"object"!=typeof t&&(n=t,t=null,"function"!=typeof n&&(n=w))),"object"!=typeof t&&(n=t,t=null),f("end :: cb? %s",!!n),n=n||w,this.disconnecting?(n(),this):(this._clearReconnect(),this.disconnecting=!0,!e&&Object.keys(this.outgoing).length>0?(f("end :: (%s) :: calling finish in 10ms once outgoing is empty",r.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,o,10))):(f("end :: (%s) :: immediately calling finish",r.options.clientId),o()),this)},k.prototype.removeOutgoingMessage=function(e){var t=this.outgoing[e]?this.outgoing[e].cb:null;return delete this.outgoing[e],this.outgoingStore.del({messageId:e},(function(){t(new Error("Message removed"))})),this},k.prototype.reconnect=function(e){f("client reconnect");var t=this,n=function(){e?(t.options.incomingStore=e.incomingStore,t.options.outgoingStore=e.outgoingStore):(t.options.incomingStore=null,t.options.outgoingStore=null),t.incomingStore=t.options.incomingStore||new o,t.outgoingStore=t.options.outgoingStore||new o,t.disconnecting=!1,t.disconnected=!1,t._deferredReconnect=null,t._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=n:n(),this},k.prototype._reconnect=function(){f("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end(()=>{this._setupStream()}),f("client already connected. disconnecting first.")):(f("_reconnect: calling _setupStream"),this._setupStream())},k.prototype._setupReconnect=function(){var e=this;!e.disconnecting&&!e.reconnectTimer&&e.options.reconnectPeriod>0?(this.reconnecting||(f("_setupReconnect :: emit `offline` state"),this.emit("offline"),f("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),f("_setupReconnect :: setting reconnectTimer for %d ms",e.options.reconnectPeriod),e.reconnectTimer=setInterval((function(){f("reconnectTimer :: reconnect triggered!"),e._reconnect()}),e.options.reconnectPeriod)):f("_setupReconnect :: doing nothing...")},k.prototype._clearReconnect=function(){f("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},k.prototype._cleanUp=function(e,t){var n=arguments[2];if(t&&(f("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",t)),f("_cleanUp :: forced? %s",e),e)0===this.options.reconnectPeriod&&this.options.clean&&v(this.outgoing),f("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{var r=h({cmd:"disconnect"},n);f("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(r,p.bind(null,this.stream.end.bind(this.stream)))}this.disconnecting||(f("_cleanUp :: client not disconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),null!==this.pingTimer&&(f("_cleanUp :: clearing pingTimer"),this.pingTimer.clear(),this.pingTimer=null),t&&!this.connected&&(f("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",t),t())},k.prototype._sendPacket=function(e,t,n){if(f("_sendPacket :: (%s) :: start",this.options.clientId),n=n||w,!this.connected)return f("_sendPacket :: client not connected. Storing packet offline."),void this._storePacket(e,t,n);switch(this._shiftPingInterval(),e.cmd){case"publish":break;case"pubrel":return void _(this,e,t,n);default:return void y(this,e,t)}switch(e.qos){case 2:case 1:_(this,e,t,n);break;case 0:default:y(this,e,t)}f("_sendPacket :: (%s) :: end",this.options.clientId)},k.prototype._storePacket=function(e,t,n){f("_storePacket :: packet: %o",e),f("_storePacket :: cb? %s",!!t),n=n||w,0===(e.qos||0)&&this.queueQoSZero||"publish"!==e.cmd?this.queue.push({packet:e,cb:t}):e.qos>0?(t=this.outgoing[e.messageId]?this.outgoing[e.messageId].cb:null,this.outgoingStore.put(e,(function(e){if(e)return t&&t(e);n()}))):t&&t(new Error("No connection to broker"))},k.prototype._setupPingTimer=function(){f("_setupPingTimer :: keepalive %d (seconds)",this.options.keepalive);var e=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=c((function(){e._checkPing()}),1e3*this.options.keepalive))},k.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},k.prototype._checkPing=function(){f("_checkPing :: checking ping..."),this.pingResp?(f("_checkPing :: ping response received. Clearing flag and sending `pingreq`"),this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):(f("_checkPing :: calling _cleanUp with force true"),this._cleanUp(!0))},k.prototype._handlePingresp=function(){this.pingResp=!0},k.prototype._handleConnack=function(e){f("_handleConnack");var t=this.options,n=5===t.protocolVersion?e.reasonCode:e.returnCode;if(clearTimeout(this.connackTimer),e.properties&&(e.properties.topicAliasMaximum&&(t.properties||(t.properties={}),t.properties.topicAliasMaximum=e.properties.topicAliasMaximum),e.properties.serverKeepAlive&&t.keepalive&&(t.keepalive=e.properties.serverKeepAlive,this._shiftPingInterval()),e.properties.maximumPacketSize&&(t.properties||(t.properties={}),t.properties.maximumPacketSize=e.properties.maximumPacketSize)),0===n)this.reconnecting=!1,this._onConnect(e);else if(n>0){var r=new Error("Connection refused: "+b[n]);r.code=n,this.emit("error",r)}},k.prototype._handlePublish=function(e,t){f("_handlePublish: packet %o",e),t=void 0!==t?t:w;var n=e.topic.toString(),r=e.payload,i=e.qos,o=e.messageId,s=this,a=this.options,u=[0,16,128,131,135,144,145,151,153];switch(f("_handlePublish: qos %d",i),i){case 2:a.customHandleAcks(n,r,e,(function(n,r){return n instanceof Error||(r=n,n=null),n?s.emit("error",n):-1===u.indexOf(r)?s.emit("error",new Error("Wrong reason code for pubrec")):void(r?s._sendPacket({cmd:"pubrec",messageId:o,reasonCode:r},t):s.incomingStore.put(e,(function(){s._sendPacket({cmd:"pubrec",messageId:o},t)})))}));break;case 1:a.customHandleAcks(n,r,e,(function(i,a){return i instanceof Error||(a=i,i=null),i?s.emit("error",i):-1===u.indexOf(a)?s.emit("error",new Error("Wrong reason code for puback")):(a||s.emit("message",n,r,e),void s.handleMessage(e,(function(e){if(e)return t&&t(e);s._sendPacket({cmd:"puback",messageId:o,reasonCode:a},t)})))}));break;case 0:this.emit("message",n,r,e),this.handleMessage(e,t);break;default:f("_handlePublish: unknown QoS. Doing nothing.")}},k.prototype.handleMessage=function(e,t){t()},k.prototype._handleAck=function(e){var t,n=e.messageId,r=e.cmd,i=null,o=this.outgoing[n]?this.outgoing[n].cb:null,s=this;if(o){switch(f("_handleAck :: packet type",r),r){case"pubcomp":case"puback":var a=e.reasonCode;a&&a>0&&16!==a&&((t=new Error("Publish error: "+b[a])).code=a,o(t,e)),delete this.outgoing[n],this.outgoingStore.del(e,o);break;case"pubrec":i={cmd:"pubrel",qos:2,messageId:n};var u=e.reasonCode;u&&u>0&&16!==u?((t=new Error("Publish error: "+b[u])).code=u,o(t,e)):this._sendPacket(i);break;case"suback":delete this.outgoing[n];for(var c=0;c<e.granted.length;c++)if(0!=(128&e.granted[c])){var l=this.messageIdToTopic[n];l&&l.forEach((function(e){delete s._resubscribeTopics[e]}))}o(null,e);break;case"unsuback":delete this.outgoing[n],o(null);break;default:s.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&0===Object.keys(this.outgoing).length&&this.emit("outgoingEmpty")}else f("_handleAck :: Server sent an ack in error. Ignoring.")},k.prototype._handlePubrel=function(e,t){f("handling pubrel packet"),t=void 0!==t?t:w;var n=e.messageId,r=this,i={cmd:"pubcomp",messageId:n};r.incomingStore.get(e,(function(e,n){e?r._sendPacket(i,t):(r.emit("message",n.topic,n.payload,n),r.handleMessage(n,(function(e){if(e)return t(e);r.incomingStore.del(n,w),r._sendPacket(i,t)})))}))},k.prototype._handleDisconnect=function(e){this.emit("disconnect",e)},k.prototype._nextId=function(){var e=this.nextId++;return 65536===this.nextId&&(this.nextId=1),e},k.prototype.getLastMessageId=function(){return 1===this.nextId?65535:this.nextId-1},k.prototype._resubscribe=function(e){f("_resubscribe");var t=Object.keys(this._resubscribeTopics);if(!this._firstConnection&&(this.options.clean||5===this.options.protocolVersion&&!e.sessionPresent)&&t.length>0)if(this.options.resubscribe)if(5===this.options.protocolVersion){f("_resubscribe: protocolVersion 5");for(var n=0;n<t.length;n++){var r={};r[t[n]]=this._resubscribeTopics[t[n]],r.resubscribe=!0,this.subscribe(r,{properties:r[t[n]].properties})}}else this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics);else this._resubscribeTopics={};this._firstConnection=!1},k.prototype._onConnect=function(e){if(this.disconnected)this.emit("connect",e);else{var t=this;this._setupPingTimer(),this._resubscribe(e),this.connected=!0,function n(){var r=t.outgoingStore.createStream();function i(){t._storeProcessing=!1,t._packetIdsDuringStoreProcessing={}}function o(){r.destroy(),r=null,i()}t.once("close",o),r.on("error",(function(e){i(),t.removeListener("close",o),t.emit("error",e)})),r.on("end",(function(){var r=!0;for(var s in t._packetIdsDuringStoreProcessing)if(!t._packetIdsDuringStoreProcessing[s]){r=!1;break}r?(i(),t.removeListener("close",o),t.emit("connect",e)):n()})),function e(){if(r){t._storeProcessing=!0;var n,i=r.read(1);i?t._packetIdsDuringStoreProcessing[i.messageId]?e():t.disconnecting||t.reconnectTimer?r.destroy&&r.destroy():(n=t.outgoing[i.messageId]?t.outgoing[i.messageId].cb:null,t.outgoing[i.messageId]={volatile:!1,cb:function(t,r){n&&n(t,r),e()}},t._packetIdsDuringStoreProcessing[i.messageId]=!0,t._sendPacket(i)):r.once("readable",e)}}()}()}},e.exports=k}).call(this,n(6),n(9))},function(e,t,n){"use strict";t.byteLength=function(e){var t=c(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,r=c(e),s=r[0],a=r[1],u=new o(function(e,t,n){return 3*(t+n)/4-n}(0,s,a)),l=0,h=a>0?s-4:s;for(n=0;n<h;n+=4)t=i[e.charCodeAt(n)]<<18|i[e.charCodeAt(n+1)]<<12|i[e.charCodeAt(n+2)]<<6|i[e.charCodeAt(n+3)],u[l++]=t>>16&255,u[l++]=t>>8&255,u[l++]=255&t;2===a&&(t=i[e.charCodeAt(n)]<<2|i[e.charCodeAt(n+1)]>>4,u[l++]=255&t);1===a&&(t=i[e.charCodeAt(n)]<<10|i[e.charCodeAt(n+1)]<<4|i[e.charCodeAt(n+2)]>>2,u[l++]=t>>8&255,u[l++]=255&t);return u},t.fromByteArray=function(e){for(var t,n=e.length,i=n%3,o=[],s=0,a=n-i;s<a;s+=16383)o.push(l(e,s,s+16383>a?a:s+16383));1===i?(t=e[n-1],o.push(r[t>>2]+r[t<<4&63]+"==")):2===i&&(t=(e[n-2]<<8)+e[n-1],o.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"="));return o.join("")};for(var r=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)r[a]=s[a],i[s.charCodeAt(a)]=a;function c(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 l(e,t,n){for(var i,o,s=[],a=t;a<n;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(r[(o=i)>>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return s.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,n,r,i){var o,s,a=8*i-r-1,u=(1<<a)-1,c=u>>1,l=-7,h=n?i-1:0,f=n?-1:1,d=e[t+h];for(h+=f,o=d&(1<<-l)-1,d>>=-l,l+=a;l>0;o=256*o+e[t+h],h+=f,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=r;l>0;s=256*s+e[t+h],h+=f,l-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,r),o-=c}return(d?-1:1)*s*Math.pow(2,o-r)},t.write=function(e,t,n,r,i,o){var s,a,u,c=8*o-i-1,l=(1<<c)-1,h=l>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:o-1,p=r?1:-1,m=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=l):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+h>=1?f/u:f*Math.pow(2,1-h))*u>=2&&(s++,u/=2),s+h>=l?(a=0,s=l):s+h>=1?(a=(t*u-1)*Math.pow(2,i),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;e[n+d]=255&a,d+=p,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[n+d]=255&s,d+=p,s/=256,c-=8);e[n+d-p]|=128*m}},function(e,t){},function(e,t,n){"use strict";function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}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)}}var s=n(7).Buffer,a=n(103).inspect,u=a&&a.custom||"inspect";e.exports=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.head=null,this.tail=null,this.length=0}var t,n,c;return t=e,(n=[{key:"push",value:function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(e){if(0===this.length)return"";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n}},{key:"concat",value:function(e){if(0===this.length)return s.alloc(0);for(var t,n,r,i=s.allocUnsafe(e>>>0),o=this.head,a=0;o;)t=o.data,n=i,r=a,s.prototype.copy.call(t,n,r),a+=o.data.length,o=o.next;return i}},{key:"consume",value:function(e,t){var n;return e<this.head.data.length?(n=this.head.data.slice(0,e),this.head.data=this.head.data.slice(e)):n=e===this.head.data.length?this.shift():t?this._getString(e):this._getBuffer(e),n}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(e){var t=this.head,n=1,r=t.data;for(e-=r.length;t=t.next;){var i=t.data,o=e>i.length?i.length:e;if(o===i.length?r+=i:r+=i.slice(0,e),0==(e-=o)){o===i.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(o));break}++n}return this.length-=n,r}},{key:"_getBuffer",value:function(e){var t=s.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,o=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,o),0==(e-=o)){o===i.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=i.slice(o));break}++r}return this.length-=r,t}},{key:u,value:function(e,t){return a(this,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},t,{depth:0,customInspect:!1}))}}])&&o(t.prototype,n),c&&o(t,c),e}()},function(e,t){},function(e,t,n){
|
|
12
|
+
var r=n(88),i=n(89),o=n(90);function s(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(s()<t)throw new RangeError("Invalid typed array length");return u.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=u.prototype:(null===e&&(e=new u(t)),e.length=t),e}function u(e,t,n){if(!(u.TYPED_ARRAY_SUPPORT||this instanceof u))return new u(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 h(this,e)}return c(this,e,t,n)}function c(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);u.TYPED_ARRAY_SUPPORT?(e=t).__proto__=u.prototype:e=f(e,t);return e}(e,t,n,r):"string"==typeof t?function(e,t,n){"string"==typeof n&&""!==n||(n="utf8");if(!u.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|d(t,n),i=(e=a(e,r)).write(t,n);i!==r&&(e=e.slice(0,i));return e}(e,t,n):function(e,t){if(u.isBuffer(t)){var n=0|p(t.length);return 0===(e=a(e,n)).length?e:(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):f(e,t);if("Buffer"===t.type&&o(t.data))return f(e,t.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function l(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 h(e,t){if(l(t),e=a(e,t<0?0:0|p(t)),!u.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)e[n]=0;return e}function f(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(u.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 B(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return H(e).length;default:if(r)return B(e).length;t=(""+t).toLowerCase(),r=!0}}function m(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 C(this,t,n);case"ascii":return x(this,t,n);case"latin1":case"binary":return I(this,t,n);case"base64":return T(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(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,i){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=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof t&&(t=u.from(t,r)),u.isBuffer(t))return 0===t.length?-1:y(e,t,n,r,i);if("number"==typeof t)return t&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):y(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function y(e,t,n,r,i){var o,s=1,a=e.length,u=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,u/=2,n/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var l=-1;for(o=n;o<a;o++)if(c(e,o)===c(t,-1===l?0:o-l)){if(-1===l&&(l=o),o-l+1===u)return l*s}else-1!==l&&(o-=o-l),l=-1}else for(n+u>a&&(n=a-u),o=n;o>=0;o--){for(var h=!0,f=0;f<u;f++)if(c(e,o+f)!==c(t,f)){h=!1;break}if(h)return o}return-1}function b(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r))>i&&(r=i):r=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/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 _(e,t,n,r){return Y(B(t,e.length-n),e,n,r)}function w(e,t,n,r){return Y(function(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function k(e,t,n,r){return w(e,t,n,r)}function S(e,t,n,r){return Y(H(t),e,n,r)}function E(e,t,n,r){return Y(function(e,t){for(var n,r,i,o=[],s=0;s<e.length&&!((t-=2)<0);++s)n=e.charCodeAt(s),r=n>>8,i=n%256,o.push(i),o.push(r);return o}(t,e.length-n),e,n,r)}function T(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function C(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i<n;){var o,s,a,u,c=e[i],l=null,h=c>239?4:c>223?3:c>191?2:1;if(i+h<=n)switch(h){case 1:c<128&&(l=c);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&c)<<6|63&o)>127&&(l=u);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(u=(15&c)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,h=1):l>65535&&(l-=65536,r.push(l>>>10&1023|55296),l=56320|1023&l),r.push(l),i+=h}return function(e){var t=e.length;if(t<=A)return String.fromCharCode.apply(String,e);var n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=A));return n}(r)}t.Buffer=u,t.SlowBuffer=function(e){+e!=e&&(e=0);return u.alloc(+e)},t.INSPECT_MAX_BYTES=50,u.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(),u.poolSize=8192,u._augment=function(e){return e.__proto__=u.prototype,e},u.from=function(e,t,n){return c(null,e,t,n)},u.TYPED_ARRAY_SUPPORT&&(u.prototype.__proto__=Uint8Array.prototype,u.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&u[Symbol.species]===u&&Object.defineProperty(u,Symbol.species,{value:null,configurable:!0})),u.alloc=function(e,t,n){return function(e,t,n,r){return l(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)},u.allocUnsafe=function(e){return h(null,e)},u.allocUnsafeSlow=function(e){return h(null,e)},u.isBuffer=function(e){return!(null==e||!e._isBuffer)},u.compare=function(e,t){if(!u.isBuffer(e)||!u.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,i=0,o=Math.min(n,r);i<o;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:r<n?1:0},u.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}},u.concat=function(e,t){if(!o(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return u.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=u.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){var s=e[n];if(!u.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(r,i),i+=s.length}return r},u.byteLength=d,u.prototype._isBuffer=!0,u.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},u.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},u.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},u.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?C(this,0,e):m.apply(this,arguments)},u.prototype.equals=function(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===u.compare(this,e)},u.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+">"},u.prototype.compare=function(e,t,n,r,i){if(!u.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===i&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(r>>>=0),s=(n>>>=0)-(t>>>=0),a=Math.min(o,s),c=this.slice(r,i),l=e.slice(t,n),h=0;h<a;++h)if(c[h]!==l[h]){o=c[h],s=l[h];break}return o<s?-1:s<o?1:0},u.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},u.prototype.indexOf=function(e,t,n){return v(this,e,t,n,!0)},u.prototype.lastIndexOf=function(e,t,n){return v(this,e,t,n,!1)},u.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 i=this.length-t;if((void 0===n||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return b(this,e,t,n);case"utf8":case"utf-8":return _(this,e,t,n);case"ascii":return w(this,e,t,n);case"latin1":case"binary":return k(this,e,t,n);case"base64":return S(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return E(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var A=4096;function x(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(127&e[i]);return r}function I(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(e[i]);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 i="",o=t;o<n;++o)i+=N(e[o]);return i}function P(e,t,n){for(var r=e.slice(t,n),i="",o=0;o<r.length;o+=2)i+=String.fromCharCode(r[o]+256*r[o+1]);return i}function O(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 M(e,t,n,r,i,o){if(!u.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function L(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-n,2);i<o;++i)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function D(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-n,4);i<o;++i)e[n+i]=t>>>8*(r?i:3-i)&255}function U(e,t,n,r,i,o){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function j(e,t,n,r,o){return o||U(e,0,n,4),i.write(e,t,n,r,23,4),n+4}function q(e,t,n,r,o){return o||U(e,0,n,8),i.write(e,t,n,r,52,8),n+8}u.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),u.TYPED_ARRAY_SUPPORT)(n=this.subarray(e,t)).__proto__=u.prototype;else{var i=t-e;n=new u(i,void 0);for(var o=0;o<i;++o)n[o]=this[o+e]}return n},u.prototype.readUIntLE=function(e,t,n){e|=0,t|=0,n||O(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r},u.prototype.readUIntBE=function(e,t,n){e|=0,t|=0,n||O(e,t,this.length);for(var r=this[e+--t],i=1;t>0&&(i*=256);)r+=this[e+--t]*i;return r},u.prototype.readUInt8=function(e,t){return t||O(e,1,this.length),this[e]},u.prototype.readUInt16LE=function(e,t){return t||O(e,2,this.length),this[e]|this[e+1]<<8},u.prototype.readUInt16BE=function(e,t){return t||O(e,2,this.length),this[e]<<8|this[e+1]},u.prototype.readUInt32LE=function(e,t){return t||O(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},u.prototype.readUInt32BE=function(e,t){return t||O(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},u.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||O(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r>=(i*=128)&&(r-=Math.pow(2,8*t)),r},u.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||O(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},u.prototype.readInt8=function(e,t){return t||O(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},u.prototype.readInt16LE=function(e,t){t||O(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt16BE=function(e,t){t||O(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt32LE=function(e,t){return t||O(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},u.prototype.readInt32BE=function(e,t){return t||O(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},u.prototype.readFloatLE=function(e,t){return t||O(e,4,this.length),i.read(this,e,!0,23,4)},u.prototype.readFloatBE=function(e,t){return t||O(e,4,this.length),i.read(this,e,!1,23,4)},u.prototype.readDoubleLE=function(e,t){return t||O(e,8,this.length),i.read(this,e,!0,52,8)},u.prototype.readDoubleBE=function(e,t){return t||O(e,8,this.length),i.read(this,e,!1,52,8)},u.prototype.writeUIntLE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||M(this,e,t,n,Math.pow(2,8*n)-1,0);var i=1,o=0;for(this[t]=255&e;++o<n&&(i*=256);)this[t+o]=e/i&255;return t+n},u.prototype.writeUIntBE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||M(this,e,t,n,Math.pow(2,8*n)-1,0);var i=n-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+n},u.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,1,255,0),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},u.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},u.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},u.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):D(this,e,t,!0),t+4},u.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):D(this,e,t,!1),t+4},u.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);M(this,e,t,n,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o<n&&(s*=256);)e<0&&0===a&&0!==this[t+o-1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n},u.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);M(this,e,t,n,i-1,-i)}var o=n-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n},u.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,1,127,-128),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},u.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},u.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},u.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):D(this,e,t,!0),t+4},u.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||M(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):D(this,e,t,!1),t+4},u.prototype.writeFloatLE=function(e,t,n){return j(this,e,t,!0,n)},u.prototype.writeFloatBE=function(e,t,n){return j(this,e,t,!1,n)},u.prototype.writeDoubleLE=function(e,t,n){return q(this,e,t,!0,n)},u.prototype.writeDoubleBE=function(e,t,n){return q(this,e,t,!1,n)},u.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 i,o=r-n;if(this===e&&n<t&&t<r)for(i=o-1;i>=0;--i)e[i+t]=this[i+n];else if(o<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)e[i+t]=this[i+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+o),t);return o},u.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 i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!u.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 o;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(o=t;o<n;++o)this[o]=e;else{var s=u.isBuffer(e)?e:B(new u(e,r).toString()),a=s.length;for(o=0;o<n-t;++o)this[o+t]=s[o%a]}return this};var F=/[^+\/0-9A-Za-z-_]/g;function N(e){return e<16?"0"+e.toString(16):e.toString(16)}function B(e,t){var n;t=t||1/0;for(var r=e.length,i=null,o=[],s=0;s<r;++s){if((n=e.charCodeAt(s))>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;o.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;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function H(e){return r.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(F,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Y(e,t,n,r){for(var i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}}).call(this,n(10))},function(e,t){var n,r,i=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(e){n=o}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var u,c=[],l=!1,h=-1;function f(){l&&u&&(l=!1,u.length?c=u.concat(c):h=-1,c.length&&p())}function p(){if(!l){var e=a(f);l=!0;for(var t=c.length;t;){for(u=c,c=[];++h<t;)u&&u[h].run();h=-1,t=c.length}u=null,l=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function d(e,t){this.fun=e,this.array=t}function m(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new d(e,t)),1!==c.length||l||a(p)},d.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=m,i.addListener=m,i.once=m,i.off=m,i.removeListener=m,i.removeAllListeners=m,i.emit=m,i.prependListener=m,i.prependOnceListener=m,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}},function(e,t,n){(t=e.exports=n(34)).Stream=t,t.Readable=t,t.Writable=n(38),t.Duplex=n(15),t.Transform=n(40),t.PassThrough=n(98),t.finished=n(21),t.pipeline=n(99)},function(e,t,n){(function(r){t.log=function(...e){return"object"==typeof console&&console.log&&console.log(...e)},t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,i=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(i=r))}),t.splice(i,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.exports=n(105)(t);const{formatters:i}=e.exports;i.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}).call(this,n(9))},function(e,t,n){"use strict";var r={};function i(e,t,n){n||(n=Error);var i=function(e){var n,r;function i(n,r,i){return e.call(this,function(e,n,r){return"string"==typeof t?t:t(e,n,r)}(n,r,i))||this}return r=e,(n=i).prototype=Object.create(r.prototype),n.prototype.constructor=n,n.__proto__=r,i}(n);i.prototype.name=n.name,i.prototype.code=e,r[e]=i}function o(e,t){if(Array.isArray(e)){var n=e.length;return e=e.map((function(e){return String(e)})),n>2?"one of ".concat(t," ").concat(e.slice(0,n-1).join(", "),", or ")+e[n-1]:2===n?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}return"of ".concat(t," ").concat(String(e))}i("ERR_INVALID_OPT_VALUE",(function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),i("ERR_INVALID_ARG_TYPE",(function(e,t,n){var r,i,s,a;if("string"==typeof t&&(i="not ",t.substr(!s||s<0?0:+s,i.length)===i)?(r="must not be",t=t.replace(/^not /,"")):r="must be",function(e,t,n){return(void 0===n||n>e.length)&&(n=e.length),e.substring(n-t.length,n)===t}(e," argument"))a="The ".concat(e," ").concat(r," ").concat(o(t,"type"));else{var u=function(e,t,n){return"number"!=typeof n&&(n=0),!(n+t.length>e.length)&&-1!==e.indexOf(t,n)}(e,".")?"property":"argument";a='The "'.concat(e,'" ').concat(u," ").concat(r," ").concat(o(t,"type"))}return a+=". Received type ".concat(typeof n)}),TypeError),i("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),i("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return"The "+e+" method is not implemented"})),i("ERR_STREAM_PREMATURE_CLOSE","Premature close"),i("ERR_STREAM_DESTROYED",(function(e){return"Cannot call "+e+" after a stream was destroyed"})),i("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),i("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),i("ERR_STREAM_WRITE_AFTER_END","write after end"),i("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),i("ERR_UNKNOWN_ENCODING",(function(e){return"Unknown encoding: "+e}),TypeError),i("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),e.exports.codes=r},function(e,t,n){"use strict";(function(t){var r=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};e.exports=c;var i=n(34),o=n(38);n(11)(c,i);for(var s=r(o.prototype),a=0;a<s.length;a++){var u=s[a];c.prototype[u]||(c.prototype[u]=o.prototype[u])}function c(e){if(!(this instanceof c))return new c(e);i.call(this,e),o.call(this,e),this.allowHalfOpen=!0,e&&(!1===e.readable&&(this.readable=!1),!1===e.writable&&(this.writable=!1),!1===e.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",l)))}function l(){this._writableState.ended||t.nextTick(h,this)}function h(e){e.end()}Object.defineProperty(c.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(c.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(c.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(c.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed&&this._writableState.destroyed)},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}})}).call(this,n(9))},function(e,t,n){"use strict";var r,i="object"==typeof Reflect?Reflect:null,o=i&&"function"==typeof i.apply?i.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};r=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var s=Number.isNaN||function(e){return e!=e};function a(){a.init.call(this)}e.exports=a,a.EventEmitter=a,a.prototype._events=void 0,a.prototype._eventsCount=0,a.prototype._maxListeners=void 0;var u=10;function c(e){return void 0===e._maxListeners?a.defaultMaxListeners:e._maxListeners}function l(e,t,n,r){var i,o,s,a;if("function"!=typeof n)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n);if(void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),s=o[t]),void 0===s)s=o[t]=n,++e._eventsCount;else if("function"==typeof s?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(i=c(e))>0&&s.length>i&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,a=u,console&&console.warn&&console.warn(a)}return e}function h(){for(var e=[],t=0;t<arguments.length;t++)e.push(arguments[t]);this.fired||(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,o(this.listener,this.target,e))}function f(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=h.bind(r);return i.listener=n,r.wrapFn=i,i}function p(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):m(i,i.length)}function d(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function m(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return u},set:function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");u=e}}),a.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},a.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},a.prototype.getMaxListeners=function(){return c(this)},a.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r="error"===e,i=this._events;if(void 0!==i)r=r&&void 0===i.error;else if(!r)return!1;if(r){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var u=i[e];if(void 0===u)return!1;if("function"==typeof u)o(u,this,t);else{var c=u.length,l=m(u,c);for(n=0;n<c;++n)o(l[n],this,t)}return!0},a.prototype.addListener=function(e,t){return l(this,e,t,!1)},a.prototype.on=a.prototype.addListener,a.prototype.prependListener=function(e,t){return l(this,e,t,!0)},a.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);return this.on(e,f(this,e,t)),this},a.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);return this.prependListener(e,f(this,e,t)),this},a.prototype.removeListener=function(e,t){var n,r,i,o,s;if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);if(void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===t||n[o].listener===t){s=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},a.prototype.off=a.prototype.removeListener,a.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,o=Object.keys(n);for(r=0;r<o.length;++r)"removeListener"!==(i=o[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},a.prototype.listeners=function(e){return p(this,e,!0)},a.prototype.rawListeners=function(e){return p(this,e,!1)},a.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},a.prototype.listenerCount=d,a.prototype.eventNames=function(){return this._eventsCount>0?r(this._events):[]}},function(e,t,n){var r=n(56),i=n(57),o=n(28),s=n(58);e.exports=function(e){return r(e)||i(e)||o(e)||s()}},function(e,t,n){var r=n(65),i=n(70),o=n(31),s=n(7),a=n(73),u=n(32);var c={M:function(e){return e.getMonth()+1},MM:function(e){return f(e.getMonth()+1,2)},Q:function(e){return Math.ceil((e.getMonth()+1)/3)},D:function(e){return e.getDate()},DD:function(e){return f(e.getDate(),2)},DDD:function(e){return r(e)},DDDD:function(e){return f(r(e),3)},d:function(e){return e.getDay()},E:function(e){return e.getDay()||7},W:function(e){return i(e)},WW:function(e){return f(i(e),2)},YY:function(e){return f(e.getFullYear(),4).substr(2)},YYYY:function(e){return f(e.getFullYear(),4)},GG:function(e){return String(o(e)).substr(2)},GGGG:function(e){return o(e)},H:function(e){return e.getHours()},HH:function(e){return f(e.getHours(),2)},h:function(e){var t=e.getHours();return 0===t?12:t>12?t%12:t},hh:function(e){return f(c.h(e),2)},m:function(e){return e.getMinutes()},mm:function(e){return f(e.getMinutes(),2)},s:function(e){return e.getSeconds()},ss:function(e){return f(e.getSeconds(),2)},S:function(e){return Math.floor(e.getMilliseconds()/100)},SS:function(e){return f(Math.floor(e.getMilliseconds()/10),2)},SSS:function(e){return f(e.getMilliseconds(),3)},Z:function(e){return h(e.getTimezoneOffset(),":")},ZZ:function(e){return h(e.getTimezoneOffset())},X:function(e){return Math.floor(e.getTime()/1e3)},x:function(e){return e.getTime()}};function l(e){return e.match(/\[[\s\S]/)?e.replace(/^\[|]$/g,""):e.replace(/\\/g,"")}function h(e,t){t=t||"";var n=e>0?"-":"+",r=Math.abs(e),i=r%60;return n+f(Math.floor(r/60),2)+t+f(i,2)}function f(e,t){for(var n=Math.abs(e).toString();n.length<t;)n="0"+n;return n}e.exports=function(e,t,n){var r=t?String(t):"YYYY-MM-DDTHH:mm:ss.SSSZ",i=(n||{}).locale,o=u.format.formatters,h=u.format.formattingTokensRegExp;i&&i.format&&i.format.formatters&&(o=i.format.formatters,i.format.formattingTokensRegExp&&(h=i.format.formattingTokensRegExp));var f=s(e);return a(f)?function(e,t,n){var r,i,o=e.match(n),s=o.length;for(r=0;r<s;r++)i=t[o[r]]||c[o[r]],o[r]=i||l(o[r]);return function(e){for(var t="",n=0;n<s;n++)o[n]instanceof Function?t+=o[n](e,c):t+=o[n];return t}}(r,o,h)(f):"Invalid Date"}},function(e,t,n){var r=n(71);e.exports=function(e){return r(e,{weekStartsOn:1})}},function(e,t){e.exports=function(){for(var e={},t=0;t<arguments.length;t++){var r=arguments[t];for(var i in r)n.call(r,i)&&(e[i]=r[i])}return e};var n=Object.prototype.hasOwnProperty},function(e,t,n){"use strict";var r=n(14).codes.ERR_STREAM_PREMATURE_CLOSE;function i(){}e.exports=function e(t,n,o){if("function"==typeof n)return e(t,null,n);n||(n={}),o=function(e){var t=!1;return function(){if(!t){t=!0;for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];e.apply(this,r)}}}(o||i);var s=n.readable||!1!==n.readable&&t.readable,a=n.writable||!1!==n.writable&&t.writable,u=function(){t.writable||l()},c=t._writableState&&t._writableState.finished,l=function(){a=!1,c=!0,s||o.call(t)},h=t._readableState&&t._readableState.endEmitted,f=function(){s=!1,h=!0,a||o.call(t)},p=function(e){o.call(t,e)},d=function(){var e;return s&&!h?(t._readableState&&t._readableState.ended||(e=new r),o.call(t,e)):a&&!c?(t._writableState&&t._writableState.ended||(e=new r),o.call(t,e)):void 0},m=function(){t.req.on("finish",l)};return!function(e){return e.setHeader&&"function"==typeof e.abort}(t)?a&&!t._writableState&&(t.on("end",u),t.on("close",u)):(t.on("complete",l),t.on("abort",d),t.req?m():t.on("request",m)),t.on("end",f),t.on("finish",l),!1!==n.error&&t.on("error",p),t.on("close",d),function(){t.removeListener("complete",l),t.removeListener("abort",d),t.removeListener("request",m),t.req&&t.req.removeListener("finish",l),t.removeListener("end",u),t.removeListener("close",u),t.removeListener("finish",l),t.removeListener("end",f),t.removeListener("error",p),t.removeListener("close",d)}}},function(e,t,n){"use strict";var r=n(120),i=n(13)("mqttjs:tls");e.exports=function(e,t){var n;function o(r){t.rejectUnauthorized&&e.emit("error",r),n.end()}return t.port=t.port||8883,t.host=t.hostname||t.host||"localhost",t.servername=t.host,t.rejectUnauthorized=!1!==t.rejectUnauthorized,delete t.path,i("port %d host %s rejectUnauthorized %b",t.port,t.host,t.rejectUnauthorized),(n=r.connect(t)).on("secureConnect",(function(){t.rejectUnauthorized&&!n.authorized?n.emit("error",new Error("TLS not authorized")):n.removeListener("error",o)})),n.on("error",o),n}},function(e,t,n){(function(t,r){var i=n(12),o=n(121),s=n(11),a=n(124),u=t.from&&t.from!==Uint8Array.from?t.from([0]):new t([0]),c=function(e,t){e._corked?e.once("uncork",t):t()},l=function(e,t){return function(n){n?function(e,t){e._autoDestroy&&e.destroy(t)}(e,"premature close"===n.message?null:n):t&&!e._ended&&e.end()}},h=function(){},f=function(e,t,n){if(!(this instanceof f))return new f(e,t,n);i.Duplex.call(this,n),this._writable=null,this._readable=null,this._readable2=null,this._autoDestroy=!n||!1!==n.autoDestroy,this._forwardDestroy=!n||!1!==n.destroy,this._forwardEnd=!n||!1!==n.end,this._corked=1,this._ondrain=null,this._drained=!1,this._forwarding=!1,this._unwrite=null,this._unread=null,this._ended=!1,this.destroyed=!1,e&&this.setWritable(e),t&&this.setReadable(t)};s(f,i.Duplex),f.obj=function(e,t,n){return n||(n={}),n.objectMode=!0,n.highWaterMark=16,new f(e,t,n)},f.prototype.cork=function(){1==++this._corked&&this.emit("cork")},f.prototype.uncork=function(){this._corked&&0==--this._corked&&this.emit("uncork")},f.prototype.setWritable=function(e){if(this._unwrite&&this._unwrite(),this.destroyed)e&&e.destroy&&e.destroy();else if(null!==e&&!1!==e){var t=this,n=o(e,{writable:!0,readable:!1},l(this,this._forwardEnd)),i=function(){var e=t._ondrain;t._ondrain=null,e&&e()};this._unwrite&&r.nextTick(i),this._writable=e,this._writable.on("drain",i),this._unwrite=function(){t._writable.removeListener("drain",i),n()},this.uncork()}else this.end()},f.prototype.setReadable=function(e){if(this._unread&&this._unread(),this.destroyed)e&&e.destroy&&e.destroy();else{if(null===e||!1===e)return this.push(null),void this.resume();var t,n=this,r=o(e,{writable:!1,readable:!0},l(this)),s=function(){n._forward()},a=function(){n.push(null)};this._drained=!0,this._readable=e,this._readable2=e._readableState?e:(t=e,new i.Readable({objectMode:!0,highWaterMark:16}).wrap(t)),this._readable2.on("readable",s),this._readable2.on("end",a),this._unread=function(){n._readable2.removeListener("readable",s),n._readable2.removeListener("end",a),r()},this._forward()}},f.prototype._read=function(){this._drained=!0,this._forward()},f.prototype._forward=function(){if(!this._forwarding&&this._readable2&&this._drained){var e;for(this._forwarding=!0;this._drained&&null!==(e=a(this._readable2));)this.destroyed||(this._drained=this.push(e));this._forwarding=!1}},f.prototype.destroy=function(e,t){if(t||(t=h),this.destroyed)return t(null);this.destroyed=!0;var n=this;r.nextTick((function(){n._destroy(e),t(null)}))},f.prototype._destroy=function(e){if(e){var t=this._ondrain;this._ondrain=null,t?t(e):this.emit("error",e)}this._forwardDestroy&&(this._readable&&this._readable.destroy&&this._readable.destroy(),this._writable&&this._writable.destroy&&this._writable.destroy()),this.emit("close")},f.prototype._write=function(e,t,n){if(!this.destroyed)return this._corked?c(this,this._write.bind(this,e,t,n)):e===u?this._finish(n):this._writable?void(!1===this._writable.write(e)?this._ondrain=n:this.destroyed||n()):n()},f.prototype._finish=function(e){var t=this;this.emit("preend"),c(this,(function(){var n,r;n=t._forwardEnd&&t._writable,r=function(){!1===t._writableState.prefinished&&(t._writableState.prefinished=!0),t.emit("prefinish"),c(t,e)},n?n._writableState&&n._writableState.finished?r():n._writableState?n.end(r):(n.end(),r()):r()}))},f.prototype.end=function(e,t,n){return"function"==typeof e?this.end(null,null,e):"function"==typeof t?this.end(e,null,t):(this._ended=!0,e&&this.write(e),this._writableState.ending||this._writableState.destroyed||this.write(u),i.Writable.prototype.end.call(this,n))},e.exports=f}).call(this,n(8).Buffer,n(9))},function(e,t){e.exports=function(e){var t;if("undefined"!=typeof Symbol){if(Symbol.asyncIterator&&null!=(t=e[Symbol.asyncIterator]))return t.call(e);if(Symbol.iterator&&null!=(t=e[Symbol.iterator]))return t.call(e)}throw new TypeError("Object is not async iterable")}},function(e,t,n){var r=n(47);e.exports=function(e){return new r(e)}},function(e,t,n){var r=n(126);e.exports=function(e){return function(){return new r(e.apply(this,arguments))}}},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}},function(e,t,n){var r=n(27);e.exports=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}},function(e,t,n){"use strict";e.exports=function(e){return null!==e&&"object"==typeof e}},function(e,t){e.exports=function(e){return e instanceof Date}},function(e,t,n){var r=n(7),i=n(19);e.exports=function(e){var t=r(e),n=t.getFullYear(),o=new Date(0);o.setFullYear(n+1,0,4),o.setHours(0,0,0,0);var s=i(o),a=new Date(0);a.setFullYear(n,0,4),a.setHours(0,0,0,0);var u=i(a);return t.getTime()>=s.getTime()?n+1:t.getTime()>=u.getTime()?n:n-1}},function(e,t,n){var r=n(74),i=n(75);e.exports={distanceInWords:r(),format:i()}},function(e,t,n){"use strict";var r=n(20),i=n(12).Readable,o={objectMode:!0},s={clean:!0};function a(e){if(!(this instanceof a))return new a(e);this.options=e||{},this.options=r(s,e),this._inflights=new Map}a.prototype.put=function(e,t){return this._inflights.set(e.messageId,e),t&&t(),this},a.prototype.createStream=function(){var e=new i(o),t=!1,n=[],r=0;return this._inflights.forEach((function(e,t){n.push(e)})),e._read=function(){!t&&r<n.length?this.push(n[r++]):this.push(null)},e.destroy=function(){if(!t){var e=this;t=!0,setTimeout((function(){e.emit("close")}),0)}},e},a.prototype.del=function(e,t){return(e=this._inflights.get(e.messageId))?(this._inflights.delete(e.messageId),t(null,e)):t&&t(new Error("missing packet")),this},a.prototype.get=function(e,t){return(e=this._inflights.get(e.messageId))?t(null,e):t&&t(new Error("missing packet")),this},a.prototype.close=function(e){this.options.clean&&(this._inflights=null),e&&e()},e.exports=a},function(e,t,n){"use strict";(function(t,r){var i;e.exports=T,T.ReadableState=E;n(16).EventEmitter;var o=function(e,t){return e.listeners(t).length},s=n(35),a=n(8).Buffer,u=t.Uint8Array||function(){};var c,l=n(91);c=l&&l.debuglog?l.debuglog("stream"):function(){};var h,f,p,d=n(92),m=n(36),g=n(37).getHighWaterMark,v=n(14).codes,y=v.ERR_INVALID_ARG_TYPE,b=v.ERR_STREAM_PUSH_AFTER_EOF,_=v.ERR_METHOD_NOT_IMPLEMENTED,w=v.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;n(11)(T,s);var k=m.errorOrDestroy,S=["error","close","destroy","pause","resume"];function E(e,t,r){i=i||n(15),e=e||{},"boolean"!=typeof r&&(r=t instanceof i),this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.readableObjectMode),this.highWaterMark=g(this,e,"readableHighWaterMark",r),this.buffer=new d,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(h||(h=n(39).StringDecoder),this.decoder=new h(e.encoding),this.encoding=e.encoding)}function T(e){if(i=i||n(15),!(this instanceof T))return new T(e);var t=this instanceof i;this._readableState=new E(e,this,t),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),s.call(this)}function C(e,t,n,r,i){c("readableAddChunk",t);var o,s=e._readableState;if(null===t)s.reading=!1,function(e,t){if(c("onEofChunk"),t.ended)return;if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,t.sync?R(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,P(e)))}(e,s);else if(i||(o=function(e,t){var n;r=t,a.isBuffer(r)||r instanceof u||"string"==typeof t||void 0===t||e.objectMode||(n=new y("chunk",["string","Buffer","Uint8Array"],t));var r;return n}(s,t)),o)k(e,o);else if(s.objectMode||t&&t.length>0)if("string"==typeof t||s.objectMode||Object.getPrototypeOf(t)===a.prototype||(t=function(e){return a.from(e)}(t)),r)s.endEmitted?k(e,new w):A(e,s,t,!0);else if(s.ended)k(e,new b);else{if(s.destroyed)return!1;s.reading=!1,s.decoder&&!n?(t=s.decoder.write(t),s.objectMode||0!==t.length?A(e,s,t,!1):O(e,s)):A(e,s,t,!1)}else r||(s.reading=!1,O(e,s));return!s.ended&&(s.length<s.highWaterMark||0===s.length)}function A(e,t,n,r){t.flowing&&0===t.length&&!t.sync?(t.awaitDrain=0,e.emit("data",n)):(t.length+=t.objectMode?1:n.length,r?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&R(e)),O(e,t)}Object.defineProperty(T.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),T.prototype.destroy=m.destroy,T.prototype._undestroy=m.undestroy,T.prototype._destroy=function(e,t){t(e)},T.prototype.push=function(e,t){var n,r=this._readableState;return r.objectMode?n=!0:"string"==typeof e&&((t=t||r.defaultEncoding)!==r.encoding&&(e=a.from(e,t),t=""),n=!0),C(this,e,t,!1,n)},T.prototype.unshift=function(e){return C(this,e,null,!0,!1)},T.prototype.isPaused=function(){return!1===this._readableState.flowing},T.prototype.setEncoding=function(e){h||(h=n(39).StringDecoder);var t=new h(e);this._readableState.decoder=t,this._readableState.encoding=this._readableState.decoder.encoding;for(var r=this._readableState.buffer.head,i="";null!==r;)i+=t.write(r.data),r=r.next;return this._readableState.buffer.clear(),""!==i&&this._readableState.buffer.push(i),this._readableState.length=i.length,this};var x=1073741824;function I(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!=e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=function(e){return e>=x?e=x:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function R(e){var t=e._readableState;c("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(c("emitReadable",t.flowing),t.emittedReadable=!0,r.nextTick(P,e))}function P(e){var t=e._readableState;c("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,j(e)}function O(e,t){t.readingMore||(t.readingMore=!0,r.nextTick(M,e,t))}function M(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&0===t.length);){var n=t.length;if(c("maybeReadMore read 0"),e.read(0),n===t.length)break}t.readingMore=!1}function L(e){var t=e._readableState;t.readableListening=e.listenerCount("readable")>0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume()}function D(e){c("readable nexttick read 0"),e.read(0)}function U(e,t){c("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),j(e),t.flowing&&!t.reading&&e.read(0)}function j(e){var t=e._readableState;for(c("flow",t.flowing);t.flowing&&null!==e.read(););}function q(e,t){return 0===t.length?null:(t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n);var n}function F(e){var t=e._readableState;c("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,r.nextTick(N,t,e))}function N(e,t){if(c("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy()}}function B(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}T.prototype.read=function(e){c("read",e),e=parseInt(e,10);var t=this._readableState,n=e;if(0!==e&&(t.emittedReadable=!1),0===e&&t.needReadable&&((0!==t.highWaterMark?t.length>=t.highWaterMark:t.length>0)||t.ended))return c("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?F(this):R(this),null;if(0===(e=I(e,t))&&t.ended)return 0===t.length&&F(this),null;var r,i=t.needReadable;return c("need readable",i),(0===t.length||t.length-e<t.highWaterMark)&&c("length less than watermark",i=!0),t.ended||t.reading?c("reading or ended",i=!1):i&&(c("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=I(n,t))),null===(r=e>0?q(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&F(this)),null!==r&&this.emit("data",r),r},T.prototype._read=function(e){k(this,new _("_read()"))},T.prototype.pipe=function(e,t){var n=this,i=this._readableState;switch(i.pipesCount){case 0:i.pipes=e;break;case 1:i.pipes=[i.pipes,e];break;default:i.pipes.push(e)}i.pipesCount+=1,c("pipe count=%d opts=%j",i.pipesCount,t);var s=(!t||!1!==t.end)&&e!==r.stdout&&e!==r.stderr?u:g;function a(t,r){c("onunpipe"),t===n&&r&&!1===r.hasUnpiped&&(r.hasUnpiped=!0,c("cleanup"),e.removeListener("close",d),e.removeListener("finish",m),e.removeListener("drain",l),e.removeListener("error",p),e.removeListener("unpipe",a),n.removeListener("end",u),n.removeListener("end",g),n.removeListener("data",f),h=!0,!i.awaitDrain||e._writableState&&!e._writableState.needDrain||l())}function u(){c("onend"),e.end()}i.endEmitted?r.nextTick(s):n.once("end",s),e.on("unpipe",a);var l=function(e){return function(){var t=e._readableState;c("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&o(e,"data")&&(t.flowing=!0,j(e))}}(n);e.on("drain",l);var h=!1;function f(t){c("ondata");var r=e.write(t);c("dest.write",r),!1===r&&((1===i.pipesCount&&i.pipes===e||i.pipesCount>1&&-1!==B(i.pipes,e))&&!h&&(c("false write response, pause",i.awaitDrain),i.awaitDrain++),n.pause())}function p(t){c("onerror",t),g(),e.removeListener("error",p),0===o(e,"error")&&k(e,t)}function d(){e.removeListener("finish",m),g()}function m(){c("onfinish"),e.removeListener("close",d),g()}function g(){c("unpipe"),n.unpipe(e)}return n.on("data",f),function(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n)}(e,"error",p),e.once("close",d),e.once("finish",m),e.emit("pipe",n),i.flowing||(c("pipe resume"),n.resume()),e},T.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n),this);if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o<i;o++)r[o].emit("unpipe",this,{hasUnpiped:!1});return this}var s=B(t.pipes,e);return-1===s?this:(t.pipes.splice(s,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,n),this)},T.prototype.on=function(e,t){var n=s.prototype.on.call(this,e,t),i=this._readableState;return"data"===e?(i.readableListening=this.listenerCount("readable")>0,!1!==i.flowing&&this.resume()):"readable"===e&&(i.endEmitted||i.readableListening||(i.readableListening=i.needReadable=!0,i.flowing=!1,i.emittedReadable=!1,c("on readable",i.length,i.reading),i.length?R(this):i.reading||r.nextTick(D,this))),n},T.prototype.addListener=T.prototype.on,T.prototype.removeListener=function(e,t){var n=s.prototype.removeListener.call(this,e,t);return"readable"===e&&r.nextTick(L,this),n},T.prototype.removeAllListeners=function(e){var t=s.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||r.nextTick(L,this),t},T.prototype.resume=function(){var e=this._readableState;return e.flowing||(c("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,r.nextTick(U,e,t))}(this,e)),e.paused=!1,this},T.prototype.pause=function(){return c("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(c("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},T.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on("end",(function(){if(c("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e)}t.push(null)})),e.on("data",(function(i){(c("wrapped data"),n.decoder&&(i=n.decoder.write(i)),n.objectMode&&null==i)||(n.objectMode||i&&i.length)&&(t.push(i)||(r=!0,e.pause()))})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var o=0;o<S.length;o++)e.on(S[o],this.emit.bind(this,S[o]));return this._read=function(t){c("wrapped _read",t),r&&(r=!1,e.resume())},this},"function"==typeof Symbol&&(T.prototype[Symbol.asyncIterator]=function(){return void 0===f&&(f=n(96)),f(this)}),Object.defineProperty(T.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(T.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(T.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),T._fromList=q,Object.defineProperty(T.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(T.from=function(e,t){return void 0===p&&(p=n(97)),p(T,e,t)})}).call(this,n(10),n(9))},function(e,t,n){e.exports=n(16).EventEmitter},function(e,t,n){"use strict";(function(t){function n(e,t){i(e,t),r(e)}function r(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function i(e,t){e.emit("error",t)}e.exports={destroy:function(e,o){var s=this,a=this._readableState&&this._readableState.destroyed,u=this._writableState&&this._writableState.destroyed;return a||u?(o?o(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,t.nextTick(i,this,e)):t.nextTick(i,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,(function(e){!o&&e?s._writableState?s._writableState.errorEmitted?t.nextTick(r,s):(s._writableState.errorEmitted=!0,t.nextTick(n,s,e)):t.nextTick(n,s,e):o?(t.nextTick(r,s),o(e)):t.nextTick(r,s)})),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(e,t){var n=e._readableState,r=e._writableState;n&&n.autoDestroy||r&&r.autoDestroy?e.destroy(t):e.emit("error",t)}}}).call(this,n(9))},function(e,t,n){"use strict";var r=n(14).codes.ERR_INVALID_OPT_VALUE;e.exports={getHighWaterMark:function(e,t,n,i){var o=function(e,t,n){return null!=e.highWaterMark?e.highWaterMark:t?e[n]:null}(t,i,n);if(null!=o){if(!isFinite(o)||Math.floor(o)!==o||o<0)throw new r(i?n:"highWaterMark",o);return Math.floor(o)}return e.objectMode?16:16384}}},function(e,t,n){"use strict";(function(t,r){function i(e){var t=this;this.next=null,this.entry=null,this.finish=function(){!function(e,t,n){var r=e.entry;e.entry=null;for(;r;){var i=r.callback;t.pendingcb--,i(n),r=r.next}t.corkedRequestsFree.next=e}(t,e)}}var o;e.exports=T,T.WritableState=E;var s={deprecate:n(94)},a=n(35),u=n(8).Buffer,c=t.Uint8Array||function(){};var l,h=n(36),f=n(37).getHighWaterMark,p=n(14).codes,d=p.ERR_INVALID_ARG_TYPE,m=p.ERR_METHOD_NOT_IMPLEMENTED,g=p.ERR_MULTIPLE_CALLBACK,v=p.ERR_STREAM_CANNOT_PIPE,y=p.ERR_STREAM_DESTROYED,b=p.ERR_STREAM_NULL_VALUES,_=p.ERR_STREAM_WRITE_AFTER_END,w=p.ERR_UNKNOWN_ENCODING,k=h.errorOrDestroy;function S(){}function E(e,t,s){o=o||n(15),e=e||{},"boolean"!=typeof s&&(s=t instanceof o),this.objectMode=!!e.objectMode,s&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=f(this,e,"writableHighWaterMark",s),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var a=!1===e.decodeStrings;this.decodeStrings=!a,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){!function(e,t){var n=e._writableState,i=n.sync,o=n.writecb;if("function"!=typeof o)throw new g;if(function(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}(n),t)!function(e,t,n,i,o){--t.pendingcb,n?(r.nextTick(o,i),r.nextTick(P,e,t),e._writableState.errorEmitted=!0,k(e,i)):(o(i),e._writableState.errorEmitted=!0,k(e,i),P(e,t))}(e,n,i,t,o);else{var s=I(n)||e.destroyed;s||n.corked||n.bufferProcessing||!n.bufferedRequest||x(e,n),i?r.nextTick(A,e,n,s,o):A(e,n,s,o)}}(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new i(this)}function T(e){var t=this instanceof(o=o||n(15));if(!t&&!l.call(T,this))return new T(e);this._writableState=new E(e,this,t),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),a.call(this)}function C(e,t,n,r,i,o,s){t.writelen=r,t.writecb=s,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new y("write")):n?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function A(e,t,n,r){n||function(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}(e,t),t.pendingcb--,r(),P(e,t)}function x(e,t){t.bufferProcessing=!0;var n=t.bufferedRequest;if(e._writev&&n&&n.next){var r=t.bufferedRequestCount,o=new Array(r),s=t.corkedRequestsFree;s.entry=n;for(var a=0,u=!0;n;)o[a]=n,n.isBuf||(u=!1),n=n.next,a+=1;o.allBuffers=u,C(e,t,!0,t.length,o,"",s.finish),t.pendingcb++,t.lastBufferedRequest=null,s.next?(t.corkedRequestsFree=s.next,s.next=null):t.corkedRequestsFree=new i(t),t.bufferedRequestCount=0}else{for(;n;){var c=n.chunk,l=n.encoding,h=n.callback;if(C(e,t,!1,t.objectMode?1:c.length,c,l,h),n=n.next,t.bufferedRequestCount--,t.writing)break}null===n&&(t.lastBufferedRequest=null)}t.bufferedRequest=n,t.bufferProcessing=!1}function I(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function R(e,t){e._final((function(n){t.pendingcb--,n&&k(e,n),t.prefinished=!0,e.emit("prefinish"),P(e,t)}))}function P(e,t){var n=I(t);if(n&&(function(e,t){t.prefinished||t.finalCalled||("function"!=typeof e._final||t.destroyed?(t.prefinished=!0,e.emit("prefinish")):(t.pendingcb++,t.finalCalled=!0,r.nextTick(R,e,t)))}(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"),t.autoDestroy))){var i=e._readableState;(!i||i.autoDestroy&&i.endEmitted)&&e.destroy()}return n}n(11)(T,a),E.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(E.prototype,"buffer",{get:s.deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(l=Function.prototype[Symbol.hasInstance],Object.defineProperty(T,Symbol.hasInstance,{value:function(e){return!!l.call(this,e)||this===T&&(e&&e._writableState instanceof E)}})):l=function(e){return e instanceof this},T.prototype.pipe=function(){k(this,new v)},T.prototype.write=function(e,t,n){var i,o=this._writableState,s=!1,a=!o.objectMode&&(i=e,u.isBuffer(i)||i instanceof c);return a&&!u.isBuffer(e)&&(e=function(e){return u.from(e)}(e)),"function"==typeof t&&(n=t,t=null),a?t="buffer":t||(t=o.defaultEncoding),"function"!=typeof n&&(n=S),o.ending?function(e,t){var n=new _;k(e,n),r.nextTick(t,n)}(this,n):(a||function(e,t,n,i){var o;return null===n?o=new b:"string"==typeof n||t.objectMode||(o=new d("chunk",["string","Buffer"],n)),!o||(k(e,o),r.nextTick(i,o),!1)}(this,o,e,n))&&(o.pendingcb++,s=function(e,t,n,r,i,o){if(!n){var s=function(e,t,n){e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=u.from(t,n));return t}(t,r,i);r!==s&&(n=!0,i="buffer",r=s)}var a=t.objectMode?1:r.length;t.length+=a;var c=t.length<t.highWaterMark;c||(t.needDrain=!0);if(t.writing||t.corked){var l=t.lastBufferedRequest;t.lastBufferedRequest={chunk:r,encoding:i,isBuf:n,callback:o,next:null},l?l.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else C(e,t,!1,a,r,i,o);return c}(this,o,a,e,t,n)),s},T.prototype.cork=function(){this._writableState.corked++},T.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.bufferProcessing||!e.bufferedRequest||x(this,e))},T.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new w(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(T.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(T.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),T.prototype._write=function(e,t,n){n(new m("_write()"))},T.prototype._writev=null,T.prototype.end=function(e,t,n){var i=this._writableState;return"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||function(e,t,n){t.ending=!0,P(e,t),n&&(t.finished?r.nextTick(n):e.once("finish",n));t.ended=!0,e.writable=!1}(this,i,n),this},Object.defineProperty(T.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(T.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),T.prototype.destroy=h.destroy,T.prototype._undestroy=h.undestroy,T.prototype._destroy=function(e,t){t(e)}}).call(this,n(10),n(9))},function(e,t,n){"use strict";var r=n(95).Buffer,i=r.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function o(e){var t;switch(this.encoding=function(e){var t=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof t&&(r.isEncoding===i||!i(e)))throw new Error("Unknown encoding: "+e);return t||e}(e),this.encoding){case"utf16le":this.text=u,this.end=c,t=4;break;case"utf8":this.fillLast=a,t=4;break;case"base64":this.text=l,this.end=h,t=3;break;default:return this.write=f,void(this.end=p)}this.lastNeed=0,this.lastTotal=0,this.lastChar=r.allocUnsafe(t)}function s(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function a(e){var t=this.lastTotal-this.lastNeed,n=function(e,t,n){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}(this,e);return void 0!==n?n:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function u(e,t){if((e.length-t)%2==0){var n=e.toString("utf16le",t);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function c(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,n)}return t}function l(e,t){var n=(e.length-t)%3;return 0===n?e.toString("base64",t):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-n))}function h(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function f(e){return e.toString(this.encoding)}function p(e){return e&&e.length?this.write(e):""}t.StringDecoder=o,o.prototype.write=function(e){if(0===e.length)return"";var t,n;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n<e.length?t?t+this.text(e,n):this.text(e,n):t||""},o.prototype.end=function(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t},o.prototype.text=function(e,t){var n=function(e,t,n){var r=t.length-1;if(r<n)return 0;var i=s(t[r]);if(i>=0)return i>0&&(e.lastNeed=i-1),i;if(--r<n||-2===i)return 0;if((i=s(t[r]))>=0)return i>0&&(e.lastNeed=i-2),i;if(--r<n||-2===i)return 0;if((i=s(t[r]))>=0)return i>0&&(2===i?i=0:e.lastNeed=i-3),i;return 0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=n;var r=e.length-(n-this.lastNeed);return e.copy(this.lastChar,0,r),e.toString("utf8",t,r)},o.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}},function(e,t,n){"use strict";e.exports=l;var r=n(14).codes,i=r.ERR_METHOD_NOT_IMPLEMENTED,o=r.ERR_MULTIPLE_CALLBACK,s=r.ERR_TRANSFORM_ALREADY_TRANSFORMING,a=r.ERR_TRANSFORM_WITH_LENGTH_0,u=n(15);function c(e,t){var n=this._transformState;n.transforming=!1;var r=n.writecb;if(null===r)return this.emit("error",new o);n.writechunk=null,n.writecb=null,null!=t&&this.push(t),r(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function l(e){if(!(this instanceof l))return new l(e);u.call(this,e),this._transformState={afterTransform:c.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.on("prefinish",h)}function h(){var e=this;"function"!=typeof this._flush||this._readableState.destroyed?f(this,null,null):this._flush((function(t,n){f(e,t,n)}))}function f(e,t,n){if(t)return e.emit("error",t);if(null!=n&&e.push(n),e._writableState.length)throw new a;if(e._transformState.transforming)throw new s;return e.push(null)}n(11)(l,u),l.prototype.push=function(e,t){return this._transformState.needTransform=!1,u.prototype.push.call(this,e,t)},l.prototype._transform=function(e,t,n){n(new i("_transform()"))},l.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var i=this._readableState;(r.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},l.prototype._read=function(e){var t=this._transformState;null===t.writechunk||t.transforming?t.needTransform=!0:(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform))},l.prototype._destroy=function(e,t){u.prototype._destroy.call(this,e,(function(e){t(e)}))}},function(e,t,n){(function(t){const n=e.exports;n.types={0:"reserved",1:"connect",2:"connack",3:"publish",4:"puback",5:"pubrec",6:"pubrel",7:"pubcomp",8:"subscribe",9:"suback",10:"unsubscribe",11:"unsuback",12:"pingreq",13:"pingresp",14:"disconnect",15:"auth"},n.codes={};for(const e in n.types){const t=n.types[e];n.codes[t]=e}n.CMD_SHIFT=4,n.CMD_MASK=240,n.DUP_MASK=8,n.QOS_MASK=3,n.QOS_SHIFT=1,n.RETAIN_MASK=1,n.VARBYTEINT_MASK=127,n.VARBYTEINT_FIN_MASK=128,n.VARBYTEINT_MAX=268435455,n.SESSIONPRESENT_MASK=1,n.SESSIONPRESENT_HEADER=t.from([n.SESSIONPRESENT_MASK]),n.CONNACK_HEADER=t.from([n.codes.connack<<n.CMD_SHIFT]),n.USERNAME_MASK=128,n.PASSWORD_MASK=64,n.WILL_RETAIN_MASK=32,n.WILL_QOS_MASK=24,n.WILL_QOS_SHIFT=3,n.WILL_FLAG_MASK=4,n.CLEAN_SESSION_MASK=2,n.CONNECT_HEADER=t.from([n.codes.connect<<n.CMD_SHIFT]),n.properties={sessionExpiryInterval:17,willDelayInterval:24,receiveMaximum:33,maximumPacketSize:39,topicAliasMaximum:34,requestResponseInformation:25,requestProblemInformation:23,userProperties:38,authenticationMethod:21,authenticationData:22,payloadFormatIndicator:1,messageExpiryInterval:2,contentType:3,responseTopic:8,correlationData:9,maximumQoS:36,retainAvailable:37,assignedClientIdentifier:18,reasonString:31,wildcardSubscriptionAvailable:40,subscriptionIdentifiersAvailable:41,sharedSubscriptionAvailable:42,serverKeepAlive:19,responseInformation:26,serverReference:28,topicAlias:35,subscriptionIdentifier:11},n.propertiesCodes={};for(const e in n.properties){const t=n.properties[e];n.propertiesCodes[t]=e}function r(e){return[0,1,2].map(r=>[0,1].map(i=>[0,1].map(o=>{const s=t.alloc(1);return s.writeUInt8(n.codes[e]<<n.CMD_SHIFT|(i?n.DUP_MASK:0)|r<<n.QOS_SHIFT|o,0,!0),s})))}n.propertiesTypes={sessionExpiryInterval:"int32",willDelayInterval:"int32",receiveMaximum:"int16",maximumPacketSize:"int32",topicAliasMaximum:"int16",requestResponseInformation:"byte",requestProblemInformation:"byte",userProperties:"pair",authenticationMethod:"string",authenticationData:"binary",payloadFormatIndicator:"byte",messageExpiryInterval:"int32",contentType:"string",responseTopic:"string",correlationData:"binary",maximumQoS:"int8",retainAvailable:"byte",assignedClientIdentifier:"string",reasonString:"string",wildcardSubscriptionAvailable:"byte",subscriptionIdentifiersAvailable:"byte",sharedSubscriptionAvailable:"byte",serverKeepAlive:"int16",responseInformation:"string",serverReference:"string",topicAlias:"int16",subscriptionIdentifier:"var"},n.PUBLISH_HEADER=r("publish"),n.SUBSCRIBE_HEADER=r("subscribe"),n.SUBSCRIBE_OPTIONS_QOS_MASK=3,n.SUBSCRIBE_OPTIONS_NL_MASK=1,n.SUBSCRIBE_OPTIONS_NL_SHIFT=2,n.SUBSCRIBE_OPTIONS_RAP_MASK=1,n.SUBSCRIBE_OPTIONS_RAP_SHIFT=3,n.SUBSCRIBE_OPTIONS_RH_MASK=3,n.SUBSCRIBE_OPTIONS_RH_SHIFT=4,n.SUBSCRIBE_OPTIONS_RH=[0,16,32],n.SUBSCRIBE_OPTIONS_NL=4,n.SUBSCRIBE_OPTIONS_RAP=8,n.SUBSCRIBE_OPTIONS_QOS=[0,1,2],n.UNSUBSCRIBE_HEADER=r("unsubscribe"),n.ACKS={unsuback:r("unsuback"),puback:r("puback"),pubcomp:r("pubcomp"),pubrel:r("pubrel"),pubrec:r("pubrec")},n.SUBACK_HEADER=t.from([n.codes.suback<<n.CMD_SHIFT]),n.VERSION3=t.from([3]),n.VERSION4=t.from([4]),n.VERSION5=t.from([5]),n.VERSION131=t.from([131]),n.VERSION132=t.from([132]),n.QOS=[0,1,2].map(e=>t.from([e])),n.EMPTY={pingreq:t.from([n.codes.pingreq<<4,0]),pingresp:t.from([n.codes.pingresp<<4,0]),disconnect:t.from([n.codes.disconnect<<4,0])}}).call(this,n(8).Buffer)},function(e,t,n){(function(t){const r=n(41),i=t.allocUnsafe(0),o=t.from([0]),s=n(108),a=n(109).nextTick,u=n(13)("mqtt-packet:writeToStream"),c=s.cache,l=s.generateNumber,h=s.generateCache,f=s.genBufVariableByteInt,p=s.generate4ByteBuffer;let d=k,m=!0;function g(e,n,s){switch(u("generate called"),n.cork&&(n.cork(),a(v,n)),m&&(m=!1,h()),u("generate: packet.cmd: %s",e.cmd),e.cmd){case"connect":return function(e,n,i){const o=e||{},s=o.protocolId||"MQTT";let a=o.protocolVersion||4;const u=o.will;let c=o.clean;const l=o.keepalive||0,h=o.clientId||"",f=o.username,p=o.password,m=o.properties;void 0===c&&(c=!0);let g=0;if(!s||"string"!=typeof s&&!t.isBuffer(s))return n.emit("error",new Error("Invalid protocolId")),!1;g+=s.length+2;if(3!==a&&4!==a&&5!==a)return n.emit("error",new Error("Invalid protocol version")),!1;g+=1;if(("string"==typeof h||t.isBuffer(h))&&(h||a>=4)&&(h||c))g+=t.byteLength(h)+2;else{if(a<4)return n.emit("error",new Error("clientId must be supplied before 3.1.1")),!1;if(1*c==0)return n.emit("error",new Error("clientId must be given if cleanSession set to 0")),!1}if("number"!=typeof l||l<0||l>65535||l%1!=0)return n.emit("error",new Error("Invalid keepalive")),!1;g+=2;if(g+=1,5===a){var v=T(n,m);if(!v)return!1;g+=v.length}if(u){if("object"!=typeof u)return n.emit("error",new Error("Invalid will")),!1;if(!u.topic||"string"!=typeof u.topic)return n.emit("error",new Error("Invalid will topic")),!1;if(g+=t.byteLength(u.topic)+2,g+=2,u.payload){if(!(u.payload.length>=0))return n.emit("error",new Error("Invalid will payload")),!1;"string"==typeof u.payload?g+=t.byteLength(u.payload):g+=u.payload.length}var y={};if(5===a){if(!(y=T(n,u.properties)))return!1;g+=y.length}}let w=!1;if(null!=f){if(!R(f))return n.emit("error",new Error("Invalid username")),!1;w=!0,g+=t.byteLength(f)+2}if(null!=p){if(!w)return n.emit("error",new Error("Username is required to use password")),!1;if(!R(p))return n.emit("error",new Error("Invalid password")),!1;g+=I(p)+2}n.write(r.CONNECT_HEADER),b(n,g),E(n,s),o.bridgeMode&&(a+=128);n.write(131===a?r.VERSION131:132===a?r.VERSION132:4===a?r.VERSION4:5===a?r.VERSION5:r.VERSION3);let k=0;k|=null!=f?r.USERNAME_MASK:0,k|=null!=p?r.PASSWORD_MASK:0,k|=u&&u.retain?r.WILL_RETAIN_MASK:0,k|=u&&u.qos?u.qos<<r.WILL_QOS_SHIFT:0,k|=u?r.WILL_FLAG_MASK:0,k|=c?r.CLEAN_SESSION_MASK:0,n.write(t.from([k])),d(n,l),5===a&&v.write();E(n,h),u&&(5===a&&y.write(),_(n,u.topic),E(n,u.payload));null!=f&&E(n,f);null!=p&&E(n,p);return!0}(e,n);case"connack":return function(e,n,i){const s=i?i.protocolVersion:4,a=e||{},u=5===s?a.reasonCode:a.returnCode,c=a.properties;let l=2;if("number"!=typeof u)return n.emit("error",new Error("Invalid return code")),!1;let h=null;if(5===s){if(!(h=T(n,c)))return!1;l+=h.length}n.write(r.CONNACK_HEADER),b(n,l),n.write(a.sessionPresent?r.SESSIONPRESENT_HEADER:o),n.write(t.from([u])),null!=h&&h.write();return!0}(e,n,s);case"publish":return function(e,n,o){u("publish: packet: %o",e);const s=o?o.protocolVersion:4,a=e||{},c=a.qos||0,l=a.retain?r.RETAIN_MASK:0,h=a.topic,f=a.payload||i,p=a.messageId,m=a.properties;let g=0;if("string"==typeof h)g+=t.byteLength(h)+2;else{if(!t.isBuffer(h))return n.emit("error",new Error("Invalid topic")),!1;g+=h.length+2}t.isBuffer(f)?g+=f.length:g+=t.byteLength(f);if(c&&"number"!=typeof p)return n.emit("error",new Error("Invalid messageId")),!1;c&&(g+=2);let v=null;if(5===s){if(!(v=T(n,m)))return!1;g+=v.length}n.write(r.PUBLISH_HEADER[c][a.dup?1:0][l?1:0]),b(n,g),d(n,I(h)),n.write(h),c>0&&d(n,p);null!=v&&v.write();return u("publish: payload: %o",f),n.write(f)}(e,n,s);case"puback":case"pubrec":case"pubrel":case"pubcomp":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.cmd||"puback",u=s.messageId,c=s.dup&&"pubrel"===a?r.DUP_MASK:0;let l=0;const h=s.reasonCode,f=s.properties;let p=5===o?3:2;"pubrel"===a&&(l=1);if("number"!=typeof u)return n.emit("error",new Error("Invalid messageId")),!1;let m=null;if(5===o&&"object"==typeof f){if(!(m=C(n,f,i,p)))return!1;p+=m.length}n.write(r.ACKS[a][l][c][0]),b(n,p),d(n,u),5===o&&n.write(t.from([h]));null!==m&&m.write();return!0}(e,n,s);case"subscribe":return function(e,n,i){u("subscribe: packet: ");const o=i?i.protocolVersion:4,s=e||{},a=s.dup?r.DUP_MASK:0,c=s.messageId,l=s.subscriptions,h=s.properties;let f=0;if("number"!=typeof c)return n.emit("error",new Error("Invalid messageId")),!1;f+=2;let p=null;if(5===o){if(!(p=T(n,h)))return!1;f+=p.length}if("object"!=typeof l||!l.length)return n.emit("error",new Error("Invalid subscriptions")),!1;for(let e=0;e<l.length;e+=1){const r=l[e].topic,i=l[e].qos;if("string"!=typeof r)return n.emit("error",new Error("Invalid subscriptions - invalid topic")),!1;if("number"!=typeof i)return n.emit("error",new Error("Invalid subscriptions - invalid qos")),!1;if(5===o){if("boolean"!=typeof(l[e].nl||!1))return n.emit("error",new Error("Invalid subscriptions - invalid No Local")),!1;if("boolean"!=typeof(l[e].rap||!1))return n.emit("error",new Error("Invalid subscriptions - invalid Retain as Published")),!1;const t=l[e].rh||0;if("number"!=typeof t||t>2)return n.emit("error",new Error("Invalid subscriptions - invalid Retain Handling")),!1}f+=t.byteLength(r)+2+1}u("subscribe: writing to stream: %o",r.SUBSCRIBE_HEADER),n.write(r.SUBSCRIBE_HEADER[1][a?1:0][0]),b(n,f),d(n,c),null!==p&&p.write();let m=!0;for(const e of l){const i=e.topic,s=e.qos,a=+e.nl,u=+e.rap,c=e.rh;let l;_(n,i),l=r.SUBSCRIBE_OPTIONS_QOS[s],5===o&&(l|=a?r.SUBSCRIBE_OPTIONS_NL:0,l|=u?r.SUBSCRIBE_OPTIONS_RAP:0,l|=c?r.SUBSCRIBE_OPTIONS_RH[c]:0),m=n.write(t.from([l]))}return m}(e,n,s);case"suback":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.messageId,u=s.granted,c=s.properties;let l=0;if("number"!=typeof a)return n.emit("error",new Error("Invalid messageId")),!1;l+=2;if("object"!=typeof u||!u.length)return n.emit("error",new Error("Invalid qos vector")),!1;for(let e=0;e<u.length;e+=1){if("number"!=typeof u[e])return n.emit("error",new Error("Invalid qos vector")),!1;l+=1}let h=null;if(5===o){if(!(h=C(n,c,i,l)))return!1;l+=h.length}n.write(r.SUBACK_HEADER),b(n,l),d(n,a),null!==h&&h.write();return n.write(t.from(u))}(e,n,s);case"unsubscribe":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.messageId,u=s.dup?r.DUP_MASK:0,c=s.unsubscriptions,l=s.properties;let h=0;if("number"!=typeof a)return n.emit("error",new Error("Invalid messageId")),!1;h+=2;if("object"!=typeof c||!c.length)return n.emit("error",new Error("Invalid unsubscriptions")),!1;for(let e=0;e<c.length;e+=1){if("string"!=typeof c[e])return n.emit("error",new Error("Invalid unsubscriptions")),!1;h+=t.byteLength(c[e])+2}let f=null;if(5===o){if(!(f=T(n,l)))return!1;h+=f.length}n.write(r.UNSUBSCRIBE_HEADER[1][u?1:0][0]),b(n,h),d(n,a),null!==f&&f.write();let p=!0;for(let e=0;e<c.length;e++)p=_(n,c[e]);return p}(e,n,s);case"unsuback":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.messageId,u=s.dup?r.DUP_MASK:0,c=s.granted,l=s.properties,h=s.cmd;let f=2;if("number"!=typeof a)return n.emit("error",new Error("Invalid messageId")),!1;if(5===o){if("object"!=typeof c||!c.length)return n.emit("error",new Error("Invalid qos vector")),!1;for(let e=0;e<c.length;e+=1){if("number"!=typeof c[e])return n.emit("error",new Error("Invalid qos vector")),!1;f+=1}}let p=null;if(5===o){if(!(p=C(n,l,i,f)))return!1;f+=p.length}n.write(r.ACKS[h][0][u][0]),b(n,f),d(n,a),null!==p&&p.write();5===o&&n.write(t.from(c));return!0}(e,n,s);case"pingreq":case"pingresp":return function(e,t,n){return t.write(r.EMPTY[e.cmd])}(e,n);case"disconnect":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.reasonCode,u=s.properties;let c=5===o?1:0,l=null;if(5===o){if(!(l=C(n,u,i,c)))return!1;c+=l.length}n.write(t.from([r.codes.disconnect<<4])),b(n,c),5===o&&n.write(t.from([a]));null!==l&&l.write();return!0}(e,n,s);case"auth":return function(e,n,i){const o=i?i.protocolVersion:4,s=e||{},a=s.reasonCode,u=s.properties;let c=5===o?1:0;5!==o&&n.emit("error",new Error("Invalid mqtt version for auth packet"));const l=C(n,u,i,c);if(!l)return!1;c+=l.length,n.write(t.from([r.codes.auth<<4])),b(n,c),n.write(t.from([a])),null!==l&&l.write();return!0}(e,n,s);default:return n.emit("error",new Error("Unknown command")),!1}}function v(e){e.uncork()}Object.defineProperty(g,"cacheNumbers",{get:()=>d===k,set(e){e?(c&&0!==Object.keys(c).length||(m=!0),d=k):(m=!1,d=S)}});const y={};function b(e,t){if(t>r.VARBYTEINT_MAX)return e.emit("error",new Error(`Invalid variable byte integer: ${t}`)),!1;let n=y[t];return n||(n=f(t),t<16384&&(y[t]=n)),u("writeVarByteInt: writing to stream: %o",n),e.write(n)}function _(e,n){const r=t.byteLength(n);return d(e,r),u("writeString: %s",n),e.write(n,"utf8")}function w(e,t,n){_(e,t),_(e,n)}function k(e,t){return u("writeNumberCached: number: %d",t),u("writeNumberCached: %o",c[t]),e.write(c[t])}function S(e,t){const n=l(t);return u("writeNumberGenerated: %o",n),e.write(n)}function E(e,t){"string"==typeof t?_(e,t):t?(d(e,t.length),e.write(t)):d(e,0)}function T(e,n){if("object"!=typeof n||null!=n.length)return{length:1,write(){x(e,{},0)}};let i=0;function o(n,i){let o=0;switch(r.propertiesTypes[n]){case"byte":if("boolean"!=typeof i)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=2;break;case"int8":if("number"!=typeof i||i<0||i>255)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=2;break;case"binary":if(i&&null===i)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=1+t.byteLength(i)+2;break;case"int16":if("number"!=typeof i||i<0||i>65535)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=3;break;case"int32":if("number"!=typeof i||i<0||i>4294967295)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=5;break;case"var":if("number"!=typeof i||i<0||i>268435455)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=1+t.byteLength(f(i));break;case"string":if("string"!=typeof i)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=3+t.byteLength(i.toString());break;case"pair":if("object"!=typeof i)return e.emit("error",new Error(`Invalid ${n}: ${i}`)),!1;o+=Object.getOwnPropertyNames(i).reduce((e,n)=>{const r=i[n];return Array.isArray(r)?e+=r.reduce((e,r)=>e+=3+t.byteLength(n.toString())+2+t.byteLength(r.toString()),0):e+=3+t.byteLength(n.toString())+2+t.byteLength(i[n].toString()),e},0);break;default:return e.emit("error",new Error(`Invalid property ${n}: ${i}`)),!1}return o}if(n)for(const e in n){let t=0,r=0;const s=n[e];if(Array.isArray(s))for(let n=0;n<s.length;n++){if(!(r=o(e,s[n])))return!1;t+=r}else{if(!(r=o(e,s)))return!1;t=r}if(!t)return!1;i+=t}return{length:t.byteLength(f(i))+i,write(){x(e,n,i)}}}function C(e,t,n,r){const i=["reasonString","userProperties"],o=n&&n.properties&&n.properties.maximumPacketSize?n.properties.maximumPacketSize:0;let s=T(e,t);if(o)for(;r+s.length>o;){const n=i.shift();if(!n||!t[n])return!1;delete t[n],s=T(e,t)}return s}function A(e,n,i){switch(r.propertiesTypes[n]){case"byte":e.write(t.from([r.properties[n]])),e.write(t.from([+i]));break;case"int8":e.write(t.from([r.properties[n]])),e.write(t.from([i]));break;case"binary":e.write(t.from([r.properties[n]])),E(e,i);break;case"int16":e.write(t.from([r.properties[n]])),d(e,i);break;case"int32":e.write(t.from([r.properties[n]])),function(e,t){const n=p(t);u("write4ByteNumber: %o",n),e.write(n)}(e,i);break;case"var":e.write(t.from([r.properties[n]])),b(e,i);break;case"string":e.write(t.from([r.properties[n]])),_(e,i);break;case"pair":Object.getOwnPropertyNames(i).forEach(o=>{const s=i[o];Array.isArray(s)?s.forEach(i=>{e.write(t.from([r.properties[n]])),w(e,o.toString(),i.toString())}):(e.write(t.from([r.properties[n]])),w(e,o.toString(),s.toString()))});break;default:return e.emit("error",new Error(`Invalid property ${n} value: ${i}`)),!1}}function x(e,t,n){b(e,n);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&null!==t[n]){const r=t[n];if(Array.isArray(r))for(let t=0;t<r.length;t++)A(e,n,r[t]);else A(e,n,r)}}function I(e){return e?e instanceof t?e.length:t.byteLength(e):0}function R(e){return"string"==typeof e||e instanceof t}e.exports=g}).call(this,n(8).Buffer)},function(e,t,n){"use strict";var r=n(119),i=n(13)("mqttjs:tcp");e.exports=function(e,t){var n,o;return t.port=t.port||1883,t.hostname=t.hostname||t.host||"localhost",n=t.port,o=t.hostname,i("port %d and host %s",n,o),r.createConnection(n,o)}},function(e,t,n){"use strict";(function(t){var r,i,o,s=n(12).Transform,a=n(23);e.exports=function(e,n){if(n.hostname=n.hostname||n.host,!n.hostname)throw new Error("Could not determine host. Specify host manually.");var u="MQIsdp"===n.protocolId&&3===n.protocolVersion?"mqttv3.1":"mqtt";!function(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}(n);var c=function(e,t){var n="wxs"===e.protocol?"wss":"ws",r=n+"://"+e.hostname+e.path;return e.port&&80!==e.port&&443!==e.port&&(r=n+"://"+e.hostname+":"+e.port+e.path),"function"==typeof e.transformWsUrl&&(r=e.transformWsUrl(r,e,t)),r}(n,e);r=wx.connectSocket({url:c,protocols:[u]}),i=function(){var e=new s;return e._write=function(e,t,n){r.send({data:e.buffer,success:function(){n()},fail:function(e){n(new Error(e))}})},e._flush=function(e){r.close({success:function(){e()}})},e}(),(o=a.obj())._destroy=function(e,t){r.close({success:function(){t&&t(e)}})};var l=o.destroy;return o.destroy=function(){o.destroy=l;var e=this;setTimeout((function(){r.close({fail:function(){e._destroy(new Error)}})}),0)}.bind(o),r.onOpen((function(){o.setReadable(i),o.setWritable(i),o.emit("connect")})),r.onMessage((function(e){var n=e.data;n=n instanceof ArrayBuffer?t.from(n):t.from(n,"utf8"),i.push(n)})),r.onClose((function(){o.end(),o.destroy()})),r.onError((function(e){o.destroy(new Error(e.errMsg))})),o}}).call(this,n(8).Buffer)},function(e,t,n){"use strict";(function(t){var r,i,o,s=n(12).Transform,a=n(23),u=!1;e.exports=function(e,n){if(n.hostname=n.hostname||n.host,!n.hostname)throw new Error("Could not determine host. Specify host manually.");var c="MQIsdp"===n.protocolId&&3===n.protocolVersion?"mqttv3.1":"mqtt";!function(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}(n);var l=function(e,t){var n="alis"===e.protocol?"wss":"ws",r=n+"://"+e.hostname+e.path;return e.port&&80!==e.port&&443!==e.port&&(r=n+"://"+e.hostname+":"+e.port+e.path),"function"==typeof e.transformWsUrl&&(r=e.transformWsUrl(r,e,t)),r}(n,e);return(r=n.my).connectSocket({url:l,protocols:c}),i=function(){var e=new s;return e._write=function(e,t,n){r.sendSocketMessage({data:e.buffer,success:function(){n()},fail:function(){n(new Error)}})},e._flush=function(e){r.closeSocket({success:function(){e()}})},e}(),o=a.obj(),u||(u=!0,r.onSocketOpen((function(){o.setReadable(i),o.setWritable(i),o.emit("connect")})),r.onSocketMessage((function(e){if("string"==typeof e.data){var n=t.from(e.data,"base64");i.push(n)}else{var r=new FileReader;r.addEventListener("load",(function(){var e=r.result;e=e instanceof ArrayBuffer?t.from(e):t.from(e,"utf8"),i.push(e)})),r.readAsArrayBuffer(e.data)}})),r.onSocketClose((function(){o.end(),o.destroy()})),r.onSocketError((function(e){o.destroy(e)}))),o}}).call(this,n(8).Buffer)},function(e,t,n){"use strict";(function(t,r){const i=n(125),o=n(13)("mqttjs:ws"),s=n(23),a=n(12).Transform;let u=["rejectUnauthorized","ca","cert","key","pfx","passphrase"];const c=void 0!==t&&"browser"===t.title||"function"==typeof n;function l(e,t){let n=e.protocol+"://"+e.hostname+":"+e.port+e.path;return"function"==typeof e.transformWsUrl&&(n=e.transformWsUrl(n,e,t)),n}function h(e){let t=e;return e.hostname||(t.hostname="localhost"),e.port||("wss"===e.protocol?t.port=443:t.port=80),e.path||(t.path="/"),e.wsOptions||(t.wsOptions={}),c||"wss"!==e.protocol||u.forEach((function(n){e.hasOwnProperty(n)&&!e.wsOptions.hasOwnProperty(n)&&(t.wsOptions[n]=e[n])})),t}e.exports=c?function(e,t){let n;o("browserStreamBuilder");const i=function(e){let t=h(e);if(t.hostname||(t.hostname=t.host),!t.hostname){if("undefined"==typeof document)throw new Error("Could not determine host. Specify host manually.");const e=new URL(document.URL);t.hostname=e.hostname,t.port||(t.port=e.port)}return void 0===t.objectMode&&(t.objectMode=!(!0===t.binary||void 0===t.binary)),t}(t).browserBufferSize||524288,u=t.browserBufferTimeout||1e3,c=!t.objectMode;let f=function(e,t){const n="MQIsdp"===t.protocolId&&3===t.protocolVersion?"mqttv3.1":"mqtt";let r=l(t,e),i=new WebSocket(r,[n]);return i.binaryType="arraybuffer",i}(e,t),p=function(e,t,n){let r=new a({objectModeMode:e.objectMode});return r._write=t,r._flush=n,r}(t,(function e(t,n,o){f.bufferedAmount>i&&setTimeout(e,u,t,n,o);c&&"string"==typeof t&&(t=r.from(t,"utf8"));try{f.send(t)}catch(e){return o(e)}o()}),(function(e){f.close(),e()}));t.objectMode||(p._writev=b),p.on("close",()=>{f.close()});const d=void 0===f.addEventListener;function m(){n.setReadable(p),n.setWritable(p),n.emit("connect")}function g(){n.end(),n.destroy()}function v(e){n.destroy(e)}function y(e){let t=e.data;t=t instanceof ArrayBuffer?r.from(t):r.from(t,"utf8"),p.push(t)}function b(e,t){const n=new Array(e.length);for(let t=0;t<e.length;t++)"string"==typeof e[t].chunk?n[t]=r.from(e[t],"utf8"):n[t]=e[t].chunk;this._write(r.concat(n),"binary",t)}return(f.readyState===f.OPEN?n=p:(n=n=s(void 0,void 0,t),t.objectMode||(n._writev=b),d?f.addEventListener("open",m):f.onopen=m),n.socket=f,d?(f.addEventListener("close",g),f.addEventListener("error",v),f.addEventListener("message",y)):(f.onclose=g,f.onerror=v,f.onmessage=y),n)}:function(e,t){o("streamBuilder");let n=h(t);const r=l(n,e);let s=function(e,t,n){o("createWebSocket"),o("protocol: "+n.protocolId+" "+n.protocolVersion);const r="MQIsdp"===n.protocolId&&3===n.protocolVersion?"mqttv3.1":"mqtt";return o("creating new Websocket for url: "+t+" and protocol: "+r),new i(t,[r],n.wsOptions)}(0,r,n),a=i.createWebSocketStream(s,n.wsOptions);return a.url=r,a}}).call(this,n(9),n(8).Buffer)},function(e,t){e.exports=function(e){this.wrapped=e}},function(e,t,n){var r=n(77);e.exports=function(e,t){return r(Date.now(),e,t)}},function(e,t,n){(function(t){var n="Expected a function",r=NaN,i="[object Symbol]",o=/^\s+|\s+$/g,s=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,u=/^0o[0-7]+$/i,c=parseInt,l="object"==typeof t&&t&&t.Object===Object&&t,h="object"==typeof self&&self&&self.Object===Object&&self,f=l||h||Function("return this")(),p=Object.prototype.toString,d=Math.max,m=Math.min,g=function(){return f.Date.now()};function v(e,t,r){var i,o,s,a,u,c,l=0,h=!1,f=!1,p=!0;if("function"!=typeof e)throw new TypeError(n);function v(t){var n=i,r=o;return i=o=void 0,l=t,a=e.apply(r,n)}function _(e){var n=e-c;return void 0===c||n>=t||n<0||f&&e-l>=s}function w(){var e=g();if(_(e))return k(e);u=setTimeout(w,function(e){var n=t-(e-c);return f?m(n,s-(e-l)):n}(e))}function k(e){return u=void 0,p&&i?v(e):(i=o=void 0,a)}function S(){var e=g(),n=_(e);if(i=arguments,o=this,c=e,n){if(void 0===u)return function(e){return l=e,u=setTimeout(w,t),h?v(e):a}(c);if(f)return u=setTimeout(w,t),v(c)}return void 0===u&&(u=setTimeout(w,t)),a}return t=b(t)||0,y(r)&&(h=!!r.leading,s=(f="maxWait"in r)?d(b(r.maxWait)||0,t):s,p="trailing"in r?!!r.trailing:p),S.cancel=function(){void 0!==u&&clearTimeout(u),l=0,i=c=o=u=void 0},S.flush=function(){return void 0===u?a:k(g())},S}function y(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function b(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&p.call(e)==i}(e))return r;if(y(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=y(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(o,"");var n=a.test(e);return n||u.test(e)?c(e.slice(2),n?2:8):s.test(e)?r:+e}e.exports=function(e,t,r){var i=!0,o=!0;if("function"!=typeof e)throw new TypeError(n);return y(r)&&(i="leading"in r?!!r.leading:i,o="trailing"in r?!!r.trailing:o),v(e,t,{leading:i,maxWait:t,trailing:o})}}).call(this,n(10))},function(e,t,n){var r=n(84),i=n(85),o=n(28),s=n(86);e.exports=function(e,t){return r(e)||i(e,t)||o(e,t)||s()}},function(e,t){function n(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?e.exports=n=function(e){return typeof e}:e.exports=n=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(t)}e.exports=n},function(e,t,n){"use strict";(function(t){var r=n(87),i=n(33),o=n(112),s=n(20),a=n(13)("mqttjs"),u={};function c(e,t){if(a("connecting to an MQTT broker..."),"object"!=typeof e||t||(t=e,e=null),t=t||{},e){var n=o.parse(e,!0);if(null!=n.port&&(n.port=Number(n.port)),null===(t=s(n,t)).protocol)throw new Error("Missing protocol");t.protocol=t.protocol.replace(/:$/,"")}if(function(e){var t;e.auth&&((t=e.auth.match(/^(.+):(.+)$/))?(e.username=t[1],e.password=t[2]):e.username=e.auth)}(t),t.query&&"string"==typeof t.query.clientId&&(t.clientId=t.query.clientId),t.cert&&t.key){if(!t.protocol)throw new Error("Missing secure protocol key");if(-1===["mqtts","wss","wxs","alis"].indexOf(t.protocol))switch(t.protocol){case"mqtt":t.protocol="mqtts";break;case"ws":t.protocol="wss";break;case"wx":t.protocol="wxs";break;case"ali":t.protocol="alis";break;default:throw new Error('Unknown protocol for secure connection: "'+t.protocol+'"!')}}if(!u[t.protocol]){var i=-1!==["mqtts","wss"].indexOf(t.protocol);t.protocol=["mqtt","mqtts","ws","wss","wx","wxs","ali","alis"].filter((function(e,t){return(!i||t%2!=0)&&"function"==typeof u[e]}))[0]}if(!1===t.clean&&!t.clientId)throw new Error("Missing clientId for unclean clients");t.protocol&&(t.defaultProtocol=t.protocol);var c=new r((function(e){return t.servers&&(e._reconnectCount&&e._reconnectCount!==t.servers.length||(e._reconnectCount=0),t.host=t.servers[e._reconnectCount].host,t.port=t.servers[e._reconnectCount].port,t.protocol=t.servers[e._reconnectCount].protocol?t.servers[e._reconnectCount].protocol:t.defaultProtocol,t.hostname=t.host,e._reconnectCount++),a("calling streambuilder for",t.protocol),u[t.protocol](e,t)}),t);return c.on("error",(function(){})),c}void 0!==t&&"browser"!==t.title||"function"!=typeof n?(u.mqtt=n(43),u.tcp=n(43),u.ssl=n(22),u.tls=n(22),u.mqtts=n(22)):(u.wx=n(44),u.wxs=n(44),u.ali=n(45),u.alis=n(45)),u.ws=n(46),u.wss=n(46),e.exports=c,e.exports.connect=c,e.exports.MqttClient=r,e.exports.Store=i}).call(this,n(9))},function(e,t,n){(function(t){var n="Expected a function",r=NaN,i="[object Symbol]",o=/^\s+|\s+$/g,s=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,u=/^0o[0-7]+$/i,c=parseInt,l="object"==typeof t&&t&&t.Object===Object&&t,h="object"==typeof self&&self&&self.Object===Object&&self,f=l||h||Function("return this")(),p=Object.prototype.toString,d=Math.max,m=Math.min,g=function(){return f.Date.now()};function v(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function y(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&p.call(e)==i}(e))return r;if(v(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=v(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(o,"");var n=a.test(e);return n||u.test(e)?c(e.slice(2),n?2:8):s.test(e)?r:+e}e.exports=function(e,t,r){var i,o,s,a,u,c,l=0,h=!1,f=!1,p=!0;if("function"!=typeof e)throw new TypeError(n);function b(t){var n=i,r=o;return i=o=void 0,l=t,a=e.apply(r,n)}function _(e){var n=e-c;return void 0===c||n>=t||n<0||f&&e-l>=s}function w(){var e=g();if(_(e))return k(e);u=setTimeout(w,function(e){var n=t-(e-c);return f?m(n,s-(e-l)):n}(e))}function k(e){return u=void 0,p&&i?b(e):(i=o=void 0,a)}function S(){var e=g(),n=_(e);if(i=arguments,o=this,c=e,n){if(void 0===u)return function(e){return l=e,u=setTimeout(w,t),h?b(e):a}(c);if(f)return u=setTimeout(w,t),b(c)}return void 0===u&&(u=setTimeout(w,t)),a}return t=y(t)||0,v(r)&&(h=!!r.leading,s=(f="maxWait"in r)?d(y(r.maxWait)||0,t):s,p="trailing"in r?!!r.trailing:p),S.cancel=function(){void 0!==u&&clearTimeout(u),l=0,i=c=o=u=void 0},S.flush=function(){return void 0===u?a:k(g())},S}}).call(this,n(10))},function(e){e.exports=JSON.parse('{"name":"qiscus-sdk-core","version":"2.12.0","description":"Qiscus Web SDK Core","license":"MIT","main":"lib/index.js","browser":"dist/qiscus-sdk-core.min.js","files":["lib","dist"],"scripts":{"build":"npm-run-all --parallel build:node build:web","build:dev":"npm-run-all --parallel build:node build:web:dev","build:dev:watch":"npm-run-all --parallel build:web:watch serve","build:node":"babel -d lib src","build:node:watch":"babel -w -d lib src","build:web":"webpack --env.production --env.target=web","build:web:dev":"webpack --env.development --env.target=web","build:web:watch":"webpack --env.development --env.target=web --watch","dev":"webpack --env.development --progress --colors --watch","watch":"npm-run-all build:web:watch build:node:watch","test":"mocha --require @babel/register --colors \'test/**/*test.js\'","test:watch":"npm run test -- -w","clean":"rimraf dist lib","preversion":"npm-run-all clean build","prepublishOnly":"npm-run-all clean build","serve":"http-server -p 1234 -c-1 dist"},"devDependencies":{"@babel/cli":"^7.10.5","@babel/core":"^7.11.4","@babel/plugin-proposal-class-properties":"^7.10.4","@babel/plugin-transform-runtime":"^7.11.0","@babel/polyfill":"^7.10.4","@babel/preset-env":"^7.11.0","@babel/register":"^7.10.5","@commitlint/cli":"^8.3.5","@commitlint/config-conventional":"^8.3.4","babel-eslint":"^8.2.6","babel-loader":"^8.0.6","babel-plugin-add-module-exports":"^1.0.2","babel-plugin-date-fns":"^0.1.0","chai":"^4.2.0","chai-spies":"^1.0.0","eslint":"5.0.0","eslint-config-standard":"^12.0.0","eslint-loader":"^2.2.1","eslint-plugin-import":"^2.22.0","eslint-plugin-node":"^8.0.1","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","http-server":"^0.12.3","mocha":"^5.2.0","npm-run-all":"^4.1.5","rimraf":"^2.7.1","serve":"^12.0.0","webpack":"^4.44.1","webpack-cli":"^3.3.12"},"dependencies":{"@babel/runtime":"^7.11.2","date-fns":"^1.30.1","is_js":"^0.9.0","lodash.debounce":"^4.0.8","lodash.throttle":"^4.1.1","mitt":"^1.2.0","mqtt":"^4.2.6","store":"^2.0.12","superagent":"^3.8.3"},"babel":{"presets":[["@babel/preset-env",{"modules":"auto"}]],"plugins":["@babel/plugin-transform-runtime","@babel/plugin-proposal-class-properties","babel-plugin-add-module-exports","date-fns"]},"prettier":{"semi":false,"singleQuote":true,"trailingComma":"es5"}}')},function(e,t,n){e.exports=n(127)},function(e,t,n){var r=n(27);e.exports=function(e){if(Array.isArray(e))return r(e)}},function(e,t){e.exports=function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}},function(e,t,n){var r=function(e){"use strict";var t,n=Object.prototype,r=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",a=i.toStringTag||"@@toStringTag";function u(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=t&&t.prototype instanceof g?t:g,o=Object.create(i.prototype),s=new x(r||[]);return o._invoke=function(e,t,n){var r=h;return function(i,o){if(r===p)throw new Error("Generator is already running");if(r===d){if("throw"===i)throw o;return R()}for(n.method=i,n.arg=o;;){var s=n.delegate;if(s){var a=T(s,n);if(a){if(a===m)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===h)throw r=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=p;var u=l(e,t,n);if("normal"===u.type){if(r=n.done?d:f,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=d,n.method="throw",n.arg=u.arg)}}}(e,n,s),o}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var h="suspendedStart",f="suspendedYield",p="executing",d="completed",m={};function g(){}function v(){}function y(){}var b={};b[o]=function(){return this};var _=Object.getPrototypeOf,w=_&&_(_(I([])));w&&w!==n&&r.call(w,o)&&(b=w);var k=y.prototype=g.prototype=Object.create(b);function S(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function E(e,t){var n;this._invoke=function(i,o){function s(){return new t((function(n,s){!function n(i,o,s,a){var u=l(e[i],e,o);if("throw"!==u.type){var c=u.arg,h=c.value;return h&&"object"==typeof h&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){n("next",e,s,a)}),(function(e){n("throw",e,s,a)})):t.resolve(h).then((function(e){c.value=e,s(c)}),(function(e){return n("throw",e,s,a)}))}a(u.arg)}(i,o,n,s)}))}return n=n?n.then(s,s):s()}}function T(e,n){var r=e.iterator[n.method];if(r===t){if(n.delegate=null,"throw"===n.method){if(e.iterator.return&&(n.method="return",n.arg=t,T(e,n),"throw"===n.method))return m;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var i=l(r,e.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,m;var o=i.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,m):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,m)}function C(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function A(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(C,this),this.reset(!0)}function I(e){if(e){var n=e[o];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,s=function n(){for(;++i<e.length;)if(r.call(e,i))return n.value=e[i],n.done=!1,n;return n.value=t,n.done=!0,n};return s.next=s}}return{next:R}}function R(){return{value:t,done:!0}}return v.prototype=k.constructor=y,y.constructor=v,v.displayName=u(y,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,u(e,a,"GeneratorFunction")),e.prototype=Object.create(k),e},e.awrap=function(e){return{__await:e}},S(E.prototype),E.prototype[s]=function(){return this},e.AsyncIterator=E,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var s=new E(c(t,n,r,i),o);return e.isGeneratorFunction(n)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},S(k),u(k,a,"Generator"),k[o]=function(){return this},k.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=I,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(A),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function i(r,i){return a.type="throw",a.arg=e,n.next=r,i&&(n.method="next",n.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var s=this.tryEntries[o],a=s.completion;if("root"===s.tryLoc)return i("end");if(s.tryLoc<=this.prev){var u=r.call(s,"catchLoc"),c=r.call(s,"finallyLoc");if(u&&c){if(this.prev<s.catchLoc)return i(s.catchLoc,!0);if(this.prev<s.finallyLoc)return i(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return i(s.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return i(s.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=e,s.arg=t,o?(this.method="next",this.next=o.finallyLoc,m):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),m},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),A(n),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;A(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:I(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),m}},e}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}},function(e,t,n){function r(e){if(e)return function(e){for(var t in r.prototype)e[t]=r.prototype[t];return e}(e)}e.exports=r,r.prototype.on=r.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},r.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},r.prototype.off=r.prototype.removeListener=r.prototype.removeAllListeners=r.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var i=0;i<r.length;i++)if((n=r[i])===t||n.fn===t){r.splice(i,1);break}return 0===r.length&&delete this._callbacks["$"+e],this},r.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),n=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){r=0;for(var i=(n=n.slice(0)).length;r<i;++r)n[r].apply(this,t)}return this},r.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},r.prototype.hasListeners=function(e){return!!this.listeners(e).length}},function(e,t,n){"use strict";var r=n(29);function i(e){if(e)return function(e){for(var t in i.prototype)e[t]=i.prototype[t];return e}(e)}e.exports=i,i.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,this},i.prototype.parse=function(e){return this._parser=e,this},i.prototype.responseType=function(e){return this._responseType=e,this},i.prototype.serialize=function(e){return this._serializer=e,this},i.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this;for(var t in e)switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;default:console.warn("Unknown timeout option",t)}return this},i.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};var o=["ECONNRESET","ETIMEDOUT","EADDRINFO","ESOCKETTIMEDOUT"];i.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{var n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&t.status>=500&&501!=t.status)return!0;if(e){if(e.code&&~o.indexOf(e.code))return!0;if(e.timeout&&"ECONNABORTED"==e.code)return!0;if(e.crossDomain)return!0}return!1},i.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this._end()},i.prototype.then=function(e,t){if(!this._fullfilledPromise){var n=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise((function(e,t){n.end((function(n,r){n?t(n):e(r)}))}))}return this._fullfilledPromise.then(e,t)},i.prototype.catch=function(e){return this.then(void 0,e)},i.prototype.use=function(e){return e(this),this},i.prototype.ok=function(e){if("function"!=typeof e)throw Error("Callback required");return this._okCallback=e,this},i.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},i.prototype.get=function(e){return this._header[e.toLowerCase()]},i.prototype.getHeader=i.prototype.get,i.prototype.set=function(e,t){if(r(e)){for(var n in e)this.set(n,e[n]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},i.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},i.prototype.field=function(e,t){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data&&console.error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()"),r(e)){for(var n in e)this.field(n,e[n]);return this}if(Array.isArray(t)){for(var i in t)this.field(e,t[i]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=""+t),this._getFormData().append(e,t),this},i.prototype.abort=function(){return this._aborted?this:(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req&&this.req.abort(),this.clearTimeout(),this.emit("abort"),this)},i.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization","Basic "+r(e+":"+t));break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization","Bearer "+e)}return this},i.prototype.withCredentials=function(e){return null==e&&(e=!0),this._withCredentials=e,this},i.prototype.redirects=function(e){return this._maxRedirects=e,this},i.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw TypeError("Invalid argument");return this._maxResponseSize=e,this},i.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},i.prototype.send=function(e){var t=r(e),n=this._header["content-type"];if(this._formData&&console.error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()"),t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw Error("Can't merge these send calls");if(t&&r(this._data))for(var i in e)this._data[i]=e[i];else"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],this._data="application/x-www-form-urlencoded"==n?this._data?this._data+"&"+e:e:(this._data||"")+e):this._data=e;return!t||this._isHost(e)?this:(n||this.type("json"),this)},i.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},i.prototype._finalizeQueryString=function(){var e=this._query.join("&");if(e&&(this.url+=(this.url.indexOf("?")>=0?"&":"?")+e),this._query.length=0,this._sort){var t=this.url.indexOf("?");if(t>=0){var n=this.url.substring(t+1).split("&");"function"==typeof this._sort?n.sort(this._sort):n.sort(),this.url=this.url.substring(0,t)+"?"+n.join("&")}}},i.prototype._appendQueryString=function(){console.trace("Unsupported")},i.prototype._timeoutError=function(e,t,n){if(!this._aborted){var r=new Error(e+t+"ms exceeded");r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.abort(),this.callback(r)}},i.prototype._setTimeouts=function(){var e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((function(){e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((function(){e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))}},function(e,t,n){"use strict";var r=n(63);function i(e){if(e)return function(e){for(var t in i.prototype)e[t]=i.prototype[t];return e}(e)}e.exports=i,i.prototype.get=function(e){return this.header[e.toLowerCase()]},i.prototype._setHeaderProperties=function(e){var t=e["content-type"]||"";this.type=r.type(t);var n=r.params(t);for(var i in n)this[i]=n[i];this.links={};try{e.link&&(this.links=r.parseLinks(e.link))}catch(e){}},i.prototype._setStatusProperties=function(e){var t=e/100|0;this.status=this.statusCode=e,this.statusType=t,this.info=1==t,this.ok=2==t,this.redirect=3==t,this.clientError=4==t,this.serverError=5==t,this.error=(4==t||5==t)&&this.toError(),this.created=201==e,this.accepted=202==e,this.noContent=204==e,this.badRequest=400==e,this.unauthorized=401==e,this.notAcceptable=406==e,this.forbidden=403==e,this.notFound=404==e,this.unprocessableEntity=422==e}},function(e,t,n){"use strict";t.type=function(e){return e.split(/ *; */).shift()},t.params=function(e){return e.split(/ *; */).reduce((function(e,t){var n=t.split(/ *= */),r=n.shift(),i=n.shift();return r&&i&&(e[r]=i),e}),{})},t.parseLinks=function(e){return e.split(/ *, */).reduce((function(e,t){var n=t.split(/ *; */),r=n[0].slice(1,-1);return e[n[1].split(/ *= */)[1].slice(1,-1)]=r,e}),{})},t.cleanHeader=function(e,t){return delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e}},function(e,t){function n(){this._defaults=[]}["use","on","once","set","query","type","accept","auth","withCredentials","sortQuery","retry","ok","redirects","timeout","buffer","serialize","parse","ca","key","pfx","cert"].forEach((function(e){n.prototype[e]=function(){return this._defaults.push({fn:e,arguments:arguments}),this}})),n.prototype._setDefaults=function(e){this._defaults.forEach((function(t){e[t.fn].apply(e,t.arguments)}))},e.exports=n},function(e,t,n){var r=n(7),i=n(67),o=n(68);e.exports=function(e){var t=r(e);return o(t,i(t))+1}},function(e,t){e.exports=function(e){var t=new Date(e.getTime()),n=t.getTimezoneOffset();return t.setSeconds(0,0),6e4*n+t.getTime()%6e4}},function(e,t,n){var r=n(7);e.exports=function(e){var t=r(e),n=new Date(0);return n.setFullYear(t.getFullYear(),0,1),n.setHours(0,0,0,0),n}},function(e,t,n){var r=n(69),i=6e4,o=864e5;e.exports=function(e,t){var n=r(e),s=r(t),a=n.getTime()-n.getTimezoneOffset()*i,u=s.getTime()-s.getTimezoneOffset()*i;return Math.round((a-u)/o)}},function(e,t,n){var r=n(7);e.exports=function(e){var t=r(e);return t.setHours(0,0,0,0),t}},function(e,t,n){var r=n(7),i=n(19),o=n(72),s=6048e5;e.exports=function(e){var t=r(e),n=i(t).getTime()-o(t).getTime();return Math.round(n/s)+1}},function(e,t,n){var r=n(7);e.exports=function(e,t){var n=t&&Number(t.weekStartsOn)||0,i=r(e),o=i.getDay(),s=(o<n?7:0)+o-n;return i.setDate(i.getDate()-s),i.setHours(0,0,0,0),i}},function(e,t,n){var r=n(31),i=n(19);e.exports=function(e){var t=r(e),n=new Date(0);return n.setFullYear(t,0,4),n.setHours(0,0,0,0),i(n)}},function(e,t,n){var r=n(30);e.exports=function(e){if(r(e))return!isNaN(e);throw new TypeError(toString.call(e)+" is not an instance of Date")}},function(e,t){e.exports=function(){var e={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};return{localize:function(t,n,r){var i;return r=r||{},i="string"==typeof e[t]?e[t]:1===n?e[t].one:e[t].other.replace("{{count}}",n),r.addSuffix?r.comparison>0?"in "+i:i+" ago":i}}}},function(e,t,n){var r=n(76);e.exports=function(){var e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],t=["January","February","March","April","May","June","July","August","September","October","November","December"],n=["Su","Mo","Tu","We","Th","Fr","Sa"],i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],o=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],s=["AM","PM"],a=["am","pm"],u=["a.m.","p.m."],c={MMM:function(t){return e[t.getMonth()]},MMMM:function(e){return t[e.getMonth()]},dd:function(e){return n[e.getDay()]},ddd:function(e){return i[e.getDay()]},dddd:function(e){return o[e.getDay()]},A:function(e){return e.getHours()/12>=1?s[1]:s[0]},a:function(e){return e.getHours()/12>=1?a[1]:a[0]},aa:function(e){return e.getHours()/12>=1?u[1]:u[0]}};return["M","D","DDD","d","Q","W"].forEach((function(e){c[e+"o"]=function(t,n){return function(e){var t=e%100;if(t>20||t<10)switch(t%10){case 1:return e+"st";case 2:return e+"nd";case 3:return e+"rd"}return e+"th"}(n[e](t))}})),{formatters:c,formattingTokensRegExp:r(c)}}},function(e,t){var n=["M","MM","Q","D","DD","DDD","DDDD","d","E","W","WW","YY","YYYY","GG","GGGG","H","HH","h","hh","m","mm","s","ss","S","SS","SSS","Z","ZZ","X","x"];e.exports=function(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(r);var i=n.concat(t).sort().reverse();return new RegExp("(\\[[^\\[]*\\])|(\\\\)?("+i.join("|")+"|.)","g")}},function(e,t,n){var r=n(78),i=n(7),o=n(79),s=n(81),a=n(32),u=1440,c=2520,l=43200,h=86400;e.exports=function(e,t,n){var f=n||{},p=r(e,t),d=f.locale,m=a.distanceInWords.localize;d&&d.distanceInWords&&d.distanceInWords.localize&&(m=d.distanceInWords.localize);var g,v,y={addSuffix:Boolean(f.addSuffix),comparison:p};p>0?(g=i(e),v=i(t)):(g=i(t),v=i(e));var b,_=o(v,g),w=v.getTimezoneOffset()-g.getTimezoneOffset(),k=Math.round(_/60)-w;if(k<2)return f.includeSeconds?_<5?m("lessThanXSeconds",5,y):_<10?m("lessThanXSeconds",10,y):_<20?m("lessThanXSeconds",20,y):_<40?m("halfAMinute",null,y):m(_<60?"lessThanXMinutes":"xMinutes",1,y):0===k?m("lessThanXMinutes",1,y):m("xMinutes",k,y);if(k<45)return m("xMinutes",k,y);if(k<90)return m("aboutXHours",1,y);if(k<u)return m("aboutXHours",Math.round(k/60),y);if(k<c)return m("xDays",1,y);if(k<l)return m("xDays",Math.round(k/u),y);if(k<h)return m("aboutXMonths",b=Math.round(k/l),y);if((b=s(v,g))<12)return m("xMonths",Math.round(k/l),y);var S=b%12,E=Math.floor(b/12);return S<3?m("aboutXYears",E,y):S<9?m("overXYears",E,y):m("almostXYears",E+1,y)}},function(e,t,n){var r=n(7);e.exports=function(e,t){var n=r(e).getTime(),i=r(t).getTime();return n>i?-1:n<i?1:0}},function(e,t,n){var r=n(80);e.exports=function(e,t){var n=r(e,t)/1e3;return n>0?Math.floor(n):Math.ceil(n)}},function(e,t,n){var r=n(7);e.exports=function(e,t){var n=r(e),i=r(t);return n.getTime()-i.getTime()}},function(e,t,n){var r=n(7),i=n(82),o=n(83);e.exports=function(e,t){var n=r(e),s=r(t),a=o(n,s),u=Math.abs(i(n,s));return n.setMonth(n.getMonth()-a*u),a*(u-(o(n,s)===-a))}},function(e,t,n){var r=n(7);e.exports=function(e,t){var n=r(e),i=r(t);return 12*(n.getFullYear()-i.getFullYear())+(n.getMonth()-i.getMonth())}},function(e,t,n){var r=n(7);e.exports=function(e,t){var n=r(e).getTime(),i=r(t).getTime();return n<i?-1:n>i?1:0}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var n=[],r=!0,i=!1,o=void 0;try{for(var s,a=e[Symbol.iterator]();!(r=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==a.return||a.return()}finally{if(i)throw o}}return n}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}},function(e,t,n){"use strict";(function(t,r){var i=n(16).EventEmitter,o=n(33),s=n(100),a=n(12).Writable,u=n(11),c=n(110),l=n(111),h=n(20),f=n(13)("mqttjs:client"),p=t?t.nextTick:function(e){setTimeout(e,0)},d=r.setImmediate||function(e){p(e)},m={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:3e4,clean:!0,resubscribe:!0},g=["ECONNREFUSED","EADDRINUSE","ECONNRESET","ENOTFOUND"],v={0:"",1:"Unacceptable protocol version",2:"Identifier rejected",3:"Server unavailable",4:"Bad username or password",5:"Not authorized",16:"No matching subscribers",17:"No subscription existed",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",132:"Unsupported Protocol Version",133:"Client Identifier not valid",134:"Bad User Name or Password",135:"Not authorized",136:"Server unavailable",137:"Server busy",138:"Banned",139:"Server shutting down",140:"Bad authentication method",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",145:"Packet identifier in use",146:"Packet Identifier not found",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"};function y(e,t,n){f("sendPacket :: packet: %O",t),f("sendPacket :: emitting `packetsend`"),e.emit("packetsend",t),f("sendPacket :: writing to stream");var r=s.writeToStream(t,e.stream,e.options);f("sendPacket :: writeToStream result %s",r),!r&&n?(f("sendPacket :: handle events on `drain` once through callback."),e.stream.once("drain",n)):n&&(f("sendPacket :: invoking cb"),n())}function b(e){e&&(f("flush: queue exists? %b",!!e),Object.keys(e).forEach((function(t){"function"==typeof e[t].cb&&(e[t].cb(new Error("Connection closed")),delete e[t])})))}function _(e,t,n,r){f("storeAndSend :: store packet with cmd %s to outgoingStore",t.cmd),e.outgoingStore.put(t,(function(i){if(i)return n&&n(i);r(),y(e,t,n)}))}function w(e){f("nop ::",e)}function k(e,t){var n,r=this;if(!(this instanceof k))return new k(e,t);for(n in this.options=t||{},m)void 0===this.options[n]?this.options[n]=m[n]:this.options[n]=t[n];f("MqttClient :: options.protocol",t.protocol),f("MqttClient :: options.protocolVersion",t.protocolVersion),f("MqttClient :: options.username",t.username),f("MqttClient :: options.keepalive",t.keepalive),f("MqttClient :: options.reconnectPeriod",t.reconnectPeriod),f("MqttClient :: options.rejectUnauthorized",t.rejectUnauthorized),this.options.clientId="string"==typeof t.clientId?t.clientId:"mqttjs_"+Math.random().toString(16).substr(2,8),f("MqttClient :: clientId",this.options.clientId),this.options.customHandleAcks=5===t.protocolVersion&&t.customHandleAcks?t.customHandleAcks:function(){arguments[3](0)},this.streamBuilder=e,this.outgoingStore=t.outgoingStore||new o,this.incomingStore=t.incomingStore||new o,this.queueQoSZero=void 0===t.queueQoSZero||t.queueQoSZero,this._resubscribeTopics={},this.messageIdToTopic={},this.pingTimer=null,this.connected=!1,this.disconnecting=!1,this.queue=[],this.connackTimer=null,this.reconnectTimer=null,this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={},this.nextId=Math.max(1,Math.floor(65535*Math.random())),this.outgoing={},this._firstConnection=!0,this.on("connect",(function(){var e=this.queue;f("connect :: sending queued packets"),function t(){var n=e.shift();f("deliver :: entry %o",n);var i;n&&(i=n.packet,f("deliver :: call _sendPacket for %o",i),r._sendPacket(i,(function(e){n.cb&&n.cb(e),t()})))}()})),this.on("close",(function(){f("close :: connected set to `false`"),this.connected=!1,f("close :: clearing connackTimer"),clearTimeout(this.connackTimer),f("close :: clearing ping timer"),null!==r.pingTimer&&(r.pingTimer.clear(),r.pingTimer=null),f("close :: calling _setupReconnect"),this._setupReconnect()})),i.call(this),f("MqttClient :: setting up stream"),this._setupStream()}u(k,i),k.prototype._setupStream=function(){var e,t=this,n=new a,r=s.parser(this.options),i=null,o=[];function u(){if(o.length)p(c);else{var e=i;i=null,e()}}function c(){f("work :: getting next packet in queue");var e=o.shift();if(e)f("work :: packet pulled from queue"),t._handlePacket(e,u);else{f("work :: no packets in queue");var n=i;i=null,f("work :: done flag is %s",!!n),n&&n()}}if(f("_setupStream :: calling method to clear reconnect"),this._clearReconnect(),f("_setupStream :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),r.on("packet",(function(e){f("parser :: on packet push to packets array."),o.push(e)})),n._write=function(e,t,n){i=n,f("writable stream :: parsing buffer"),r.parse(e),c()},f("_setupStream :: pipe stream to writable stream"),this.stream.pipe(n),this.stream.on("error",(function(e){f("streamErrorHandler :: error",e.message),g.includes(e.code)?(f("streamErrorHandler :: emitting error"),t.emit("error",e)):w(e)})),this.stream.on("close",(function(){var e;f("(%s)stream :: on close",t.options.clientId),(e=t.outgoing)&&(f("flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(e).forEach((function(t){e[t].volatile&&"function"==typeof e[t].cb&&(e[t].cb(new Error("Connection closed")),delete e[t])}))),f("stream: emit close to MqttClient"),t.emit("close")})),f("_setupStream: sending packet `connect`"),(e=Object.create(this.options)).cmd="connect",y(this,e),r.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return t.end(()=>this.emit("error",new Error("Packet has no Authentication Method"))),this;if(this.options.properties.authenticationMethod&&this.options.authPacket&&"object"==typeof this.options.authPacket)y(this,h({cmd:"auth",reasonCode:0},this.options.authPacket))}this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout((function(){f("!!connectTimeout hit!! Calling _cleanUp with force `true`"),t._cleanUp(!0)}),this.options.connectTimeout)},k.prototype._handlePacket=function(e,t){var n=this.options;if(5===n.protocolVersion&&n.properties&&n.properties.maximumPacketSize&&n.properties.maximumPacketSize<e.length)return this.emit("error",new Error("exceeding packets size "+e.cmd)),this.end({reasonCode:149,properties:{reasonString:"Maximum packet size was exceeded"}}),this;switch(f("_handlePacket :: emitting packetreceive"),this.emit("packetreceive",e),e.cmd){case"publish":this._handlePublish(e,t);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(e),t();break;case"pubrel":this._handlePubrel(e,t);break;case"connack":this._handleConnack(e),t();break;case"pingresp":this._handlePingresp(e),t();break;case"disconnect":this._handleDisconnect(e),t()}},k.prototype._checkDisconnecting=function(e){return this.disconnecting&&(e?e(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting},k.prototype.publish=function(e,t,n,r){var i;f("publish :: message `%s` to topic `%s`",t,e);var o=this.options;"function"==typeof n&&(r=n,n=null);if(n=h({qos:0,retain:!1,dup:!1},n),this._checkDisconnecting(r))return this;switch(i={cmd:"publish",topic:e,payload:t,qos:n.qos,retain:n.retain,messageId:this._nextId(),dup:n.dup},5===o.protocolVersion&&(i.properties=n.properties,(!o.properties&&i.properties&&i.properties.topicAlias||n.properties&&o.properties&&(n.properties.topicAlias&&o.properties.topicAliasMaximum&&n.properties.topicAlias>o.properties.topicAliasMaximum||!o.properties.topicAliasMaximum&&n.properties.topicAlias))&&delete i.properties.topicAlias),f("publish :: qos",n.qos),n.qos){case 1:case 2:this.outgoing[i.messageId]={volatile:!1,cb:r||w},this._storeProcessing?(f("_storeProcessing enabled"),this._packetIdsDuringStoreProcessing[i.messageId]=!1,this._storePacket(i,void 0,n.cbStorePut)):(f("MqttClient:publish: packet cmd: %s",i.cmd),this._sendPacket(i,void 0,n.cbStorePut));break;default:this._storeProcessing?(f("_storeProcessing enabled"),this._storePacket(i,r,n.cbStorePut)):(f("MqttClient:publish: packet cmd: %s",i.cmd),this._sendPacket(i,r,n.cbStorePut))}return this},k.prototype.subscribe=function(){for(var e,t=new Array(arguments.length),n=0;n<arguments.length;n++)t[n]=arguments[n];var r,i=[],o=t.shift(),s=o.resubscribe,a=t.pop()||w,u=t.pop(),c=this,p=this.options.protocolVersion;if(delete o.resubscribe,"string"==typeof o&&(o=[o]),"function"!=typeof a&&(u=a,a=w),null!==(r=l.validateTopics(o)))return d(a,new Error("Invalid topic "+r)),this;if(this._checkDisconnecting(a))return f("subscribe: discconecting true"),this;var m={qos:0};if(5===p&&(m.nl=!1,m.rap=!1,m.rh=0),u=h(m,u),Array.isArray(o)?o.forEach((function(e){if(f("subscribe: array topic %s",e),!c._resubscribeTopics.hasOwnProperty(e)||c._resubscribeTopics[e].qos<u.qos||s){var t={topic:e,qos:u.qos};5===p&&(t.nl=u.nl,t.rap=u.rap,t.rh=u.rh,t.properties=u.properties),f("subscribe: pushing topic `%s` and qos `%s` to subs list",t.topic,t.qos),i.push(t)}})):Object.keys(o).forEach((function(e){if(f("subscribe: object topic %s",e),!c._resubscribeTopics.hasOwnProperty(e)||c._resubscribeTopics[e].qos<o[e].qos||s){var t={topic:e,qos:o[e].qos};5===p&&(t.nl=o[e].nl,t.rap=o[e].rap,t.rh=o[e].rh,t.properties=u.properties),f("subscribe: pushing `%s` to subs list",t),i.push(t)}})),e={cmd:"subscribe",subscriptions:i,qos:1,retain:!1,dup:!1,messageId:this._nextId()},u.properties&&(e.properties=u.properties),i.length){if(this.options.resubscribe){f("subscribe :: resubscribe true");var g=[];i.forEach((function(e){if(c.options.reconnectPeriod>0){var t={qos:e.qos};5===p&&(t.nl=e.nl||!1,t.rap=e.rap||!1,t.rh=e.rh||0,t.properties=e.properties),c._resubscribeTopics[e.topic]=t,g.push(e.topic)}})),c.messageIdToTopic[e.messageId]=g}return this.outgoing[e.messageId]={volatile:!0,cb:function(e,t){if(!e)for(var n=t.granted,r=0;r<n.length;r+=1)i[r].qos=n[r];a(e,i)}},f("subscribe :: call _sendPacket"),this._sendPacket(e),this}a(null,[])},k.prototype.unsubscribe=function(){for(var e={cmd:"unsubscribe",qos:1,messageId:this._nextId()},t=this,n=new Array(arguments.length),r=0;r<arguments.length;r++)n[r]=arguments[r];var i=n.shift(),o=n.pop()||w,s=n.pop();return"string"==typeof i&&(i=[i]),"function"!=typeof o&&(s=o,o=w),this._checkDisconnecting(o)?this:("string"==typeof i?e.unsubscriptions=[i]:Array.isArray(i)&&(e.unsubscriptions=i),this.options.resubscribe&&e.unsubscriptions.forEach((function(e){delete t._resubscribeTopics[e]})),"object"==typeof s&&s.properties&&(e.properties=s.properties),this.outgoing[e.messageId]={volatile:!0,cb:o},f("unsubscribe: call _sendPacket"),this._sendPacket(e),this)},k.prototype.end=function(e,t,n){var r=this;function i(){f("end :: closeStores: closing incoming and outgoing stores"),r.disconnected=!0,r.incomingStore.close((function(e){r.outgoingStore.close((function(t){if(f("end :: closeStores: emitting end"),r.emit("end"),n){let r=e||t;f("end :: closeStores: invoking callback with args"),n(r)}}))})),r._deferredReconnect&&r._deferredReconnect()}function o(){f("end :: (%s) :: finish :: calling _cleanUp with force %s",r.options.clientId,e),r._cleanUp(e,()=>{f("end :: finish :: calling process.nextTick on closeStores"),p(i.bind(r))},t)}return f("end :: (%s)",this.options.clientId),null!=e&&"boolean"==typeof e||(n=t||w,t=e,e=!1,"object"!=typeof t&&(n=t,t=null,"function"!=typeof n&&(n=w))),"object"!=typeof t&&(n=t,t=null),f("end :: cb? %s",!!n),n=n||w,this.disconnecting?(n(),this):(this._clearReconnect(),this.disconnecting=!0,!e&&Object.keys(this.outgoing).length>0?(f("end :: (%s) :: calling finish in 10ms once outgoing is empty",r.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,o,10))):(f("end :: (%s) :: immediately calling finish",r.options.clientId),o()),this)},k.prototype.removeOutgoingMessage=function(e){var t=this.outgoing[e]?this.outgoing[e].cb:null;return delete this.outgoing[e],this.outgoingStore.del({messageId:e},(function(){t(new Error("Message removed"))})),this},k.prototype.reconnect=function(e){f("client reconnect");var t=this,n=function(){e?(t.options.incomingStore=e.incomingStore,t.options.outgoingStore=e.outgoingStore):(t.options.incomingStore=null,t.options.outgoingStore=null),t.incomingStore=t.options.incomingStore||new o,t.outgoingStore=t.options.outgoingStore||new o,t.disconnecting=!1,t.disconnected=!1,t._deferredReconnect=null,t._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=n:n(),this},k.prototype._reconnect=function(){f("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end(()=>{this._setupStream()}),f("client already connected. disconnecting first.")):(f("_reconnect: calling _setupStream"),this._setupStream())},k.prototype._setupReconnect=function(){var e=this;!e.disconnecting&&!e.reconnectTimer&&e.options.reconnectPeriod>0?(this.reconnecting||(f("_setupReconnect :: emit `offline` state"),this.emit("offline"),f("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),f("_setupReconnect :: setting reconnectTimer for %d ms",e.options.reconnectPeriod),e.reconnectTimer=setInterval((function(){f("reconnectTimer :: reconnect triggered!"),e._reconnect()}),e.options.reconnectPeriod)):f("_setupReconnect :: doing nothing...")},k.prototype._clearReconnect=function(){f("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},k.prototype._cleanUp=function(e,t){var n=arguments[2];if(t&&(f("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",t)),f("_cleanUp :: forced? %s",e),e)0===this.options.reconnectPeriod&&this.options.clean&&b(this.outgoing),f("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{var r=h({cmd:"disconnect"},n);f("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(r,d.bind(null,this.stream.end.bind(this.stream)))}this.disconnecting||(f("_cleanUp :: client not disconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),null!==this.pingTimer&&(f("_cleanUp :: clearing pingTimer"),this.pingTimer.clear(),this.pingTimer=null),t&&!this.connected&&(f("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",t),t())},k.prototype._sendPacket=function(e,t,n){if(f("_sendPacket :: (%s) :: start",this.options.clientId),n=n||w,!this.connected)return f("_sendPacket :: client not connected. Storing packet offline."),void this._storePacket(e,t,n);switch(this._shiftPingInterval(),e.cmd){case"publish":break;case"pubrel":return void _(this,e,t,n);default:return void y(this,e,t)}switch(e.qos){case 2:case 1:_(this,e,t,n);break;case 0:default:y(this,e,t)}f("_sendPacket :: (%s) :: end",this.options.clientId)},k.prototype._storePacket=function(e,t,n){f("_storePacket :: packet: %o",e),f("_storePacket :: cb? %s",!!t),n=n||w,0===(e.qos||0)&&this.queueQoSZero||"publish"!==e.cmd?this.queue.push({packet:e,cb:t}):e.qos>0?(t=this.outgoing[e.messageId]?this.outgoing[e.messageId].cb:null,this.outgoingStore.put(e,(function(e){if(e)return t&&t(e);n()}))):t&&t(new Error("No connection to broker"))},k.prototype._setupPingTimer=function(){f("_setupPingTimer :: keepalive %d (seconds)",this.options.keepalive);var e=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=c((function(){e._checkPing()}),1e3*this.options.keepalive))},k.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},k.prototype._checkPing=function(){f("_checkPing :: checking ping..."),this.pingResp?(f("_checkPing :: ping response received. Clearing flag and sending `pingreq`"),this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):(f("_checkPing :: calling _cleanUp with force true"),this._cleanUp(!0))},k.prototype._handlePingresp=function(){this.pingResp=!0},k.prototype._handleConnack=function(e){f("_handleConnack");var t=this.options,n=5===t.protocolVersion?e.reasonCode:e.returnCode;if(clearTimeout(this.connackTimer),e.properties&&(e.properties.topicAliasMaximum&&(t.properties||(t.properties={}),t.properties.topicAliasMaximum=e.properties.topicAliasMaximum),e.properties.serverKeepAlive&&t.keepalive&&(t.keepalive=e.properties.serverKeepAlive,this._shiftPingInterval()),e.properties.maximumPacketSize&&(t.properties||(t.properties={}),t.properties.maximumPacketSize=e.properties.maximumPacketSize)),0===n)this.reconnecting=!1,this._onConnect(e);else if(n>0){var r=new Error("Connection refused: "+v[n]);r.code=n,this.emit("error",r)}},k.prototype._handlePublish=function(e,t){f("_handlePublish: packet %o",e),t=void 0!==t?t:w;var n=e.topic.toString(),r=e.payload,i=e.qos,o=e.messageId,s=this,a=this.options,u=[0,16,128,131,135,144,145,151,153];switch(f("_handlePublish: qos %d",i),i){case 2:a.customHandleAcks(n,r,e,(function(n,r){return n instanceof Error||(r=n,n=null),n?s.emit("error",n):-1===u.indexOf(r)?s.emit("error",new Error("Wrong reason code for pubrec")):void(r?s._sendPacket({cmd:"pubrec",messageId:o,reasonCode:r},t):s.incomingStore.put(e,(function(){s._sendPacket({cmd:"pubrec",messageId:o},t)})))}));break;case 1:a.customHandleAcks(n,r,e,(function(i,a){return i instanceof Error||(a=i,i=null),i?s.emit("error",i):-1===u.indexOf(a)?s.emit("error",new Error("Wrong reason code for puback")):(a||s.emit("message",n,r,e),void s.handleMessage(e,(function(e){if(e)return t&&t(e);s._sendPacket({cmd:"puback",messageId:o,reasonCode:a},t)})))}));break;case 0:this.emit("message",n,r,e),this.handleMessage(e,t);break;default:f("_handlePublish: unknown QoS. Doing nothing.")}},k.prototype.handleMessage=function(e,t){t()},k.prototype._handleAck=function(e){var t,n=e.messageId,r=e.cmd,i=null,o=this.outgoing[n]?this.outgoing[n].cb:null,s=this;if(o){switch(f("_handleAck :: packet type",r),r){case"pubcomp":case"puback":var a=e.reasonCode;a&&a>0&&16!==a&&((t=new Error("Publish error: "+v[a])).code=a,o(t,e)),delete this.outgoing[n],this.outgoingStore.del(e,o);break;case"pubrec":i={cmd:"pubrel",qos:2,messageId:n};var u=e.reasonCode;u&&u>0&&16!==u?((t=new Error("Publish error: "+v[u])).code=u,o(t,e)):this._sendPacket(i);break;case"suback":delete this.outgoing[n];for(var c=0;c<e.granted.length;c++)if(0!=(128&e.granted[c])){var l=this.messageIdToTopic[n];l&&l.forEach((function(e){delete s._resubscribeTopics[e]}))}o(null,e);break;case"unsuback":delete this.outgoing[n],o(null);break;default:s.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&0===Object.keys(this.outgoing).length&&this.emit("outgoingEmpty")}else f("_handleAck :: Server sent an ack in error. Ignoring.")},k.prototype._handlePubrel=function(e,t){f("handling pubrel packet"),t=void 0!==t?t:w;var n=e.messageId,r=this,i={cmd:"pubcomp",messageId:n};r.incomingStore.get(e,(function(e,n){e?r._sendPacket(i,t):(r.emit("message",n.topic,n.payload,n),r.handleMessage(n,(function(e){if(e)return t(e);r.incomingStore.del(n,w),r._sendPacket(i,t)})))}))},k.prototype._handleDisconnect=function(e){this.emit("disconnect",e)},k.prototype._nextId=function(){var e=this.nextId++;return 65536===this.nextId&&(this.nextId=1),e},k.prototype.getLastMessageId=function(){return 1===this.nextId?65535:this.nextId-1},k.prototype._resubscribe=function(e){f("_resubscribe");var t=Object.keys(this._resubscribeTopics);if(!this._firstConnection&&(this.options.clean||5===this.options.protocolVersion&&!e.sessionPresent)&&t.length>0)if(this.options.resubscribe)if(5===this.options.protocolVersion){f("_resubscribe: protocolVersion 5");for(var n=0;n<t.length;n++){var r={};r[t[n]]=this._resubscribeTopics[t[n]],r.resubscribe=!0,this.subscribe(r,{properties:r[t[n]].properties})}}else this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics);else this._resubscribeTopics={};this._firstConnection=!1},k.prototype._onConnect=function(e){if(this.disconnected)this.emit("connect",e);else{var t=this;this._setupPingTimer(),this._resubscribe(e),this.connected=!0,function n(){var r=t.outgoingStore.createStream();function i(){t._storeProcessing=!1,t._packetIdsDuringStoreProcessing={}}function o(){r.destroy(),r=null,i()}t.once("close",o),r.on("error",(function(e){i(),t.removeListener("close",o),t.emit("error",e)})),r.on("end",(function(){var r=!0;for(var s in t._packetIdsDuringStoreProcessing)if(!t._packetIdsDuringStoreProcessing[s]){r=!1;break}r?(i(),t.removeListener("close",o),t.emit("connect",e)):n()})),function e(){if(r){t._storeProcessing=!0;var n,i=r.read(1);i?t._packetIdsDuringStoreProcessing[i.messageId]?e():t.disconnecting||t.reconnectTimer?r.destroy&&r.destroy():(n=t.outgoing[i.messageId]?t.outgoing[i.messageId].cb:null,t.outgoing[i.messageId]={volatile:!1,cb:function(t,r){n&&n(t,r),e()}},t._packetIdsDuringStoreProcessing[i.messageId]=!0,t._sendPacket(i)):r.once("readable",e)}}()}()}},e.exports=k}).call(this,n(9),n(10))},function(e,t,n){"use strict";t.byteLength=function(e){var t=c(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,r=c(e),s=r[0],a=r[1],u=new o(function(e,t,n){return 3*(t+n)/4-n}(0,s,a)),l=0,h=a>0?s-4:s;for(n=0;n<h;n+=4)t=i[e.charCodeAt(n)]<<18|i[e.charCodeAt(n+1)]<<12|i[e.charCodeAt(n+2)]<<6|i[e.charCodeAt(n+3)],u[l++]=t>>16&255,u[l++]=t>>8&255,u[l++]=255&t;2===a&&(t=i[e.charCodeAt(n)]<<2|i[e.charCodeAt(n+1)]>>4,u[l++]=255&t);1===a&&(t=i[e.charCodeAt(n)]<<10|i[e.charCodeAt(n+1)]<<4|i[e.charCodeAt(n+2)]>>2,u[l++]=t>>8&255,u[l++]=255&t);return u},t.fromByteArray=function(e){for(var t,n=e.length,i=n%3,o=[],s=0,a=n-i;s<a;s+=16383)o.push(l(e,s,s+16383>a?a:s+16383));1===i?(t=e[n-1],o.push(r[t>>2]+r[t<<4&63]+"==")):2===i&&(t=(e[n-2]<<8)+e[n-1],o.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"="));return o.join("")};for(var r=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)r[a]=s[a],i[s.charCodeAt(a)]=a;function c(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 l(e,t,n){for(var i,o,s=[],a=t;a<n;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(r[(o=i)>>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return s.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(e,t){
|
|
13
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
14
|
+
t.read=function(e,t,n,r,i){var o,s,a=8*i-r-1,u=(1<<a)-1,c=u>>1,l=-7,h=n?i-1:0,f=n?-1:1,p=e[t+h];for(h+=f,o=p&(1<<-l)-1,p>>=-l,l+=a;l>0;o=256*o+e[t+h],h+=f,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=r;l>0;s=256*s+e[t+h],h+=f,l-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,r),o-=c}return(p?-1:1)*s*Math.pow(2,o-r)},t.write=function(e,t,n,r,i,o){var s,a,u,c=8*o-i-1,l=(1<<c)-1,h=l>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:o-1,d=r?1:-1,m=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=l):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+h>=1?f/u:f*Math.pow(2,1-h))*u>=2&&(s++,u/=2),s+h>=l?(a=0,s=l):s+h>=1?(a=(t*u-1)*Math.pow(2,i),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;e[n+p]=255&a,p+=d,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[n+p]=255&s,p+=d,s/=256,c-=8);e[n+p-d]|=128*m}},function(e,t){var n={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},function(e,t){},function(e,t,n){"use strict";function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}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)}}var s=n(8).Buffer,a=n(93).inspect,u=a&&a.custom||"inspect";e.exports=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.head=null,this.tail=null,this.length=0}var t,n,c;return t=e,(n=[{key:"push",value:function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(e){if(0===this.length)return"";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n}},{key:"concat",value:function(e){if(0===this.length)return s.alloc(0);for(var t,n,r,i=s.allocUnsafe(e>>>0),o=this.head,a=0;o;)t=o.data,n=i,r=a,s.prototype.copy.call(t,n,r),a+=o.data.length,o=o.next;return i}},{key:"consume",value:function(e,t){var n;return e<this.head.data.length?(n=this.head.data.slice(0,e),this.head.data=this.head.data.slice(e)):n=e===this.head.data.length?this.shift():t?this._getString(e):this._getBuffer(e),n}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(e){var t=this.head,n=1,r=t.data;for(e-=r.length;t=t.next;){var i=t.data,o=e>i.length?i.length:e;if(o===i.length?r+=i:r+=i.slice(0,e),0==(e-=o)){o===i.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(o));break}++n}return this.length-=n,r}},{key:"_getBuffer",value:function(e){var t=s.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,o=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,o),0==(e-=o)){o===i.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=i.slice(o));break}++r}return this.length-=r,t}},{key:u,value:function(e,t){return a(this,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},t,{depth:0,customInspect:!1}))}}])&&o(t.prototype,n),c&&o(t,c),e}()},function(e,t){},function(e,t,n){(function(t){function n(e){try{if(!t.localStorage)return!1}catch(e){return!1}var n=t.localStorage[e];return null!=n&&"true"===String(n).toLowerCase()}e.exports=function(e,t){if(n("noDeprecation"))return e;var r=!1;return function(){if(!r){if(n("throwDeprecation"))throw new Error(t);n("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}}}).call(this,n(10))},function(e,t,n){
|
|
13
15
|
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
14
|
-
var r=n(7),i=r.Buffer;function o(e,t){for(var n in e)t[n]=e[n]}function s(e,t,n){return i(e,t,n)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?e.exports=r:(o(r,t),t.Buffer=s),s.prototype=Object.create(i.prototype),o(i,s),s.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return i(e,t,n)},s.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var r=i(e);return void 0!==t?"string"==typeof n?r.fill(t,n):r.fill(t):r.fill(0),r},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i(e)},s.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}},function(e,t,n){"use strict";(function(t){var r;function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=n(25),s=Symbol("lastResolve"),a=Symbol("lastReject"),u=Symbol("error"),c=Symbol("ended"),l=Symbol("lastPromise"),h=Symbol("handlePromise"),f=Symbol("stream");function d(e,t){return{value:e,done:t}}function p(e){var t=e[s];if(null!==t){var n=e[f].read();null!==n&&(e[l]=null,e[s]=null,e[a]=null,t(d(n,!1)))}}function m(e){t.nextTick(p,e)}var g=Object.getPrototypeOf((function(){})),b=Object.setPrototypeOf((i(r={get stream(){return this[f]},next:function(){var e=this,n=this[u];if(null!==n)return Promise.reject(n);if(this[c])return Promise.resolve(d(void 0,!0));if(this[f].destroyed)return new Promise((function(n,r){t.nextTick((function(){e[u]?r(e[u]):n(d(void 0,!0))}))}));var r,i=this[l];if(i)r=new Promise(function(e,t){return function(n,r){e.then((function(){t[c]?n(d(void 0,!0)):t[h](n,r)}),r)}}(i,this));else{var o=this[f].read();if(null!==o)return Promise.resolve(d(o,!1));r=new Promise(this[h])}return this[l]=r,r}},Symbol.asyncIterator,(function(){return this})),i(r,"return",(function(){var e=this;return new Promise((function(t,n){e[f].destroy(null,(function(e){e?n(e):t(d(void 0,!0))}))}))})),r),g);e.exports=function(e){var t,n=Object.create(b,(i(t={},f,{value:e,writable:!0}),i(t,s,{value:null,writable:!0}),i(t,a,{value:null,writable:!0}),i(t,u,{value:null,writable:!0}),i(t,c,{value:e._readableState.endEmitted,writable:!0}),i(t,h,{value:function(e,t){var r=n[f].read();r?(n[l]=null,n[s]=null,n[a]=null,e(d(r,!1))):(n[s]=e,n[a]=t)},writable:!0}),t));return n[l]=null,o(e,(function(e){if(e&&"ERR_STREAM_PREMATURE_CLOSE"!==e.code){var t=n[a];return null!==t&&(n[l]=null,n[s]=null,n[a]=null,t(e)),void(n[u]=e)}var r=n[s];null!==r&&(n[l]=null,n[s]=null,n[a]=null,r(d(void 0,!0))),n[c]=!0})),e.on("readable",m.bind(null,n)),n}}).call(this,n(6))},function(e,t){e.exports=function(){throw new Error("Readable.from is not available in the browser")}},function(e,t,n){"use strict";e.exports=i;var r=n(46);function i(e){if(!(this instanceof i))return new i(e);r.call(this,e)}n(11)(i,r),i.prototype._transform=function(e,t,n){n(null,e)}},function(e,t,n){"use strict";var r;var i=n(15).codes,o=i.ERR_MISSING_ARGS,s=i.ERR_STREAM_DESTROYED;function a(e){if(e)throw e}function u(e){e()}function c(e,t){return e.pipe(t)}e.exports=function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];var l,h=function(e){return e.length?"function"!=typeof e[e.length-1]?a:e.pop():a}(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new o("streams");var f=t.map((function(e,i){var o=i<t.length-1;return function(e,t,i,o){o=function(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}(o);var a=!1;e.on("close",(function(){a=!0})),void 0===r&&(r=n(25)),r(e,{readable:t,writable:i},(function(e){if(e)return o(e);a=!0,o()}));var u=!1;return function(t){if(!a&&!u)return u=!0,function(e){return e.setHeader&&"function"==typeof e.abort}(e)?e.abort():"function"==typeof e.destroy?e.destroy():void o(t||new s("pipe"))}}(e,o,i>0,(function(e){l||(l=e),e&&f.forEach(u),o||(f.forEach(u),h(l))}))}));return t.reduce(c)}},function(e,t,n){t.parser=n(110).parser,t.generate=n(116),t.writeToStream=n(48)},function(e,t,n){const r=n(111),i=n(12),o=n(113),s=n(47),a=n(13)("mqtt-packet:parser");class u extends i{constructor(){super(),this.parser=this.constructor.parser}static parser(e){return this instanceof u?(this.settings=e||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):(new u).parser(e)}_resetState(){a("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new o,this.error=null,this._list=r(),this._stateCounter=0}parse(e){for(this.error&&this._resetState(),this._list.append(e),a("parse: current state: %s",this._states[this._stateCounter]);(-1!==this.packet.length||this._list.length>0)&&this[this._states[this._stateCounter]]()&&!this.error;)this._stateCounter++,a("parse: state complete. _stateCounter is now: %d",this._stateCounter),a("parse: packet.length: %d, buffer list length: %d",this.packet.length,this._list.length),this._stateCounter>=this._states.length&&(this._stateCounter=0);return a("parse: exited while loop. packet: %d, buffer list length: %d",this.packet.length,this._list.length),this._list.length}_parseHeader(){const e=this._list.readUInt8(0);return this.packet.cmd=s.types[e>>s.CMD_SHIFT],this.packet.retain=0!=(e&s.RETAIN_MASK),this.packet.qos=e>>s.QOS_SHIFT&s.QOS_MASK,this.packet.dup=0!=(e&s.DUP_MASK),a("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0}_parseLength(){const e=this._parseVarByteNum(!0);return e&&(this.packet.length=e.value,this._list.consume(e.bytes)),a("_parseLength %d",e.value),!!e}_parsePayload(){a("_parsePayload: payload %O",this._list);let e=!1;if(0===this.packet.length||this._list.length>=this.packet.length){switch(this._pos=0,this.packet.cmd){case"connect":this._parseConnect();break;case"connack":this._parseConnack();break;case"publish":this._parsePublish();break;case"puback":case"pubrec":case"pubrel":case"pubcomp":this._parseConfirmation();break;case"subscribe":this._parseSubscribe();break;case"suback":this._parseSuback();break;case"unsubscribe":this._parseUnsubscribe();break;case"unsuback":this._parseUnsuback();break;case"pingreq":case"pingresp":break;case"disconnect":this._parseDisconnect();break;case"auth":this._parseAuth();break;default:this._emitError(new Error("Not supported"))}e=!0}return a("_parsePayload complete result: %s",e),e}_parseConnect(){let e,t,n,r;a("_parseConnect");const i={},o=this.packet,u=this._parseString();if(null===u)return this._emitError(new Error("Cannot parse protocolId"));if("MQTT"!==u&&"MQIsdp"!==u)return this._emitError(new Error("Invalid protocolId"));if(o.protocolId=u,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(o.protocolVersion=this._list.readUInt8(this._pos),o.protocolVersion>=128&&(o.bridgeMode=!0,o.protocolVersion=o.protocolVersion-128),3!==o.protocolVersion&&4!==o.protocolVersion&&5!==o.protocolVersion)return this._emitError(new Error("Invalid protocol version"));if(this._pos++,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(i.username=this._list.readUInt8(this._pos)&s.USERNAME_MASK,i.password=this._list.readUInt8(this._pos)&s.PASSWORD_MASK,i.will=this._list.readUInt8(this._pos)&s.WILL_FLAG_MASK,i.will&&(o.will={},o.will.retain=0!=(this._list.readUInt8(this._pos)&s.WILL_RETAIN_MASK),o.will.qos=(this._list.readUInt8(this._pos)&s.WILL_QOS_MASK)>>s.WILL_QOS_SHIFT),o.clean=0!=(this._list.readUInt8(this._pos)&s.CLEAN_SESSION_MASK),this._pos++,o.keepalive=this._parseNum(),-1===o.keepalive)return this._emitError(new Error("Packet too short"));if(5===o.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(o.properties=e)}const c=this._parseString();if(null===c)return this._emitError(new Error("Packet too short"));if(o.clientId=c,a("_parseConnect: packet.clientId: %s",o.clientId),i.will){if(5===o.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(o.will.properties=e)}if(null===(e=this._parseString()))return this._emitError(new Error("Cannot parse will topic"));if(o.will.topic=e,a("_parseConnect: packet.will.topic: %s",o.will.topic),null===(t=this._parseBuffer()))return this._emitError(new Error("Cannot parse will payload"));o.will.payload=t,a("_parseConnect: packet.will.paylaod: %s",o.will.payload)}if(i.username){if(null===(r=this._parseString()))return this._emitError(new Error("Cannot parse username"));o.username=r,a("_parseConnect: packet.username: %s",o.username)}if(i.password){if(null===(n=this._parseBuffer()))return this._emitError(new Error("Cannot parse password"));o.password=n}return this.settings=o,a("_parseConnect: complete"),o}_parseConnack(){a("_parseConnack");const e=this.packet;if(this._list.length<1)return null;if(e.sessionPresent=!!(this._list.readUInt8(this._pos++)&s.SESSIONPRESENT_MASK),5===this.settings.protocolVersion)this._list.length>=2?e.reasonCode=this._list.readUInt8(this._pos++):e.reasonCode=0;else{if(this._list.length<2)return null;e.returnCode=this._list.readUInt8(this._pos++)}if(-1===e.returnCode||-1===e.reasonCode)return this._emitError(new Error("Cannot parse return code"));if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}a("_parseConnack: complete")}_parsePublish(){a("_parsePublish");const e=this.packet;if(e.topic=this._parseString(),null===e.topic)return this._emitError(new Error("Cannot parse topic"));if(!(e.qos>0)||this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}e.payload=this._list.slice(this._pos,e.length),a("_parsePublish: payload from buffer list: %o",e.payload)}}_parseSubscribe(){a("_parseSubscribe");const e=this.packet;let t,n,r,i,o,u,c;if(1!==e.qos)return this._emitError(new Error("Wrong subscribe header"));if(e.subscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<e.length;){if(null===(t=this._parseString()))return this._emitError(new Error("Cannot parse topic"));if(this._pos>=e.length)return this._emitError(new Error("Malformed Subscribe Payload"));r=(n=this._parseByte())&s.SUBSCRIBE_OPTIONS_QOS_MASK,u=0!=(n>>s.SUBSCRIBE_OPTIONS_NL_SHIFT&s.SUBSCRIBE_OPTIONS_NL_MASK),o=0!=(n>>s.SUBSCRIBE_OPTIONS_RAP_SHIFT&s.SUBSCRIBE_OPTIONS_RAP_MASK),i=n>>s.SUBSCRIBE_OPTIONS_RH_SHIFT&s.SUBSCRIBE_OPTIONS_RH_MASK,c={topic:t,qos:r},5===this.settings.protocolVersion?(c.nl=u,c.rap=o,c.rh=i):this.settings.bridgeMode&&(c.rh=0,c.rap=!0,c.nl=!0),a("_parseSubscribe: push subscription `%s` to subscription",c),e.subscriptions.push(c)}}}_parseSuback(){a("_parseSuback");const e=this.packet;if(this.packet.granted=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseUnsubscribe(){a("_parseUnsubscribe");const e=this.packet;if(e.unsubscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<e.length;){const t=this._parseString();if(null===t)return this._emitError(new Error("Cannot parse topic"));a("_parseUnsubscribe: push topic `%s` to unsubscriptions",t),e.unsubscriptions.push(t)}}}_parseUnsuback(){a("_parseUnsuback");const e=this.packet;if(!this._parseMessageId())return this._emitError(new Error("Cannot parse messageId"));if(5===this.settings.protocolVersion){const t=this._parseProperties();for(Object.getOwnPropertyNames(t).length&&(e.properties=t),e.granted=[];this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseConfirmation(){a("_parseConfirmation: packet.cmd: `%s`",this.packet.cmd);const e=this.packet;if(this._parseMessageId(),5===this.settings.protocolVersion&&(e.length>2?(e.reasonCode=this._parseByte(),a("_parseConfirmation: packet.reasonCode `%d`",e.reasonCode)):e.reasonCode=0,e.length>3)){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}return!0}_parseDisconnect(){const e=this.packet;if(a("_parseDisconnect"),5===this.settings.protocolVersion){this._list.length>0?e.reasonCode=this._parseByte():e.reasonCode=0;const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}return a("_parseDisconnect result: true"),!0}_parseAuth(){a("_parseAuth");const e=this.packet;if(5!==this.settings.protocolVersion)return this._emitError(new Error("Not supported auth packet for this version MQTT"));e.reasonCode=this._parseByte();const t=this._parseProperties();return Object.getOwnPropertyNames(t).length&&(e.properties=t),a("_parseAuth: result: true"),!0}_parseMessageId(){const e=this.packet;return e.messageId=this._parseNum(),null===e.messageId?(this._emitError(new Error("Cannot parse messageId")),!1):(a("_parseMessageId: packet.messageId %d",e.messageId),!0)}_parseString(e){const t=this._parseNum(),n=t+this._pos;if(-1===t||n>this._list.length||n>this.packet.length)return null;const r=this._list.toString("utf8",this._pos,n);return this._pos+=t,a("_parseString: result: %s",r),r}_parseStringPair(){return a("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){const e=this._parseNum(),t=e+this._pos;if(-1===e||t>this._list.length||t>this.packet.length)return null;const n=this._list.slice(this._pos,t);return this._pos+=e,a("_parseBuffer: result: %o",n),n}_parseNum(){if(this._list.length-this._pos<2)return-1;const e=this._list.readUInt16BE(this._pos);return this._pos+=2,a("_parseNum: result: %s",e),e}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;const e=this._list.readUInt32BE(this._pos);return this._pos+=4,a("_parse4ByteNum: result: %s",e),e}_parseVarByteNum(e){a("_parseVarByteNum");let t,n=0,r=1,i=0,o=!1;const u=this._pos?this._pos:0;for(;n<4&&u+n<this._list.length;){if(i+=r*((t=this._list.readUInt8(u+n++))&s.VARBYTEINT_MASK),r*=128,0==(t&s.VARBYTEINT_FIN_MASK)){o=!0;break}if(this._list.length<=n)break}return!o&&4===n&&this._list.length>=n&&this._emitError(new Error("Invalid variable byte integer")),u&&(this._pos+=n),a("_parseVarByteNum: result: %o",o=!!o&&(e?{bytes:n,value:i}:i)),o}_parseByte(){const e=this._list.readUInt8(this._pos);return this._pos++,a("_parseByte: result: %o",e),e}_parseByType(e){switch(a("_parseByType: type: %s",e),e){case"byte":return 0!==this._parseByte();case"int8":return this._parseByte();case"int16":return this._parseNum();case"int32":return this._parse4ByteNum();case"var":return this._parseVarByteNum();case"string":return this._parseString();case"pair":return this._parseStringPair();case"binary":return this._parseBuffer()}}_parseProperties(){a("_parseProperties");const e=this._parseVarByteNum(),t=this._pos+e,n={};for(;this._pos<t;){const e=this._parseByte(),t=s.propertiesCodes[e];if(!t)return this._emitError(new Error("Unknown property")),!1;if("userProperties"!==t)n[t]?Array.isArray(n[t])?n[t].push(this._parseByType(s.propertiesTypes[t])):(n[t]=[n[t]],n[t].push(this._parseByType(s.propertiesTypes[t]))):n[t]=this._parseByType(s.propertiesTypes[t]);else{n[t]||(n[t]=Object.create(null));const e=this._parseByType(s.propertiesTypes[t]);if(n[t][e.name])if(Array.isArray(n[t][e.name]))n[t][e.name].push(e.value);else{const r=n[t][e.name];n[t][e.name]=[r],n[t][e.name].push(e.value)}else n[t][e.name]=e.value}}return n}_newPacket(){return a("_newPacket"),this.packet&&(this._list.consume(this.packet.length),a("_newPacket: parser emit packet: packet.cmd: %s, packet.payload: %s, packet.length: %d",this.packet.cmd,this.packet.payload,this.packet.length),this.emit("packet",this.packet)),a("_newPacket: new packet"),this.packet=new o,this._pos=0,!0}_emitError(e){a("_emitError"),this.error=e,this.emit("error",e)}}e.exports=u},function(e,t,n){"use strict";const r=n(14).Duplex,i=n(11),o=n(112);function s(e){if(!(this instanceof s))return new s(e);if("function"==typeof e){this._callback=e;const t=function(e){this._callback&&(this._callback(e),this._callback=null)}.bind(this);this.on("pipe",(function(e){e.on("error",t)})),this.on("unpipe",(function(e){e.removeListener("error",t)})),e=null}o._init.call(this,e),r.call(this)}i(s,r),Object.assign(s.prototype,o.prototype),s.prototype._new=function(e){return new s(e)},s.prototype._write=function(e,t,n){this._appendBuffer(e),"function"==typeof n&&n()},s.prototype._read=function(e){if(!this.length)return this.push(null);e=Math.min(e,this.length),this.push(this.slice(0,e)),this.consume(e)},s.prototype.end=function(e){r.prototype.end.call(this,e),this._callback&&(this._callback(null,this.slice()),this._callback=null)},s.prototype._destroy=function(e,t){this._bufs.length=0,this.length=0,t(e)},s.prototype._isBufferList=function(e){return e instanceof s||e instanceof o||s.isBufferList(e)},s.isBufferList=o.isBufferList,e.exports=s,e.exports.BufferListStream=s,e.exports.BufferList=o},function(e,t,n){"use strict";const{Buffer:r}=n(7),i=Symbol.for("BufferList");function o(e){if(!(this instanceof o))return new o(e);o._init.call(this,e)}o._init=function(e){Object.defineProperty(this,i,{value:!0}),this._bufs=[],this.length=0,e&&this.append(e)},o.prototype._new=function(e){return new o(e)},o.prototype._offset=function(e){if(0===e)return[0,0];let t=0;for(let n=0;n<this._bufs.length;n++){const r=t+this._bufs[n].length;if(e<r||n===this._bufs.length-1)return[n,e-t];t=r}},o.prototype._reverseOffset=function(e){const t=e[0];let n=e[1];for(let e=0;e<t;e++)n+=this._bufs[e].length;return n},o.prototype.get=function(e){if(e>this.length||e<0)return;const t=this._offset(e);return this._bufs[t[0]][t[1]]},o.prototype.slice=function(e,t){return"number"==typeof e&&e<0&&(e+=this.length),"number"==typeof t&&t<0&&(t+=this.length),this.copy(null,0,e,t)},o.prototype.copy=function(e,t,n,i){if(("number"!=typeof n||n<0)&&(n=0),("number"!=typeof i||i>this.length)&&(i=this.length),n>=this.length)return e||r.alloc(0);if(i<=0)return e||r.alloc(0);const o=!!e,s=this._offset(n),a=i-n;let u=a,c=o&&t||0,l=s[1];if(0===n&&i===this.length){if(!o)return 1===this._bufs.length?this._bufs[0]:r.concat(this._bufs,this.length);for(let t=0;t<this._bufs.length;t++)this._bufs[t].copy(e,c),c+=this._bufs[t].length;return e}if(u<=this._bufs[s[0]].length-l)return o?this._bufs[s[0]].copy(e,t,l,l+u):this._bufs[s[0]].slice(l,l+u);o||(e=r.allocUnsafe(a));for(let t=s[0];t<this._bufs.length;t++){const n=this._bufs[t].length-l;if(!(u>n)){this._bufs[t].copy(e,c,l,l+u),c+=n;break}this._bufs[t].copy(e,c,l),c+=n,u-=n,l&&(l=0)}return e.length>c?e.slice(0,c):e},o.prototype.shallowSlice=function(e,t){if(e=e||0,t="number"!=typeof t?this.length:t,e<0&&(e+=this.length),t<0&&(t+=this.length),e===t)return this._new();const n=this._offset(e),r=this._offset(t),i=this._bufs.slice(n[0],r[0]+1);return 0===r[1]?i.pop():i[i.length-1]=i[i.length-1].slice(0,r[1]),0!==n[1]&&(i[0]=i[0].slice(n[1])),this._new(i)},o.prototype.toString=function(e,t,n){return this.slice(t,n).toString(e)},o.prototype.consume=function(e){if(e=Math.trunc(e),Number.isNaN(e)||e<=0)return this;for(;this._bufs.length;){if(!(e>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(e),this.length-=e;break}e-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},o.prototype.duplicate=function(){const e=this._new();for(let t=0;t<this._bufs.length;t++)e.append(this._bufs[t]);return e},o.prototype.append=function(e){if(null==e)return this;if(e.buffer)this._appendBuffer(r.from(e.buffer,e.byteOffset,e.byteLength));else if(Array.isArray(e))for(let t=0;t<e.length;t++)this.append(e[t]);else if(this._isBufferList(e))for(let t=0;t<e._bufs.length;t++)this.append(e._bufs[t]);else"number"==typeof e&&(e=e.toString()),this._appendBuffer(r.from(e));return this},o.prototype._appendBuffer=function(e){this._bufs.push(e),this.length+=e.length},o.prototype.indexOf=function(e,t,n){if(void 0===n&&"string"==typeof t&&(n=t,t=void 0),"function"==typeof e||Array.isArray(e))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if("number"==typeof e?e=r.from([e]):"string"==typeof e?e=r.from(e,n):this._isBufferList(e)?e=e.slice():Array.isArray(e.buffer)?e=r.from(e.buffer,e.byteOffset,e.byteLength):r.isBuffer(e)||(e=r.from(e)),t=Number(t||0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),0===e.length)return t>this.length?this.length:t;const i=this._offset(t);let o=i[0],s=i[1];for(;o<this._bufs.length;o++){const t=this._bufs[o];for(;s<t.length;){if(t.length-s>=e.length){const n=t.indexOf(e,s);if(-1!==n)return this._reverseOffset([o,n]);s=t.length-e.length+1}else{const t=this._reverseOffset([o,s]);if(this._match(t,e))return t;s++}}s=0}return-1},o.prototype._match=function(e,t){if(this.length-e<t.length)return!1;for(let n=0;n<t.length;n++)if(this.get(e+n)!==t[n])return!1;return!0},function(){const e={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1,readIntBE:null,readIntLE:null,readUIntBE:null,readUIntLE:null};for(const t in e)!function(t){o.prototype[t]=null===e[t]?function(e,n){return this.slice(e,e+n)[t](0,n)}:function(n=0){return this.slice(n,n+e[t])[t](0)}}(t)}(),o.prototype._isBufferList=function(e){return e instanceof o||o.isBufferList(e)},o.isBufferList=function(e){return null!=e&&e[i]},e.exports=o},function(e,t){e.exports=class{constructor(){this.cmd=null,this.retain=!1,this.qos=0,this.dup=!1,this.length=-1,this.topic=null,this.payload=null}}},function(e,t,n){e.exports=function(e){function t(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return r.colors[Math.abs(t)%r.colors.length]}function r(e){let n;function s(...e){if(!s.enabled)return;const t=s,i=Number(new Date),o=i-(n||i);t.diff=o,t.prev=n,t.curr=i,n=i,e[0]=r.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let a=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(n,i)=>{if("%%"===n)return n;a++;const o=r.formatters[i];if("function"==typeof o){const r=e[a];n=o.call(t,r),e.splice(a,1),a--}return n}),r.formatArgs.call(t,e),(t.log||r.log).apply(t,e)}return s.namespace=e,s.enabled=r.enabled(e),s.useColors=r.useColors(),s.color=t(e),s.destroy=i,s.extend=o,"function"==typeof r.init&&r.init(s),r.instances.push(s),s}function i(){const e=r.instances.indexOf(this);return-1!==e&&(r.instances.splice(e,1),!0)}function o(e,t){const n=r(this.namespace+(void 0===t?":":t)+e);return n.log=this.log,n}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return r.debug=r,r.default=r,r.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},r.disable=function(){const e=[...r.names.map(s),...r.skips.map(s).map(e=>"-"+e)].join(",");return r.enable(""),e},r.enable=function(e){let t;r.save(e),r.names=[],r.skips=[];const n=("string"==typeof e?e:"").split(/[\s,]+/),i=n.length;for(t=0;t<i;t++)n[t]&&("-"===(e=n[t].replace(/\*/g,".*?"))[0]?r.skips.push(new RegExp("^"+e.substr(1)+"$")):r.names.push(new RegExp("^"+e+"$")));for(t=0;t<r.instances.length;t++){const e=r.instances[t];e.enabled=r.enabled(e.namespace)}},r.enabled=function(e){if("*"===e[e.length-1])return!0;let t,n;for(t=0,n=r.skips.length;t<n;t++)if(r.skips[t].test(e))return!1;for(t=0,n=r.names.length;t<n;t++)if(r.names[t].test(e))return!0;return!1},r.humanize=n(115),Object.keys(e).forEach(t=>{r[t]=e[t]}),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=t,r.enable(r.load()),r}},function(e,t){var n=1e3,r=60*n,i=60*r,o=24*i,s=7*o,a=365.25*o;function u(e,t,n,r){var i=t>=1.5*n;return Math.round(e/n)+" "+r+(i?"s":"")}e.exports=function(e,t){t=t||{};var c=typeof e;if("string"===c&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var u=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return u*a;case"weeks":case"week":case"w":return u*s;case"days":case"day":case"d":return u*o;case"hours":case"hour":case"hrs":case"hr":case"h":return u*i;case"minutes":case"minute":case"mins":case"min":case"m":return u*r;case"seconds":case"second":case"secs":case"sec":case"s":return u*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return u;default:return}}(e);if("number"===c&&isFinite(e))return t.long?function(e){var t=Math.abs(e);if(t>=o)return u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=r)return u(e,t,r,"minute");if(t>=n)return u(e,t,n,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=o)return Math.round(e/o)+"d";if(t>=i)return Math.round(e/i)+"h";if(t>=r)return Math.round(e/r)+"m";if(t>=n)return Math.round(e/n)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,t,n){(function(t){const r=n(48),i=n(12);class o extends i{constructor(){super(),this._array=new Array(20),this._i=0}write(e){return this._array[this._i++]=e,!0}concat(){let e=0;const n=new Array(this._array.length),r=this._array;let i,o=0;for(i=0;i<r.length&&void 0!==r[i];i++)"string"!=typeof r[i]?n[i]=r[i].length:n[i]=t.byteLength(r[i]),e+=n[i];const s=t.allocUnsafe(e);for(i=0;i<r.length&&void 0!==r[i];i++)"string"!=typeof r[i]?(r[i].copy(s,o),o+=n[i]):(s.write(r[i],o),o+=n[i]);return s}}e.exports=function(e,t){const n=new o;return r(e,n,t),n.concat()}}).call(this,n(7).Buffer)},function(e,t,n){(function(t){const n=65536,r={},i=t.isBuffer(t.from([1,2]).subarray(0,1));function o(e){const n=t.allocUnsafe(2);return n.writeUInt8(e>>8,0),n.writeUInt8(255&e,1),n}e.exports={cache:r,generateCache:function(){for(let e=0;e<n;e++)r[e]=o(e)},generateNumber:o,genBufVariableByteInt:function(e){let n=0,r=0;const o=t.allocUnsafe(4);do{n=e%128|0,(e=e/128|0)>0&&(n|=128),o.writeUInt8(n,r++)}while(e>0&&r<4);return e>0&&(r=0),i?o.subarray(0,r):o.slice(0,r)},generate4ByteBuffer:function(e){const n=t.allocUnsafe(4);return n.writeUInt32BE(e,0),n}}}).call(this,n(7).Buffer)},function(e,t,n){"use strict";function r(e,t,n){var r=this;this._callback=e,this._args=n,this._interval=setInterval(e,t,this._args),this.reschedule=function(e){e||(e=r._interval),r._interval&&clearInterval(r._interval),r._interval=setInterval(r._callback,e,r._args)},this.clear=function(){r._interval&&(clearInterval(r._interval),r._interval=void 0)},this.destroy=function(){r._interval&&clearInterval(r._interval),r._callback=void 0,r._interval=void 0,r._args=void 0}}e.exports=function(){if("function"!=typeof arguments[0])throw new Error("callback needed");if("number"!=typeof arguments[1])throw new Error("interval needed");var e;if(arguments.length>0){e=new Array(arguments.length-2);for(var t=0;t<e.length;t++)e[t]=arguments[t+2]}return new r(arguments[0],arguments[1],e)}},function(e,t,n){"use strict";function r(e){for(var t=e.split("/"),n=0;n<t.length;n++)if("+"!==t[n]){if("#"===t[n])return n===t.length-1;if(-1!==t[n].indexOf("+")||-1!==t[n].indexOf("#"))return!1}return!0}e.exports={validateTopics:function(e){if(0===e.length)return"empty_topic_list";for(var t=0;t<e.length;t++)if(!r(e[t]))return e[t];return null}}},function(e,t,n){"use strict";var r=n(121),i=n(123);function o(){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=v,t.resolve=function(e,t){return v(e,!1,!0).resolve(t)},t.resolveObject=function(e,t){return e?v(e,!1,!0).resolveObject(t):t},t.format=function(e){i.isString(e)&&(e=v(e));return e instanceof o?e.format():o.prototype.format.call(e)},t.Url=o;var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,u=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,c=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),l=["'"].concat(c),h=["%","/","?",";","#"].concat(l),f=["/","?","#"],d=/^[+a-z0-9A-Z_-]{0,63}$/,p=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,m={javascript:!0,"javascript:":!0},g={javascript:!0,"javascript:":!0},b={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},y=n(124);function v(e,t,n){if(e&&i.isObject(e)&&e instanceof o)return e;var r=new o;return r.parse(e,t,n),r}o.prototype.parse=function(e,t,n){if(!i.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var o=e.indexOf("?"),a=-1!==o&&o<e.indexOf("#")?"?":"#",c=e.split(a);c[0]=c[0].replace(/\\/g,"/");var v=e=c.join(a);if(v=v.trim(),!n&&1===e.split("#").length){var _=u.exec(v);if(_)return this.path=v,this.href=v,this.pathname=_[1],_[2]?(this.search=_[2],this.query=t?y.parse(this.search.substr(1)):this.search.substr(1)):t&&(this.search="",this.query={}),this}var w=s.exec(v);if(w){var k=(w=w[0]).toLowerCase();this.protocol=k,v=v.substr(w.length)}if(n||w||v.match(/^\/\/[^@\/]+@[^@\/]+/)){var S="//"===v.substr(0,2);!S||w&&g[w]||(v=v.substr(2),this.slashes=!0)}if(!g[w]&&(S||w&&!b[w])){for(var E,T,C=-1,x=0;x<f.length;x++){-1!==(R=v.indexOf(f[x]))&&(-1===C||R<C)&&(C=R)}-1!==(T=-1===C?v.lastIndexOf("@"):v.lastIndexOf("@",C))&&(E=v.slice(0,T),v=v.slice(T+1),this.auth=decodeURIComponent(E)),C=-1;for(x=0;x<h.length;x++){var R;-1!==(R=v.indexOf(h[x]))&&(-1===C||R<C)&&(C=R)}-1===C&&(C=v.length),this.host=v.slice(0,C),v=v.slice(C),this.parseHost(),this.hostname=this.hostname||"";var A="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!A)for(var I=this.hostname.split(/\./),P=(x=0,I.length);x<P;x++){var O=I[x];if(O&&!O.match(d)){for(var M="",L=0,D=O.length;L<D;L++)O.charCodeAt(L)>127?M+="x":M+=O[L];if(!M.match(d)){var j=I.slice(0,x),U=I.slice(x+1),q=O.match(p);q&&(j.push(q[1]),U.unshift(q[2])),U.length&&(v="/"+U.join(".")+v),this.hostname=j.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),A||(this.hostname=r.toASCII(this.hostname));var F=this.port?":"+this.port:"",N=this.hostname||"";this.host=N+F,this.href+=this.host,A&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==v[0]&&(v="/"+v))}if(!m[k])for(x=0,P=l.length;x<P;x++){var B=l[x];if(-1!==v.indexOf(B)){var H=encodeURIComponent(B);H===B&&(H=escape(B)),v=v.split(B).join(H)}}var W=v.indexOf("#");-1!==W&&(this.hash=v.substr(W),v=v.slice(0,W));var Y=v.indexOf("?");if(-1!==Y?(this.search=v.substr(Y),this.query=v.substr(Y+1),t&&(this.query=y.parse(this.query)),v=v.slice(0,Y)):t&&(this.search="",this.query={}),v&&(this.pathname=v),b[k]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){F=this.pathname||"";var z=this.search||"";this.path=F+z}return this.href=this.format(),this},o.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||"",o=!1,s="";this.host?o=e+this.host:this.hostname&&(o=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(o+=":"+this.port)),this.query&&i.isObject(this.query)&&Object.keys(this.query).length&&(s=y.stringify(this.query));var a=this.search||s&&"?"+s||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||b[t])&&!1!==o?(o="//"+(o||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):o||(o=""),r&&"#"!==r.charAt(0)&&(r="#"+r),a&&"?"!==a.charAt(0)&&(a="?"+a),t+o+(n=n.replace(/[?#]/g,(function(e){return encodeURIComponent(e)})))+(a=a.replace("#","%23"))+r},o.prototype.resolve=function(e){return this.resolveObject(v(e,!1,!0)).format()},o.prototype.resolveObject=function(e){if(i.isString(e)){var t=new o;t.parse(e,!1,!0),e=t}for(var n=new o,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 u=Object.keys(e),c=0;c<u.length;c++){var l=u[c];"protocol"!==l&&(n[l]=e[l])}return b[n.protocol]&&n.hostname&&!n.pathname&&(n.path=n.pathname="/"),n.href=n.format(),n}if(e.protocol&&e.protocol!==n.protocol){if(!b[e.protocol]){for(var h=Object.keys(e),f=0;f<h.length;f++){var d=h[f];n[d]=e[d]}return n.href=n.format(),n}if(n.protocol=e.protocol,e.host||g[e.protocol])n.pathname=e.pathname;else{for(var p=(e.pathname||"").split("/");p.length&&!(e.host=p.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==p[0]&&p.unshift(""),p.length<2&&p.unshift(""),n.pathname=p.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 m=n.pathname||"",y=n.search||"";n.path=m+y}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var v=n.pathname&&"/"===n.pathname.charAt(0),_=e.host||e.pathname&&"/"===e.pathname.charAt(0),w=_||v||n.host&&e.pathname,k=w,S=n.pathname&&n.pathname.split("/")||[],E=(p=e.pathname&&e.pathname.split("/")||[],n.protocol&&!b[n.protocol]);if(E&&(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&&(""===p[0]?p[0]=e.host:p.unshift(e.host)),e.host=null),w=w&&(""===p[0]||""===S[0])),_)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=p;else if(p.length)S||(S=[]),S.pop(),S=S.concat(p),n.search=e.search,n.query=e.query;else if(!i.isNullOrUndefined(e.search)){if(E)n.hostname=n.host=S.shift(),(A=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=A.shift(),n.host=n.hostname=A.shift());return n.search=e.search,n.query=e.query,i.isNull(n.pathname)&&i.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 T=S.slice(-1)[0],C=(n.host||e.host||S.length>1)&&("."===T||".."===T)||""===T,x=0,R=S.length;R>=0;R--)"."===(T=S[R])?S.splice(R,1):".."===T?(S.splice(R,1),x++):x&&(S.splice(R,1),x--);if(!w&&!k)for(;x--;x)S.unshift("..");!w||""===S[0]||S[0]&&"/"===S[0].charAt(0)||S.unshift(""),C&&"/"!==S.join("/").substr(-1)&&S.push("");var A,I=""===S[0]||S[0]&&"/"===S[0].charAt(0);E&&(n.hostname=n.host=I?"":S.length?S.shift():"",(A=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=A.shift(),n.host=n.hostname=A.shift()));return(w=w||n.host&&S.length)&&!I&&S.unshift(""),S.length?n.pathname=S.join("/"):(n.pathname=null,n.path=null),i.isNull(n.pathname)&&i.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},o.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,n){(function(e,r){var i;/*! https://mths.be/punycode v1.4.1 by @mathias */!function(o){t&&t.nodeType,e&&e.nodeType;var s="object"==typeof r&&r;s.global!==s&&s.window!==s&&s.self;var a,u=2147483647,c=36,l=1,h=26,f=38,d=700,p=72,m=128,g="-",b=/^xn--/,y=/[^\x20-\x7E]/,v=/[\x2E\u3002\uFF0E\uFF61]/g,_={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},w=c-l,k=Math.floor,S=String.fromCharCode;function E(e){throw new RangeError(_[e])}function T(e,t){for(var n=e.length,r=[];n--;)r[n]=t(e[n]);return r}function C(e,t){var n=e.split("@"),r="";return n.length>1&&(r=n[0]+"@",e=n[1]),r+T((e=e.replace(v,".")).split("."),t).join(".")}function x(e){for(var t,n,r=[],i=0,o=e.length;i<o;)(t=e.charCodeAt(i++))>=55296&&t<=56319&&i<o?56320==(64512&(n=e.charCodeAt(i++)))?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),i--):r.push(t);return r}function R(e){return T(e,(function(e){var t="";return e>65535&&(t+=S((e-=65536)>>>10&1023|55296),e=56320|1023&e),t+=S(e)})).join("")}function A(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function I(e,t,n){var r=0;for(e=n?k(e/d):e>>1,e+=k(e/t);e>w*h>>1;r+=c)e=k(e/w);return k(r+(w+1)*e/(e+f))}function P(e){var t,n,r,i,o,s,a,f,d,b,y,v=[],_=e.length,w=0,S=m,T=p;for((n=e.lastIndexOf(g))<0&&(n=0),r=0;r<n;++r)e.charCodeAt(r)>=128&&E("not-basic"),v.push(e.charCodeAt(r));for(i=n>0?n+1:0;i<_;){for(o=w,s=1,a=c;i>=_&&E("invalid-input"),((f=(y=e.charCodeAt(i++))-48<10?y-22:y-65<26?y-65:y-97<26?y-97:c)>=c||f>k((u-w)/s))&&E("overflow"),w+=f*s,!(f<(d=a<=T?l:a>=T+h?h:a-T));a+=c)s>k(u/(b=c-d))&&E("overflow"),s*=b;T=I(w-o,t=v.length+1,0==o),k(w/t)>u-S&&E("overflow"),S+=k(w/t),w%=t,v.splice(w++,0,S)}return R(v)}function O(e){var t,n,r,i,o,s,a,f,d,b,y,v,_,w,T,C=[];for(v=(e=x(e)).length,t=m,n=0,o=p,s=0;s<v;++s)(y=e[s])<128&&C.push(S(y));for(r=i=C.length,i&&C.push(g);r<v;){for(a=u,s=0;s<v;++s)(y=e[s])>=t&&y<a&&(a=y);for(a-t>k((u-n)/(_=r+1))&&E("overflow"),n+=(a-t)*_,t=a,s=0;s<v;++s)if((y=e[s])<t&&++n>u&&E("overflow"),y==t){for(f=n,d=c;!(f<(b=d<=o?l:d>=o+h?h:d-o));d+=c)T=f-b,w=c-b,C.push(S(A(b+T%w,0))),f=k(T/w);C.push(S(A(f,0))),o=I(n,_,r==i),n=0,++r}++n,++t}return C.join("")}a={version:"1.4.1",ucs2:{decode:x,encode:R},decode:P,encode:O,toASCII:function(e){return C(e,(function(e){return y.test(e)?"xn--"+O(e):e}))},toUnicode:function(e){return C(e,(function(e){return b.test(e)?P(e.slice(4).toLowerCase()):e}))}},void 0===(i=function(){return a}.call(t,n,t,e))||(e.exports=i)}()}).call(this,n(122)(e),n(9))},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(125),t.encode=t.stringify=n(126)},function(e,t,n){"use strict";function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,n,o){t=t||"&",n=n||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var u=1e3;o&&"number"==typeof o.maxKeys&&(u=o.maxKeys);var c=e.length;u>0&&c>u&&(c=u);for(var l=0;l<c;++l){var h,f,d,p,m=e[l].replace(a,"%20"),g=m.indexOf(n);g>=0?(h=m.substr(0,g),f=m.substr(g+1)):(h=m,f=""),d=decodeURIComponent(h),p=decodeURIComponent(f),r(s,d)?i(s[d])?s[d].push(p):s[d]=[s[d],p]:s[d]=p}return s};var i=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?o(s(e),(function(s){var a=encodeURIComponent(r(s))+n;return i(e[s])?o(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 i=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function o(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){},function(e,t){},function(e,t,n){(t=e.exports=n(51)).Stream=t,t.Readable=t,t.Writable=n(54),t.Duplex=n(17),t.Transform=n(55),t.PassThrough=n(135)},function(e,t){},function(e,t,n){"use strict";var r=n(28).Buffer,i=n(132);e.exports=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.head=null,this.tail=null,this.length=0}return e.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},e.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},e.prototype.shift=function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},e.prototype.clear=function(){this.head=this.tail=null,this.length=0},e.prototype.join=function(e){if(0===this.length)return"";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n},e.prototype.concat=function(e){if(0===this.length)return r.alloc(0);if(1===this.length)return this.head.data;for(var t,n,i,o=r.allocUnsafe(e>>>0),s=this.head,a=0;s;)t=s.data,n=o,i=a,t.copy(n,i),a+=s.data.length,s=s.next;return o},e}(),i&&i.inspect&&i.inspect.custom&&(e.exports.prototype[i.inspect.custom]=function(){var e=i.inspect({length:this.length});return this.constructor.name+" "+e})},function(e,t){},function(e,t,n){(function(e){var r=void 0!==e&&e||"undefined"!=typeof self&&self||window,i=Function.prototype.apply;function o(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new o(i.call(setTimeout,r,arguments),clearTimeout)},t.setInterval=function(){return new o(i.call(setInterval,r,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},o.prototype.unref=o.prototype.ref=function(){},o.prototype.close=function(){this._clearFn.call(r,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout((function(){e._onTimeout&&e._onTimeout()}),t))},n(134),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(this,n(9))},function(e,t,n){(function(e,t){!function(e,n){"use strict";if(!e.setImmediate){var r,i,o,s,a,u=1,c={},l=!1,h=e.document,f=Object.getPrototypeOf&&Object.getPrototypeOf(e);f=f&&f.setTimeout?f:e,"[object process]"==={}.toString.call(e.process)?r=function(e){t.nextTick((function(){p(e)}))}:!function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}()?e.MessageChannel?((o=new MessageChannel).port1.onmessage=function(e){p(e.data)},r=function(e){o.port2.postMessage(e)}):h&&"onreadystatechange"in h.createElement("script")?(i=h.documentElement,r=function(e){var t=h.createElement("script");t.onreadystatechange=function(){p(e),t.onreadystatechange=null,i.removeChild(t),t=null},i.appendChild(t)}):r=function(e){setTimeout(p,0,e)}:(s="setImmediate$"+Math.random()+"$",a=function(t){t.source===e&&"string"==typeof t.data&&0===t.data.indexOf(s)&&p(+t.data.slice(s.length))},e.addEventListener?e.addEventListener("message",a,!1):e.attachEvent("onmessage",a),r=function(t){e.postMessage(s+t,"*")}),f.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n<t.length;n++)t[n]=arguments[n+1];var i={callback:e,args:t};return c[u]=i,r(u),u++},f.clearImmediate=d}function d(e){delete c[e]}function p(e){if(l)setTimeout(p,0,e);else{var t=c[e];if(t){l=!0;try{!function(e){var t=e.callback,r=e.args;switch(r.length){case 0:t();break;case 1:t(r[0]);break;case 2:t(r[0],r[1]);break;case 3:t(r[0],r[1],r[2]);break;default:t.apply(n,r)}}(t)}finally{d(e),l=!1}}}}}("undefined"==typeof self?void 0===e?this:e:self)}).call(this,n(9),n(6))},function(e,t,n){"use strict";e.exports=o;var r=n(55),i=Object.create(n(19));function o(e){if(!(this instanceof o))return new o(e);r.call(this,e)}i.inherits=n(11),i.inherits(o,r),o.prototype._transform=function(e,t,n){n(null,e)}},function(e,t,n){(function(t){var r=n(137),i=function(){},o=function(e,n,s){if("function"==typeof n)return o(e,null,n);n||(n={}),s=r(s||i);var a=e._writableState,u=e._readableState,c=n.readable||!1!==n.readable&&e.readable,l=n.writable||!1!==n.writable&&e.writable,h=!1,f=function(){e.writable||d()},d=function(){l=!1,c||s.call(e)},p=function(){c=!1,l||s.call(e)},m=function(t){s.call(e,t?new Error("exited with error code: "+t):null)},g=function(t){s.call(e,t)},b=function(){t.nextTick(y)},y=function(){if(!h)return(!c||u&&u.ended&&!u.destroyed)&&(!l||a&&a.ended&&!a.destroyed)?void 0:s.call(e,new Error("premature close"))},v=function(){e.req.on("finish",d)};return!function(e){return e.setHeader&&"function"==typeof e.abort}(e)?l&&!a&&(e.on("end",f),e.on("close",f)):(e.on("complete",d),e.on("abort",b),e.req?v():e.on("request",v)),function(e){return e.stdio&&Array.isArray(e.stdio)&&3===e.stdio.length}(e)&&e.on("exit",m),e.on("end",p),e.on("finish",d),!1!==n.error&&e.on("error",g),e.on("close",b),function(){h=!0,e.removeListener("complete",d),e.removeListener("abort",b),e.removeListener("request",v),e.req&&e.req.removeListener("finish",d),e.removeListener("end",f),e.removeListener("close",f),e.removeListener("finish",d),e.removeListener("exit",m),e.removeListener("end",p),e.removeListener("error",g),e.removeListener("close",b)}};e.exports=o}).call(this,n(6))},function(e,t,n){var r=n(138);function i(e){var t=function(){return t.called?t.value:(t.called=!0,t.value=e.apply(this,arguments))};return t.called=!1,t}function o(e){var t=function(){if(t.called)throw new Error(t.onceError);return t.called=!0,t.value=e.apply(this,arguments)},n=e.name||"Function wrapped with `once`";return t.onceError=n+" shouldn't be called more than once",t.called=!1,t}e.exports=r(i),e.exports.strict=r(o),i.proto=i((function(){Object.defineProperty(Function.prototype,"once",{value:function(){return i(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return o(this)},configurable:!0})}))},function(e,t){e.exports=function e(t,n){if(t&&n)return e(t)(n);if("function"!=typeof t)throw new TypeError("need wrapper function");Object.keys(t).forEach((function(e){r[e]=t[e]}));return r;function r(){for(var e=new Array(arguments.length),n=0;n<e.length;n++)e[n]=arguments[n];var r=t.apply(this,e),i=e[e.length-1];return"function"==typeof r&&r!==i&&Object.keys(i).forEach((function(e){r[e]=i[e]})),r}}},function(e,t){e.exports=function(e){var t=e._readableState;return t?t.objectMode||"number"==typeof e._duplexState?e.read():e.read(function(e){if(e.buffer.length)return e.buffer.head?e.buffer.head.data.length:e.buffer[0].length;return e.length}(t)):null}},function(e,t,n){"use strict";e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},function(e,t,n){var r=n(58);function i(e){var t,n;function i(t,n){try{var s=e[t](n),a=s.value,u=a instanceof r;Promise.resolve(u?a.wrapped:a).then((function(e){u?i("return"===t?"return":"next",e):o(s.done?"return":"normal",e)}),(function(e){i("throw",e)}))}catch(e){o("throw",e)}}function o(e,r){switch(e){case"return":t.resolve({value:r,done:!0});break;case"throw":t.reject(r);break;default:t.resolve({value:r,done:!1})}(t=t.next)?i(t.key,t.arg):n=null}this._invoke=function(e,r){return new Promise((function(o,s){var a={key:e,arg:r,resolve:o,reject:s,next:null};n?n=n.next=a:(t=n=a,i(e,r))}))},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(i.prototype[Symbol.asyncIterator]=function(){return this}),i.prototype.next=function(e){return this._invoke("next",e)},i.prototype.throw=function(e){return this._invoke("throw",e)},i.prototype.return=function(e){return this._invoke("return",e)},e.exports=i},function(e,t,n){"use strict";n.r(t);var r=n(20),i=n.n(r),o=n(0),s=n.n(o),a=n(2),u=n.n(a),c=n(3),l=n.n(c),h=n(4),f=n.n(h),d=n(1),p=n.n(d),m=n(8),g=n.n(m);var b=function(e){return e=e||Object.create(null),{on:function(t,n){(e[t]||(e[t]=[])).push(n)},off:function(t,n){e[t]&&e[t].splice(e[t].indexOf(n)>>>0,1)},emit:function(t,n){(e[t]||[]).slice().map((function(e){e(n)})),(e["*"]||[]).slice().map((function(e){e(t,n)}))}}},y=n(5),v=n.n(y),_=n(21),w=n.n(_),k=n(59),S=n.n(k);function E(e){return e.replace(/<[^>]*\/?>([\s\S]*)?<\/.*?>/gi,(function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}))}var T=function(){function e(t){l()(this,e),this.roomAdapter=t,this.name=null,this.emails=[],this.options={}}return f()(e,[{key:"withName",value:function(e){return this.name=e,this}},{key:"withOptions",value:function(e){return this.options=e,this}},{key:"addParticipants",value:function(){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return this.emails=(e=this.emails.filter((function(e){return-1===n.indexOf(e)}))).concat.apply(e,n),this}},{key:"create",value:function(){var e=this.name,t=this.emails,n=this.options;return this.roomAdapter.createRoom(e,t,{avatarURL:n.avatarURL},n)}}]),e}();var C=function(){function e(t){l()(this,e),this.id=t.id,this.before_id=t.comment_before_id,this.message=E(t.message),this.username_as=t.username_as||t.username,this.username_real=t.username_real||t.email,this.email=this.username_real,this.user_extras=t.user_extras,this.date=w()(t.timestamp,"YYYY-MM-DD"),this.time=w()(t.timestamp,"HH:mm"),this.timestamp=t.timestamp,this.unique_id=t.unique_temp_id||t.unique_id,this.unique_temp_id=t.unique_temp_id||t.unique_id,this.avatar=t.user_avatar_url,this.room_id=t.room_id,this.isChannel=t.is_public_channel,this.unix_timestamp=t.unix_timestamp,this.extras=t.extras,this.is_deleted=t.is_deleted,this.isPending=!1,this.isFailed=!1,this.isDelivered=!1,this.isRead=!1,this.isSent=!1,this.attachment=null,this.payload=t.payload,this.status=t.status,"reply"===t.type&&(t.payload.replied_comment_message=E(t.payload.replied_comment_message),t.payload.text=E(t.payload.text)),this.type=t.type,this.subtype="custom"===t.type?t.payload.type:null,"sent"===t.status?this.markAsSent():"delivered"===t.status?this.markAsDelivered():"read"===t.status&&this.markAsRead()}return f()(e,[{key:"isAttachment",value:function(e){return"[file]"===e.substring(0,"[file]".length)}},{key:"isImageAttachment",value:function(e){return this.isAttachment(e)&&null!=e.match(/\.(jpg|jpeg|gif|png)/i)}},{key:"attachUniqueId",value:function(e){this.unique_id=e}},{key:"getAttachmentURI",value:function(e){if(this.isAttachment(e)){var t=e.length,n="[file]".length,r=t-"[/file]".length;return e.substring(n,r).trim()}}},{key:"setAttachment",value:function(e){this.attachment=e}},{key:"markAsPending",value:function(){this.isPending=!0,this.isDelivered=!1,this.status="pending"}},{key:"markAsSent",value:function(){this.isSent=!0,this.isPending=!1,this.isFailed=!1,this.status="sent"}},{key:"markAsDelivered",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.actor,n=e.activeActorId;t!==n&&(this.isRead||"read"===this.status||(this.isSent=!0,this.isRead=!1,this.isDelivered=!0,this.status="delivered"))}},{key:"markAsRead",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.actor,n=e.activeActorId;t!==n&&(this.isPending=!1,this.isSent=!0,this.isDelivered=!0,this.isRead=!0,this.status="read")}},{key:"markAsFailed",value:function(){this.isFailed=!0,this.isPending=!1,this.isStatus="failed"}},{key:"update",value:function(e){this.id=e.id,this.before_id=e.comment_before_id,this.message=E(e.message),e.payload&&(this.payload=e.payload),e.status&&(this.status=e.status),"reply"===e.type&&(this.payload.replied_comment_message=E(e.payload.replied_comment_message),this.payload.text=E(e.payload.text)),"sent"===e.status?this.markAsSent():"delivered"===e.status?this.markAsDelivered():"read"===e.status&&this.markAsRead()}}]),e}(),x=function(){function e(t){l()(this,e),this.id=t.id,this.last_comment_id=t.last_comment_id,this.last_comment_message=t.last_comment_message,this.last_comment_message_created_at=t.last_comment_message_created_at,this.last_comment_topic_title=t.last_comment_topic_title,this.avatar=t.room_avatar||t.avatarURL||t.avatar_url,this.name=t.room_name,this.room_type=t.room_type||t.chat_type,this.secret_code=t.secret_code,this.participants=t.participants,this.options=t.options,this.topics=[],this.last_comment=t.last_comment,this.comments=[],this.count_notif=t.unread_count,this.isLoaded=!1,this.custom_title=null,this.custom_subtitle=null,this.options=t.options,this.unique_id=t.unique_id,this.isChannel=t.is_public_channel,this.participantNumber=t.room_total_participants,t.comments&&this.receiveComments(t.comments)}return f()(e,[{key:"isCurrentlySelected",value:function(e){return this.id===e.id}},{key:"getParticipantCount",value:function(){return null==this.participants?this.participantNumber:this.participants.length}},{key:"setTitle",value:function(e){this.custom_title=e}},{key:"setSubTitle",value:function(e){this.custom_subtitle=e}},{key:"receiveComment",value:function(e){if(e.room_id===this.id){var t=this.comments.find((function(t){return t.unique_id===e.unique_id}));t?(t.id=e.id,t.message=e.message,t.date=e.date,t.time=e.time,t.unix_timestamp=e.unix_timestamp):this.comments.push(e)}}},{key:"receiveComments",value:function(e){var t=this;e.forEach((function(e){t.receiveComment(new C(e))}))}},{key:"getParticipant",value:function(e){return this.participants.find((function(t){return t.email===e}))||null}},{key:"addParticipant",value:function(e){this.getParticipant(e.email)||this.participants.push(e)}}]),e}(),R=function(){function e(t){var n=t.baseURL,r=t.AppId,i=t.userId,o=t.version,s=t.getCustomHeader;l()(this,e),this.baseURL=n,this.token=null,this.userId=i,this.AppId=r,this.version=o,this.getCustomHeader=s}return f()(e,[{key:"setToken",value:function(e){this.token=e}},{key:"get",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;return new Promise((function(i,o){var s=g.a.get("".concat(t.baseURL,"/").concat(e));r&&r.baseURL&&(s=g.a.get("".concat(r.baseURL,"/").concat(e))),(s=t.setupHeaders(s,n)).end((function(e,t){return e?o(e):i(t)}))}))}},{key:"get_request",value:function(e){var t=g.a.get("".concat(this.baseURL,"/").concat(e));return t=this.setupHeaders(t,{})}},{key:"post",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,o){var s=g.a.post("".concat(t.baseURL,"/").concat(e));(s=t.setupHeaders(s,r)).send(n).set("Content-Type","application/x-www-form-urlencoded").end((function(e,t){return e?o(e):i(t)}))}))}},{key:"post_json",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,o){var s=g.a.post("".concat(t.baseURL,"/").concat(e));(s=t.setupHeaders(s,r)).send(n).set("Content-Type","application/json").end((function(e,t){return e?o(e):i(t)}))}))}},{key:"put",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,o){var s=g.a.put("".concat(t.baseURL,"/").concat(e));(s=t.setupHeaders(s,r)).send(n).set("Content-Type","application/x-www-form-urlencoded").end((function(e,t){return e?o(e):i(t)}))}))}},{key:"patch",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,o){var s=g.a.patch("".concat(t.baseURL,"/").concat(e));(s=t.setupHeaders(s,r)).send(n).set("Content-Type","application/x-www-form-urlencoded").end((function(e,t){return e?o(e):i(t)}))}))}},{key:"del",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,o){var s=g.a.del("".concat(t.baseURL,"/").concat(e));(s=t.setupHeaders(s,r)).send(n).set("Content-Type","application/json").end((function(e,t){return e?o(e):i(t)}))}))}},{key:"setupHeaders",value:function(e,t){if(e.set("QISCUS-SDK-APP-ID","".concat(this.AppId)),e.set("QISCUS-SDK-USER-ID","".concat(this.userId)),e.set("QISCUS-SDK-TOKEN","".concat(this.token)),e.set("QISCUS-SDK-VERSION","".concat(this.version)),null!=this.getCustomHeader){var n=this.getCustomHeader();Object.keys(n).forEach((function(t){e.set(t,n[t])}))}if(Object.keys(t).length<1)return e;for(var r in t)t.hasOwnProperty(r)&&e.set(r,t[r]);return e}}]),e}(),A=function(){function e(t){l()(this,e),this.HTTPAdapter=t}return f()(e,[{key:"getNonce",value:function(){return this.HTTPAdapter.post("api/v2/sdk/auth/nonce").then((function(e){return e.body.results}))}},{key:"loginOrRegister",value:function(e){return this.HTTPAdapter.post("api/v2/sdk/login_or_register",e).then((function(e){return 200!==e.body.status?Promise.reject(e):e.body.results}))}},{key:"verifyIdentityToken",value:function(e){return this.HTTPAdapter.post("api/v2/sdk/auth/verify_identity_token",{identity_token:e}).then((function(e){return e.body.results}))}}]),e}(),I=n(60),P=n.n(I);function O(e){var t={},n=function(e,t){return"".concat(e,"=").concat(t)};return{param:function(e,n){return t[e]=n,this},build:function(){var r=Object.keys(t).filter((function(e){return null!=t[e]})).map((function(e){return Array.isArray(t[e])?t[e].map((function(t){return n("".concat(e,"[]"),t)})).join("&"):n(e,t[e])})).join("&");return[e].concat(r).join("?")}}}var M=function(){function e(t){var n=this;l()(this,e),p()(this,"updateCommentStatus",P()((function(e,t,r){var i={room_id:e};return t&&(i.last_comment_read_id=t),r&&(i.last_comment_received_id=r),n.HTTPAdapter.post("api/v2/sdk/update_comment_status",i)}),500)),this.HTTPAdapter=t,this.token=t.token}return f()(e,[{key:"postComment",value:function(e,t,n,r,i,o){return this.HTTPAdapter.post_json("api/v2/sdk/post_comment",{comment:t,topic_id:e,unique_temp_id:n,type:r,payload:i,extras:o}).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.comment)}))}},{key:"loadRoomList",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=O("api/v2/sdk/user_rooms").param("page",t.page).param("show_participants",t.show_participants||!0).param("limit",t.limit).param("show_empty",t.show_empty).param("room_type",null!==(e=t.room_type)&&void 0!==e?e:"default").build();return this.HTTPAdapter.get(n).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.rooms_info)}))}},{key:"searchMessages",value:function(e){var t={query:e.query||null,room_id:e.room_id||null,last_comment_id:e.last_comment_id||null};return this.HTTPAdapter.post("api/v2/sdk/search_messages",t).then((function(e){return e.body.results.comments}))}},{key:"updateProfile",value:function(e){var t={name:e.name||null,avatar_url:e.avatar_url||null,extras:e.extras?JSON.stringify(e.extras):null};return this.HTTPAdapter.patch("api/v2/sdk/my_profile",t).then((function(e){return e.body.results.user}))}},{key:"uploadFile",value:function(e){var t={file:e};return this.HTTPAdapter.post("api/v2/sdk/upload",t).then((function(e){return e.body}))}},{key:"getRoomsInfo",value:function(e){var t={show_participants:!0,show_removed:!1};return e.room_ids&&(t.room_id=e.room_ids),e.room_unique_ids&&(t.room_unique_id=e.room_unique_ids),e.show_participants&&(t.show_participants=e.show_participants),e.show_removed&&(t.show_removed=e.show_removed),this.HTTPAdapter.post_json("api/v2/sdk/rooms_info",t).then((function(e){return e.body}))}},{key:"loadComments",value:function(e,t){var n=O("api/v2/sdk/load_comments").param("topic_id",e).param("last_comment_id",t.last_comment_id).param("timestamp",t.timestamp).param("after",t.after).param("limit",t.limit).build();return this.HTTPAdapter.get(n).then((function(e){return 200!==e.status?Promise.reject(e):Promise.resolve(e.body.results.comments)}))}},{key:"deleteComment",value:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];!1===n&&console.warn("Deprecated: delete comment for me will be removed on next release"),!1===r&&console.warn("Deprecated: soft delete will be removed on next release");var i={unique_ids:t,is_delete_for_everyone:n,is_hard_delete:r};return this.HTTPAdapter.del("api/v2/sdk/delete_messages",i).then((function(e){return e.body}))}},{key:"clearRoomMessages",value:function(e){var t={room_channel_ids:e};return this.HTTPAdapter.del("api/v2/sdk/clear_room_messages",t).then((function(e){return e.body}))}},{key:"getCommentReceiptStatus",value:function(e){return this.HTTPAdapter.get("api/v2/sdk/comment_receipt?comment_id=".concat(e)).then((function(e){return e.body}))}},{key:"getBlockedUser",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,n="api/v2/sdk/get_blocked_users?page=".concat(e,"&limit=").concat(t);return this.HTTPAdapter.get(n).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.blocked_users)}))}},{key:"blockUser",value:function(e){if(!e)throw new Error("email is required");var t={user_email:e};return this.HTTPAdapter.post("api/v2/sdk/block_user",t).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.user)}))}},{key:"unblockUser",value:function(e){if(!e)throw new Error("email is required");var t={user_email:e};return this.HTTPAdapter.post("api/v2/sdk/unblock_user",t).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.user)}))}},{key:"getProfile",value:function(){return this.HTTPAdapter.get("api/v2/sdk/my_profile").then((function(e){return e.body.results.user}))}},{key:"getUserPresences",value:function(e){var t={user_ids:e};return this.HTTPAdapter.post_json("api/v2/sdk/users/status",t).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.user_status)}))}},{key:"updateMessage",value:function(e){var t={token:this.token,comment:e.message,unique_id:e.unique_id||e.unique_temp_id};return null!=e.extras&&(t.extras=e.extras),null!=e.payload&&(t.payload=e.payload),this.HTTPAdapter.post_json("api/v2/sdk/update_message",t).then((function(e){return e.body.results.comment}))}}]),e}(),L=function(){function e(t){l()(this,e),this.HTTPAdapter=t,this.token=t.token}return f()(e,[{key:"getOrCreateRoom",value:function(e,t,n){var r={emails:e};return n&&(r[n]=n),t&&(r.options=JSON.stringify(t)),this.HTTPAdapter.post("api/v2/sdk/get_or_create_room_with_target",r).then((function(t){if(200!==t.body.status)return Promise.reject(t);var n=t.body.results.room;n.avatar=n.avatar_url,n.comments=t.body.results.comments.reverse();var r=n.participants.find((function(t){return t.email===e}));return n.name=r?r.username:"Room name",Promise.resolve(n)}))}},{key:"getRoomById",value:function(e){return this.HTTPAdapter.get("api/v2/sdk/get_room_by_id?id=".concat(e)).then((function(e){return e.body}))}},{key:"getOrCreateRoomByUniqueId",value:function(e,t,n){var r={unique_id:e,name:t,avatar_url:n};return this.HTTPAdapter.post("api/v2/sdk/get_or_create_room_with_unique_id",r).then((function(e){if(200!==e.body.status)return Promise.reject(e);var t=e.body.results.room;return t.avatar=t.avatar_url,t.comments=e.body.results.comments.reverse(),t.name=t.room_name,Promise.resolve(t)}))}},{key:"createRoom",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=Object.keys(r).length<=0?null:JSON.stringify(r),o={name:e,"participants[]":t,avatar_url:n.avatarURL,options:i};return this.HTTPAdapter.post("api/v2/sdk/create_room",o).then((function(e){if(200!==e.body.status)return Promise.reject(e);var t=e.body.results.room;return t.comments=e.body.results.comments,Promise.resolve({id:t.id,name:t.room_name,lastCommentId:t.last_comment_id,lastCommentMessage:t.last_comment_message,lastTopicId:t.last_topic_id,avatarURL:t.avatar_url,options:t.options,participants:t.participants.map((function(e){return{id:e.id,email:e.email,username:e.username,avatarURL:e.avatar_url}}))})}))}},{key:"updateRoom",value:function(e){if(!e.id)throw new Error("id is required");var t={id:e.id};return e.room_name&&(t.room_name=e.room_name),e.avatar_url&&(t.avatar_url=e.avatar_url),e.options&&(t.options=JSON.stringify(e.options)),this.HTTPAdapter.post("api/v2/sdk/update_room",t).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.room)}))}},{key:"getTotalUnreadCount",value:function(){return this.HTTPAdapter.get("api/v2/sdk/total_unread_count").then((function(e){return e.body.results.total_unread_count}))}},{key:"getRoomUnreadCount",value:function(){return this.HTTPAdapter.get("api/v2/sdk/get_room_unread_count").then((function(e){return e.body.results.total_unread_count}))}},{key:"addParticipantsToGroup",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(!e||!t)throw new Error("room_id and emails is required");var n={room_id:e,"emails[]":t};return this.HTTPAdapter.post("api/v2/sdk/add_room_participants",n).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.participants_added)}))}},{key:"removeParticipantsFromGroup",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(!e||!t)throw new Error("room_id and emails is required");var n={room_id:e,"emails[]":t};return this.HTTPAdapter.post("api/v2/sdk/remove_room_participants",n).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.participants_removed)}))}}]),e}(),D=n(61),j=n.n(D),U=n(62),q=n.n(U),F=String("match.pattern.catchAll"),N=String("match.pattern.OR"),B=N.toString(),H=String("match.pattern.AND"),W=H.toString(),Y=String("match.pattern.RANGE"),z=Y.toString(),$=String("match.pattern.REGEXP"),V=$.toString(),K=/\/(.*)\/(.*)/;function Q(){Error.call(this,"Missing when() catch-all pattern as last match argument, add [when()]: void 0"),"stack"in this||(this.stack=(new Error).stack)}function G(e){return void 0===e?F:e instanceof RegExp?X([$.toString(),e.toString()]):X(e)}function X(e){return JSON.stringify([G.__uid++,e])}function J(){return!0}function Z(e){if(Array.isArray(e)){if(e[0]===B)return e.shift(),function(t){return e[0].some((function(e){return n(e,t)}))};if(e[0]===W)return e.shift(),function(t){return e[0].every((function(e){return n(e,t)}))};if(e[0]===z)return e.shift(),function(t){return e[0]<=t&&t<=e[1]};if(e[0]===V){var t=K.exec(e[1]);return n.bind(null,new RegExp(t[1],t[2]))}}function n(e,t){if(Array.isArray(t))return JSON.stringify(e)===JSON.stringify(t);if(e instanceof RegExp)return e.test(t);if("object"===q()(t)){for(var n in e)if(t[n]!==e[n])return!1;return!0}return e===t}return function(t){return n(e,t)}}Q.prototype=Object.create(Error.prototype),G.__uid=0,G.or=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return X([N.toString(),t])},G.and=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return X([H.toString(),t])},G.range=function(e,t){return X([Y.toString(),e,t])},G.unserialize=function(e,t){if(e===F)return{match:J,result:t,position:1/0};var n,r=(n=e,JSON.parse(n)),i=r[1],o=r[0];return{match:Z(i),result:t,position:o}};var ee=n(63),te=n.n(ee),ne=n(64),re=n.n(ne),ie=function(e,t,n,r){try{var i=e();return null!=r&&r(i),i}catch(e){return null!=n&&n(e),t}},oe=function(e){return e.then((function(e){return[e,null]})).catch((function(e){return[null,e]}))},se=function(){function e(t,n,r,o){var a,c=this,h=o.shouldConnect,f=void 0===h||h,d=o.brokerLbUrl,m=o.enableLb,g=o.getClientId;l()(this,e),p()(this,"_getClientId",(function(){return null==c.getClientId?"".concat(c.core.AppId,"_").concat(c.core.user_id,"_").concat(Date.now()):c.getClientId()})),p()(this,"__mqtt_connected_handler",(function(){c.emitter.emit("connected")})),p()(this,"__mqtt_reconnect_handler",(function(){c.emitter.emit("reconnect")})),p()(this,"__mqtt_closed_handler",(function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];c.emitter.emit("close",t)})),p()(this,"__mqtt_message_handler",(function(e,t){var n=t.toString(),r=c.matcher(e);c.logger("message",e,t),null!=r&&r(n)})),p()(this,"__mqtt_error_handler",(function(e){e&&"client disconnecting"===e.message||(c.emitter.emit("error",e.message),c.logger("error",e.message))})),p()(this,"__mqtt_conneck",(function(e){var t=[],n={will:{topic:"u/".concat(c.core.user_id,"/s"),payload:0,retain:!0},clientId:c._getClientId()};if(null==e&&(e=c.cacheRealtimeURL),null!=c.mqtt){var r=Object.keys(c.mqtt._resubscribeTopics);t.push.apply(t,i()(r)),c.mqtt.removeAllListeners(),c.mqtt.end(!0),delete c.mqtt,c.mqtt=null}var o=te()(e,n);return o.addListener("connect",c.__mqtt_connected_handler),o.addListener("reconnect",c.__mqtt_reconnect_handler),o.addListener("close",c.__mqtt_closed_handler),o.addListener("error",c.__mqtt_error_handler),o.addListener("message",c.__mqtt_message_handler),c.logger("resubscribe to old topics ".concat(t)),t.forEach((function(e){return o.subscribe(e)})),o})),p()(this,"_on_close_handler",re()(u()(s.a.mark((function e(){var t,n,r,i;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=!0===c.enableLb&&!0===c.core.isLogin&&!0===c.shouldConnect&&!c.willConnectToRealtime,c.logEnabled&&(console.group("@mqtt.closed"),console.log("this.enableLb(".concat(c.enableLb,")")),console.log("this.core.isLogin(".concat(c.core.isLogin,")")),console.log("this.shouldConnect(".concat(c.shouldConnect,")")),console.log("this.willConnectToRealtime(".concat(c.willConnectToRealtime,")")),console.log("shouldReconnect(".concat(t,")")),console.groupEnd()),t){e.next=4;break}return e.abrupt("return");case 4:return c.willConnectToRealtime=!0,e.next=7,oe(c.getMqttNode());case 7:n=e.sent,r=j()(n,2),i=r[0],r[1]?(c.logger("cannot get new brokerURL, using old url instead (".concat(c.cacheRealtimeURL,")")),c.mqtt=c.__mqtt_conneck(c.cacheRealtimeURL)):(c.cacheRealtimeURL=i,c.logger("trying to reconnect to",i),c.mqtt=c.__mqtt_conneck(i)),c.willConnectToRealtime=!1;case 13:case"end":return e.stop()}}),e)}))),1e3)),p()(this,"subscribtionBuffer",[]),p()(this,"unsubscribtionBuffer",[]),p()(this,"publishBuffer",[]),this.emitter=b(),this.core=n,this.mqtt=null,this.brokerLbUrl=d,this.getClientId=g,this.enableLb=m,this.shouldConnect=f,this.matcher=function(){var e,t=(e=arguments.length-1)<0||arguments.length<=e?void 0:arguments[e],n=[];for(var r in t)n.push(G.unserialize(r,t[r]));n.sort((function(e,t){return e.position<t.position?-1:1})),-1!==Object.getOwnPropertySymbols(t).indexOf(F)&&n.push(G.unserialize(F,t[F]));var i=function(e){var t=n.find((function(t){return t.match(e)}));if(!t)throw new Q;return"function"==typeof t.result?t.result(e):t.result};return 2===arguments.length?i(arguments.length<=0?void 0:arguments[0]):i}((a={},p()(a,G(this.reNewMessage),(function(e){return c.newMessageHandler.bind(c,e)})),p()(a,G(this.reNotification),(function(e){return c.notificationHandler.bind(c,e)})),p()(a,G(this.reTyping),(function(e){return c.typingHandler.bind(c,e)})),p()(a,G(this.reDelivery),(function(e){return c.deliveryReceiptHandler.bind(c,e)})),p()(a,G(this.reRead),(function(e){return c.readReceiptHandler.bind(c,e)})),p()(a,G(this.reOnlineStatus),(function(e){return c.onlinePresenceHandler.bind(c,e)})),p()(a,G(this.reChannelMessage),(function(e){return c.channelMessageHandler.bind(c,e)})),p()(a,G(this.reMessageUpdated),(function(e){return c.messageUpdatedHandler.bind(c,e)})),p()(a,G(),(function(e){return c.logger("topic not handled",e)})),a));var y=this.__mqtt_conneck(t);this.mqtt=y,f||y.end(!0),this.willConnectToRealtime=!1,this.emitter.on("close",this._on_close_handler)}var t,n,r;return f()(e,[{key:"connect",value:function(){this.mqtt=this.__mqtt_conneck()}},{key:"openConnection",value:(r=u()(s.a.mark((function e(){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.shouldConnect=!0,this.__mqtt_conneck();case 2:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"closeConnection",value:(n=u()(s.a.mark((function e(){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.shouldConnect=!1,this.mqtt.end(!0);case 2:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getMqttNode",value:(t=u()(s.a.mark((function e(){var t,n,r;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,g.a.get(this.brokerLbUrl);case 2:return t=e.sent,n=t.body.data.url,r=t.body.data.wss_port,e.abrupt("return","wss://".concat(n,":").concat(r,"/mqtt"));case 6:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"subscribe",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(this.logger("subscribe to",t),this.subscribtionBuffer.push(t),null!=this.mqtt)do{var r,i=this.subscribtionBuffer.shift();null!=i&&(r=this.mqtt).subscribe.apply(r,t)}while(this.subscribtionBuffer.length>0)}},{key:"unsubscribe",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(this.logger("unsubscribe from",t),this.unsubscribtionBuffer.push(t),null!=this.mqtt)do{var r,o=this.unsubscribtionBuffer.shift();if(null!=o)(r=this.mqtt).unsubscribe.apply(r,i()(o))}while(this.unsubscribtionBuffer.length>0)}},{key:"publish",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.publishBuffer.push({topic:e,payload:t,options:n});do{var r=this.publishBuffer.shift();if(null!=r)return this.mqtt.publish(r.topic,r.payload.toString(),r.options)}while(this.publishBuffer.length>0)}},{key:"emit",value:function(){var e;(e=this.emitter).emit.apply(e,arguments)}},{key:"on",value:function(){var e;(e=this.emitter).on.apply(e,arguments)}},{key:"off",value:function(){var e;(e=this.emitter).off.apply(e,arguments)}},{key:"noop",value:function(){}},{key:"newMessageHandler",value:function(e,t){t=JSON.parse(t),this.logger("on:new-message",t),this.emit("new-message",t)}},{key:"notificationHandler",value:function(e,t){var n=this;this.logger("on:notification",t);var r=(t=JSON.parse(t)).payload.data;"deleted_messages"in r&&r.deleted_messages.forEach((function(e){n.emit("comment-deleted",{roomId:e.room_id,commentUniqueIds:e.message_unique_ids,isForEveryone:!0,isHard:!0})})),"deleted_rooms"in r&&r.deleted_rooms.forEach((function(e){n.emit("room-cleared",e)}))}},{key:"typingHandler",value:function(e,t){this.logger("on:typing",e);var n=e.match(this.reTyping);if(n[3]!==this.core.user_id){var r=n[3],i=n[1];if(this.emit("typing",{message:t,userId:r,roomId:i}),null!=this.core.selected)if("1"===t&&i===this.core.selected.id){var o=this.core.selected.participants.find((function(e){return e.email===r}));if(null==o)return;var s=o.username;this.core.isTypingStatus="".concat(s," is typing ...")}else this.core.isTypingStatus=null}}},{key:"deliveryReceiptHandler",value:function(e,t){this.logger("on:delivered",e,t);var n=e.match(this.reDelivery),r=t.split(":"),i=Number(r[0]),o=r[1],s=n[3];this.emit("message-delivered",{commentId:i,commentUniqueId:o,userId:s})}},{key:"readReceiptHandler",value:function(e,t){this.logger("on:read",e,t);var n=e.match(this.reRead),r=t.split(":"),i=Number(r[0]),o=r[1],s=n[3];this.emit("message-read",{commentId:i,commentUniqueId:o,userId:s})}},{key:"onlinePresenceHandler",value:function(e,t){this.logger("on:online-presence",e,t);var n=this.reOnlineStatus.exec(e)[1];this.emit("presence",{message:t,userId:n})}},{key:"channelMessageHandler",value:function(e,t){this.logger("on:channel-message",e,t),this.emit("new-message",JSON.parse(t))}},{key:"messageUpdatedHandler",value:function(e,t){t=JSON.parse(t),this.logger("on:message-updated",e,t),this.emit("message:updated",t)}},{key:"subscribeChannel",value:function(e,t){this.subscribe("".concat(e,"/").concat(t,"/c"))}},{key:"subscribeRoom",value:function(e){null!=this.core.selected&&(e=e||this.core.selected.id,this.subscribe("r/".concat(e,"/").concat(e,"/+/t")),this.subscribe("r/".concat(e,"/").concat(e,"/+/d")),this.subscribe("r/".concat(e,"/").concat(e,"/+/r")))}},{key:"unsubscribeRoom",value:function(e){null!=this.core.selected&&(e=e||this.core.selected.id,this.unsubscribe("r/".concat(e,"/").concat(e,"/+/t")),this.unsubscribe("r/".concat(e,"/").concat(e,"/+/d")),this.unsubscribe("r/".concat(e,"/").concat(e,"/+/r")))}},{key:"subscribeUserChannel",value:function(){this.subscribe("".concat(this.core.userData.token,"/c")),this.subscribe("".concat(this.core.userData.token,"/n")),this.subscribe("".concat(this.core.userData.token,"/update"))}},{key:"publishPresence",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];t?this.publish("u/".concat(e,"/s"),1,{retain:!0}):this.publish("u/".concat(e,"/s"),0,{retain:!0})}},{key:"disconnect",value:function(){this.publishPresence(this.core.userData.email,!1),this.unsubscribe(Object.keys(this.mqtt._resubscribeTopics))}},{key:"subscribeUserPresence",value:function(e){this.subscribe("u/".concat(e,"/s"))}},{key:"unsubscribeUserPresence",value:function(e){this.unsubscribe("u/".concat(e,"/s"))}},{key:"publishTyping",value:function(e){if(null!=this.core.selected){var t=this.core.selected.id,n=this.core.user_id;this.publish("r/".concat(t,"/").concat(t,"/").concat(n,"/t"),e)}}},{key:"cacheRealtimeURL",get:function(){return this.core.mqttURL},set:function(e){this.core.mqttURL=e}},{key:"connected",get:function(){return null!=this.mqtt&&this.mqtt.connected}},{key:"logEnabled",get:function(){return this.core.debugMQTTMode}},{key:"logger",get:function(){return this.core.debugMQTTMode?console.log.bind(console,"QRealtime ->"):this.noop}},{key:"reNewMessage",get:function(){return/^(.+)\/c$/i}},{key:"reNotification",get:function(){return/^(.+)\/n$/i}},{key:"reTyping",get:function(){return/^r\/([\d]+)\/([\d]+)\/(.+)\/t$/i}},{key:"reDelivery",get:function(){return/^r\/([\d]+)\/([\d]+)\/(.+)\/d$/i}},{key:"reRead",get:function(){return/^r\/([\d]+)\/([\d]+)\/(.+)\/r$/i}},{key:"reOnlineStatus",get:function(){return/^u\/(.+)\/s$/i}},{key:"reChannelMessage",get:function(){return/^(.+)\/(.+)\/c$/i}},{key:"reMessageUpdated",get:function(){return/^(.+)\/update$/i}},{key:"subscribeTyping",get:function(){return this.subscribeRoom.bind(this)}},{key:"unsubscribeTyping",get:function(){return this.unsubscribeRoom.bind(this)}},{key:"subscribeRoomPresence",get:function(){return this.subscribeUserPresence.bind(this)}},{key:"unsubscribeRoomPresence",get:function(){return this.unsubscribeUserPresence.bind(this)}}]),e}();function ae(e,t){var n=b(),r={},i=/^r\/[\w]+\/[\w]+\/e$/i;e.mqtt.on("message",(function(e,t){i.test(e)&&n.emit(e,t)}));var o=function(e){return"r/".concat(e,"/").concat(e,"/e")};return{publishEvent:function(n,r){if(v.a.undefined(n))throw new Error("`roomId` required");if(v.a.not.string(n))throw new TypeError("`roomId` must have type of string");if(v.a.undefined(r))throw new Error("`payload` required");if(v.a.not.object(r))throw new TypeError("`payload` must have type of object");var i=JSON.stringify({sender:t,data:r});e.mqtt.publish(o(n),i)},subscribeEvent:function(t,i){if(v.a.undefined(t))throw new Error("`roomId` required");if(v.a.not.string(t))throw new TypeError("`roomId` must have type of string");if(v.a.undefined(i))throw new Error("`callback` required");if(v.a.not.function(i))throw new TypeError("`callback` must have type of function");var s=o(t);if(!r[s]){e.mqtt.subscribe(s);var a=function(e){var t=JSON.parse(e);i(t)};n.on(s,a),r[s]=a}},unsubscribeEvent:function(t){if(v.a.undefined(t))throw new Error("`roomId` required");if(v.a.not.string(t))throw new TypeError("`roomId` must have type of string");var i=o(t);r[i]&&(e.mqtt.unsubscribe(i),n.off(i,r[i]),r[i]=null,delete r[i])}}}var ue=n(29),ce=n.n(ue),le=n(30),he=n.n(le),fe=n(31),de=n.n(fe),pe=function(){},me=function(e){return new Promise((function(t){return setTimeout(t,e)}))};function ge(e,t){var n=t.isDebug,r=void 0!==n&&n,i=t.syncInterval,o=t.getShouldSync,a=t.syncOnConnect,c=t.lastCommentId,l=t.statusLogin,h=b(),f=function(){for(var e,t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return r?(e=console).log.apply(e,["QSync:"].concat(n)):{}},d=0,p=function(){if(l())return o()?i():a()},m=function(e,t,n,r,i){var o=b(),a=function(n){var r=O("api/v2/sdk/sync").param("last_received_comment_id",n).build();return e().get(r).then((function(e){var n=e.body.results,r=n.comments,i=n.meta.last_received_comment_id;return r.sort((function(e,t){return e.id-t.id})),Promise.resolve({lastMessageId:i,messages:r,interval:t()})})).catch(pe)};function c(){return l.apply(this,arguments)}function l(){return(l=de()(s.a.mark((function i(){var o,u,c;return s.a.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:o=0,u=100,c=function(){return null!=e()&&n()};case 3:if(!((o+=u)>=t()&&c)){i.next=9;break}return o=0,i.next=9,a(r());case 9:return i.next=11,he()(me(u));case 11:i.next=3;break;case 13:case"end":return i.stop()}}),i)})))).apply(this,arguments)}return{get synchronize(){return a},get on(){return o.on},get off(){return o.off},run:function(){return u()(s.a.mark((function e(){var t,n,a,u,l,h,f,d,p;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=!0,n=!1,e.prev=2,u=ce()(c());case 4:return e.next=6,u.next();case 6:return l=e.sent,t=l.done,e.next=10,l.value;case 10:if(h=e.sent,t){e.next=17;break}f=h;try{d=f.lastMessageId,p=f.messages,d>r()&&(p.forEach((function(e){return o.emit("message.new",e)})),o.emit("last-message-id.new",d))}catch(e){i("error when sync",e.message)}case 14:t=!0,e.next=4;break;case 17:e.next=23;break;case 19:e.prev=19,e.t0=e.catch(2),n=!0,a=e.t0;case 23:if(e.prev=23,e.prev=24,t||null==u.return){e.next=28;break}return e.next=28,u.return();case 28:if(e.prev=28,!n){e.next=31;break}throw a;case 31:return e.finish(28);case 32:return e.finish(23);case 33:case"end":return e.stop()}}),e,null,[[2,19,23,33],[24,,28,32]])})))()}}}(e,p,o,c,f);m.on("last-message-id.new",(function(e){return lastMessageId=e})),m.on("message.new",(function(e){return h.emit("message.new",e)})),m.run().catch((function(e){return f("got error when sync",e)}));var g=function(e,t,n,r,i){var o=b(),a=function(n){var r=O("api/v2/sdk/sync_event").param("start_event_id",n).build();return e().get(r).then((function(e){var n=e.body.events,r=n.map((function(e){return e.id})).sort((function(e,t){return e-t})).pop(),i=n.filter((function(e){return"delivered"===e.action_topic})).map((function(e){return e.payload.data})),o=n.filter((function(e){return"read"===e.action_topic})).map((function(e){return e.payload.data})),s=n.filter((function(e){return"delete_message"===e.action_topic})).map((function(e){return e.payload.data})),a=n.filter((function(e){return"clear_room"===e.action_topic})).map((function(e){return e.payload.data}));return Promise.resolve({lastId:r,messageDelivered:i,messageRead:o,messageDeleted:s,roomCleared:a,interval:t()})})).catch(pe)};function c(){return l.apply(this,arguments)}function l(){return(l=de()(s.a.mark((function i(){var o,u,c;return s.a.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:o=0,u=100,c=function(){return null!=e()&&n()};case 3:if(!((o+=u)>=t()&&c)){i.next=9;break}return o=0,i.next=9,a(r());case 9:return i.next=11,he()(me(u));case 11:i.next=3;break;case 13:case"end":return i.stop()}}),i)})))).apply(this,arguments)}return{get synchronize(){return a},get on(){return o.on},get off(){return o.off},run:function(){return u()(s.a.mark((function e(){var t,n,a,u,l,h,f,d;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=!0,n=!1,e.prev=2,u=ce()(c());case 4:return e.next=6,u.next();case 6:return l=e.sent,t=l.done,e.next=10,l.value;case 10:if(h=e.sent,t){e.next=17;break}f=h;try{(d=f.lastId)>r()&&(o.emit("last-event-id.new",d),f.messageDelivered.forEach((function(e){return o.emit("message.delivered",e)})),f.messageDeleted.forEach((function(e){return o.emit("message.deleted",e)})),f.messageRead.forEach((function(e){return o.emit("message.read",e)})),f.roomCleared.forEach((function(e){return o.emit("room.cleared",e)})))}catch(e){i("error when sync event",e.message)}case 14:t=!0,e.next=4;break;case 17:e.next=23;break;case 19:e.prev=19,e.t0=e.catch(2),n=!0,a=e.t0;case 23:if(e.prev=23,e.prev=24,t||null==u.return){e.next=28;break}return e.next=28,u.return();case 28:if(e.prev=28,!n){e.next=31;break}throw a;case 31:return e.finish(28);case 32:return e.finish(23);case 33:case"end":return e.stop()}}),e,null,[[2,19,23,33],[24,,28,32]])})))()}}}(e,p,o,(function(){return d}),f);return g.on("last-event-id.new",(function(e){d=e})),g.on("message.read",(function(e){h.emit("message.read",e)})),g.on("message.delivered",(function(e){return h.emit("message.delivered",e)})),g.on("message.deleted",(function(e){return h.emit("message.deleted",e)})),g.on("room.cleared",(function(e){return h.emit("room.cleared",e)})),g.run().catch((function(e){return f("got error when sync event",e)})),{get on(){return h.on},get off(){return h.off},synchronize:function(){m.synchronize()},synchronizeEvent:function(){g.synchronize()}}}var be,ye=n(65),ve={MESSAGE_BEFORE_SENT:"message::before-sent",MESSAGE_BEFORE_RECEIVED:"message::before-received"};function _e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function we(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?_e(Object(n),!0).forEach((function(t){p()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):_e(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function ke(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Se(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Se(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,a=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,o=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw o}}}}function Se(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var Ee=Object.freeze({disabled:"UpdateCommentStatusMode.disabled",throttled:"UpdateCommentStatusMode.throttled",enabled:"UpdateCommentStatusMode.enabled"}),Te=function(){function e(){var t,n,r=this;l()(this,e),p()(this,"_readComment",(function(e,t){return r._updateStatus(e,t)})),p()(this,"_readCommentT",this._throttle((function(e,t){r._updateStatus(e,t)}),(function(){return r._throttleDelay}))),p()(this,"_deliverComment",(function(e,t){return r._updateStatus(e,void 0,t)})),p()(this,"_deliverCommentT",this._throttle((function(e,t){r._updateStatus(e,void 0,t)}),(function(){return r._throttleDelay}))),this.events=b(),this.rooms=[],this.selected=null,this.room_name_id_map={},this.pendingCommentId=0,this.uploadedFiles=[],this.chatmateStatus=null,this.version="WEB_".concat(ye.version),this.userData={},this.AppId=null,this.baseURL="https://api.qiscus.com",this.mqttURL="wss://realtime-jogja.qiscus.com:1886/mqtt",this.brokerLbUrl="https://realtime-lb.qiscus.com",this.syncOnConnect=1e4,this.enableEventReport=!1,this.enableRealtime=!0,this.enableRealtimeCheck=!0,this.HTTPAdapter=null,this.realtimeAdapter=null,this.customEventAdapter=null,this.isInit=!1,this.isSynced=!1,this.syncInterval=5e3,this.sync="socket",this.enableLb=!0,this.httpsync=null,this.eventsync=null,this.extras=null,this.last_received_comment_id=0,this.googleMapKey="",this.options={avatar:!0},this.isConfigLoaded=!1,this.updateCommentStatusMode=e.UpdateCommentStatusMode.enabled,this.updateCommentStatusThrottleDelay=300,this.UI={},this.mode="widget",this.avatar=!0,this.plugins=[],this.isLogin=!1,this.isLoading=!1,this.isInit=!1,this.emoji=!1,this.isTypingStatus="",this.customTemplate=!1,this.templateFunction=null,this.debugMode=!1,this.debugMQTTMode=!1,this._customHeader={},this.lastReceiveMessages=[],this._hookAdapter=(t={},n=function(e){return Array.isArray(t[e])||(t[e]=[]),t[e]},{trigger:function(e,t){return n(e).reduce((function(e,t){return Promise.resolve(e).then(t)}),Promise.resolve(t))},intercept:function(e,t){n(e).push(t);var r=n(e).length;return function(){return n(e).splice(r,1)}}}),this._uploadURL=null}var t,n,r,o,a,c,h,d,m,y,_;return f()(e,[{key:"init",value:(_=u()(s.a.mark((function e(t){var n,r,i,o,a,c=this;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.AppId){e.next=2;break}throw new Error("Please provide valid AppId");case 2:return this.AppId=t.AppId,n=null!=t.baseURL&&this.baseURL!==t.baseURL,r=null!=t.mqttURL&&this.mqttURL!==t.mqttURL,i=null!=t.brokerLbURL&&this.brokerLbUrl!==t.brokerLbURL,!n&&!r||i?null!=t.enableRealtimeLB&&(this.enableLb=t.enableRealtimeLB):(this.logger("force disable load balancing for realtime server, because `baseURL` or `mqttURL` get changed but did not provide `brokerLbURL`"),this.enableLb=!1),null!=t.updateCommentStatusMode&&(this.updateCommentStatusMode=t.updateCommentStatusMode),null!=t.updateCommentStatusThrottleDelay&&(this.updateCommentStatusThrottleDelay=t.updateCommentStatusThrottleDelay),t.baseURL&&(this.baseURL=t.baseURL),t.mqttURL&&(this.mqttURL=t.brokerUrl||t.mqttURL),t.mqttURL&&(this.brokerUrl=t.brokerUrl||t.mqttURL),t.brokerLbURL&&(this.brokerLbUrl=t.brokerLbURL),t.uploadURL&&(this.uploadURL=t.uploadURL),t.sync&&(this.sync=t.sync),t.mode&&(this.mode=t.mode),t.syncInterval&&(this.syncInterval=t.syncInterval||5e3),t.googleMapKey&&(this.googleMapKey=t.googleMapKey),t.allowedFileTypes&&(this.allowedFileTypes=t.allowedFileTypes),t.options&&(this.options=Object.assign({},this.options,t.options)),t.customTemplate&&(this.customTemplate=t.customTemplate),t.templateFunction&&(this.templateFunction=t.templateFunction),null!=t.syncInterval&&(this.syncInterval=t.syncInterval),this.HTTPAdapter=new R({baseURL:this.baseURL,AppId:this.AppId,userId:this.user_id,version:this.version,getCustomHeader:function(){return c._customHeader}}),o=function(e,t,n){if(""==t&&null!=e){if("string"!=typeof e)return e;if(e.length>0)return e}if(null!=t){if(t.length>0)return t;if("string"!=typeof t)return t}return n},a=function(e){return e.includes("wss://")?e:"wss://".concat(e,":1886/mqtt")},e.next=28,this.HTTPAdapter.get_request("api/v2/sdk/config").then((function(e){return 200==e.status?c.isConfigLoaded=!0:c.isConfigLoaded=!1,e.body.results})).then((function(e){var n=c.baseURL,r=c.brokerLbUrl,i=c.mqttURL,s=c.enableRealtime,u=c.enableRealtimeCheck,l=c.syncInterval,h=c.syncOnConnect,f=c.enableEventReport;c.baseURL=o(t.baseURL,e.base_url,n),c.brokerLbUrl=o(t.brokerLbURL,e.broker_lb_url,r),c.mqttURL=a(o(t.mqttURL,e.broker_url,i)),c.enableRealtime=o(t.enableRealtime,e.enable_realtime,s),c.syncInterval=o(t.syncInterval,e.sync_interval,l),c.syncOnConnect=o(t.syncOnConnect,e.sync_on_connect,h),c.enableRealtimeCheck=o(null,e.enable_realtime_check,u),c.enableEventReport=o(null,e.enable_event_report,f),c.extras=o(null,e.extras,{})})).catch((function(e){c.logger("got error when trying to get app config",e),c.isConfigLoaded=!0}));case 28:this._getMqttClientId=function(){return"".concat(c.AppId,"_").concat(c.user_id,"_").concat(Date.now())},this.realtimeAdapter=new se(this.mqttURL,this,this.isLogin,{brokerLbUrl:this.brokerLbUrl,enableLb:this.enableLb,shouldConnect:this.enableRealtime,getClientId:this._getMqttClientId}),this.realtimeAdapter.on("connected",(function(){!c.isLogin&&c.realtimeAdapter.connected||(c.last_received_comment_id=c.userData.last_comment_id,c.updateLastReceivedComment(c.last_received_comment_id))})),this.realtimeAdapter.on("close",(function(){})),this.realtimeAdapter.on("reconnect",(function(){var e,t;null===(e=(t=c.options).onReconnectCallback)||void 0===e||e.call(t)})),this.realtimeAdapter.on("message-delivered",(function(e){var t=e.commentId,n=e.commentUniqueId,r=e.userId;return c._setDelivered(t,n,r)})),this.realtimeAdapter.on("message-read",(function(e){var t=e.commentId,n=e.commentUniqueId,r=e.userId;return c._setRead(t,n,r)})),this.realtimeAdapter.on("new-message",function(){var e=u()(s.a.mark((function e(t){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,c._hookAdapter.trigger(ve.MESSAGE_BEFORE_RECEIVED,t);case 2:t=e.sent,c.events.emit("newmessages",[t]);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),this.realtimeAdapter.on("presence",(function(e){return c.events.emit("presence",e)})),this.realtimeAdapter.on("comment-deleted",(function(e){return c.events.emit("comment-deleted",e)})),this.realtimeAdapter.on("room-cleared",(function(e){return c.events.emit("room-cleared",e)})),this.realtimeAdapter.on("typing",(function(e){return c.events.emit("typing",{message:e.message,username:e.userId,room_id:e.roomId})})),this.realtimeAdapter.on("message:updated",(function(e){null!=c.options.messageUpdatedCallback&&c.options.messageUpdatedCallback(e)})),this.syncAdapter=ge((function(){return c.HTTPAdapter}),{getToken:function(){return c.userData.token},syncInterval:function(){return c.syncInterval},getShouldSync:function(){return c.isLogin&&!c.realtimeAdapter.connected},syncOnConnect:function(){return c.syncOnConnect},lastCommentId:function(){return c.last_received_comment_id},statusLogin:function(){return c.isLogin}}),this.syncAdapter.on("message.new",function(){var e=u()(s.a.mark((function e(t){var n;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,c._hookAdapter.trigger(ve.MESSAGE_BEFORE_RECEIVED,t);case 2:t=e.sent,null!=c.selected?-1===c.selected.comments.findIndex((function(e){return e.id===t.id||e.unique_id===t.unique_temp_id}))&&((n=new C(t)).room_id===c.selected.id&&(c.selected.comments.push(n),c.sortComments()),c.events.emit("newmessages",[t])):c.events.emit("newmessages",[t]);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),this.syncAdapter.on("message.delivered",(function(e){c._setDelivered(e.comment_id,e.comment_unique_id,e.email)})),this.syncAdapter.on("message.read",(function(e){c._setRead(e.comment_id,e.comment_unique_id,e.email)})),this.syncAdapter.on("message.deleted",(function(e){e.deleted_messages.forEach((function(e){c.events.emit("comment-deleted",{roomId:e.room_id,commentUniqueIds:e.message_unique_ids,isForEveryone:!0,isHard:!0})}))})),this.syncAdapter.on("room.cleared",(function(e){e.deleted_rooms.forEach((function(e){c.events.emit("room-cleared",e)}))})),this.customEventAdapter=ae(this.realtimeAdapter,this.user_id),this.setEventListeners();case 49:case"end":return e.stop()}}),e,this)}))),function(e){return _.apply(this,arguments)})},{key:"_setRead",value:function(e,t,n){if(null!=this.selected){var r=this.selected,i=r.comments.find((function(n){return n.id===e||n.unique_id===t}));if(null!=i&&"read"!==i.status){var o={participants:r.participants,actor:n,comment_id:e,activeActorId:this.user_id};r.comments.forEach((function(e){e.id<=i.id&&e.markAsRead(o)})),i.isRead&&this.events.emit("comment-read",{comment:i,userId:n})}}}},{key:"_setDelivered",value:function(e,t,n){if(null!=this.selected){var r=this.selected,i=r.comments.find((function(n){return n.id===e||n.unique_id===t}));if(null!=i&&"read"!==i.status){var o={participants:r.participants,actor:n,comment_id:e,activeActorId:this.user_id};r.comments.forEach((function(e){e.id<=i.id&&e.markAsDelivered(o)})),i.isDelivered&&this.events.emit("comment-delivered",{comment:i,userId:n})}}}},{key:"setEventListeners",value:function(){var e=this,t=this;t.events.on("start-init",(function(){t.HTTPAdapter=new R({baseURL:t.baseURL,AppId:t.AppId,userId:t.user_id,version:t.version,getCustomHeader:function(){return e._customHeader}}),t.HTTPAdapter.setToken(t.userData.token),t.authAdapter=new A(t.HTTPAdapter)})),t.events.on("room-changed",(function(n){e.logging("room changed",n),t.options.roomChangedCallback&&t.options.roomChangedCallback(n)})),t.events.on("file-uploaded",(function(e){t.options.fileUploadedCallback&&t.options.fileUploadedCallback(e)})),t.events.on("profile-updated",(function(e){t.username=e.name,t.avatar_url=e.avatar_url,t.options.updateProfileCallback&&t.options.updateProfileCallback(e)})),t.events.on("newmessages",(function(n){e.logging("newmessages",n),e.lastReceiveMessages.length>0&&e.lastReceiveMessages[0].unique_temp_id===n[0].unique_temp_id?e.logging("lastReceiveMessages double",n):(e.lastReceiveMessages=n,t._callNewMessagesCallback(n),n.forEach((function(n){t.receiveComment(n.room_id,n.id);var r=!!t.selected&&n.room_id===t.selected.id,i=n.id<=t.last_received_comment_id;if(r){var o=t.selected,s=t.selected.comments[t.selected.comments.length-1];s.isPending||i||t.user_id===n.email||t.readComment(n.room_id,n.id);var a=s.id,u=t.selected.comments.find((function(e){return e.id===s.comment_before_id}));s.isPending||u||(e.logging("comment before id not found! ",n.comment_before_id),t.synchronize(a));var c=new C(n);o.receiveComment(c),o.last_comment_id=c.id,o.last_comment_message=c.message}t.updateLastReceivedComment(n.id),e.sortComments()})))})),this.events.on("login-success",(function(t){e.isLogin=!0,e.userData=t.user,e.last_received_comment_id=e.userData.last_comment_id,e.realtimeAdapter.connected||e.updateLastReceivedComment(e.last_received_comment_id),e.HTTPAdapter=new R({baseURL:e.baseURL,AppId:e.AppId,userId:e.user_id,version:e.version,getCustomHeader:function(){return e._customHeader}}),e.HTTPAdapter.setToken(e.userData.token),e.userAdapter=new M(e.HTTPAdapter),e.roomAdapter=new L(e.HTTPAdapter),e.realtimeAdapter.subscribeUserChannel(),null!=e.presensePublisherId&&-1!==e.presensePublisherId&&clearInterval(e.presensePublisherId),e.presensePublisherId=setInterval((function(){e.realtimeAdapter.publishPresence(e.user_id,!0)}),3500),e.options.loginSuccessCallback&&e.options.loginSuccessCallback(t)})),t.events.on("login-error",(function(e){t.options.loginErrorCallback&&t.options.loginErrorCallback(e)})),t.events.on("room-cleared",(function(e){if(t.selected){var n=t.selected;t.selected.unique_id===e.unique_id&&(t.selected=null,t.selected=n)}t.options.roomClearedCallback&&t.options.roomClearedCallback(e)})),t.events.on("comment-deleted",(function(e){var n=e.roomId,r=e.commentUniqueIds,i=(e.isForEveryone,e.isHard);t.selected&&t.selected.id==n&&r.map((function(e){var n=t.selected.comments.findIndex((function(t){return t.unique_id===e}));n>-1&&(i?t.selected.comments.splice(n,1):t.selected.comments[n].message="this message has been deleted")})),t.options.commentDeletedCallback&&t.options.commentDeletedCallback(e)})),t.events.on("comment-delivered",(function(e){return t.logging("comment-delivered",e),!!e&&(t.options.commentDeliveredCallback?t.options.commentDeliveredCallback(e):void 0)})),t.events.on("chat-room-created",(function(e){t.isLoading=!1,t.options.chatRoomCreatedCallback&&t.options.chatRoomCreatedCallback(e)})),t.events.on("group-room-created",(function(e){t.isLoading=!1,t.options.groupRoomCreatedCallback&&t.options.groupRoomCreatedCallback(e)})),t.events.on("header-clicked",(function(e){t.options.headerClickedCallback&&t.options.headerClickedCallback(e)})),t.events.on("comment-read",(function(e){t.logging("comment-read",e),t.options.commentReadCallback&&t.options.commentReadCallback(e)})),t.events.on("presence",(function(n){var r=n.message,i=n.userId,o=r.split(":");e.chatmateStatus!==o[0]&&(e.chatmateStatus=1===o[0]?"Online":"Last seen ".concat(S()(Number(o[1].substring(0,13))))),t.options.presenceCallback&&t.options.presenceCallback(r,i)})),t.events.on("typing",(function(e){t.options.typingCallback&&t.options.typingCallback(e)})),t.events.on("message-info",(function(e){t.options.messageInfoCallback&&t.options.messageInfoCallback(e)})),t.events.on("participants-added",(function(t){var n;null!=t&&null!=e.selected&&(n=e.selected.participants).push.apply(n,i()(t))})),t.events.on("participants-removed",(function(t){if(null!=t&&null!=e.selected){var n=e.selected.participants.filter((function(e){return t.indexOf(e.email)<=-1}));e.selected.participants=n}})),t.events.on("block-user",(function(e){t.options.blockUserCallback&&t.options.blockUserCallback(e)})),t.events.on("unblock-user",(function(e){t.options.unblockUserCallback&&t.options.unblockUserCallback(e)}))}},{key:"onReconnectMqtt",value:function(){this.options.onReconnectCallback&&this.options.onReconnectedCallback(),this.selected&&this.loadComments(this.selected.id)}},{key:"_callNewMessagesCallback",value:function(e){this.options.newMessagesCallback&&this.options.newMessagesCallback(e)}},{key:"updateLastReceivedComment",value:function(e){this.last_received_comment_id<e&&(this.last_received_comment_id=e)}},{key:"setUser",value:function(e,t,n,r,i){var o=this,s=this;s.user_id=e,s.key=t,s.username=n,s.avatar_url=r;var a={email:this.user_id,password:this.key,username:this.username,extras:i?JSON.stringify(i):null};return this.avatar_url&&(a.avatar_url=this.avatar_url),new Promise((function(e,t){var n=setInterval((function(){if(o.isConfigLoaded)return clearInterval(n),o.logger("Config Success!"),s.events.emit("start-init"),s.authAdapter.loginOrRegister(a).then((function(t){s.isInit=!0,s.events.emit("login-success",t),o.realtimeAdapter.connect(),e(t)}),(function(e){s.events.emit("login-error",e),t(e)}));o.debugMode&&o.logger("Waiting for init config...")}),300)}))}},{key:"setUserWithIdentityToken",value:function(e){var t=this;if(!(e&&"user"in e))return this.events.emit("login-error",e);this.email=e.user.email,this.user_id=e.user.email,this.key=e.identity_token,this.username=e.user.username,this.avatar_url=e.user.avatar_url,this.isInit=!0;var n=setInterval((function(){t.isConfigLoaded?(clearInterval(n),t.logger("Config Success!"),t.events.emit("login-success",e)):t.debugMode&&t.logger("Waiting for init config...")}),300)}},{key:"publishOnlinePresence",value:function(e){var t=this;!0===e?be=setInterval((function(){t.realtimeAdapter.publishPresence(t.user_id,!0)}),3500):(clearInterval(this.presensePublisherId),clearInterval(be),setTimeout((function(){t.realtimeAdapter.publishPresence(t.user_id,!1)}),3500))}},{key:"subscribeUserPresence",value:function(e){this.realtimeAdapter.subscribeUserPresence(e)}},{key:"unsubscribeUserPresence",value:function(e){this.realtimeAdapter.unsubscribeUserPresence(e)}},{key:"logout",value:function(){clearInterval(this.presensePublisherId),this.publishOnlinePresence(!1),this.selected=null,this.isInit=!1,this.isLogin=!1,this.realtimeAdapter.disconnect(),this.userData={}}},{key:"disconnect",value:function(){this.logout()}},{key:"setActiveRoom",value:function(e){var t=this;if(this.selected&&(this.realtimeAdapter.unsubscribeTyping(),"single"===this.selected.room_type)){var n=this.selected.participants.filter((function(e){return e.email!==t.user_id}));n.length>0&&this.realtimeAdapter.unsubscribeRoomPresence(n[0].email)}null==e.participants&&(e.participants=[]);var r=e.participants.find((function(e){return e.email!==t.user_id}));this.chatmateStatus=null,this.isTypingStatus=null,this.selected=e;var i=setInterval((function(){t.debugMode&&t.logger("Trying Initial Subscribe"),null!=t.realtimeAdapter?(t.debugMode&&t.logger("MQTT Connected"),clearInterval(i),"single"===e.room_type&&null!=r&&t.realtimeAdapter.subscribeRoomPresence(r.email),null==t.selected||t.selected.isChannel||(t.realtimeAdapter.subscribeTyping(e.id),t.events.emit("room-changed",t.selected)),t.debugMode&&null==t.realtimeAdapter&&t.logger("Retry")):t.debugMode&&t.logger("MQTT Not Connected, yet")}),3e3)}},{key:"chatTarget",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null!=this.userData.length)return!1;var r=n?n.message:null,i=n.distinctId;return this.isLoading=!0,this.isTypingStatus="",this.roomAdapter.getOrCreateRoom(e,n,i).then(function(){var e=u()(s.a.mark((function e(n){var i,o,a,c;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=new x(n),t.updateLastReceivedComment(i.last_comment_id),t.isLoading=!1,o=function(){var e=u()(s.a.mark((function e(n){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._hookAdapter.trigger(ve.MESSAGE_BEFORE_RECEIVED,n);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.next=6,Promise.all(i.comments.map((function(e){return o(e)})));case 6:if(i.comments=e.sent,t.setActiveRoom(i),(a=i.comments[i.comments.length-1])&&t.readComment(i.id,a.id),t.events.emit("chat-room-created",{room:i}),r){e.next=13;break}return e.abrupt("return",i);case 13:return c=i.id,e.abrupt("return",t.sendComment(c,r).then((function(){return Promise.resolve(i)})).catch((function(e){console.error("Error when submit comment",e)})));case 15:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){return console.error("Error when creating room",e),t.isLoading=!1,Promise.reject(e)}))}},{key:"chatGroup",value:function(e){if(this.isInit)return this.getRoomById(e).then((function(e){return Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"getRoomById",value:function(e){var t=this;if(this.isInit){var n=this;return n.isLoading=!0,n.isTypingStatus="",n.roomAdapter.getRoomById(e).then(function(){var e=u()(s.a.mark((function e(r){var i,o,a,u,c,l,h,f;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=r.results.room,o=[],a=ke(r.results.comments.reverse()),e.prev=3,a.s();case 5:if((u=a.n()).done){e.next=13;break}return c=u.value,e.next=9,t._hookAdapter.trigger(ve.MESSAGE_BEFORE_RECEIVED,c);case 9:l=e.sent,o.push(l);case 11:e.next=5;break;case 13:e.next=18;break;case 15:e.prev=15,e.t0=e.catch(3),a.e(e.t0);case 18:return e.prev=18,a.f(),e.finish(18);case 21:return h=new x(we(we({},i),{},{comments:o,name:i.room_name})),n.updateLastReceivedComment(h.last_comment_id),n.setActiveRoom(h),n.isLoading=!1,(f=h.comments[h.comments.length-1])&&n.readComment(h.id,f.id),h.isChannel&&t.realtimeAdapter.subscribeChannel(t.AppId,h.unique_id),e.abrupt("return",h);case 29:case"end":return e.stop()}}),e,null,[[3,15,18,21]])})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){return console.error("Error getting room by id",e),Promise.reject(e)}))}}},{key:"getOrCreateRoomByUniqueId",value:function(e,t,n){var r=this,i=this;return i.isLoading=!0,i.isTypingStatus="",i.roomAdapter.getOrCreateRoomByUniqueId(e,t,n).then(function(){var e=u()(s.a.mark((function e(t){var n,o,a;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new x(t),i.updateLastReceivedComment(n.last_comment_id),o=function(){var e=u()(s.a.mark((function e(t){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r._hookAdapter.trigger(ve.MESSAGE_BEFORE_RECEIVED,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.next=5,Promise.all(n.comments.map((function(e){return o(e)})));case 5:return n.comments=e.sent,i.setActiveRoom(n),i.isLoading=!1,(a=n.comments[n.comments.length-1])&&i.readComment(n.id,a.id),r.realtimeAdapter.subscribeChannel(r.AppId,n.unique_id),e.abrupt("return",Promise.resolve(n));case 12:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){return Promise.reject(e)}))}},{key:"getOrCreateRoomByChannel",value:function(e,t,n){return this.getOrCreateRoomByUniqueId(e,t,n)}},{key:"sortComments",value:function(){this.selected&&this.selected.comments.sort((function(e,t){return e.unix_timestamp-t.unix_timestamp}))}},{key:"loadRoomList",value:(y=u()(s.a.mark((function e(){var t,n,r=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:{},e.next=3,this.userAdapter.loadRoomList(t);case 3:return n=e.sent,e.abrupt("return",n.map((function(e){return e.last_comment_id=e.last_comment.id,e.last_comment_message=e.last_comment.message,e.last_comment_message_created_at=e.last_comment.timestamp,e.room_type=e.chat_type,e.comments=[],new x(e)})));case 5:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"loadComments",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.userAdapter.loadComments(e,n).then(function(){var e=u()(s.a.mark((function e(n){var r,i,o,a;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=[],i=ke(n),e.prev=2,i.s();case 4:if((o=i.n()).done){e.next=13;break}return a=o.value,e.t0=r,e.next=9,t._hookAdapter.trigger(ve.MESSAGE_BEFORE_RECEIVED,a);case 9:e.t1=e.sent,e.t0.push.call(e.t0,e.t1);case 11:e.next=4;break;case 13:e.next=18;break;case 15:e.prev=15,e.t2=e.catch(2),i.e(e.t2);case 18:return e.prev=18,i.f(),e.finish(18);case 21:return null!=t.selected&&(t.selected.receiveComments(r.reverse()),t.sortComments()),e.abrupt("return",r);case 23:case"end":return e.stop()}}),e,null,[[2,15,18,21]])})));return function(t){return e.apply(this,arguments)}}())}},{key:"loadMore",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null!=this.selected)return t.last_comment_id=e,t.after=!1,this.loadComments(this.selected.id,t)}},{key:"registerDeviceToken",value:(m=u()(s.a.mark((function e(t){var n,r,i=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]&&i[1],e.next=3,this.HTTPAdapter.post("api/v2/sdk/set_user_device_token",{device_token:t,device_platform:"rn",is_development:n});case 3:return r=e.sent,e.abrupt("return",r.body.results);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return m.apply(this,arguments)})},{key:"removeDeviceToken",value:(d=u()(s.a.mark((function e(t){var n,r,i=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]&&i[1],e.next=3,this.HTTPAdapter.post("api/v2/sdk/remove_user_device_token",{device_token:t,device_platform:"rn",is_development:n});case 3:return r=e.sent,e.abrupt("return",r.body.results);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"searchMessages",value:(h=u()(s.a.mark((function e(){var t,n,r=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:{},console.warn("Deprecated: search message will be removed on next release"),e.next=4,this.userAdapter.searchMessages(t);case 4:return n=e.sent,e.abrupt("return",n.map((function(e){return new C(e)})));case 6:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"updateProfile",value:function(e){var t=this;return this.userAdapter.updateProfile(e).then((function(n){return t.events.emit("profile-updated",e),t.userData=n,Promise.resolve(n)}),(function(e){return t.logger(e)}))}},{key:"getNonce",value:function(){return g.a.post("".concat(this.baseURL,"/api/v2/sdk/auth/nonce")).send().set("qiscus_sdk_app_id","".concat(this.AppId)).set("qiscus_sdk_version","".concat(this.version)).then((function(e){return Promise.resolve(e.body.results)}),(function(e){return Promise.reject(e)}))}},{key:"verifyIdentityToken",value:function(e){return g.a.post("".concat(this.baseURL,"/api/v2/sdk/auth/verify_identity_token")).send({identity_token:e}).set("qiscus_sdk_app_id","".concat(this.AppId)).set("qiscus_sdk_version","".concat(this.version)).then((function(e){return Promise.resolve(e.body.results)}),(function(e){return Promise.reject(e)}))}},{key:"sendComment",value:(c=u()(s.a.mark((function e(t,n,r){var i,o,a,c,l,h,f,d,p,m,g=this,b=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=b.length>3&&void 0!==b[3]?b[3]:"text",o=b.length>4?b[4]:void 0,a=b.length>5?b[5]:void 0,(c=this).options.prePostCommentCallback&&c.options.prePostCommentCallback(n),c.options.commentFormaterCallback&&(n=c.options.commentFormaterCallback(n)),c.pendingCommentId--,l={message:n,username_as:this.username,username_real:this.user_id,user_avatar_url:this.userData.avatar_url,user_extras:this.userData.user_extras,id:Math.round(1e7*Math.random()),type:i||"text",timestamp:w()(new Date),unique_id:r?String(r):null,payload:ie((function(){return JSON.parse(o)}),o,(function(e){return g.logger("Error when parsing payload",e.message)}))},h=c.prepareCommentToBeSubmitted(l),"reply"===i&&(f=JSON.parse(o),d=c.selected.comments.find((function(e){return e.id===f.replied_comment_id})),f.replied_comment_message="reply"===d.type?d.payload.text:d.message,f.replied_comment_sender_username=d.username_as,h.payload=f),p=a||c.extras,e.next=13,this._hookAdapter.trigger(ve.MESSAGE_BEFORE_SENT,we(we({},h),{},{extras:p}));case 13:return m=e.sent,m=c.prepareCommentToBeSubmitted(m),c.selected&&c.selected.comments.push(m),e.abrupt("return",this.userAdapter.postComment(""+t,m.message,m.unique_id,m.type,m.payload,m.extras).then(function(){var e=u()(s.a.mark((function e(t){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,g._hookAdapter.trigger(ve.MESSAGE_BEFORE_RECEIVED,t);case 2:if(t=e.sent,Object.assign(m,t),c.selected){e.next=6;break}return e.abrupt("return",Promise.resolve(m));case 6:return m.markAsSent(),m.id=t.id,m.before_id=t.comment_before_id,m.unix_timestamp=t.unix_timestamp,c.sortComments(),e.abrupt("return",m);case 12:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){return m.markAsFailed(),Promise.reject(e)})));case 17:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return c.apply(this,arguments)})},{key:"getUsers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:20;return this.HTTPAdapter.get_request("api/v2/sdk/get_user_list").query({query:e,page:t,limit:n}).then((function(e){return Promise.resolve(e.body.results)}))}},{key:"getParticipants",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:20;return this.HTTPAdapter.get_request("api/v2/sdk/room_participants").query({room_unique_id:e,page:t,limit:n}).then((function(e){return e.body.results}))}},{key:"getRoomParticipants",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return console.warn("`getRoomParticipants` are deprecated, use `getParticipants` instead."),this.HTTPAdapter.get_request("api/v2/sdk/room_participants").query({room_unique_id:e,offset:t}).then((function(e){return Promise.resolve(e.body.results)}))}},{key:"resendComment",value:function(e){if(null!=this.selected){var t=this,n=t.selected,r=n.comments.find((function(t){return t.id===e.id})),i=t.extras;return this.userAdapter.postComment(""+n.id,r.message,r.unique_id,e.type,e.payload,i).then((function(e){return r.markAsSent(),r.id=e.id,r.before_id=e.comment_before_id,new Promise((function(e,n){return e(t.selected)}))}),(function(e){return r.markAsFailed(),new Promise((function(t,n){return n(e)}))}))}}},{key:"prepareCommentToBeSubmitted",value:function(e){var t,n;return t=new C(e),n="bq"+Date.now(),e.unique_id&&(n=e.unique_id),t.attachUniqueId(n),t.markAsPending(),t.isDelivered=!1,t.isSent=!1,t.isRead=!1,t.unix_timestamp=Math.round((new Date).getTime()/1e3),t}},{key:"updateRoom",value:function(e){return this.roomAdapter.updateRoom(e)}},{key:"removeSelectedRoomParticipants",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id";if(v.a.not.array(e))return Promise.reject(new Error("`values` must have type of array"));var n=this.selected.participants;if(!n)return Promise.reject(new Error("Nothing selected room chat."));var r=n;return"id"===t&&(r=n.filter((function(t){return e.indexOf(t.id)<=-1}))),"email"===t&&(r=n.filter((function(t){return e.indexOf(t.email)<=-1}))),"username"===t&&(r=n.filter((function(t){return e.indexOf(t.username)<=-1}))),this.selected.participants=r,Promise.resolve(n)}},{key:"createGroupRoom",value:function(e,t,n){var r=this;if(!this.isLogin)throw new Error("Please initiate qiscus SDK first");return new T(this.roomAdapter).withName(e).withOptions(n).addParticipants(t).create().then((function(e){return r.events.emit("group-room-created",e),Promise.resolve(e)}))}},{key:"addParticipantsToGroup",value:function(e,t){var n=this;if(!Array.isArray(t))throw new Error("emails' must be type of Array");return n.roomAdapter.addParticipantsToGroup(e,t).then((function(e){return n.events.emit("participants-added",e),Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"removeParticipantsFromGroup",value:function(e,t){var n=this;return v.a.not.array(t)?Promise.reject(new Error("`emails` must have type of array")):this.roomAdapter.removeParticipantsFromGroup(e,t).then((function(e){return n.events.emit("participants-removed",t),Promise.resolve(e)}))}},{key:"getBlockedUser",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,n=this;return n.userAdapter.getBlockedUser(e,t).then((function(e){return Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"blockUser",value:function(e){var t=this;return t.userAdapter.blockUser(e).then((function(e){return t.events.emit("block-user",e),Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"unblockUser",value:function(e){var t=this;return t.userAdapter.unblockUser(e).then((function(e){return t.events.emit("unblock-user",e),Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"getUserPresences",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(v.a.not.array(e))return Promise.reject(new Error("`email` must have type of array"));var t=this;return t.userAdapter.getUserPresences(e).then((function(e){return t.events.emit("user-status",e),Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"upload",value:function(e,t){return g.a.post(this.uploadURL).attach("file",e).set("qiscus_sdk_app_id",this.AppId).set("qiscus_sdk_token",this.userData.token).set("qiscus_sdk_user_id",this.user_id).on("progress",(function(e){"upload"===e.direction&&t(null,e)})).then((function(e){var n=e.body.results.file.url;return t(null,null,e.body.results.file.url),Promise.resolve(n)})).catch((function(e){return t(e),Promise.reject(e)}))}},{key:"uploadFile",value:function(e,t){var n=this,r=new FormData;r.append("file",t);var i=new XMLHttpRequest;i.open("POST","".concat(n.baseURL,"/api/v2/sdk/upload"),!0),i.setRequestHeader("qiscus_sdk_app_id","".concat(n.AppId)),i.setRequestHeader("qiscus_sdk_user_id","".concat(n.user_id)),i.setRequestHeader("qiscus_sdk_token","".concat(n.userData.token)),i.onload=function(){if(200===i.status){var t=JSON.parse(i.response).results.file.url;return n.events.emit("fileupload",t),n.sendComment(e,"[file] ".concat(t," [/file]"))}return Promise.reject(i)},i.send(r)}},{key:"addUploadedFile",value:function(e,t){this.uploadedFiles.push(new Ce(e,t))}},{key:"removeUploadedFile",value:function(e,t){var n=this.uploadedFiles.findIndex((function(n){return n.name===e&&n.roomId===t}));this.uploadedFiles.splice(n,1)}},{key:"publishTyping",value:function(e){this.realtimeAdapter.publishTyping(e)}},{key:"getRoomsInfo",value:function(e){return this.userAdapter.getRoomsInfo(e)}},{key:"deleteComment",value:function(e,t,n,r){var i=this;if(!Array.isArray(t))throw new Error("unique ids' must be type of Array");return this.userAdapter.deleteComment(e,t,n,r).then((function(o){return i.events.emit("comment-deleted",{roomId:e,commentUniqueIds:t,isForEveryone:n,isHard:r}),Promise.resolve(o)}),(function(e){return Promise.reject(e)}))}},{key:"clearRoomsCache",value:function(){var e=this;if(this.selected){this.room_name_id_map=p()({},this.selected.name,this.selected.id);var t=this.rooms.length,n=this.rooms.findIndex((function(t){return t.id===e.selected.id}));n+1!==t&&this.rooms.splice(n+1,t-(n+1)),(n=this.rooms.findIndex((function(t){return t.id===e.selected.id})))>0&&this.rooms.length>1&&this.rooms.splice(1,this.rooms.length-1)}}},{key:"exitChatRoom",value:function(){var e=this;this.realtimeAdapter.unsubscribeTyping(),ie((function(){return e.selected.participants.filter((function(t){return t.email!==e.user_id})).map((function(e){return e.email}))}),null,this.noop,(function(t){return t.forEach((function(t){return e.realtimeAdapter.unsubscribeRoomPresence(t)}))})),this.selected=null}},{key:"clearRoomMessages",value:function(e){if(!Array.isArray(e))throw new Error("room_ids must be type of array");return this.userAdapter.clearRoomMessages(e)}},{key:"logging",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.debugMode&&console.log(e,t)}},{key:"getTotalUnreadCount",value:function(){return this.roomAdapter.getTotalUnreadCount().then((function(e){return Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"getRoomUnreadCount",value:function(){return this.roomAdapter.getRoomUnreadCount()}},{key:"publishEvent",value:function(){var e;(e=this.customEventAdapter).publishEvent.apply(e,arguments)}},{key:"subscribeEvent",value:function(){var e;(e=this.customEventAdapter).subscribeEvent.apply(e,arguments)}},{key:"unsubscribeEvent",value:function(){var e;(e=this.customEventAdapter).unsubscribeEvent.apply(e,arguments)}},{key:"setCustomHeader",value:function(e){if(v.a.not.json(e))throw new TypeError("`headers` must have type of object");this._customHeader=e}},{key:"getUserProfile",value:function(){return this.userAdapter.getProfile()}},{key:"intercept",value:function(e,t){return this._hookAdapter.intercept(e,t)}},{key:"getThumbnailURL",value:function(e){return e.replace(/^https?:\/\/\S+(\/upload\/)\S+(\.\w+)$/i,(function(e,t,n){return e.replace(t,"/upload/w_320,h_320,c_limit/").replace(n,".png")}))}},{key:"getBlurryThumbnailURL",value:function(e){return e.replace(/^https?:\/\/\S+(\/upload\/)\S+(\.\w+)$/i,(function(e,t,n){return e.replace(t,"/upload/w_320,h_320,c_limit,e_blur:300/").replace(n,".png")}))}},{key:"noop",value:function(){}},{key:"_updateStatus",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=null!=n,i=null!=t,o=(null!=this.selected&&this.selected.id,null!=this.selected&&this.selected.isChannel||!1),s=!this._updateStatusEnabled,a=i?"read":r?"receive":void 0,u=!(o||r&&s);if(this.debugMode&&(console.group("update-command-status"),console.log("run:",a,"on: roomId(".concat(e,") commentId(").concat(t||n,")")),console.log("is able to run command?",u),console.groupEnd()),!u)return!1;this.userAdapter.updateCommentStatus(e,t,n).catch((function(e){}))}},{key:"readComment",value:function(t,n){return this.updateCommentStatusMode===e.UpdateCommentStatusMode.enabled?this._readComment(t,n):this._readCommentT(t,n)}},{key:"receiveComment",value:function(t,n){return this.updateCommentStatusMode===e.UpdateCommentStatusMode.enabled?this._deliverComment(t,n):this._deliverCommentT(t,n)}},{key:"_throttle",value:function(e,t){var n=!1;return function(){var r=t();n||(e.apply(void 0,arguments),n=!0,setTimeout((function(){return n=!1}),r))}}},{key:"searchMessage",value:(a=u()(s.a.mark((function e(){var t,n,r,i,o,a,u,c,l,h,f,d,p=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=p.length>0&&void 0!==p[0]?p[0]:{},n=t.query,r=t.roomIds,i=void 0===r?[]:r,o=t.userId,a=t.type,u=t.roomType,c=t.page,l=t.limit,h="api/v2/sdk/search",f=["group","single","channel"].some((function(e){return e===u})),null==u||f){e.next=5;break}return e.abrupt("return",Promise.reject("Invalid room type, valid room type are: `group`, `single`, and `channel`"));case 5:return d=function(e){return{type:null==e?void 0:"single"===e?"single":"group",isPublic:null==e?void 0:"channel"===e}}(u),e.abrupt("return",this.HTTPAdapter.post_json(h,{token:this.token,query:n,sender:o,type:a,room_ids:i.map((function(e){return String(e)})),room_type:d.type||void 0,is_public:d.isPublic||void 0,page:c,limit:l}).then((function(e){return e.body})));case 7:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"getFileList",value:(o=u()(s.a.mark((function e(){var t,n,r,i,o,a,u,c,l,h,f,d,p=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=p.length>0&&void 0!==p[0]?p[0]:{},n=t.roomIds,r=void 0===n?[]:n,i=t.fileType,o=t.page,a=t.limit,u=t.sender,c=t.userId,l=t.includeExtensions,h=t.excludeExtensions,f="api/v2/sdk/file_list",this.isLogin){e.next=4;break}return e.abrupt("return",Promise.reject("You need to login to use this method"));case 4:return void 0===u&&(u=this.user_id),void 0===c&&(u=c=this.user_id),d={room_ids:r.map((function(e){return String(e)})),file_type:i,page:o,limit:a,include_extensions:l,exclude_extensions:h},null!=u&&(d.sender=u),e.abrupt("return",this.HTTPAdapter.post_json(f,d).then((function(e){return e.body})));case 9:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"_generateUniqueId",value:function(){return"javascript-".concat(Date.now())}},{key:"generateMessage",value:function(e){var t=e.roomId,n=e.text,r=e.extras,i=Date.now();return new C({id:i,message:n,room_id:t,extras:r,timestamp:new Date,unique_id:this._generateUniqueId(),before_id:0,username:this.userData.username,email:this.userData.email,status:"pending",type:"text"})}},{key:"generateFileAttachmentMessage",value:function(e){var t=e.roomId,n=e.caption,r=e.url,i=e.text,o=void 0===i?"File attachment":i,s=e.extras,a=e.filename,u=e.size,c=Date.now();return new C({id:c,message:o,room_id:t,extras:s,timestamp:new Date,unique_id:this._generateUniqueId(),before_id:0,username:this.userData.username,email:this.userData.email,status:"pending",type:"file_attachment",payload:{url:r,file_name:a,size:u,caption:n}})}},{key:"generateCustomMessage",value:function(e){var t=e.roomId,n=e.text,r=e.type,i=e.payload,o=e.extras,s=Date.now();return new C({id:s,message:n,room_id:t,extras:o,timestamp:new Date,unique_id:this._generateUniqueId(),before_id:0,username:this.userData.username,email:this.userData.email,status:"pending",type:"custom",payload:{type:r,content:i}})}},{key:"generateReplyMessage",value:function(e){var t=e.roomId,n=e.text,r=e.repliedMessage,i=e.extras,o=Date.now();return new C({id:o,message:n,room_id:t,extras:i,timestamp:new Date,unique_id:this._generateUniqueId(),before_id:0,username:this.userData.username,email:this.userData.email,status:"pending",type:"reply",payload:{text:n,replied_comment_id:r.id,replied_comment_message:r.message,replied_comment_type:r.type,replied_comment_payload:r.payload,replied_comment_sender_username:r.username_as,replied_comment_sender_email:r.username_real}})}},{key:"updateMessage",value:(r=u()(s.a.mark((function e(t){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.userAdapter.updateMessage(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"onMessageUpdated",value:function(e){var t=this;return this.realtimeAdapter.on("message:updated",e),function(){return t.realtimeAdapter.off("message:updated",e)}}},{key:"closeRealtimeConnection",value:(n=u()(s.a.mark((function e(){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.realtimeAdapter.closeConnection());case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"openRealtimeConnection",value:(t=u()(s.a.mark((function e(){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.realtimeAdapter.openConnection());case 1:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"uploadURL",get:function(){return this._uploadURL||"".concat(this.baseURL,"/api/v2/sdk/upload")},set:function(e){this._uploadURL=e}},{key:"synchronize",get:function(){return this.syncAdapter.synchronize}},{key:"synchronizeEvent",get:function(){return this.syncAdapter.synchronizeEvent}},{key:"Interceptor",get:function(){return ve}},{key:"logger",get:function(){return this.debugMode?console.log.bind(console,"Qiscus ->"):this.noop}},{key:"_throttleDelay",get:function(){return this.updateCommentStatusMode===e.UpdateCommentStatusMode.enabled?0:this.updateCommentStatusThrottleDelay||300}},{key:"_updateStatusEnabled",get:function(){return this.updateCommentStatusMode!==e.UpdateCommentStatusMode.disabled}}]),e}();p()(Te,"UpdateCommentStatusMode",Ee),p()(Te,"Interceptor",ve);var Ce=function e(t,n){l()(this,e),this.name=t,this.roomId=n,this.progress=0};t.default=Te}]).default}));
|
|
16
|
+
var r=n(8),i=r.Buffer;function o(e,t){for(var n in e)t[n]=e[n]}function s(e,t,n){return i(e,t,n)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?e.exports=r:(o(r,t),t.Buffer=s),s.prototype=Object.create(i.prototype),o(i,s),s.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return i(e,t,n)},s.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var r=i(e);return void 0!==t?"string"==typeof n?r.fill(t,n):r.fill(t):r.fill(0),r},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i(e)},s.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}},function(e,t,n){"use strict";(function(t){var r;function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=n(21),s=Symbol("lastResolve"),a=Symbol("lastReject"),u=Symbol("error"),c=Symbol("ended"),l=Symbol("lastPromise"),h=Symbol("handlePromise"),f=Symbol("stream");function p(e,t){return{value:e,done:t}}function d(e){var t=e[s];if(null!==t){var n=e[f].read();null!==n&&(e[l]=null,e[s]=null,e[a]=null,t(p(n,!1)))}}function m(e){t.nextTick(d,e)}var g=Object.getPrototypeOf((function(){})),v=Object.setPrototypeOf((i(r={get stream(){return this[f]},next:function(){var e=this,n=this[u];if(null!==n)return Promise.reject(n);if(this[c])return Promise.resolve(p(void 0,!0));if(this[f].destroyed)return new Promise((function(n,r){t.nextTick((function(){e[u]?r(e[u]):n(p(void 0,!0))}))}));var r,i=this[l];if(i)r=new Promise(function(e,t){return function(n,r){e.then((function(){t[c]?n(p(void 0,!0)):t[h](n,r)}),r)}}(i,this));else{var o=this[f].read();if(null!==o)return Promise.resolve(p(o,!1));r=new Promise(this[h])}return this[l]=r,r}},Symbol.asyncIterator,(function(){return this})),i(r,"return",(function(){var e=this;return new Promise((function(t,n){e[f].destroy(null,(function(e){e?n(e):t(p(void 0,!0))}))}))})),r),g);e.exports=function(e){var t,n=Object.create(v,(i(t={},f,{value:e,writable:!0}),i(t,s,{value:null,writable:!0}),i(t,a,{value:null,writable:!0}),i(t,u,{value:null,writable:!0}),i(t,c,{value:e._readableState.endEmitted,writable:!0}),i(t,h,{value:function(e,t){var r=n[f].read();r?(n[l]=null,n[s]=null,n[a]=null,e(p(r,!1))):(n[s]=e,n[a]=t)},writable:!0}),t));return n[l]=null,o(e,(function(e){if(e&&"ERR_STREAM_PREMATURE_CLOSE"!==e.code){var t=n[a];return null!==t&&(n[l]=null,n[s]=null,n[a]=null,t(e)),void(n[u]=e)}var r=n[s];null!==r&&(n[l]=null,n[s]=null,n[a]=null,r(p(void 0,!0))),n[c]=!0})),e.on("readable",m.bind(null,n)),n}}).call(this,n(9))},function(e,t){e.exports=function(){throw new Error("Readable.from is not available in the browser")}},function(e,t,n){"use strict";e.exports=i;var r=n(40);function i(e){if(!(this instanceof i))return new i(e);r.call(this,e)}n(11)(i,r),i.prototype._transform=function(e,t,n){n(null,e)}},function(e,t,n){"use strict";var r;var i=n(14).codes,o=i.ERR_MISSING_ARGS,s=i.ERR_STREAM_DESTROYED;function a(e){if(e)throw e}function u(e){e()}function c(e,t){return e.pipe(t)}e.exports=function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];var l,h=function(e){return e.length?"function"!=typeof e[e.length-1]?a:e.pop():a}(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new o("streams");var f=t.map((function(e,i){var o=i<t.length-1;return function(e,t,i,o){o=function(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}(o);var a=!1;e.on("close",(function(){a=!0})),void 0===r&&(r=n(21)),r(e,{readable:t,writable:i},(function(e){if(e)return o(e);a=!0,o()}));var u=!1;return function(t){if(!a&&!u)return u=!0,function(e){return e.setHeader&&"function"==typeof e.abort}(e)?e.abort():"function"==typeof e.destroy?e.destroy():void o(t||new s("pipe"))}}(e,o,i>0,(function(e){l||(l=e),e&&f.forEach(u),o||(f.forEach(u),h(l))}))}));return t.reduce(c)}},function(e,t,n){t.parser=n(101).parser,t.generate=n(107),t.writeToStream=n(42)},function(e,t,n){const r=n(102),i=n(16),o=n(104),s=n(41),a=n(13)("mqtt-packet:parser");class u extends i{constructor(){super(),this.parser=this.constructor.parser}static parser(e){return this instanceof u?(this.settings=e||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):(new u).parser(e)}_resetState(){a("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new o,this.error=null,this._list=r(),this._stateCounter=0}parse(e){for(this.error&&this._resetState(),this._list.append(e),a("parse: current state: %s",this._states[this._stateCounter]);(-1!==this.packet.length||this._list.length>0)&&this[this._states[this._stateCounter]]()&&!this.error;)this._stateCounter++,a("parse: state complete. _stateCounter is now: %d",this._stateCounter),a("parse: packet.length: %d, buffer list length: %d",this.packet.length,this._list.length),this._stateCounter>=this._states.length&&(this._stateCounter=0);return a("parse: exited while loop. packet: %d, buffer list length: %d",this.packet.length,this._list.length),this._list.length}_parseHeader(){const e=this._list.readUInt8(0);return this.packet.cmd=s.types[e>>s.CMD_SHIFT],this.packet.retain=0!=(e&s.RETAIN_MASK),this.packet.qos=e>>s.QOS_SHIFT&s.QOS_MASK,this.packet.dup=0!=(e&s.DUP_MASK),a("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0}_parseLength(){const e=this._parseVarByteNum(!0);return e&&(this.packet.length=e.value,this._list.consume(e.bytes)),a("_parseLength %d",e.value),!!e}_parsePayload(){a("_parsePayload: payload %O",this._list);let e=!1;if(0===this.packet.length||this._list.length>=this.packet.length){switch(this._pos=0,this.packet.cmd){case"connect":this._parseConnect();break;case"connack":this._parseConnack();break;case"publish":this._parsePublish();break;case"puback":case"pubrec":case"pubrel":case"pubcomp":this._parseConfirmation();break;case"subscribe":this._parseSubscribe();break;case"suback":this._parseSuback();break;case"unsubscribe":this._parseUnsubscribe();break;case"unsuback":this._parseUnsuback();break;case"pingreq":case"pingresp":break;case"disconnect":this._parseDisconnect();break;case"auth":this._parseAuth();break;default:this._emitError(new Error("Not supported"))}e=!0}return a("_parsePayload complete result: %s",e),e}_parseConnect(){let e,t,n,r;a("_parseConnect");const i={},o=this.packet,u=this._parseString();if(null===u)return this._emitError(new Error("Cannot parse protocolId"));if("MQTT"!==u&&"MQIsdp"!==u)return this._emitError(new Error("Invalid protocolId"));if(o.protocolId=u,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(o.protocolVersion=this._list.readUInt8(this._pos),o.protocolVersion>=128&&(o.bridgeMode=!0,o.protocolVersion=o.protocolVersion-128),3!==o.protocolVersion&&4!==o.protocolVersion&&5!==o.protocolVersion)return this._emitError(new Error("Invalid protocol version"));if(this._pos++,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(i.username=this._list.readUInt8(this._pos)&s.USERNAME_MASK,i.password=this._list.readUInt8(this._pos)&s.PASSWORD_MASK,i.will=this._list.readUInt8(this._pos)&s.WILL_FLAG_MASK,i.will&&(o.will={},o.will.retain=0!=(this._list.readUInt8(this._pos)&s.WILL_RETAIN_MASK),o.will.qos=(this._list.readUInt8(this._pos)&s.WILL_QOS_MASK)>>s.WILL_QOS_SHIFT),o.clean=0!=(this._list.readUInt8(this._pos)&s.CLEAN_SESSION_MASK),this._pos++,o.keepalive=this._parseNum(),-1===o.keepalive)return this._emitError(new Error("Packet too short"));if(5===o.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(o.properties=e)}const c=this._parseString();if(null===c)return this._emitError(new Error("Packet too short"));if(o.clientId=c,a("_parseConnect: packet.clientId: %s",o.clientId),i.will){if(5===o.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(o.will.properties=e)}if(null===(e=this._parseString()))return this._emitError(new Error("Cannot parse will topic"));if(o.will.topic=e,a("_parseConnect: packet.will.topic: %s",o.will.topic),null===(t=this._parseBuffer()))return this._emitError(new Error("Cannot parse will payload"));o.will.payload=t,a("_parseConnect: packet.will.paylaod: %s",o.will.payload)}if(i.username){if(null===(r=this._parseString()))return this._emitError(new Error("Cannot parse username"));o.username=r,a("_parseConnect: packet.username: %s",o.username)}if(i.password){if(null===(n=this._parseBuffer()))return this._emitError(new Error("Cannot parse password"));o.password=n}return this.settings=o,a("_parseConnect: complete"),o}_parseConnack(){a("_parseConnack");const e=this.packet;if(this._list.length<1)return null;if(e.sessionPresent=!!(this._list.readUInt8(this._pos++)&s.SESSIONPRESENT_MASK),5===this.settings.protocolVersion)this._list.length>=2?e.reasonCode=this._list.readUInt8(this._pos++):e.reasonCode=0;else{if(this._list.length<2)return null;e.returnCode=this._list.readUInt8(this._pos++)}if(-1===e.returnCode||-1===e.reasonCode)return this._emitError(new Error("Cannot parse return code"));if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}a("_parseConnack: complete")}_parsePublish(){a("_parsePublish");const e=this.packet;if(e.topic=this._parseString(),null===e.topic)return this._emitError(new Error("Cannot parse topic"));if(!(e.qos>0)||this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}e.payload=this._list.slice(this._pos,e.length),a("_parsePublish: payload from buffer list: %o",e.payload)}}_parseSubscribe(){a("_parseSubscribe");const e=this.packet;let t,n,r,i,o,u,c;if(1!==e.qos)return this._emitError(new Error("Wrong subscribe header"));if(e.subscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<e.length;){if(null===(t=this._parseString()))return this._emitError(new Error("Cannot parse topic"));if(this._pos>=e.length)return this._emitError(new Error("Malformed Subscribe Payload"));r=(n=this._parseByte())&s.SUBSCRIBE_OPTIONS_QOS_MASK,u=0!=(n>>s.SUBSCRIBE_OPTIONS_NL_SHIFT&s.SUBSCRIBE_OPTIONS_NL_MASK),o=0!=(n>>s.SUBSCRIBE_OPTIONS_RAP_SHIFT&s.SUBSCRIBE_OPTIONS_RAP_MASK),i=n>>s.SUBSCRIBE_OPTIONS_RH_SHIFT&s.SUBSCRIBE_OPTIONS_RH_MASK,c={topic:t,qos:r},5===this.settings.protocolVersion?(c.nl=u,c.rap=o,c.rh=i):this.settings.bridgeMode&&(c.rh=0,c.rap=!0,c.nl=!0),a("_parseSubscribe: push subscription `%s` to subscription",c),e.subscriptions.push(c)}}}_parseSuback(){a("_parseSuback");const e=this.packet;if(this.packet.granted=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseUnsubscribe(){a("_parseUnsubscribe");const e=this.packet;if(e.unsubscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<e.length;){const t=this._parseString();if(null===t)return this._emitError(new Error("Cannot parse topic"));a("_parseUnsubscribe: push topic `%s` to unsubscriptions",t),e.unsubscriptions.push(t)}}}_parseUnsuback(){a("_parseUnsuback");const e=this.packet;if(!this._parseMessageId())return this._emitError(new Error("Cannot parse messageId"));if(5===this.settings.protocolVersion){const t=this._parseProperties();for(Object.getOwnPropertyNames(t).length&&(e.properties=t),e.granted=[];this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseConfirmation(){a("_parseConfirmation: packet.cmd: `%s`",this.packet.cmd);const e=this.packet;if(this._parseMessageId(),5===this.settings.protocolVersion&&(e.length>2?(e.reasonCode=this._parseByte(),a("_parseConfirmation: packet.reasonCode `%d`",e.reasonCode)):e.reasonCode=0,e.length>3)){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}return!0}_parseDisconnect(){const e=this.packet;if(a("_parseDisconnect"),5===this.settings.protocolVersion){this._list.length>0?e.reasonCode=this._parseByte():e.reasonCode=0;const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}return a("_parseDisconnect result: true"),!0}_parseAuth(){a("_parseAuth");const e=this.packet;if(5!==this.settings.protocolVersion)return this._emitError(new Error("Not supported auth packet for this version MQTT"));e.reasonCode=this._parseByte();const t=this._parseProperties();return Object.getOwnPropertyNames(t).length&&(e.properties=t),a("_parseAuth: result: true"),!0}_parseMessageId(){const e=this.packet;return e.messageId=this._parseNum(),null===e.messageId?(this._emitError(new Error("Cannot parse messageId")),!1):(a("_parseMessageId: packet.messageId %d",e.messageId),!0)}_parseString(e){const t=this._parseNum(),n=t+this._pos;if(-1===t||n>this._list.length||n>this.packet.length)return null;const r=this._list.toString("utf8",this._pos,n);return this._pos+=t,a("_parseString: result: %s",r),r}_parseStringPair(){return a("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){const e=this._parseNum(),t=e+this._pos;if(-1===e||t>this._list.length||t>this.packet.length)return null;const n=this._list.slice(this._pos,t);return this._pos+=e,a("_parseBuffer: result: %o",n),n}_parseNum(){if(this._list.length-this._pos<2)return-1;const e=this._list.readUInt16BE(this._pos);return this._pos+=2,a("_parseNum: result: %s",e),e}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;const e=this._list.readUInt32BE(this._pos);return this._pos+=4,a("_parse4ByteNum: result: %s",e),e}_parseVarByteNum(e){a("_parseVarByteNum");let t,n=0,r=1,i=0,o=!1;const u=this._pos?this._pos:0;for(;n<4&&u+n<this._list.length;){if(i+=r*((t=this._list.readUInt8(u+n++))&s.VARBYTEINT_MASK),r*=128,0==(t&s.VARBYTEINT_FIN_MASK)){o=!0;break}if(this._list.length<=n)break}return!o&&4===n&&this._list.length>=n&&this._emitError(new Error("Invalid variable byte integer")),u&&(this._pos+=n),a("_parseVarByteNum: result: %o",o=!!o&&(e?{bytes:n,value:i}:i)),o}_parseByte(){const e=this._list.readUInt8(this._pos);return this._pos++,a("_parseByte: result: %o",e),e}_parseByType(e){switch(a("_parseByType: type: %s",e),e){case"byte":return 0!==this._parseByte();case"int8":return this._parseByte();case"int16":return this._parseNum();case"int32":return this._parse4ByteNum();case"var":return this._parseVarByteNum();case"string":return this._parseString();case"pair":return this._parseStringPair();case"binary":return this._parseBuffer()}}_parseProperties(){a("_parseProperties");const e=this._parseVarByteNum(),t=this._pos+e,n={};for(;this._pos<t;){const e=this._parseByte(),t=s.propertiesCodes[e];if(!t)return this._emitError(new Error("Unknown property")),!1;if("userProperties"!==t)n[t]?Array.isArray(n[t])?n[t].push(this._parseByType(s.propertiesTypes[t])):(n[t]=[n[t]],n[t].push(this._parseByType(s.propertiesTypes[t]))):n[t]=this._parseByType(s.propertiesTypes[t]);else{n[t]||(n[t]=Object.create(null));const e=this._parseByType(s.propertiesTypes[t]);if(n[t][e.name])if(Array.isArray(n[t][e.name]))n[t][e.name].push(e.value);else{const r=n[t][e.name];n[t][e.name]=[r],n[t][e.name].push(e.value)}else n[t][e.name]=e.value}}return n}_newPacket(){return a("_newPacket"),this.packet&&(this._list.consume(this.packet.length),a("_newPacket: parser emit packet: packet.cmd: %s, packet.payload: %s, packet.length: %d",this.packet.cmd,this.packet.payload,this.packet.length),this.emit("packet",this.packet)),a("_newPacket: new packet"),this.packet=new o,this._pos=0,!0}_emitError(e){a("_emitError"),this.error=e,this.emit("error",e)}}e.exports=u},function(e,t,n){"use strict";const r=n(12).Duplex,i=n(11),o=n(103);function s(e){if(!(this instanceof s))return new s(e);if("function"==typeof e){this._callback=e;const t=function(e){this._callback&&(this._callback(e),this._callback=null)}.bind(this);this.on("pipe",(function(e){e.on("error",t)})),this.on("unpipe",(function(e){e.removeListener("error",t)})),e=null}o._init.call(this,e),r.call(this)}i(s,r),Object.assign(s.prototype,o.prototype),s.prototype._new=function(e){return new s(e)},s.prototype._write=function(e,t,n){this._appendBuffer(e),"function"==typeof n&&n()},s.prototype._read=function(e){if(!this.length)return this.push(null);e=Math.min(e,this.length),this.push(this.slice(0,e)),this.consume(e)},s.prototype.end=function(e){r.prototype.end.call(this,e),this._callback&&(this._callback(null,this.slice()),this._callback=null)},s.prototype._destroy=function(e,t){this._bufs.length=0,this.length=0,t(e)},s.prototype._isBufferList=function(e){return e instanceof s||e instanceof o||s.isBufferList(e)},s.isBufferList=o.isBufferList,e.exports=s,e.exports.BufferListStream=s,e.exports.BufferList=o},function(e,t,n){"use strict";const{Buffer:r}=n(8),i=Symbol.for("BufferList");function o(e){if(!(this instanceof o))return new o(e);o._init.call(this,e)}o._init=function(e){Object.defineProperty(this,i,{value:!0}),this._bufs=[],this.length=0,e&&this.append(e)},o.prototype._new=function(e){return new o(e)},o.prototype._offset=function(e){if(0===e)return[0,0];let t=0;for(let n=0;n<this._bufs.length;n++){const r=t+this._bufs[n].length;if(e<r||n===this._bufs.length-1)return[n,e-t];t=r}},o.prototype._reverseOffset=function(e){const t=e[0];let n=e[1];for(let e=0;e<t;e++)n+=this._bufs[e].length;return n},o.prototype.get=function(e){if(e>this.length||e<0)return;const t=this._offset(e);return this._bufs[t[0]][t[1]]},o.prototype.slice=function(e,t){return"number"==typeof e&&e<0&&(e+=this.length),"number"==typeof t&&t<0&&(t+=this.length),this.copy(null,0,e,t)},o.prototype.copy=function(e,t,n,i){if(("number"!=typeof n||n<0)&&(n=0),("number"!=typeof i||i>this.length)&&(i=this.length),n>=this.length)return e||r.alloc(0);if(i<=0)return e||r.alloc(0);const o=!!e,s=this._offset(n),a=i-n;let u=a,c=o&&t||0,l=s[1];if(0===n&&i===this.length){if(!o)return 1===this._bufs.length?this._bufs[0]:r.concat(this._bufs,this.length);for(let t=0;t<this._bufs.length;t++)this._bufs[t].copy(e,c),c+=this._bufs[t].length;return e}if(u<=this._bufs[s[0]].length-l)return o?this._bufs[s[0]].copy(e,t,l,l+u):this._bufs[s[0]].slice(l,l+u);o||(e=r.allocUnsafe(a));for(let t=s[0];t<this._bufs.length;t++){const n=this._bufs[t].length-l;if(!(u>n)){this._bufs[t].copy(e,c,l,l+u),c+=n;break}this._bufs[t].copy(e,c,l),c+=n,u-=n,l&&(l=0)}return e.length>c?e.slice(0,c):e},o.prototype.shallowSlice=function(e,t){if(e=e||0,t="number"!=typeof t?this.length:t,e<0&&(e+=this.length),t<0&&(t+=this.length),e===t)return this._new();const n=this._offset(e),r=this._offset(t),i=this._bufs.slice(n[0],r[0]+1);return 0===r[1]?i.pop():i[i.length-1]=i[i.length-1].slice(0,r[1]),0!==n[1]&&(i[0]=i[0].slice(n[1])),this._new(i)},o.prototype.toString=function(e,t,n){return this.slice(t,n).toString(e)},o.prototype.consume=function(e){if(e=Math.trunc(e),Number.isNaN(e)||e<=0)return this;for(;this._bufs.length;){if(!(e>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(e),this.length-=e;break}e-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},o.prototype.duplicate=function(){const e=this._new();for(let t=0;t<this._bufs.length;t++)e.append(this._bufs[t]);return e},o.prototype.append=function(e){if(null==e)return this;if(e.buffer)this._appendBuffer(r.from(e.buffer,e.byteOffset,e.byteLength));else if(Array.isArray(e))for(let t=0;t<e.length;t++)this.append(e[t]);else if(this._isBufferList(e))for(let t=0;t<e._bufs.length;t++)this.append(e._bufs[t]);else"number"==typeof e&&(e=e.toString()),this._appendBuffer(r.from(e));return this},o.prototype._appendBuffer=function(e){this._bufs.push(e),this.length+=e.length},o.prototype.indexOf=function(e,t,n){if(void 0===n&&"string"==typeof t&&(n=t,t=void 0),"function"==typeof e||Array.isArray(e))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if("number"==typeof e?e=r.from([e]):"string"==typeof e?e=r.from(e,n):this._isBufferList(e)?e=e.slice():Array.isArray(e.buffer)?e=r.from(e.buffer,e.byteOffset,e.byteLength):r.isBuffer(e)||(e=r.from(e)),t=Number(t||0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),0===e.length)return t>this.length?this.length:t;const i=this._offset(t);let o=i[0],s=i[1];for(;o<this._bufs.length;o++){const t=this._bufs[o];for(;s<t.length;){if(t.length-s>=e.length){const n=t.indexOf(e,s);if(-1!==n)return this._reverseOffset([o,n]);s=t.length-e.length+1}else{const t=this._reverseOffset([o,s]);if(this._match(t,e))return t;s++}}s=0}return-1},o.prototype._match=function(e,t){if(this.length-e<t.length)return!1;for(let n=0;n<t.length;n++)if(this.get(e+n)!==t[n])return!1;return!0},function(){const e={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1,readIntBE:null,readIntLE:null,readUIntBE:null,readUIntLE:null};for(const t in e)!function(t){o.prototype[t]=null===e[t]?function(e,n){return this.slice(e,e+n)[t](0,n)}:function(n=0){return this.slice(n,n+e[t])[t](0)}}(t)}(),o.prototype._isBufferList=function(e){return e instanceof o||o.isBufferList(e)},o.isBufferList=function(e){return null!=e&&e[i]},e.exports=o},function(e,t){e.exports=class{constructor(){this.cmd=null,this.retain=!1,this.qos=0,this.dup=!1,this.length=-1,this.topic=null,this.payload=null}}},function(e,t,n){e.exports=function(e){function t(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return r.colors[Math.abs(t)%r.colors.length]}function r(e){let n;function s(...e){if(!s.enabled)return;const t=s,i=Number(new Date),o=i-(n||i);t.diff=o,t.prev=n,t.curr=i,n=i,e[0]=r.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let a=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(n,i)=>{if("%%"===n)return n;a++;const o=r.formatters[i];if("function"==typeof o){const r=e[a];n=o.call(t,r),e.splice(a,1),a--}return n}),r.formatArgs.call(t,e),(t.log||r.log).apply(t,e)}return s.namespace=e,s.enabled=r.enabled(e),s.useColors=r.useColors(),s.color=t(e),s.destroy=i,s.extend=o,"function"==typeof r.init&&r.init(s),r.instances.push(s),s}function i(){const e=r.instances.indexOf(this);return-1!==e&&(r.instances.splice(e,1),!0)}function o(e,t){const n=r(this.namespace+(void 0===t?":":t)+e);return n.log=this.log,n}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return r.debug=r,r.default=r,r.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},r.disable=function(){const e=[...r.names.map(s),...r.skips.map(s).map(e=>"-"+e)].join(",");return r.enable(""),e},r.enable=function(e){let t;r.save(e),r.names=[],r.skips=[];const n=("string"==typeof e?e:"").split(/[\s,]+/),i=n.length;for(t=0;t<i;t++)n[t]&&("-"===(e=n[t].replace(/\*/g,".*?"))[0]?r.skips.push(new RegExp("^"+e.substr(1)+"$")):r.names.push(new RegExp("^"+e+"$")));for(t=0;t<r.instances.length;t++){const e=r.instances[t];e.enabled=r.enabled(e.namespace)}},r.enabled=function(e){if("*"===e[e.length-1])return!0;let t,n;for(t=0,n=r.skips.length;t<n;t++)if(r.skips[t].test(e))return!1;for(t=0,n=r.names.length;t<n;t++)if(r.names[t].test(e))return!0;return!1},r.humanize=n(106),Object.keys(e).forEach(t=>{r[t]=e[t]}),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=t,r.enable(r.load()),r}},function(e,t){var n=1e3,r=60*n,i=60*r,o=24*i,s=7*o,a=365.25*o;function u(e,t,n,r){var i=t>=1.5*n;return Math.round(e/n)+" "+r+(i?"s":"")}e.exports=function(e,t){t=t||{};var c=typeof e;if("string"===c&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var u=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return u*a;case"weeks":case"week":case"w":return u*s;case"days":case"day":case"d":return u*o;case"hours":case"hour":case"hrs":case"hr":case"h":return u*i;case"minutes":case"minute":case"mins":case"min":case"m":return u*r;case"seconds":case"second":case"secs":case"sec":case"s":return u*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return u;default:return}}(e);if("number"===c&&isFinite(e))return t.long?function(e){var t=Math.abs(e);if(t>=o)return u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=r)return u(e,t,r,"minute");if(t>=n)return u(e,t,n,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=o)return Math.round(e/o)+"d";if(t>=i)return Math.round(e/i)+"h";if(t>=r)return Math.round(e/r)+"m";if(t>=n)return Math.round(e/n)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,t,n){(function(t){const r=n(42),i=n(16);class o extends i{constructor(){super(),this._array=new Array(20),this._i=0}write(e){return this._array[this._i++]=e,!0}concat(){let e=0;const n=new Array(this._array.length),r=this._array;let i,o=0;for(i=0;i<r.length&&void 0!==r[i];i++)"string"!=typeof r[i]?n[i]=r[i].length:n[i]=t.byteLength(r[i]),e+=n[i];const s=t.allocUnsafe(e);for(i=0;i<r.length&&void 0!==r[i];i++)"string"!=typeof r[i]?(r[i].copy(s,o),o+=n[i]):(s.write(r[i],o),o+=n[i]);return s}}e.exports=function(e,t){const n=new o;return r(e,n,t),n.concat()}}).call(this,n(8).Buffer)},function(e,t,n){(function(t){const n=65536,r={},i=t.isBuffer(t.from([1,2]).subarray(0,1));function o(e){const n=t.allocUnsafe(2);return n.writeUInt8(e>>8,0),n.writeUInt8(255&e,1),n}e.exports={cache:r,generateCache:function(){for(let e=0;e<n;e++)r[e]=o(e)},generateNumber:o,genBufVariableByteInt:function(e){let n=0,r=0;const o=t.allocUnsafe(4);do{n=e%128|0,(e=e/128|0)>0&&(n|=128),o.writeUInt8(n,r++)}while(e>0&&r<4);return e>0&&(r=0),i?o.subarray(0,r):o.slice(0,r)},generate4ByteBuffer:function(e){const n=t.allocUnsafe(4);return n.writeUInt32BE(e,0),n}}}).call(this,n(8).Buffer)},function(e,t,n){"use strict";(function(t){void 0===t||!t.version||0===t.version.indexOf("v0.")||0===t.version.indexOf("v1.")&&0!==t.version.indexOf("v1.8.")?e.exports={nextTick:function(e,n,r,i){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return t.nextTick(e);case 2:return t.nextTick((function(){e.call(null,n)}));case 3:return t.nextTick((function(){e.call(null,n,r)}));case 4:return t.nextTick((function(){e.call(null,n,r,i)}));default:for(o=new Array(a-1),s=0;s<o.length;)o[s++]=arguments[s];return t.nextTick((function(){e.apply(null,o)}))}}}:e.exports=t}).call(this,n(9))},function(e,t,n){"use strict";function r(e,t,n){var r=this;this._callback=e,this._args=n,this._interval=setInterval(e,t,this._args),this.reschedule=function(e){e||(e=r._interval),r._interval&&clearInterval(r._interval),r._interval=setInterval(r._callback,e,r._args)},this.clear=function(){r._interval&&(clearInterval(r._interval),r._interval=void 0)},this.destroy=function(){r._interval&&clearInterval(r._interval),r._callback=void 0,r._interval=void 0,r._args=void 0}}e.exports=function(){if("function"!=typeof arguments[0])throw new Error("callback needed");if("number"!=typeof arguments[1])throw new Error("interval needed");var e;if(arguments.length>0){e=new Array(arguments.length-2);for(var t=0;t<e.length;t++)e[t]=arguments[t+2]}return new r(arguments[0],arguments[1],e)}},function(e,t,n){"use strict";function r(e){for(var t=e.split("/"),n=0;n<t.length;n++)if("+"!==t[n]){if("#"===t[n])return n===t.length-1;if(-1!==t[n].indexOf("+")||-1!==t[n].indexOf("#"))return!1}return!0}e.exports={validateTopics:function(e){if(0===e.length)return"empty_topic_list";for(var t=0;t<e.length;t++)if(!r(e[t]))return e[t];return null}}},function(e,t,n){"use strict";var r=n(113),i=n(115);function o(){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=b,t.resolve=function(e,t){return b(e,!1,!0).resolve(t)},t.resolveObject=function(e,t){return e?b(e,!1,!0).resolveObject(t):t},t.format=function(e){i.isString(e)&&(e=b(e));return e instanceof o?e.format():o.prototype.format.call(e)},t.Url=o;var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,u=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,c=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),l=["'"].concat(c),h=["%","/","?",";","#"].concat(l),f=["/","?","#"],p=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,m={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},y=n(116);function b(e,t,n){if(e&&i.isObject(e)&&e instanceof o)return e;var r=new o;return r.parse(e,t,n),r}o.prototype.parse=function(e,t,n){if(!i.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var o=e.indexOf("?"),a=-1!==o&&o<e.indexOf("#")?"?":"#",c=e.split(a);c[0]=c[0].replace(/\\/g,"/");var b=e=c.join(a);if(b=b.trim(),!n&&1===e.split("#").length){var _=u.exec(b);if(_)return this.path=b,this.href=b,this.pathname=_[1],_[2]?(this.search=_[2],this.query=t?y.parse(this.search.substr(1)):this.search.substr(1)):t&&(this.search="",this.query={}),this}var w=s.exec(b);if(w){var k=(w=w[0]).toLowerCase();this.protocol=k,b=b.substr(w.length)}if(n||w||b.match(/^\/\/[^@\/]+@[^@\/]+/)){var S="//"===b.substr(0,2);!S||w&&g[w]||(b=b.substr(2),this.slashes=!0)}if(!g[w]&&(S||w&&!v[w])){for(var E,T,C=-1,A=0;A<f.length;A++){-1!==(x=b.indexOf(f[A]))&&(-1===C||x<C)&&(C=x)}-1!==(T=-1===C?b.lastIndexOf("@"):b.lastIndexOf("@",C))&&(E=b.slice(0,T),b=b.slice(T+1),this.auth=decodeURIComponent(E)),C=-1;for(A=0;A<h.length;A++){var x;-1!==(x=b.indexOf(h[A]))&&(-1===C||x<C)&&(C=x)}-1===C&&(C=b.length),this.host=b.slice(0,C),b=b.slice(C),this.parseHost(),this.hostname=this.hostname||"";var I="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!I)for(var R=this.hostname.split(/\./),P=(A=0,R.length);A<P;A++){var O=R[A];if(O&&!O.match(p)){for(var M="",L=0,D=O.length;L<D;L++)O.charCodeAt(L)>127?M+="x":M+=O[L];if(!M.match(p)){var U=R.slice(0,A),j=R.slice(A+1),q=O.match(d);q&&(U.push(q[1]),j.unshift(q[2])),j.length&&(b="/"+j.join(".")+b),this.hostname=U.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),I||(this.hostname=r.toASCII(this.hostname));var F=this.port?":"+this.port:"",N=this.hostname||"";this.host=N+F,this.href+=this.host,I&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==b[0]&&(b="/"+b))}if(!m[k])for(A=0,P=l.length;A<P;A++){var B=l[A];if(-1!==b.indexOf(B)){var H=encodeURIComponent(B);H===B&&(H=escape(B)),b=b.split(B).join(H)}}var Y=b.indexOf("#");-1!==Y&&(this.hash=b.substr(Y),b=b.slice(0,Y));var W=b.indexOf("?");if(-1!==W?(this.search=b.substr(W),this.query=b.substr(W+1),t&&(this.query=y.parse(this.query)),b=b.slice(0,W)):t&&(this.search="",this.query={}),b&&(this.pathname=b),v[k]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){F=this.pathname||"";var z=this.search||"";this.path=F+z}return this.href=this.format(),this},o.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||"",o=!1,s="";this.host?o=e+this.host:this.hostname&&(o=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(o+=":"+this.port)),this.query&&i.isObject(this.query)&&Object.keys(this.query).length&&(s=y.stringify(this.query));var a=this.search||s&&"?"+s||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||v[t])&&!1!==o?(o="//"+(o||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):o||(o=""),r&&"#"!==r.charAt(0)&&(r="#"+r),a&&"?"!==a.charAt(0)&&(a="?"+a),t+o+(n=n.replace(/[?#]/g,(function(e){return encodeURIComponent(e)})))+(a=a.replace("#","%23"))+r},o.prototype.resolve=function(e){return this.resolveObject(b(e,!1,!0)).format()},o.prototype.resolveObject=function(e){if(i.isString(e)){var t=new o;t.parse(e,!1,!0),e=t}for(var n=new o,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 u=Object.keys(e),c=0;c<u.length;c++){var l=u[c];"protocol"!==l&&(n[l]=e[l])}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 h=Object.keys(e),f=0;f<h.length;f++){var p=h[f];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 m=n.pathname||"",y=n.search||"";n.path=m+y}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var b=n.pathname&&"/"===n.pathname.charAt(0),_=e.host||e.pathname&&"/"===e.pathname.charAt(0),w=_||b||n.host&&e.pathname,k=w,S=n.pathname&&n.pathname.split("/")||[],E=(d=e.pathname&&e.pathname.split("/")||[],n.protocol&&!v[n.protocol]);if(E&&(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])),_)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(!i.isNullOrUndefined(e.search)){if(E)n.hostname=n.host=S.shift(),(I=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=I.shift(),n.host=n.hostname=I.shift());return n.search=e.search,n.query=e.query,i.isNull(n.pathname)&&i.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 T=S.slice(-1)[0],C=(n.host||e.host||S.length>1)&&("."===T||".."===T)||""===T,A=0,x=S.length;x>=0;x--)"."===(T=S[x])?S.splice(x,1):".."===T?(S.splice(x,1),A++):A&&(S.splice(x,1),A--);if(!w&&!k)for(;A--;A)S.unshift("..");!w||""===S[0]||S[0]&&"/"===S[0].charAt(0)||S.unshift(""),C&&"/"!==S.join("/").substr(-1)&&S.push("");var I,R=""===S[0]||S[0]&&"/"===S[0].charAt(0);E&&(n.hostname=n.host=R?"":S.length?S.shift():"",(I=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=I.shift(),n.host=n.hostname=I.shift()));return(w=w||n.host&&S.length)&&!R&&S.unshift(""),S.length?n.pathname=S.join("/"):(n.pathname=null,n.path=null),i.isNull(n.pathname)&&i.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},o.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,n){(function(e,r){var i;/*! https://mths.be/punycode v1.4.1 by @mathias */!function(o){t&&t.nodeType,e&&e.nodeType;var s="object"==typeof r&&r;s.global!==s&&s.window!==s&&s.self;var a,u=2147483647,c=36,l=1,h=26,f=38,p=700,d=72,m=128,g="-",v=/^xn--/,y=/[^\x20-\x7E]/,b=/[\x2E\u3002\uFF0E\uFF61]/g,_={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},w=c-l,k=Math.floor,S=String.fromCharCode;function E(e){throw new RangeError(_[e])}function T(e,t){for(var n=e.length,r=[];n--;)r[n]=t(e[n]);return r}function C(e,t){var n=e.split("@"),r="";return n.length>1&&(r=n[0]+"@",e=n[1]),r+T((e=e.replace(b,".")).split("."),t).join(".")}function A(e){for(var t,n,r=[],i=0,o=e.length;i<o;)(t=e.charCodeAt(i++))>=55296&&t<=56319&&i<o?56320==(64512&(n=e.charCodeAt(i++)))?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),i--):r.push(t);return r}function x(e){return T(e,(function(e){var t="";return e>65535&&(t+=S((e-=65536)>>>10&1023|55296),e=56320|1023&e),t+=S(e)})).join("")}function I(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function R(e,t,n){var r=0;for(e=n?k(e/p):e>>1,e+=k(e/t);e>w*h>>1;r+=c)e=k(e/w);return k(r+(w+1)*e/(e+f))}function P(e){var t,n,r,i,o,s,a,f,p,v,y,b=[],_=e.length,w=0,S=m,T=d;for((n=e.lastIndexOf(g))<0&&(n=0),r=0;r<n;++r)e.charCodeAt(r)>=128&&E("not-basic"),b.push(e.charCodeAt(r));for(i=n>0?n+1:0;i<_;){for(o=w,s=1,a=c;i>=_&&E("invalid-input"),((f=(y=e.charCodeAt(i++))-48<10?y-22:y-65<26?y-65:y-97<26?y-97:c)>=c||f>k((u-w)/s))&&E("overflow"),w+=f*s,!(f<(p=a<=T?l:a>=T+h?h:a-T));a+=c)s>k(u/(v=c-p))&&E("overflow"),s*=v;T=R(w-o,t=b.length+1,0==o),k(w/t)>u-S&&E("overflow"),S+=k(w/t),w%=t,b.splice(w++,0,S)}return x(b)}function O(e){var t,n,r,i,o,s,a,f,p,v,y,b,_,w,T,C=[];for(b=(e=A(e)).length,t=m,n=0,o=d,s=0;s<b;++s)(y=e[s])<128&&C.push(S(y));for(r=i=C.length,i&&C.push(g);r<b;){for(a=u,s=0;s<b;++s)(y=e[s])>=t&&y<a&&(a=y);for(a-t>k((u-n)/(_=r+1))&&E("overflow"),n+=(a-t)*_,t=a,s=0;s<b;++s)if((y=e[s])<t&&++n>u&&E("overflow"),y==t){for(f=n,p=c;!(f<(v=p<=o?l:p>=o+h?h:p-o));p+=c)T=f-v,w=c-v,C.push(S(I(v+T%w,0))),f=k(T/w);C.push(S(I(f,0))),o=R(n,_,r==i),n=0,++r}++n,++t}return C.join("")}a={version:"1.4.1",ucs2:{decode:A,encode:x},decode:P,encode:O,toASCII:function(e){return C(e,(function(e){return y.test(e)?"xn--"+O(e):e}))},toUnicode:function(e){return C(e,(function(e){return v.test(e)?P(e.slice(4).toLowerCase()):e}))}},void 0===(i=function(){return a}.call(t,n,t,e))||(e.exports=i)}()}).call(this,n(114)(e),n(10))},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(117),t.encode=t.stringify=n(118)},function(e,t,n){"use strict";function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,n,o){t=t||"&",n=n||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var u=1e3;o&&"number"==typeof o.maxKeys&&(u=o.maxKeys);var c=e.length;u>0&&c>u&&(c=u);for(var l=0;l<c;++l){var h,f,p,d,m=e[l].replace(a,"%20"),g=m.indexOf(n);g>=0?(h=m.substr(0,g),f=m.substr(g+1)):(h=m,f=""),p=decodeURIComponent(h),d=decodeURIComponent(f),r(s,p)?i(s[p])?s[p].push(d):s[p]=[s[p],d]:s[p]=d}return s};var i=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?o(s(e),(function(s){var a=encodeURIComponent(r(s))+n;return i(e[s])?o(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 i=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function o(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){},function(e,t){},function(e,t,n){(function(t){var r=n(122),i=function(){},o=function(e,n,s){if("function"==typeof n)return o(e,null,n);n||(n={}),s=r(s||i);var a=e._writableState,u=e._readableState,c=n.readable||!1!==n.readable&&e.readable,l=n.writable||!1!==n.writable&&e.writable,h=!1,f=function(){e.writable||p()},p=function(){l=!1,c||s.call(e)},d=function(){c=!1,l||s.call(e)},m=function(t){s.call(e,t?new Error("exited with error code: "+t):null)},g=function(t){s.call(e,t)},v=function(){t.nextTick(y)},y=function(){if(!h)return(!c||u&&u.ended&&!u.destroyed)&&(!l||a&&a.ended&&!a.destroyed)?void 0:s.call(e,new Error("premature close"))},b=function(){e.req.on("finish",p)};return!function(e){return e.setHeader&&"function"==typeof e.abort}(e)?l&&!a&&(e.on("end",f),e.on("close",f)):(e.on("complete",p),e.on("abort",v),e.req?b():e.on("request",b)),function(e){return e.stdio&&Array.isArray(e.stdio)&&3===e.stdio.length}(e)&&e.on("exit",m),e.on("end",d),e.on("finish",p),!1!==n.error&&e.on("error",g),e.on("close",v),function(){h=!0,e.removeListener("complete",p),e.removeListener("abort",v),e.removeListener("request",b),e.req&&e.req.removeListener("finish",p),e.removeListener("end",f),e.removeListener("close",f),e.removeListener("finish",p),e.removeListener("exit",m),e.removeListener("end",d),e.removeListener("error",g),e.removeListener("close",v)}};e.exports=o}).call(this,n(9))},function(e,t,n){var r=n(123);function i(e){var t=function(){return t.called?t.value:(t.called=!0,t.value=e.apply(this,arguments))};return t.called=!1,t}function o(e){var t=function(){if(t.called)throw new Error(t.onceError);return t.called=!0,t.value=e.apply(this,arguments)},n=e.name||"Function wrapped with `once`";return t.onceError=n+" shouldn't be called more than once",t.called=!1,t}e.exports=r(i),e.exports.strict=r(o),i.proto=i((function(){Object.defineProperty(Function.prototype,"once",{value:function(){return i(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return o(this)},configurable:!0})}))},function(e,t){e.exports=function e(t,n){if(t&&n)return e(t)(n);if("function"!=typeof t)throw new TypeError("need wrapper function");Object.keys(t).forEach((function(e){r[e]=t[e]}));return r;function r(){for(var e=new Array(arguments.length),n=0;n<e.length;n++)e[n]=arguments[n];var r=t.apply(this,e),i=e[e.length-1];return"function"==typeof r&&r!==i&&Object.keys(i).forEach((function(e){r[e]=i[e]})),r}}},function(e,t){e.exports=function(e){var t=e._readableState;return t?t.objectMode||"number"==typeof e._duplexState?e.read():e.read(function(e){if(e.buffer.length)return e.buffer.head?e.buffer.head.data.length:e.buffer[0].length;return e.length}(t)):null}},function(e,t,n){"use strict";e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},function(e,t,n){var r=n(47);function i(e){var t,n;function i(t,n){try{var s=e[t](n),a=s.value,u=a instanceof r;Promise.resolve(u?a.wrapped:a).then((function(e){u?i("return"===t?"return":"next",e):o(s.done?"return":"normal",e)}),(function(e){i("throw",e)}))}catch(e){o("throw",e)}}function o(e,r){switch(e){case"return":t.resolve({value:r,done:!0});break;case"throw":t.reject(r);break;default:t.resolve({value:r,done:!1})}(t=t.next)?i(t.key,t.arg):n=null}this._invoke=function(e,r){return new Promise((function(o,s){var a={key:e,arg:r,resolve:o,reject:s,next:null};n?n=n.next=a:(t=n=a,i(e,r))}))},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(i.prototype[Symbol.asyncIterator]=function(){return this}),i.prototype.next=function(e){return this._invoke("next",e)},i.prototype.throw=function(e){return this._invoke("throw",e)},i.prototype.return=function(e){return this._invoke("return",e)},e.exports=i},function(e,t,n){"use strict";n.r(t);var r=n(17),i=n.n(r),o=n(0),s=n.n(o),a=n(2),u=n.n(a),c=n(3),l=n.n(c),h=n(4),f=n.n(h),p=n(1),d=n.n(p),m=n(6),g=n.n(m);var v=function(e){return e=e||Object.create(null),{on:function(t,n){(e[t]||(e[t]=[])).push(n)},off:function(t,n){e[t]&&e[t].splice(e[t].indexOf(n)>>>0,1)},emit:function(t,n){(e[t]||[]).slice().map((function(e){e(n)})),(e["*"]||[]).slice().map((function(e){e(t,n)}))}}},y=n(5),b=n.n(y),_=n(18),w=n.n(_),k=n(48),S=n.n(k);function E(e){return e.replace(/<[^>]*\/?>([\s\S]*)?<\/.*?>/gi,(function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}))}var T=function(){function e(t){l()(this,e),this.roomAdapter=t,this.name=null,this.emails=[],this.options={}}return f()(e,[{key:"withName",value:function(e){return this.name=e,this}},{key:"withOptions",value:function(e){return this.options=e,this}},{key:"addParticipants",value:function(){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return this.emails=(e=this.emails.filter((function(e){return-1===n.indexOf(e)}))).concat.apply(e,n),this}},{key:"create",value:function(){var e=this.name,t=this.emails,n=this.options;return this.roomAdapter.createRoom(e,t,{avatarURL:n.avatarURL},n)}}]),e}();var C=function(){function e(t){l()(this,e),this.id=t.id,this.before_id=t.comment_before_id,this.message=E(t.message),this.username_as=t.username_as||t.username,this.username_real=t.username_real||t.email,this.email=this.username_real,this.user_extras=t.user_extras,this.date=w()(t.timestamp,"YYYY-MM-DD"),this.time=w()(t.timestamp,"HH:mm"),this.timestamp=t.timestamp,this.unique_id=t.unique_temp_id||t.unique_id,this.unique_temp_id=t.unique_temp_id||t.unique_id,this.avatar=t.user_avatar_url,this.room_id=t.room_id,this.isChannel=t.is_public_channel,this.unix_timestamp=t.unix_timestamp,this.unix_nano_timestamp=t.unix_nano_timestamp,this.extras=t.extras,this.is_deleted=t.is_deleted,this.isPending=!1,this.isFailed=!1,this.isDelivered=!1,this.isRead=!1,this.isSent=!1,this.attachment=null,this.payload=t.payload,this.status=t.status,"reply"===t.type&&(t.payload.replied_comment_message=E(t.payload.replied_comment_message),t.payload.text=E(t.payload.text)),this.type=t.type,this.subtype="custom"===t.type?t.payload.type:null,"sent"===t.status?this.markAsSent():"delivered"===t.status?this.markAsDelivered():"read"===t.status&&this.markAsRead()}return f()(e,[{key:"isAttachment",value:function(e){return"[file]"===e.substring(0,"[file]".length)}},{key:"isImageAttachment",value:function(e){return this.isAttachment(e)&&null!=e.match(/\.(jpg|jpeg|gif|png)/i)}},{key:"attachUniqueId",value:function(e){this.unique_id=e}},{key:"getAttachmentURI",value:function(e){if(this.isAttachment(e)){var t=e.length,n="[file]".length,r=t-"[/file]".length;return e.substring(n,r).trim()}}},{key:"setAttachment",value:function(e){this.attachment=e}},{key:"markAsPending",value:function(){this.isPending=!0,this.isDelivered=!1,this.status="pending"}},{key:"markAsSent",value:function(){this.isSent=!0,this.isPending=!1,this.isFailed=!1,this.status="sent"}},{key:"markAsDelivered",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.actor,n=e.activeActorId;t!==n&&(this.isRead||"read"===this.status||(this.isSent=!0,this.isRead=!1,this.isDelivered=!0,this.status="delivered"))}},{key:"markAsRead",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.actor,n=e.activeActorId;t!==n&&(this.isPending=!1,this.isSent=!0,this.isDelivered=!0,this.isRead=!0,this.status="read")}},{key:"markAsFailed",value:function(){this.isFailed=!0,this.isPending=!1,this.isStatus="failed"}},{key:"update",value:function(e){this.id=e.id,this.before_id=e.comment_before_id,this.message=E(e.message),e.payload&&(this.payload=e.payload),e.status&&(this.status=e.status),"reply"===e.type&&(this.payload.replied_comment_message=E(e.payload.replied_comment_message),this.payload.text=E(e.payload.text)),"sent"===e.status?this.markAsSent():"delivered"===e.status?this.markAsDelivered():"read"===e.status&&this.markAsRead()}}]),e}(),A=function(){function e(t){l()(this,e),this.id=t.id,this.last_comment_id=t.last_comment_id,this.last_comment_message=t.last_comment_message,this.last_comment_message_created_at=t.last_comment_message_created_at,this.last_comment_topic_title=t.last_comment_topic_title,this.avatar=t.room_avatar||t.avatarURL||t.avatar_url,this.name=t.room_name,this.room_type=t.room_type||t.chat_type,this.secret_code=t.secret_code,this.participants=t.participants,this.options=t.options,this.topics=[],this.last_comment=t.last_comment,this.comments=[],this.count_notif=t.unread_count,this.isLoaded=!1,this.custom_title=null,this.custom_subtitle=null,this.options=t.options,this.unique_id=t.unique_id,this.isChannel=t.is_public_channel,this.participantNumber=t.room_total_participants,t.comments&&this.receiveComments(t.comments)}return f()(e,[{key:"isCurrentlySelected",value:function(e){return this.id===e.id}},{key:"getParticipantCount",value:function(){return null==this.participants?this.participantNumber:this.participants.length}},{key:"setTitle",value:function(e){this.custom_title=e}},{key:"setSubTitle",value:function(e){this.custom_subtitle=e}},{key:"receiveComment",value:function(e){if(e.room_id===this.id){var t=this.comments.find((function(t){return t.unique_id===e.unique_id}));t?(t.id=e.id,t.message=e.message,t.date=e.date,t.time=e.time,t.unix_timestamp=e.unix_timestamp):this.comments.push(e)}}},{key:"receiveComments",value:function(e){var t=this;e.forEach((function(e){t.receiveComment(new C(e))}))}},{key:"getParticipant",value:function(e){return this.participants.find((function(t){return t.email===e}))||null}},{key:"addParticipant",value:function(e){this.getParticipant(e.email)||this.participants.push(e)}}]),e}(),x=function(){function e(t){var n=t.baseURL,r=t.AppId,i=t.userId,o=t.version,s=t.getCustomHeader;l()(this,e),this.baseURL=n,this.token=null,this.userId=i,this.AppId=r,this.version=o,this.getCustomHeader=s}return f()(e,[{key:"setToken",value:function(e){this.token=e}},{key:"get",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;return new Promise((function(i,o){var s=g.a.get("".concat(t.baseURL,"/").concat(e));r&&r.baseURL&&(s=g.a.get("".concat(r.baseURL,"/").concat(e))),(s=t.setupHeaders(s,n)).end((function(e,n){return e?(t._rethrowIfExpiredToken(e),o(e)):i(n)}))}))}},{key:"get_request",value:function(e){var t=g.a.get("".concat(this.baseURL,"/").concat(e));return t=this.setupHeaders(t,{})}},{key:"post",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,o){var s=g.a.post("".concat(t.baseURL,"/").concat(e));(s=t.setupHeaders(s,r)).send(n).set("Content-Type","application/x-www-form-urlencoded").end((function(e,n){return e?(t._rethrowIfExpiredToken(e),o(e)):i(n)}))}))}},{key:"post_json",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,o){var s=g.a.post("".concat(t.baseURL,"/").concat(e));(s=t.setupHeaders(s,r)).send(n).set("Content-Type","application/json").end((function(e,n){return e?(t._rethrowIfExpiredToken(e),o(e)):i(n)}))}))}},{key:"put",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,o){var s=g.a.put("".concat(t.baseURL,"/").concat(e));(s=t.setupHeaders(s,r)).send(n).set("Content-Type","application/x-www-form-urlencoded").end((function(e,n){return e?(t._rethrowIfExpiredToken(e),o(e)):i(n)}))}))}},{key:"patch",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,o){var s=g.a.patch("".concat(t.baseURL,"/").concat(e));(s=t.setupHeaders(s,r)).send(n).set("Content-Type","application/x-www-form-urlencoded").end((function(e,n){return e?(t._rethrowIfExpiredToken(e),o(e)):i(n)}))}))}},{key:"del",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,o){var s=g.a.del("".concat(t.baseURL,"/").concat(e));(s=t.setupHeaders(s,r)).send(n).set("Content-Type","application/json").end((function(e,n){return e?(t._rethrowIfExpiredToken(e),o(e)):i(n)}))}))}},{key:"setupHeaders",value:function(e,t){if(null!=this.AppId&&e.set("QISCUS-SDK-APP-ID","".concat(this.AppId)),null!=this.userId&&e.set("QISCUS-SDK-USER-ID","".concat(this.userId)),console.log("this.token:",this.token),null!=this.token&&e.set("QISCUS-SDK-TOKEN","".concat(this.token)),null!=this.version&&e.set("QISCUS-SDK-VERSION","".concat(this.version)),null!=this.getCustomHeader){var n=this.getCustomHeader();Object.keys(n).filter((function(e){return null!=n[e]})).forEach((function(t){e.set(t,n[t])}))}if(Object.keys(t).length<1)return e;for(var r in t)t.hasOwnProperty(r)&&e.set(r,t[r]);return e}},{key:"_rethrowIfExpiredToken",value:function(e){var t,n,r,i,o=null===(t=e.response)||void 0===t?void 0:t.status,s=null===(n=e.response)||void 0===n?void 0:n.body;if(403===o&&"unauthorized. token is expired"===(null===(r=s.error)||void 0===r?void 0:null===(i=r.message)||void 0===i?void 0:i.toLowerCase()))throw new Error("Token expired")}}]),e}(),I=function(){function e(t){l()(this,e),this.HTTPAdapter=t,this.refreshToken=null,this.userId=null}return f()(e,[{key:"getNonce",value:function(){return this.HTTPAdapter.post("api/v2/sdk/auth/nonce").then((function(e){return e.body.results}))}},{key:"loginOrRegister",value:function(e){var t=this;return this.HTTPAdapter.post("api/v2/sdk/login_or_register",e).then((function(e){if(200!==e.body.status)return Promise.reject(e);var n=e.body.results;return t.userId=n.user.email,t.refreshToken=n.user.refresh_token,n}))}},{key:"verifyIdentityToken",value:function(e){var t=this;return this.HTTPAdapter.post("api/v2/sdk/auth/verify_identity_token",{identity_token:e}).then((function(e){var n=e.body.results;return t.userId=n.user.email,t.refreshToken=n.user.refresh_token,n}))}},{key:"refreshAuthToken",value:function(){var e=this;return this.HTTPAdapter.post("api/v2/sdk/refresh_user_token",{user_id:this.userId,refresh_token:this.refreshToken}).then((function(t){var n=t.body.results;return e.refreshToken=n.refresh_token,e.HTTPAdapter.token=n.token,n}))}},{key:"expiredAuthToken",value:function(){return this.HTTPAdapter.post("api/v2/sdk/expire_user_token",{user_id:this.userId}).then((function(e){return e.body.results}))}}]),e}(),R=n(49),P=n.n(R);function O(e){var t={},n=function(e,t){return"".concat(e,"=").concat(t)};return{param:function(e,n){return t[e]=n,this},build:function(){var r=Object.keys(t).filter((function(e){return null!=t[e]})).map((function(e){return Array.isArray(t[e])?t[e].map((function(t){return n("".concat(e,"[]"),t)})).join("&"):n(e,t[e])})).join("&");return[e].concat(r).join("?")}}}var M=function(){function e(t){var n=this;l()(this,e),d()(this,"updateCommentStatus",P()((function(e,t,r){var i={room_id:e};return t&&(i.last_comment_read_id=t),r&&(i.last_comment_received_id=r),n.HTTPAdapter.post("api/v2/sdk/update_comment_status",i)}),500)),this.HTTPAdapter=t,this.token=t.token}return f()(e,[{key:"postComment",value:function(e,t,n,r,i,o){return this.HTTPAdapter.post_json("api/v2/sdk/post_comment",{comment:t,topic_id:e,unique_temp_id:n,type:r,payload:i,extras:o}).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.comment)}))}},{key:"loadRoomList",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=O("api/v2/sdk/user_rooms").param("page",t.page).param("show_participants",t.show_participants||!0).param("limit",t.limit).param("show_empty",t.show_empty).param("room_type",null!==(e=t.room_type)&&void 0!==e?e:"default").build();return this.HTTPAdapter.get(n).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.rooms_info)}))}},{key:"searchMessages",value:function(e){var t={query:e.query||null,room_id:e.room_id||null,last_comment_id:e.last_comment_id||null};return this.HTTPAdapter.post("api/v2/sdk/search_messages",t).then((function(e){return e.body.results.comments}))}},{key:"updateProfile",value:function(e){var t={name:e.name||null,avatar_url:e.avatar_url||null,extras:e.extras?JSON.stringify(e.extras):null};return this.HTTPAdapter.patch("api/v2/sdk/my_profile",t).then((function(e){return e.body.results.user}))}},{key:"uploadFile",value:function(e){var t={file:e};return this.HTTPAdapter.post("api/v2/sdk/upload",t).then((function(e){return e.body}))}},{key:"getRoomsInfo",value:function(e){var t={show_participants:!0,show_removed:!1};return e.room_ids&&(t.room_id=e.room_ids),e.room_unique_ids&&(t.room_unique_id=e.room_unique_ids),e.show_participants&&(t.show_participants=e.show_participants),e.show_removed&&(t.show_removed=e.show_removed),this.HTTPAdapter.post_json("api/v2/sdk/rooms_info",t).then((function(e){return e.body}))}},{key:"loadComments",value:function(e,t){var n=O("api/v2/sdk/load_comments").param("topic_id",e).param("last_comment_id",t.last_comment_id).param("timestamp",t.timestamp).param("after",t.after).param("limit",t.limit).build();return this.HTTPAdapter.get(n).then((function(e){return 200!==e.status?Promise.reject(e):Promise.resolve(e.body.results.comments)}))}},{key:"deleteComment",value:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];!1===n&&console.warn("Deprecated: delete comment for me will be removed on next release"),!1===r&&console.warn("Deprecated: soft delete will be removed on next release");var i={unique_ids:t,is_delete_for_everyone:n,is_hard_delete:r};return this.HTTPAdapter.del("api/v2/sdk/delete_messages",i).then((function(e){return e.body}))}},{key:"clearRoomMessages",value:function(e){var t={room_channel_ids:e};return this.HTTPAdapter.del("api/v2/sdk/clear_room_messages",t).then((function(e){return e.body}))}},{key:"getCommentReceiptStatus",value:function(e){return this.HTTPAdapter.get("api/v2/sdk/comment_receipt?comment_id=".concat(e)).then((function(e){return e.body}))}},{key:"getBlockedUser",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,n="api/v2/sdk/get_blocked_users?page=".concat(e,"&limit=").concat(t);return this.HTTPAdapter.get(n).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.blocked_users)}))}},{key:"blockUser",value:function(e){if(!e)throw new Error("email is required");var t={user_email:e};return this.HTTPAdapter.post("api/v2/sdk/block_user",t).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.user)}))}},{key:"unblockUser",value:function(e){if(!e)throw new Error("email is required");var t={user_email:e};return this.HTTPAdapter.post("api/v2/sdk/unblock_user",t).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.user)}))}},{key:"getProfile",value:function(){return this.HTTPAdapter.get("api/v2/sdk/my_profile").then((function(e){return e.body.results.user}))}},{key:"getUserPresences",value:function(e){var t={user_ids:e};return this.HTTPAdapter.post_json("api/v2/sdk/users/status",t).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.user_status)}))}},{key:"updateMessage",value:function(e){var t={token:this.token,comment:e.message,unique_id:e.unique_id||e.unique_temp_id};return null!=e.extras&&(t.extras=e.extras),null!=e.payload&&(t.payload=e.payload),this.HTTPAdapter.post_json("api/v2/sdk/update_message",t).then((function(e){return e.body.results.comment}))}}]),e}(),L=function(){function e(t){l()(this,e),this.HTTPAdapter=t,this.token=t.token}return f()(e,[{key:"getOrCreateRoom",value:function(e,t,n){var r={emails:e};return n&&(r[n]=n),t&&(r.options=JSON.stringify(t)),this.HTTPAdapter.post("api/v2/sdk/get_or_create_room_with_target",r).then((function(t){if(200!==t.body.status)return Promise.reject(t);var n=t.body.results.room;n.avatar=n.avatar_url,n.comments=t.body.results.comments.reverse();var r=n.participants.find((function(t){return t.email===e}));return n.name=r?r.username:"Room name",Promise.resolve(n)}))}},{key:"getRoomById",value:function(e){return this.HTTPAdapter.get("api/v2/sdk/get_room_by_id?id=".concat(e)).then((function(e){return e.body}))}},{key:"getOrCreateRoomByUniqueId",value:function(e,t,n){var r={unique_id:e,name:t,avatar_url:n};return this.HTTPAdapter.post("api/v2/sdk/get_or_create_room_with_unique_id",r).then((function(e){if(200!==e.body.status)return Promise.reject(e);var t=e.body.results.room;return t.avatar=t.avatar_url,t.comments=e.body.results.comments.reverse(),t.name=t.room_name,Promise.resolve(t)}))}},{key:"createRoom",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=Object.keys(r).length<=0?null:JSON.stringify(r),o={name:e,"participants[]":t,avatar_url:n.avatarURL,options:i};return this.HTTPAdapter.post("api/v2/sdk/create_room",o).then((function(e){if(200!==e.body.status)return Promise.reject(e);var t=e.body.results.room;return t.comments=e.body.results.comments,Promise.resolve({id:t.id,name:t.room_name,lastCommentId:t.last_comment_id,lastCommentMessage:t.last_comment_message,lastTopicId:t.last_topic_id,avatarURL:t.avatar_url,options:t.options,participants:t.participants.map((function(e){return{id:e.id,email:e.email,username:e.username,avatarURL:e.avatar_url}}))})}))}},{key:"updateRoom",value:function(e){if(!e.id)throw new Error("id is required");var t={id:e.id};return e.room_name&&(t.room_name=e.room_name),e.avatar_url&&(t.avatar_url=e.avatar_url),e.options&&(t.options=JSON.stringify(e.options)),this.HTTPAdapter.post("api/v2/sdk/update_room",t).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.room)}))}},{key:"getTotalUnreadCount",value:function(){return this.HTTPAdapter.get("api/v2/sdk/total_unread_count").then((function(e){return e.body.results.total_unread_count}))}},{key:"getRoomUnreadCount",value:function(){return this.HTTPAdapter.get("api/v2/sdk/get_room_unread_count").then((function(e){return e.body.results.total_unread_count}))}},{key:"addParticipantsToGroup",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(!e||!t)throw new Error("room_id and emails is required");var n={room_id:e,"emails[]":t};return this.HTTPAdapter.post("api/v2/sdk/add_room_participants",n).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.participants_added)}))}},{key:"removeParticipantsFromGroup",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(!e||!t)throw new Error("room_id and emails is required");var n={room_id:e,"emails[]":t};return this.HTTPAdapter.post("api/v2/sdk/remove_room_participants",n).then((function(e){return 200!==e.body.status?Promise.reject(e):Promise.resolve(e.body.results.participants_removed)}))}}]),e}(),D=n(50),U=n.n(D),j=n(51),q=n.n(j),F=String("match.pattern.catchAll"),N=String("match.pattern.OR"),B=N.toString(),H=String("match.pattern.AND"),Y=H.toString(),W=String("match.pattern.RANGE"),z=W.toString(),$=String("match.pattern.REGEXP"),V=$.toString(),K=/\/(.*)\/(.*)/;function Q(){Error.call(this,"Missing when() catch-all pattern as last match argument, add [when()]: void 0"),"stack"in this||(this.stack=(new Error).stack)}function G(e){return void 0===e?F:e instanceof RegExp?X([$.toString(),e.toString()]):X(e)}function X(e){return JSON.stringify([G.__uid++,e])}function J(){return!0}function Z(e){if(Array.isArray(e)){if(e[0]===B)return e.shift(),function(t){return e[0].some((function(e){return n(e,t)}))};if(e[0]===Y)return e.shift(),function(t){return e[0].every((function(e){return n(e,t)}))};if(e[0]===z)return e.shift(),function(t){return e[0]<=t&&t<=e[1]};if(e[0]===V){var t=K.exec(e[1]);return n.bind(null,new RegExp(t[1],t[2]))}}function n(e,t){if(Array.isArray(t))return JSON.stringify(e)===JSON.stringify(t);if(e instanceof RegExp)return e.test(t);if("object"===q()(t)){for(var n in e)if(t[n]!==e[n])return!1;return!0}return e===t}return function(t){return n(e,t)}}Q.prototype=Object.create(Error.prototype),G.__uid=0,G.or=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return X([N.toString(),t])},G.and=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return X([H.toString(),t])},G.range=function(e,t){return X([W.toString(),e,t])},G.unserialize=function(e,t){if(e===F)return{match:J,result:t,position:1/0};var n,r=(n=e,JSON.parse(n)),i=r[1],o=r[0];return{match:Z(i),result:t,position:o}};var ee=n(52),te=n.n(ee),ne=n(53),re=n.n(ne),ie=function(e,t,n,r){try{var i=e();return null!=r&&r(i),i}catch(e){return null!=n&&n(e),t}},oe=function(e){return e.then((function(e){return[e,null]})).catch((function(e){return[null,e]}))},se=function(){function e(t,n,r,o){var a,c=this,h=o.shouldConnect,f=void 0===h||h,p=o.brokerLbUrl,m=o.enableLb,g=o.getClientId;l()(this,e),d()(this,"_getClientId",(function(){return null==c.getClientId?"".concat(c.core.AppId,"_").concat(c.core.user_id,"_").concat(Date.now()):c.getClientId()})),d()(this,"__mqtt_connected_handler",(function(){c.emitter.emit("connected")})),d()(this,"__mqtt_reconnect_handler",(function(){c.emitter.emit("reconnect")})),d()(this,"__mqtt_closed_handler",(function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];c.emitter.emit("close",t)})),d()(this,"__mqtt_message_handler",(function(e,t){var n=t.toString(),r=c.matcher(e);c.logger("message",e,t),null!=r&&r(n)})),d()(this,"__mqtt_error_handler",(function(e){e&&"client disconnecting"===e.message||(c.emitter.emit("error",e.message),c.logger("error",e.message))})),d()(this,"__mqtt_conneck",(function(e){var t=[],n={will:{topic:"u/".concat(c.core.user_id,"/s"),payload:0,retain:!0},clientId:c._getClientId()};if(null==e&&(e=c.cacheRealtimeURL),null!=c.mqtt){var r=Object.keys(c.mqtt._resubscribeTopics);t.push.apply(t,i()(r)),c.mqtt.removeAllListeners(),c.mqtt.end(!0),delete c.mqtt,c.mqtt=null}var o=te()(e,n);return o.addListener("connect",c.__mqtt_connected_handler),o.addListener("reconnect",c.__mqtt_reconnect_handler),o.addListener("close",c.__mqtt_closed_handler),o.addListener("error",c.__mqtt_error_handler),o.addListener("message",c.__mqtt_message_handler),c.logger("resubscribe to old topics ".concat(t)),t.forEach((function(e){return o.subscribe(e)})),o})),d()(this,"_on_close_handler",re()(u()(s.a.mark((function e(){var t,n,r,i;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=!0===c.enableLb&&!0===c.core.isLogin&&!0===c.shouldConnect&&!c.willConnectToRealtime,c.logEnabled&&(console.group("@mqtt.closed"),console.log("this.enableLb(".concat(c.enableLb,")")),console.log("this.core.isLogin(".concat(c.core.isLogin,")")),console.log("this.shouldConnect(".concat(c.shouldConnect,")")),console.log("this.willConnectToRealtime(".concat(c.willConnectToRealtime,")")),console.log("shouldReconnect(".concat(t,")")),console.groupEnd()),t){e.next=4;break}return e.abrupt("return");case 4:return c.willConnectToRealtime=!0,e.next=7,oe(c.getMqttNode());case 7:n=e.sent,r=U()(n,2),i=r[0],r[1]?(c.logger("cannot get new brokerURL, using old url instead (".concat(c.cacheRealtimeURL,")")),c.mqtt=c.__mqtt_conneck(c.cacheRealtimeURL)):(c.cacheRealtimeURL=i,c.logger("trying to reconnect to",i),c.mqtt=c.__mqtt_conneck(i)),c.willConnectToRealtime=!1;case 13:case"end":return e.stop()}}),e)}))),1e3)),d()(this,"subscribtionBuffer",[]),d()(this,"unsubscribtionBuffer",[]),d()(this,"publishBuffer",[]),this.emitter=v(),this.core=n,this.mqtt=null,this.brokerLbUrl=p,this.getClientId=g,this.enableLb=m,this.shouldConnect=f,this.matcher=function(){var e,t=(e=arguments.length-1)<0||arguments.length<=e?void 0:arguments[e],n=[];for(var r in t)n.push(G.unserialize(r,t[r]));n.sort((function(e,t){return e.position<t.position?-1:1})),-1!==Object.getOwnPropertySymbols(t).indexOf(F)&&n.push(G.unserialize(F,t[F]));var i=function(e){var t=n.find((function(t){return t.match(e)}));if(!t)throw new Q;return"function"==typeof t.result?t.result(e):t.result};return 2===arguments.length?i(arguments.length<=0?void 0:arguments[0]):i}((a={},d()(a,G(this.reNewMessage),(function(e){return c.newMessageHandler.bind(c,e)})),d()(a,G(this.reNotification),(function(e){return c.notificationHandler.bind(c,e)})),d()(a,G(this.reTyping),(function(e){return c.typingHandler.bind(c,e)})),d()(a,G(this.reDelivery),(function(e){return c.deliveryReceiptHandler.bind(c,e)})),d()(a,G(this.reRead),(function(e){return c.readReceiptHandler.bind(c,e)})),d()(a,G(this.reOnlineStatus),(function(e){return c.onlinePresenceHandler.bind(c,e)})),d()(a,G(this.reChannelMessage),(function(e){return c.channelMessageHandler.bind(c,e)})),d()(a,G(this.reMessageUpdated),(function(e){return c.messageUpdatedHandler.bind(c,e)})),d()(a,G(),(function(e){return c.logger("topic not handled",e)})),a));var y=this.__mqtt_conneck(t);this.mqtt=y,f||y.end(!0),this.willConnectToRealtime=!1,this.emitter.on("close",this._on_close_handler)}var t,n,r;return f()(e,[{key:"connect",value:function(){this.mqtt=this.__mqtt_conneck()}},{key:"openConnection",value:(r=u()(s.a.mark((function e(){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.shouldConnect=!0,this.__mqtt_conneck();case 2:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"closeConnection",value:(n=u()(s.a.mark((function e(){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.shouldConnect=!1,this.mqtt.end(!0);case 2:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getMqttNode",value:(t=u()(s.a.mark((function e(){var t,n,r;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,g.a.get(this.brokerLbUrl);case 2:return t=e.sent,n=t.body.data.url,r=t.body.data.wss_port,e.abrupt("return","wss://".concat(n,":").concat(r,"/mqtt"));case 6:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"subscribe",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(this.logger("subscribe to",t),this.subscribtionBuffer.push(t),null!=this.mqtt)do{var r,i=this.subscribtionBuffer.shift();null!=i&&(r=this.mqtt).subscribe.apply(r,t)}while(this.subscribtionBuffer.length>0)}},{key:"unsubscribe",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(this.logger("unsubscribe from",t),this.unsubscribtionBuffer.push(t),null!=this.mqtt)do{var r,o=this.unsubscribtionBuffer.shift();if(null!=o)(r=this.mqtt).unsubscribe.apply(r,i()(o))}while(this.unsubscribtionBuffer.length>0)}},{key:"publish",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.publishBuffer.push({topic:e,payload:t,options:n});do{var r=this.publishBuffer.shift();if(null!=r)return this.mqtt.publish(r.topic,r.payload.toString(),r.options)}while(this.publishBuffer.length>0)}},{key:"emit",value:function(){var e;(e=this.emitter).emit.apply(e,arguments)}},{key:"on",value:function(){var e;(e=this.emitter).on.apply(e,arguments)}},{key:"off",value:function(){var e;(e=this.emitter).off.apply(e,arguments)}},{key:"noop",value:function(){}},{key:"newMessageHandler",value:function(e,t){t=JSON.parse(t),this.logger("on:new-message",t),this.emit("new-message",t)}},{key:"notificationHandler",value:function(e,t){var n=this;this.logger("on:notification",t);var r=(t=JSON.parse(t)).payload.data;"deleted_messages"in r&&r.deleted_messages.forEach((function(e){n.emit("comment-deleted",{roomId:e.room_id,commentUniqueIds:e.message_unique_ids,isForEveryone:!0,isHard:!0})})),"deleted_rooms"in r&&r.deleted_rooms.forEach((function(e){n.emit("room-cleared",e)}))}},{key:"typingHandler",value:function(e,t){this.logger("on:typing",e);var n=e.match(this.reTyping);if(n[3]!==this.core.user_id){var r=n[3],i=n[1];if(this.emit("typing",{message:t,userId:r,roomId:i}),null!=this.core.selected)if("1"===t&&i===this.core.selected.id){var o=this.core.selected.participants.find((function(e){return e.email===r}));if(null==o)return;var s=o.username;this.core.isTypingStatus="".concat(s," is typing ...")}else this.core.isTypingStatus=null}}},{key:"deliveryReceiptHandler",value:function(e,t){this.logger("on:delivered",e,t);var n=e.match(this.reDelivery),r=t.split(":"),i=Number(r[0]),o=r[1],s=n[3];this.emit("message-delivered",{commentId:i,commentUniqueId:o,userId:s})}},{key:"readReceiptHandler",value:function(e,t){this.logger("on:read",e,t);var n=e.match(this.reRead),r=t.split(":"),i=Number(r[0]),o=r[1],s=n[3];this.emit("message-read",{commentId:i,commentUniqueId:o,userId:s})}},{key:"onlinePresenceHandler",value:function(e,t){this.logger("on:online-presence",e,t);var n=this.reOnlineStatus.exec(e)[1];this.emit("presence",{message:t,userId:n})}},{key:"channelMessageHandler",value:function(e,t){this.logger("on:channel-message",e,t),this.emit("new-message",JSON.parse(t))}},{key:"messageUpdatedHandler",value:function(e,t){t=JSON.parse(t),this.logger("on:message-updated",e,t),this.emit("message:updated",t)}},{key:"subscribeChannel",value:function(e,t){this.subscribe("".concat(e,"/").concat(t,"/c"))}},{key:"subscribeRoom",value:function(e){null!=this.core.selected&&(e=e||this.core.selected.id,this.subscribe("r/".concat(e,"/").concat(e,"/+/t")),this.subscribe("r/".concat(e,"/").concat(e,"/+/d")),this.subscribe("r/".concat(e,"/").concat(e,"/+/r")))}},{key:"unsubscribeRoom",value:function(e){null!=this.core.selected&&(e=e||this.core.selected.id,this.unsubscribe("r/".concat(e,"/").concat(e,"/+/t")),this.unsubscribe("r/".concat(e,"/").concat(e,"/+/d")),this.unsubscribe("r/".concat(e,"/").concat(e,"/+/r")))}},{key:"subscribeUserChannel",value:function(){this.subscribe("".concat(this.core.userData.token,"/c")),this.subscribe("".concat(this.core.userData.token,"/n")),this.subscribe("".concat(this.core.userData.token,"/update"))}},{key:"publishPresence",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];t?this.publish("u/".concat(e,"/s"),1,{retain:!0}):this.publish("u/".concat(e,"/s"),0,{retain:!0})}},{key:"disconnect",value:function(){this.publishPresence(this.core.userData.email,!1),this.unsubscribe(Object.keys(this.mqtt._resubscribeTopics))}},{key:"subscribeUserPresence",value:function(e){this.subscribe("u/".concat(e,"/s"))}},{key:"unsubscribeUserPresence",value:function(e){this.unsubscribe("u/".concat(e,"/s"))}},{key:"publishTyping",value:function(e){if(null!=this.core.selected){var t=this.core.selected.id,n=this.core.user_id;this.publish("r/".concat(t,"/").concat(t,"/").concat(n,"/t"),e)}}},{key:"cacheRealtimeURL",get:function(){return this.core.mqttURL},set:function(e){this.core.mqttURL=e}},{key:"connected",get:function(){return null!=this.mqtt&&this.mqtt.connected}},{key:"logEnabled",get:function(){return this.core.debugMQTTMode}},{key:"logger",get:function(){return this.core.debugMQTTMode?console.log.bind(console,"QRealtime ->"):this.noop}},{key:"reNewMessage",get:function(){return/^(.+)\/c$/i}},{key:"reNotification",get:function(){return/^(.+)\/n$/i}},{key:"reTyping",get:function(){return/^r\/([\d]+)\/([\d]+)\/(.+)\/t$/i}},{key:"reDelivery",get:function(){return/^r\/([\d]+)\/([\d]+)\/(.+)\/d$/i}},{key:"reRead",get:function(){return/^r\/([\d]+)\/([\d]+)\/(.+)\/r$/i}},{key:"reOnlineStatus",get:function(){return/^u\/(.+)\/s$/i}},{key:"reChannelMessage",get:function(){return/^(.+)\/(.+)\/c$/i}},{key:"reMessageUpdated",get:function(){return/^(.+)\/update$/i}},{key:"subscribeTyping",get:function(){return this.subscribeRoom.bind(this)}},{key:"unsubscribeTyping",get:function(){return this.unsubscribeRoom.bind(this)}},{key:"subscribeRoomPresence",get:function(){return this.subscribeUserPresence.bind(this)}},{key:"unsubscribeRoomPresence",get:function(){return this.unsubscribeUserPresence.bind(this)}}]),e}();function ae(e,t){var n=v(),r={},i=/^r\/[\w]+\/[\w]+\/e$/i;e.mqtt.on("message",(function(e,t){i.test(e)&&n.emit(e,t)}));var o=function(e){return"r/".concat(e,"/").concat(e,"/e")};return{publishEvent:function(n,r){if(b.a.undefined(n))throw new Error("`roomId` required");if(b.a.not.string(n))throw new TypeError("`roomId` must have type of string");if(b.a.undefined(r))throw new Error("`payload` required");if(b.a.not.object(r))throw new TypeError("`payload` must have type of object");var i=JSON.stringify({sender:t,data:r});e.mqtt.publish(o(n),i)},subscribeEvent:function(t,i){if(b.a.undefined(t))throw new Error("`roomId` required");if(b.a.not.string(t))throw new TypeError("`roomId` must have type of string");if(b.a.undefined(i))throw new Error("`callback` required");if(b.a.not.function(i))throw new TypeError("`callback` must have type of function");var s=o(t);if(!r[s]){e.mqtt.subscribe(s);var a=function(e){var t=JSON.parse(e);i(t)};n.on(s,a),r[s]=a}},unsubscribeEvent:function(t){if(b.a.undefined(t))throw new Error("`roomId` required");if(b.a.not.string(t))throw new TypeError("`roomId` must have type of string");var i=o(t);r[i]&&(e.mqtt.unsubscribe(i),n.off(i,r[i]),r[i]=null,delete r[i])}}}var ue=n(24),ce=n.n(ue),le=n(25),he=n.n(le),fe=n(26),pe=n.n(fe),de=function(){},me=function(e){return new Promise((function(t){return setTimeout(t,e)}))};function ge(e,t){var n=t.isDebug,r=void 0!==n&&n,i=t.syncInterval,o=t.getShouldSync,a=t.syncOnConnect,c=t.lastCommentId,l=t.statusLogin,h=v(),f=function(){for(var e,t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return r?(e=console).log.apply(e,["QSync:"].concat(n)):{}},p=0,d=function(){if(l())return o()?i():a()},m=function(e,t,n,r,i){var o=v(),a=function(n){var r=O("api/v2/sdk/sync").param("last_received_comment_id",n).build();return e().get(r).then((function(e){var n=e.body.results,r=n.comments,i=n.meta.last_received_comment_id;return r.sort((function(e,t){return e.id-t.id})),Promise.resolve({lastMessageId:i,messages:r,interval:t()})})).catch(de)};function c(){return l.apply(this,arguments)}function l(){return(l=pe()(s.a.mark((function i(){var o,u,c;return s.a.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:o=0,u=100,c=function(){return null!=e()&&n()};case 3:if(!((o+=u)>=t()&&c)){i.next=9;break}return o=0,i.next=9,a(r());case 9:return i.next=11,he()(me(u));case 11:i.next=3;break;case 13:case"end":return i.stop()}}),i)})))).apply(this,arguments)}return{get synchronize(){return a},get on(){return o.on},get off(){return o.off},run:function(){return u()(s.a.mark((function e(){var t,n,a,u,l,h,f,p,d;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=!0,n=!1,e.prev=2,u=ce()(c());case 4:return e.next=6,u.next();case 6:return l=e.sent,t=l.done,e.next=10,l.value;case 10:if(h=e.sent,t){e.next=17;break}f=h;try{p=f.lastMessageId,d=f.messages,p>r()&&(d.forEach((function(e){return o.emit("message.new",e)})),o.emit("last-message-id.new",p))}catch(e){i("error when sync",e.message)}case 14:t=!0,e.next=4;break;case 17:e.next=23;break;case 19:e.prev=19,e.t0=e.catch(2),n=!0,a=e.t0;case 23:if(e.prev=23,e.prev=24,t||null==u.return){e.next=28;break}return e.next=28,u.return();case 28:if(e.prev=28,!n){e.next=31;break}throw a;case 31:return e.finish(28);case 32:return e.finish(23);case 33:case"end":return e.stop()}}),e,null,[[2,19,23,33],[24,,28,32]])})))()}}}(e,d,o,c,f);m.on("last-message-id.new",(function(e){return lastMessageId=e})),m.on("message.new",(function(e){return h.emit("message.new",e)})),m.run().catch((function(e){return f("got error when sync",e)}));var g=function(e,t,n,r,i){var o=v(),a=function(n){var r=O("api/v2/sdk/sync_event").param("start_event_id",n).build();return e().get(r).then((function(e){var n=e.body.events,r=n.map((function(e){return e.id})).sort((function(e,t){return e-t})).pop(),i=n.filter((function(e){return"delivered"===e.action_topic})).map((function(e){return e.payload.data})),o=n.filter((function(e){return"read"===e.action_topic})).map((function(e){return e.payload.data})),s=n.filter((function(e){return"delete_message"===e.action_topic})).map((function(e){return e.payload.data})),a=n.filter((function(e){return"clear_room"===e.action_topic})).map((function(e){return e.payload.data}));return Promise.resolve({lastId:r,messageDelivered:i,messageRead:o,messageDeleted:s,roomCleared:a,interval:t()})})).catch(de)};function c(){return l.apply(this,arguments)}function l(){return(l=pe()(s.a.mark((function i(){var o,u,c;return s.a.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:o=0,u=100,c=function(){return null!=e()&&n()};case 3:if(!((o+=u)>=t()&&c)){i.next=9;break}return o=0,i.next=9,a(r());case 9:return i.next=11,he()(me(u));case 11:i.next=3;break;case 13:case"end":return i.stop()}}),i)})))).apply(this,arguments)}return{get synchronize(){return a},get on(){return o.on},get off(){return o.off},run:function(){return u()(s.a.mark((function e(){var t,n,a,u,l,h,f,p;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=!0,n=!1,e.prev=2,u=ce()(c());case 4:return e.next=6,u.next();case 6:return l=e.sent,t=l.done,e.next=10,l.value;case 10:if(h=e.sent,t){e.next=17;break}f=h;try{(p=f.lastId)>r()&&(o.emit("last-event-id.new",p),f.messageDelivered.forEach((function(e){return o.emit("message.delivered",e)})),f.messageDeleted.forEach((function(e){return o.emit("message.deleted",e)})),f.messageRead.forEach((function(e){return o.emit("message.read",e)})),f.roomCleared.forEach((function(e){return o.emit("room.cleared",e)})))}catch(e){i("error when sync event",e.message)}case 14:t=!0,e.next=4;break;case 17:e.next=23;break;case 19:e.prev=19,e.t0=e.catch(2),n=!0,a=e.t0;case 23:if(e.prev=23,e.prev=24,t||null==u.return){e.next=28;break}return e.next=28,u.return();case 28:if(e.prev=28,!n){e.next=31;break}throw a;case 31:return e.finish(28);case 32:return e.finish(23);case 33:case"end":return e.stop()}}),e,null,[[2,19,23,33],[24,,28,32]])})))()}}}(e,d,o,(function(){return p}),f);return g.on("last-event-id.new",(function(e){p=e})),g.on("message.read",(function(e){h.emit("message.read",e)})),g.on("message.delivered",(function(e){return h.emit("message.delivered",e)})),g.on("message.deleted",(function(e){return h.emit("message.deleted",e)})),g.on("room.cleared",(function(e){return h.emit("room.cleared",e)})),g.run().catch((function(e){return f("got error when sync event",e)})),{get on(){return h.on},get off(){return h.off},synchronize:function(){m.synchronize()},synchronizeEvent:function(){g.synchronize()}}}var ve,ye=n(54),be={MESSAGE_BEFORE_SENT:"message::before-sent",MESSAGE_BEFORE_RECEIVED:"message::before-received"};function _e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function we(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?_e(Object(n),!0).forEach((function(t){d()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):_e(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function ke(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Se(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Se(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,a=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,o=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw o}}}}function Se(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var Ee=Object.freeze({disabled:"UpdateCommentStatusMode.disabled",throttled:"UpdateCommentStatusMode.throttled",enabled:"UpdateCommentStatusMode.enabled"}),Te=function(){function e(){var t,n,r=this;l()(this,e),d()(this,"_readComment",(function(e,t){return r._updateStatus(e,t)})),d()(this,"_readCommentT",this._throttle((function(e,t){r._updateStatus(e,t)}),(function(){return r._throttleDelay}))),d()(this,"_deliverComment",(function(e,t){return r._updateStatus(e,void 0,t)})),d()(this,"_deliverCommentT",this._throttle((function(e,t){r._updateStatus(e,void 0,t)}),(function(){return r._throttleDelay}))),this.events=v(),this.rooms=[],this.selected=null,this.room_name_id_map={},this.pendingCommentId=0,this.uploadedFiles=[],this.chatmateStatus=null,this.version="WEB_".concat(ye.version),this.userData={},this.AppId=null,this.baseURL="https://api.qiscus.com",this.mqttURL="wss://realtime-jogja.qiscus.com:1886/mqtt",this.brokerLbUrl="https://realtime-lb.qiscus.com",this.syncOnConnect=1e4,this.enableEventReport=!1,this.enableRealtime=!0,this.enableRealtimeCheck=!0,this.HTTPAdapter=null,this.realtimeAdapter=null,this.customEventAdapter=null,this.isInit=!1,this.isSynced=!1,this.syncInterval=5e3,this.sync="socket",this.enableLb=!0,this.httpsync=null,this.eventsync=null,this.extras=null,this.last_received_comment_id=0,this.googleMapKey="",this.options={avatar:!0},this.isConfigLoaded=!1,this.updateCommentStatusMode=e.UpdateCommentStatusMode.enabled,this.updateCommentStatusThrottleDelay=300,this.UI={},this.mode="widget",this.avatar=!0,this.plugins=[],this.isLogin=!1,this.isLoading=!1,this.isInit=!1,this.emoji=!1,this.isTypingStatus="",this.customTemplate=!1,this.templateFunction=null,this.debugMode=!1,this.debugMQTTMode=!1,this._customHeader={},this.lastReceiveMessages=[],this._hookAdapter=(t={},n=function(e){return Array.isArray(t[e])||(t[e]=[]),t[e]},{trigger:function(e,t){return n(e).reduce((function(e,t){return Promise.resolve(e).then(t)}),Promise.resolve(t))},intercept:function(e,t){n(e).push(t);var r=n(e).length;return function(){return n(e).splice(r,1)}}}),this._uploadURL=null}var t,n,r,o,a,c,h,p,m,y,_;return f()(e,[{key:"init",value:(_=u()(s.a.mark((function e(t){var n,r,i,o,a,c,l=this;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.AppId){e.next=2;break}throw new Error("Please provide valid AppId");case 2:if(this.AppId=t.AppId,r=null!=t.baseURL&&this.baseURL!==t.baseURL,i=null!=t.mqttURL&&this.mqttURL!==t.mqttURL,o=null!=t.brokerLbURL&&this.brokerLbUrl!==t.brokerLbURL,!r&&!i||o?null!=t.enableRealtimeLB&&(this.enableLb=t.enableRealtimeLB):(this.logger("force disable load balancing for realtime server, because `baseURL` or `mqttURL` get changed but did not provide `brokerLbURL`"),this.enableLb=!1),null!=t.updateCommentStatusMode&&(this.updateCommentStatusMode=t.updateCommentStatusMode),null!=t.updateCommentStatusThrottleDelay&&(this.updateCommentStatusThrottleDelay=t.updateCommentStatusThrottleDelay),t.baseURL&&(this.baseURL=t.baseURL),t.mqttURL&&(this.mqttURL=t.brokerUrl||t.mqttURL),t.mqttURL&&(this.brokerUrl=t.brokerUrl||t.mqttURL),t.brokerLbURL&&(this.brokerLbUrl=t.brokerLbURL),t.uploadURL&&(this.uploadURL=t.uploadURL),t.sync&&(this.sync=t.sync),t.mode&&(this.mode=t.mode),t.syncInterval&&(this.syncInterval=t.syncInterval||5e3),t.googleMapKey&&(this.googleMapKey=t.googleMapKey),t.allowedFileTypes&&(this.allowedFileTypes=t.allowedFileTypes),t.options&&(this.options=Object.assign({},this.options,t.options)),t.customTemplate&&(this.customTemplate=t.customTemplate),t.templateFunction&&(this.templateFunction=t.templateFunction),null!=t.syncInterval&&(this.syncInterval=t.syncInterval),this.HTTPAdapter=new x({baseURL:this.baseURL,AppId:this.AppId,userId:this.user_id,version:this.version,getCustomHeader:function(){return l._customHeader}}),a=function(e,t,n){if(""==t&&null!=e){if("string"!=typeof e)return e;if(e.length>0)return e}if(null!=t){if(t.length>0)return t;if("string"!=typeof t)return t}return n},c=function(e){return e.includes("wss://")?e:"wss://".concat(e,":1886/mqtt")},this.withConfig=null===(n=t.withConfig)||void 0===n||n,!0!==this.withConfig){e.next=32;break}return e.next=30,this.HTTPAdapter.get_request("api/v2/sdk/config").then((function(e){return 200==e.status?l.isConfigLoaded=!0:l.isConfigLoaded=!1,e.body.results})).then((function(e){var n=l.baseURL,r=l.brokerLbUrl,i=l.mqttURL,o=l.enableRealtime,s=l.enableRealtimeCheck,u=l.syncInterval,h=l.syncOnConnect,f=l.enableEventReport;l.baseURL=a(t.baseURL,e.base_url,n),l.brokerLbUrl=a(t.brokerLbURL,e.broker_lb_url,r),l.mqttURL=c(a(t.mqttURL,e.broker_url,i)),l.enableRealtime=a(t.enableRealtime,e.enable_realtime,o),l.syncInterval=a(t.syncInterval,e.sync_interval,u),l.syncOnConnect=a(t.syncOnConnect,e.sync_on_connect,h),l.enableRealtimeCheck=a(null,e.enable_realtime_check,s),l.enableEventReport=a(null,e.enable_event_report,f),l.extras=a(null,e.extras,{})})).catch((function(e){l.logger("got error when trying to get app config",e),l.isConfigLoaded=!0}));case 30:e.next=33;break;case 32:this.isConfigLoaded=!0;case 33:this._getMqttClientId=function(){return"".concat(l.AppId,"_").concat(l.user_id,"_").concat(Date.now())},this.realtimeAdapter=new se(this.mqttURL,this,this.isLogin,{brokerLbUrl:this.brokerLbUrl,enableLb:this.enableLb,shouldConnect:this.enableRealtime,getClientId:this._getMqttClientId}),this.realtimeAdapter.on("connected",(function(){!l.isLogin&&l.realtimeAdapter.connected||(l.last_received_comment_id=l.userData.last_comment_id,l.updateLastReceivedComment(l.last_received_comment_id))})),this.realtimeAdapter.on("close",(function(){})),this.realtimeAdapter.on("reconnect",(function(){var e,t;null===(e=(t=l.options).onReconnectCallback)||void 0===e||e.call(t)})),this.realtimeAdapter.on("message-delivered",(function(e){var t=e.commentId,n=e.commentUniqueId,r=e.userId;return l._setDelivered(t,n,r)})),this.realtimeAdapter.on("message-read",(function(e){var t=e.commentId,n=e.commentUniqueId,r=e.userId;return l._setRead(t,n,r)})),this.realtimeAdapter.on("new-message",function(){var e=u()(s.a.mark((function e(t){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,l._hookAdapter.trigger(be.MESSAGE_BEFORE_RECEIVED,t);case 2:t=e.sent,l.events.emit("newmessages",[t]);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),this.realtimeAdapter.on("presence",(function(e){return l.events.emit("presence",e)})),this.realtimeAdapter.on("comment-deleted",(function(e){return l.events.emit("comment-deleted",e)})),this.realtimeAdapter.on("room-cleared",(function(e){return l.events.emit("room-cleared",e)})),this.realtimeAdapter.on("typing",(function(e){return l.events.emit("typing",{message:e.message,username:e.userId,room_id:e.roomId})})),this.realtimeAdapter.on("message:updated",(function(e){null!=l.options.messageUpdatedCallback&&l.options.messageUpdatedCallback(e)})),this.syncAdapter=ge((function(){return l.HTTPAdapter}),{getToken:function(){return l.userData.token},syncInterval:function(){return l.syncInterval},getShouldSync:function(){return l.isLogin&&!l.realtimeAdapter.connected},syncOnConnect:function(){return l.syncOnConnect},lastCommentId:function(){return l.last_received_comment_id},statusLogin:function(){return l.isLogin}}),this.syncAdapter.on("message.new",function(){var e=u()(s.a.mark((function e(t){var n;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,l._hookAdapter.trigger(be.MESSAGE_BEFORE_RECEIVED,t);case 2:t=e.sent,null!=l.selected?-1===l.selected.comments.findIndex((function(e){return e.id===t.id||e.unique_id===t.unique_temp_id}))&&((n=new C(t)).room_id===l.selected.id&&(l.selected.comments.push(n),l.sortComments()),l.events.emit("newmessages",[t])):l.events.emit("newmessages",[t]);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),this.syncAdapter.on("message.delivered",(function(e){l._setDelivered(e.comment_id,e.comment_unique_id,e.email)})),this.syncAdapter.on("message.read",(function(e){l._setRead(e.comment_id,e.comment_unique_id,e.email)})),this.syncAdapter.on("message.deleted",(function(e){e.deleted_messages.forEach((function(e){l.events.emit("comment-deleted",{roomId:e.room_id,commentUniqueIds:e.message_unique_ids,isForEveryone:!0,isHard:!0})}))})),this.syncAdapter.on("room.cleared",(function(e){e.deleted_rooms.forEach((function(e){l.events.emit("room-cleared",e)}))})),this.customEventAdapter=ae(this.realtimeAdapter,this.user_id),this.setEventListeners();case 54:case"end":return e.stop()}}),e,this)}))),function(e){return _.apply(this,arguments)})},{key:"_setRead",value:function(e,t,n){if(null!=this.selected){var r=this.selected,i=r.comments.find((function(n){return n.id===e||n.unique_id===t}));if(null!=i&&"read"!==i.status){var o={participants:r.participants,actor:n,comment_id:e,activeActorId:this.user_id};r.comments.forEach((function(e){e.id<=i.id&&e.markAsRead(o)})),i.isRead&&this.events.emit("comment-read",{comment:i,userId:n})}}}},{key:"_setDelivered",value:function(e,t,n){if(null!=this.selected){var r=this.selected,i=r.comments.find((function(n){return n.id===e||n.unique_id===t}));if(null!=i&&"read"!==i.status){var o={participants:r.participants,actor:n,comment_id:e,activeActorId:this.user_id};r.comments.forEach((function(e){e.id<=i.id&&e.markAsDelivered(o)})),i.isDelivered&&this.events.emit("comment-delivered",{comment:i,userId:n})}}}},{key:"setEventListeners",value:function(){var e=this,t=this;this.authAdapter=new I(t.HTTPAdapter),null!=this.userData.email&&(this.authAdapter.userId=this.userData.email),t.events.on("start-init",(function(){t.HTTPAdapter=new x({baseURL:t.baseURL,AppId:t.AppId,userId:t.user_id,version:t.version,getCustomHeader:function(){return e._customHeader}}),t.HTTPAdapter.setToken(t.userData.token)})),t.events.on("room-changed",(function(n){e.logging("room changed",n),t.options.roomChangedCallback&&t.options.roomChangedCallback(n)})),t.events.on("file-uploaded",(function(e){t.options.fileUploadedCallback&&t.options.fileUploadedCallback(e)})),t.events.on("profile-updated",(function(e){t.username=e.name,t.avatar_url=e.avatar_url,t.options.updateProfileCallback&&t.options.updateProfileCallback(e)})),t.events.on("newmessages",(function(n){e.logging("newmessages",n),e.lastReceiveMessages.length>0&&e.lastReceiveMessages[0].unique_temp_id===n[0].unique_temp_id?e.logging("lastReceiveMessages double",n):(e.lastReceiveMessages=n,t._callNewMessagesCallback(n),n.forEach((function(n){t.receiveComment(n.room_id,n.id);var r=!!t.selected&&n.room_id===t.selected.id,i=n.id<=t.last_received_comment_id;if(r){var o=t.selected,s=t.selected.comments[t.selected.comments.length-1];s.isPending||i||t.user_id===n.email||t.readComment(n.room_id,n.id);var a=s.id,u=t.selected.comments.find((function(e){return e.id===s.comment_before_id}));s.isPending||u||(e.logging("comment before id not found! ",n.comment_before_id),t.synchronize(a));var c=new C(n);o.receiveComment(c),o.last_comment_id=c.id,o.last_comment_message=c.message}t.updateLastReceivedComment(n.id),e.sortComments()})))})),this.events.on("login-success",(function(t){e.isLogin=!0,e.userData=t.user,e.last_received_comment_id=e.userData.last_comment_id,e.realtimeAdapter.connected||e.updateLastReceivedComment(e.last_received_comment_id),e.HTTPAdapter=new x({baseURL:e.baseURL,AppId:e.AppId,userId:e.user_id,version:e.version,getCustomHeader:function(){return e._customHeader}}),e.HTTPAdapter.setToken(e.userData.token),e.userAdapter=new M(e.HTTPAdapter),e.roomAdapter=new L(e.HTTPAdapter),e.realtimeAdapter.subscribeUserChannel(),null!=e.presensePublisherId&&-1!==e.presensePublisherId&&clearInterval(e.presensePublisherId),e.presensePublisherId=setInterval((function(){e.realtimeAdapter.publishPresence(e.user_id,!0)}),3500),e.options.loginSuccessCallback&&e.options.loginSuccessCallback(t),e.authAdapter.userId=e.userData.email,e.authAdapter.refreshToken=e.userData.refresh_token})),t.events.on("login-error",(function(e){t.options.loginErrorCallback&&t.options.loginErrorCallback(e)})),t.events.on("room-cleared",(function(e){if(t.selected){var n=t.selected;t.selected.unique_id===e.unique_id&&(t.selected=null,t.selected=n)}t.options.roomClearedCallback&&t.options.roomClearedCallback(e)})),t.events.on("comment-deleted",(function(e){var n=e.roomId,r=e.commentUniqueIds,i=(e.isForEveryone,e.isHard);t.selected&&t.selected.id==n&&r.map((function(e){var n=t.selected.comments.findIndex((function(t){return t.unique_id===e}));n>-1&&(i?t.selected.comments.splice(n,1):t.selected.comments[n].message="this message has been deleted")})),t.options.commentDeletedCallback&&t.options.commentDeletedCallback(e)})),t.events.on("comment-delivered",(function(e){return t.logging("comment-delivered",e),!!e&&(t.options.commentDeliveredCallback?t.options.commentDeliveredCallback(e):void 0)})),t.events.on("chat-room-created",(function(e){t.isLoading=!1,t.options.chatRoomCreatedCallback&&t.options.chatRoomCreatedCallback(e)})),t.events.on("group-room-created",(function(e){t.isLoading=!1,t.options.groupRoomCreatedCallback&&t.options.groupRoomCreatedCallback(e)})),t.events.on("header-clicked",(function(e){t.options.headerClickedCallback&&t.options.headerClickedCallback(e)})),t.events.on("comment-read",(function(e){t.logging("comment-read",e),t.options.commentReadCallback&&t.options.commentReadCallback(e)})),t.events.on("presence",(function(n){var r=n.message,i=n.userId,o=r.split(":");e.chatmateStatus!==o[0]&&(e.chatmateStatus=1===o[0]?"Online":"Last seen ".concat(S()(Number(o[1].substring(0,13))))),t.options.presenceCallback&&t.options.presenceCallback(r,i)})),t.events.on("typing",(function(e){t.options.typingCallback&&t.options.typingCallback(e)})),t.events.on("message-info",(function(e){t.options.messageInfoCallback&&t.options.messageInfoCallback(e)})),t.events.on("participants-added",(function(t){var n;null!=t&&null!=e.selected&&(n=e.selected.participants).push.apply(n,i()(t))})),t.events.on("participants-removed",(function(t){if(null!=t&&null!=e.selected){var n=e.selected.participants.filter((function(e){return t.indexOf(e.email)<=-1}));e.selected.participants=n}})),t.events.on("block-user",(function(e){t.options.blockUserCallback&&t.options.blockUserCallback(e)})),t.events.on("unblock-user",(function(e){t.options.unblockUserCallback&&t.options.unblockUserCallback(e)}))}},{key:"onReconnectMqtt",value:function(){this.options.onReconnectCallback&&this.options.onReconnectedCallback(),this.selected&&this.loadComments(this.selected.id)}},{key:"_callNewMessagesCallback",value:function(e){this.options.newMessagesCallback&&this.options.newMessagesCallback(e)}},{key:"updateLastReceivedComment",value:function(e){this.last_received_comment_id<e&&(this.last_received_comment_id=e)}},{key:"setUser",value:function(e,t,n,r,i){var o=this,s=this;s.user_id=e,s.key=t,s.username=n,s.avatar_url=r;var a={email:this.user_id,password:this.key,username:this.username,extras:i?JSON.stringify(i):null};return this.avatar_url&&(a.avatar_url=this.avatar_url),new Promise((function(e,t){var n=setInterval((function(){if(o.isConfigLoaded)return clearInterval(n),o.logger("Config Success!"),s.events.emit("start-init"),s.authAdapter.loginOrRegister(a).then((function(t){s.isInit=!0,console.log("response",t),s.refresh_token=t.user.refresh_token,s.events.emit("login-success",t),o.realtimeAdapter.connect(),e(t)}),(function(e){s.events.emit("login-error",e),t(e)}));o.debugMode&&o.logger("Waiting for init config...")}),300)}))}},{key:"setUserWithIdentityToken",value:function(e){var t=this;if(!(e&&"user"in e))return this.events.emit("login-error",e);this.email=e.user.email,this.user_id=e.user.email,this.key=e.identity_token,this.username=e.user.username,this.avatar_url=e.user.avatar_url,this.isInit=!0;var n=setInterval((function(){t.isConfigLoaded?(clearInterval(n),t.logger("Config Success!"),t.events.emit("login-success",e)):t.debugMode&&t.logger("Waiting for init config...")}),300)}},{key:"refreshAuthToken",value:function(){var e=this;return this.authAdapter.refreshAuthToken().then((function(t){return console.log("resp:",t),e.token=t.token,e.HTTPAdapter.token=t.token,t}))}},{key:"expiredAuthToken",value:function(){return this.authAdapter.expiredAuthToken()}},{key:"publishOnlinePresence",value:function(e){var t=this;!0===e?ve=setInterval((function(){t.realtimeAdapter.publishPresence(t.user_id,!0)}),3500):(clearInterval(this.presensePublisherId),clearInterval(ve),setTimeout((function(){t.realtimeAdapter.publishPresence(t.user_id,!1)}),3500))}},{key:"subscribeUserPresence",value:function(e){this.realtimeAdapter.subscribeUserPresence(e)}},{key:"unsubscribeUserPresence",value:function(e){this.realtimeAdapter.unsubscribeUserPresence(e)}},{key:"logout",value:function(){clearInterval(this.presensePublisherId),this.publishOnlinePresence(!1),this.selected=null,this.isInit=!1,this.isLogin=!1,this.realtimeAdapter.disconnect(),this.userData={}}},{key:"disconnect",value:function(){this.logout()}},{key:"setActiveRoom",value:function(e){var t=this;if(this.selected&&(this.realtimeAdapter.unsubscribeTyping(),"single"===this.selected.room_type)){var n=this.selected.participants.filter((function(e){return e.email!==t.user_id}));n.length>0&&this.realtimeAdapter.unsubscribeRoomPresence(n[0].email)}null==e.participants&&(e.participants=[]);var r=e.participants.find((function(e){return e.email!==t.user_id}));this.chatmateStatus=null,this.isTypingStatus=null,this.selected=e;var i=setInterval((function(){t.debugMode&&t.logger("Trying Initial Subscribe"),null!=t.realtimeAdapter?(t.debugMode&&t.logger("MQTT Connected"),clearInterval(i),"single"===e.room_type&&null!=r&&t.realtimeAdapter.subscribeRoomPresence(r.email),null==t.selected||t.selected.isChannel||(t.realtimeAdapter.subscribeTyping(e.id),t.events.emit("room-changed",t.selected)),t.debugMode&&null==t.realtimeAdapter&&t.logger("Retry")):t.debugMode&&t.logger("MQTT Not Connected, yet")}),3e3)}},{key:"chatTarget",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null!=this.userData.length)return!1;var r=n?n.message:null,i=n.distinctId;return this.isLoading=!0,this.isTypingStatus="",this.roomAdapter.getOrCreateRoom(e,n,i).then(function(){var e=u()(s.a.mark((function e(n){var i,o,a,c;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=new A(n),t.updateLastReceivedComment(i.last_comment_id),t.isLoading=!1,o=function(){var e=u()(s.a.mark((function e(n){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._hookAdapter.trigger(be.MESSAGE_BEFORE_RECEIVED,n);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.next=6,Promise.all(i.comments.map((function(e){return o(e)})));case 6:if(i.comments=e.sent,t.setActiveRoom(i),(a=i.comments[i.comments.length-1])&&t.readComment(i.id,a.id),t.events.emit("chat-room-created",{room:i}),r){e.next=13;break}return e.abrupt("return",i);case 13:return c=i.id,e.abrupt("return",t.sendComment(c,r).then((function(){return Promise.resolve(i)})).catch((function(e){console.error("Error when submit comment",e)})));case 15:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){return console.error("Error when creating room",e),t.isLoading=!1,Promise.reject(e)}))}},{key:"chatGroup",value:function(e){if(this.isInit)return this.getRoomById(e).then((function(e){return Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"getRoomById",value:function(e){var t=this;if(this.isInit){var n=this;return n.isLoading=!0,n.isTypingStatus="",n.roomAdapter.getRoomById(e).then(function(){var e=u()(s.a.mark((function e(r){var i,o,a,u,c,l,h,f;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=r.results.room,o=[],a=ke(r.results.comments.reverse()),e.prev=3,a.s();case 5:if((u=a.n()).done){e.next=13;break}return c=u.value,e.next=9,t._hookAdapter.trigger(be.MESSAGE_BEFORE_RECEIVED,c);case 9:l=e.sent,o.push(l);case 11:e.next=5;break;case 13:e.next=18;break;case 15:e.prev=15,e.t0=e.catch(3),a.e(e.t0);case 18:return e.prev=18,a.f(),e.finish(18);case 21:return h=new A(we(we({},i),{},{comments:o,name:i.room_name})),n.updateLastReceivedComment(h.last_comment_id),n.setActiveRoom(h),n.isLoading=!1,(f=h.comments[h.comments.length-1])&&n.readComment(h.id,f.id),h.isChannel&&t.realtimeAdapter.subscribeChannel(t.AppId,h.unique_id),e.abrupt("return",h);case 29:case"end":return e.stop()}}),e,null,[[3,15,18,21]])})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){return console.error("Error getting room by id",e),Promise.reject(e)}))}}},{key:"getOrCreateRoomByUniqueId",value:function(e,t,n){var r=this,i=this;return i.isLoading=!0,i.isTypingStatus="",i.roomAdapter.getOrCreateRoomByUniqueId(e,t,n).then(function(){var e=u()(s.a.mark((function e(t){var n,o,a;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new A(t),i.updateLastReceivedComment(n.last_comment_id),o=function(){var e=u()(s.a.mark((function e(t){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r._hookAdapter.trigger(be.MESSAGE_BEFORE_RECEIVED,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.next=5,Promise.all(n.comments.map((function(e){return o(e)})));case 5:return n.comments=e.sent,i.setActiveRoom(n),i.isLoading=!1,(a=n.comments[n.comments.length-1])&&i.readComment(n.id,a.id),r.realtimeAdapter.subscribeChannel(r.AppId,n.unique_id),e.abrupt("return",Promise.resolve(n));case 12:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){return Promise.reject(e)}))}},{key:"getOrCreateRoomByChannel",value:function(e,t,n){return this.getOrCreateRoomByUniqueId(e,t,n)}},{key:"sortComments",value:function(){this.selected&&this.selected.comments.sort((function(e,t){return e.unix_timestamp-t.unix_timestamp}))}},{key:"loadRoomList",value:(y=u()(s.a.mark((function e(){var t,n,r=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:{},e.next=3,this.userAdapter.loadRoomList(t);case 3:return n=e.sent,e.abrupt("return",n.map((function(e){return e.last_comment_id=e.last_comment.id,e.last_comment_message=e.last_comment.message,e.last_comment_message_created_at=e.last_comment.timestamp,e.room_type=e.chat_type,e.comments=[],new A(e)})));case 5:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"loadComments",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.userAdapter.loadComments(e,n).then(function(){var e=u()(s.a.mark((function e(n){var r,i,o,a;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=[],i=ke(n),e.prev=2,i.s();case 4:if((o=i.n()).done){e.next=13;break}return a=o.value,e.t0=r,e.next=9,t._hookAdapter.trigger(be.MESSAGE_BEFORE_RECEIVED,a);case 9:e.t1=e.sent,e.t0.push.call(e.t0,e.t1);case 11:e.next=4;break;case 13:e.next=18;break;case 15:e.prev=15,e.t2=e.catch(2),i.e(e.t2);case 18:return e.prev=18,i.f(),e.finish(18);case 21:return null!=t.selected&&(t.selected.receiveComments(r.reverse()),t.sortComments()),e.abrupt("return",r);case 23:case"end":return e.stop()}}),e,null,[[2,15,18,21]])})));return function(t){return e.apply(this,arguments)}}())}},{key:"loadMore",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null!=this.selected)return t.last_comment_id=e,t.after=!1,this.loadComments(this.selected.id,t)}},{key:"registerDeviceToken",value:(m=u()(s.a.mark((function e(t){var n,r,i=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]&&i[1],e.next=3,this.HTTPAdapter.post("api/v2/sdk/set_user_device_token",{device_token:t,device_platform:"rn",is_development:n});case 3:return r=e.sent,e.abrupt("return",r.body.results);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return m.apply(this,arguments)})},{key:"removeDeviceToken",value:(p=u()(s.a.mark((function e(t){var n,r,i=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]&&i[1],e.next=3,this.HTTPAdapter.post("api/v2/sdk/remove_user_device_token",{device_token:t,device_platform:"rn",is_development:n});case 3:return r=e.sent,e.abrupt("return",r.body.results);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"searchMessages",value:(h=u()(s.a.mark((function e(){var t,n,r=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:{},console.warn("Deprecated: search message will be removed on next release"),e.next=4,this.userAdapter.searchMessages(t);case 4:return n=e.sent,e.abrupt("return",n.map((function(e){return new C(e)})));case 6:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"updateProfile",value:function(e){var t=this;return this.userAdapter.updateProfile(e).then((function(n){return t.events.emit("profile-updated",e),t.userData=n,Promise.resolve(n)}),(function(e){return t.logger(e)}))}},{key:"getNonce",value:function(){return g.a.post("".concat(this.baseURL,"/api/v2/sdk/auth/nonce")).send().set("qiscus_sdk_app_id","".concat(this.AppId)).set("qiscus_sdk_version","".concat(this.version)).then((function(e){return Promise.resolve(e.body.results)}),(function(e){return Promise.reject(e)}))}},{key:"verifyIdentityToken",value:function(e){return g.a.post("".concat(this.baseURL,"/api/v2/sdk/auth/verify_identity_token")).send({identity_token:e}).set("qiscus_sdk_app_id","".concat(this.AppId)).set("qiscus_sdk_version","".concat(this.version)).then((function(e){return Promise.resolve(e.body.results)}),(function(e){return Promise.reject(e)}))}},{key:"sendComment",value:(c=u()(s.a.mark((function e(t,n,r){var i,o,a,c,l,h,f,p,d,m,g=this,v=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=v.length>3&&void 0!==v[3]?v[3]:"text",o=v.length>4?v[4]:void 0,a=v.length>5?v[5]:void 0,(c=this).options.prePostCommentCallback&&c.options.prePostCommentCallback(n),c.options.commentFormaterCallback&&(n=c.options.commentFormaterCallback(n)),c.pendingCommentId--,l={message:n,username_as:this.username,username_real:this.user_id,user_avatar_url:this.userData.avatar_url,user_extras:this.userData.user_extras,id:Math.round(1e6*Date.now()+Date.now()),type:i||"text",timestamp:w()(new Date),unique_id:r?String(r):null,payload:ie((function(){return JSON.parse(o)}),o,(function(e){return g.logger("Error when parsing payload",e.message)}))},h=c.prepareCommentToBeSubmitted(l),"reply"===i&&(f=JSON.parse(o),p=c.selected.comments.find((function(e){return e.id===f.replied_comment_id})),f.replied_comment_message="reply"===p.type?p.payload.text:p.message,f.replied_comment_sender_username=p.username_as,h.payload=f),d=a||c.extras,e.next=13,this._hookAdapter.trigger(be.MESSAGE_BEFORE_SENT,we(we({},h),{},{extras:d}));case 13:return m=e.sent,m=c.prepareCommentToBeSubmitted(m),c.selected&&c.selected.comments.push(m),e.abrupt("return",this.userAdapter.postComment(""+t,m.message,m.unique_id,m.type,m.payload,m.extras).then(function(){var e=u()(s.a.mark((function e(t){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,g._hookAdapter.trigger(be.MESSAGE_BEFORE_RECEIVED,t);case 2:if(t=e.sent,Object.assign(m,t),c.selected){e.next=6;break}return e.abrupt("return",Promise.resolve(m));case 6:return m.markAsSent(),m.id=t.id,m.before_id=t.comment_before_id,m.unix_timestamp=t.unix_timestamp,c.sortComments(),e.abrupt("return",m);case 12:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){return m.markAsFailed(),Promise.reject(e)})));case 17:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return c.apply(this,arguments)})},{key:"getUsers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:20;return this.HTTPAdapter.get_request("api/v2/sdk/get_user_list").query({query:e,page:t,limit:n}).then((function(e){return Promise.resolve(e.body.results)}))}},{key:"getParticipants",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:20;return this.HTTPAdapter.get_request("api/v2/sdk/room_participants").query({room_unique_id:e,page:t,limit:n}).then((function(e){return e.body.results}))}},{key:"getRoomParticipants",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return console.warn("`getRoomParticipants` are deprecated, use `getParticipants` instead."),this.HTTPAdapter.get_request("api/v2/sdk/room_participants").query({room_unique_id:e,offset:t}).then((function(e){return Promise.resolve(e.body.results)}))}},{key:"resendComment",value:function(e){if(null!=this.selected){var t=this,n=t.selected,r=n.comments.find((function(t){return t.id===e.id})),i=t.extras;return this.userAdapter.postComment(""+n.id,r.message,r.unique_id,e.type,e.payload,i).then((function(e){return r.markAsSent(),r.id=e.id,r.before_id=e.comment_before_id,new Promise((function(e,n){return e(t.selected)}))}),(function(e){return r.markAsFailed(),new Promise((function(t,n){return n(e)}))}))}}},{key:"prepareCommentToBeSubmitted",value:function(e){var t,n;return t=new C(e),n="bq"+Date.now(),e.unique_id&&(n=e.unique_id),t.attachUniqueId(n),t.markAsPending(),t.isDelivered=!1,t.isSent=!1,t.isRead=!1,t.unix_timestamp=Math.round((new Date).getTime()/1e3),t}},{key:"updateRoom",value:function(e){return this.roomAdapter.updateRoom(e)}},{key:"removeSelectedRoomParticipants",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id";if(b.a.not.array(e))return Promise.reject(new Error("`values` must have type of array"));var n=this.selected.participants;if(!n)return Promise.reject(new Error("Nothing selected room chat."));var r=n;return"id"===t&&(r=n.filter((function(t){return e.indexOf(t.id)<=-1}))),"email"===t&&(r=n.filter((function(t){return e.indexOf(t.email)<=-1}))),"username"===t&&(r=n.filter((function(t){return e.indexOf(t.username)<=-1}))),this.selected.participants=r,Promise.resolve(n)}},{key:"createGroupRoom",value:function(e,t,n){var r=this;if(!this.isLogin)throw new Error("Please initiate qiscus SDK first");return new T(this.roomAdapter).withName(e).withOptions(n).addParticipants(t).create().then((function(e){return r.events.emit("group-room-created",e),Promise.resolve(e)}))}},{key:"addParticipantsToGroup",value:function(e,t){var n=this;if(!Array.isArray(t))throw new Error("emails' must be type of Array");return n.roomAdapter.addParticipantsToGroup(e,t).then((function(e){return n.events.emit("participants-added",e),Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"removeParticipantsFromGroup",value:function(e,t){var n=this;return b.a.not.array(t)?Promise.reject(new Error("`emails` must have type of array")):this.roomAdapter.removeParticipantsFromGroup(e,t).then((function(e){return n.events.emit("participants-removed",t),Promise.resolve(e)}))}},{key:"getBlockedUser",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,n=this;return n.userAdapter.getBlockedUser(e,t).then((function(e){return Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"blockUser",value:function(e){var t=this;return t.userAdapter.blockUser(e).then((function(e){return t.events.emit("block-user",e),Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"unblockUser",value:function(e){var t=this;return t.userAdapter.unblockUser(e).then((function(e){return t.events.emit("unblock-user",e),Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"getUserPresences",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(b.a.not.array(e))return Promise.reject(new Error("`email` must have type of array"));var t=this;return t.userAdapter.getUserPresences(e).then((function(e){return t.events.emit("user-status",e),Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"upload",value:function(e,t){return g.a.post(this.uploadURL).attach("file",e).set("qiscus_sdk_app_id",this.AppId).set("qiscus_sdk_token",this.userData.token).set("qiscus_sdk_user_id",this.user_id).on("progress",(function(e){"upload"===e.direction&&t(null,e)})).then((function(e){var n=e.body.results.file.url;return t(null,null,e.body.results.file.url),Promise.resolve(n)})).catch((function(e){return t(e),Promise.reject(e)}))}},{key:"uploadFile",value:function(e,t){var n=this,r=new FormData;r.append("file",t);var i=new XMLHttpRequest;i.open("POST","".concat(n.baseURL,"/api/v2/sdk/upload"),!0),i.setRequestHeader("qiscus_sdk_app_id","".concat(n.AppId)),i.setRequestHeader("qiscus_sdk_user_id","".concat(n.user_id)),i.setRequestHeader("qiscus_sdk_token","".concat(n.userData.token)),i.onload=function(){if(200===i.status){var t=JSON.parse(i.response).results.file.url;return n.events.emit("fileupload",t),n.sendComment(e,"[file] ".concat(t," [/file]"))}return Promise.reject(i)},i.send(r)}},{key:"addUploadedFile",value:function(e,t){this.uploadedFiles.push(new Ce(e,t))}},{key:"removeUploadedFile",value:function(e,t){var n=this.uploadedFiles.findIndex((function(n){return n.name===e&&n.roomId===t}));this.uploadedFiles.splice(n,1)}},{key:"publishTyping",value:function(e){this.realtimeAdapter.publishTyping(e)}},{key:"getRoomsInfo",value:function(e){return this.userAdapter.getRoomsInfo(e)}},{key:"deleteComment",value:function(e,t,n,r){var i=this;if(!Array.isArray(t))throw new Error("unique ids' must be type of Array");return this.userAdapter.deleteComment(e,t,n,r).then((function(o){return i.events.emit("comment-deleted",{roomId:e,commentUniqueIds:t,isForEveryone:n,isHard:r}),Promise.resolve(o)}),(function(e){return Promise.reject(e)}))}},{key:"clearRoomsCache",value:function(){var e=this;if(this.selected){this.room_name_id_map=d()({},this.selected.name,this.selected.id);var t=this.rooms.length,n=this.rooms.findIndex((function(t){return t.id===e.selected.id}));n+1!==t&&this.rooms.splice(n+1,t-(n+1)),(n=this.rooms.findIndex((function(t){return t.id===e.selected.id})))>0&&this.rooms.length>1&&this.rooms.splice(1,this.rooms.length-1)}}},{key:"exitChatRoom",value:function(){var e=this;this.realtimeAdapter.unsubscribeTyping(),ie((function(){return e.selected.participants.filter((function(t){return t.email!==e.user_id})).map((function(e){return e.email}))}),null,this.noop,(function(t){return t.forEach((function(t){return e.realtimeAdapter.unsubscribeRoomPresence(t)}))})),this.selected=null}},{key:"clearRoomMessages",value:function(e){if(!Array.isArray(e))throw new Error("room_ids must be type of array");return this.userAdapter.clearRoomMessages(e)}},{key:"logging",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.debugMode&&console.log(e,t)}},{key:"getTotalUnreadCount",value:function(){return this.roomAdapter.getTotalUnreadCount().then((function(e){return Promise.resolve(e)}),(function(e){return Promise.reject(e)}))}},{key:"getRoomUnreadCount",value:function(){return this.roomAdapter.getRoomUnreadCount()}},{key:"publishEvent",value:function(){var e;(e=this.customEventAdapter).publishEvent.apply(e,arguments)}},{key:"subscribeEvent",value:function(){var e;(e=this.customEventAdapter).subscribeEvent.apply(e,arguments)}},{key:"unsubscribeEvent",value:function(){var e;(e=this.customEventAdapter).unsubscribeEvent.apply(e,arguments)}},{key:"setCustomHeader",value:function(e){if(b.a.not.json(e))throw new TypeError("`headers` must have type of object");this._customHeader=e}},{key:"getUserProfile",value:function(){return this.userAdapter.getProfile()}},{key:"intercept",value:function(e,t){return this._hookAdapter.intercept(e,t)}},{key:"getThumbnailURL",value:function(e){return e.replace(/^https?:\/\/\S+(\/upload\/)\S+(\.\w+)$/i,(function(e,t,n){return e.replace(t,"/upload/w_320,h_320,c_limit/").replace(n,".png")}))}},{key:"getBlurryThumbnailURL",value:function(e){return e.replace(/^https?:\/\/\S+(\/upload\/)\S+(\.\w+)$/i,(function(e,t,n){return e.replace(t,"/upload/w_320,h_320,c_limit,e_blur:300/").replace(n,".png")}))}},{key:"noop",value:function(){}},{key:"_updateStatus",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=null!=n,i=null!=t,o=(null!=this.selected&&this.selected.id,null!=this.selected&&this.selected.isChannel||!1),s=!this._updateStatusEnabled,a=i?"read":r?"receive":void 0,u=!(o||r&&s);if(this.debugMode&&(console.group("update-command-status"),console.log("run:",a,"on: roomId(".concat(e,") commentId(").concat(t||n,")")),console.log("is able to run command?",u),console.groupEnd()),!u)return!1;this.userAdapter.updateCommentStatus(e,t,n).catch((function(e){}))}},{key:"readComment",value:function(t,n){return this.updateCommentStatusMode===e.UpdateCommentStatusMode.enabled?this._readComment(t,n):this._readCommentT(t,n)}},{key:"receiveComment",value:function(t,n){return this.updateCommentStatusMode===e.UpdateCommentStatusMode.enabled?this._deliverComment(t,n):this._deliverCommentT(t,n)}},{key:"_throttle",value:function(e,t){var n=!1;return function(){var r=t();n||(e.apply(void 0,arguments),n=!0,setTimeout((function(){return n=!1}),r))}}},{key:"searchMessage",value:(a=u()(s.a.mark((function e(){var t,n,r,i,o,a,u,c,l,h,f,p,d=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=d.length>0&&void 0!==d[0]?d[0]:{},n=t.query,r=t.roomIds,i=void 0===r?[]:r,o=t.userId,a=t.type,u=t.roomType,c=t.page,l=t.limit,h="api/v2/sdk/search",f=["group","single","channel"].some((function(e){return e===u})),null==u||f){e.next=5;break}return e.abrupt("return",Promise.reject("Invalid room type, valid room type are: `group`, `single`, and `channel`"));case 5:return p=function(e){return{type:null==e?void 0:"single"===e?"single":"group",isPublic:null==e?void 0:"channel"===e}}(u),e.abrupt("return",this.HTTPAdapter.post_json(h,{token:this.token,query:n,sender:o,type:a,room_ids:i.map((function(e){return String(e)})),room_type:p.type||void 0,is_public:p.isPublic||void 0,page:c,limit:l}).then((function(e){return e.body})));case 7:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"getFileList",value:(o=u()(s.a.mark((function e(){var t,n,r,i,o,a,u,c,l,h,f,p,d=arguments;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=d.length>0&&void 0!==d[0]?d[0]:{},n=t.roomIds,r=void 0===n?[]:n,i=t.fileType,o=t.page,a=t.limit,u=t.sender,c=t.userId,l=t.includeExtensions,h=t.excludeExtensions,f="api/v2/sdk/file_list",this.isLogin){e.next=4;break}return e.abrupt("return",Promise.reject("You need to login to use this method"));case 4:return void 0===u&&(u=this.user_id),void 0===c&&(u=c=this.user_id),p={room_ids:r.map((function(e){return String(e)})),file_type:i,page:o,limit:a,include_extensions:l,exclude_extensions:h},null!=u&&(p.sender=u),e.abrupt("return",this.HTTPAdapter.post_json(f,p).then((function(e){return e.body})));case 9:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"_generateUniqueId",value:function(){return"javascript-".concat(Date.now())}},{key:"generateMessage",value:function(e){var t=e.roomId,n=e.text,r=e.extras,i=Date.now();return new C({id:i,message:n,room_id:t,extras:r,timestamp:new Date,unique_id:this._generateUniqueId(),before_id:0,username:this.userData.username,email:this.userData.email,status:"pending",type:"text"})}},{key:"generateFileAttachmentMessage",value:function(e){var t=e.roomId,n=e.caption,r=e.url,i=e.text,o=void 0===i?"File attachment":i,s=e.extras,a=e.filename,u=e.size,c=Date.now();return new C({id:c,message:o,room_id:t,extras:s,timestamp:new Date,unique_id:this._generateUniqueId(),before_id:0,username:this.userData.username,email:this.userData.email,status:"pending",type:"file_attachment",payload:{url:r,file_name:a,size:u,caption:n}})}},{key:"generateCustomMessage",value:function(e){var t=e.roomId,n=e.text,r=e.type,i=e.payload,o=e.extras,s=Date.now();return new C({id:s,message:n,room_id:t,extras:o,timestamp:new Date,unique_id:this._generateUniqueId(),before_id:0,username:this.userData.username,email:this.userData.email,status:"pending",type:"custom",payload:{type:r,content:i}})}},{key:"generateReplyMessage",value:function(e){var t=e.roomId,n=e.text,r=e.repliedMessage,i=e.extras,o=Date.now();return new C({id:o,message:n,room_id:t,extras:i,timestamp:new Date,unique_id:this._generateUniqueId(),before_id:0,username:this.userData.username,email:this.userData.email,status:"pending",type:"reply",payload:{text:n,replied_comment_id:r.id,replied_comment_message:r.message,replied_comment_type:r.type,replied_comment_payload:r.payload,replied_comment_sender_username:r.username_as,replied_comment_sender_email:r.username_real}})}},{key:"updateMessage",value:(r=u()(s.a.mark((function e(t){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.userAdapter.updateMessage(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"onMessageUpdated",value:function(e){var t=this;return this.realtimeAdapter.on("message:updated",e),function(){return t.realtimeAdapter.off("message:updated",e)}}},{key:"closeRealtimeConnection",value:(n=u()(s.a.mark((function e(){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.realtimeAdapter.closeConnection());case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"openRealtimeConnection",value:(t=u()(s.a.mark((function e(){return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.realtimeAdapter.openConnection());case 1:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"uploadURL",get:function(){return this._uploadURL||"".concat(this.baseURL,"/api/v2/sdk/upload")},set:function(e){this._uploadURL=e}},{key:"synchronize",get:function(){return this.syncAdapter.synchronize}},{key:"synchronizeEvent",get:function(){return this.syncAdapter.synchronizeEvent}},{key:"Interceptor",get:function(){return be}},{key:"logger",get:function(){return this.debugMode?console.log.bind(console,"Qiscus ->"):this.noop}},{key:"_throttleDelay",get:function(){return this.updateCommentStatusMode===e.UpdateCommentStatusMode.enabled?0:this.updateCommentStatusThrottleDelay||300}},{key:"_updateStatusEnabled",get:function(){return this.updateCommentStatusMode!==e.UpdateCommentStatusMode.disabled}}]),e}();d()(Te,"UpdateCommentStatusMode",Ee),d()(Te,"Interceptor",be);var Ce=function e(t,n){l()(this,e),this.name=t,this.roomId=n,this.progress=0};t.default=Te}]).default}));
|
|
15
17
|
//# sourceMappingURL=qiscus-sdk-core.min.js.map
|