From 4cfca896649067d2a1d887a942ed690165b07e33 Mon Sep 17 00:00:00 2001 From: Corina Udrescu Date: Wed, 24 Oct 2018 15:39:45 +0200 Subject: [PATCH] Remove Typescript so that only one language is used in the project (ES6) --- .babelrc | 9 - babel.config.js | 4 + dist/bundle.js | 4 +- jestconfig.json | 7 +- package-lock.json | 267 +++++++----------- package.json | 17 +- .../{MockMqttClient.ts => MockMqttClient.js} | 14 +- .../{VenusClient.ts => VenusClient.js} | 37 ++- src/service/{index.ts => index.js} | 0 src/service/{topics.ts => topics.js} | 58 ++-- src/service/{util.ts => util.js} | 42 ++- .../{venusSystem.ts => venusSystem.js} | 54 ++-- test/PowerSupplySystem.test.ts | 57 ---- ...enusClient.test.ts => VenusClient.test.js} | 13 +- test/{util.test.ts => util.test.js} | 0 test/venusSystem.test.js | 58 ++++ tsconfig.json | 12 - tslint.json | 3 - 18 files changed, 285 insertions(+), 371 deletions(-) delete mode 100644 .babelrc create mode 100644 babel.config.js rename src/service/{MockMqttClient.ts => MockMqttClient.js} (89%) rename src/service/{VenusClient.ts => VenusClient.js} (82%) rename src/service/{index.ts => index.js} (100%) rename src/service/{topics.ts => topics.js} (67%) rename src/service/{util.ts => util.js} (57%) rename src/service/{venusSystem.ts => venusSystem.js} (79%) delete mode 100644 test/PowerSupplySystem.test.ts rename test/{VenusClient.test.ts => VenusClient.test.js} (76%) rename test/{util.test.ts => util.test.js} (100%) create mode 100644 test/venusSystem.test.js delete mode 100644 tsconfig.json delete mode 100644 tslint.json diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 834df698f..000000000 --- a/.babelrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "presets": [ - "@babel/typescript" - ], - "plugins": [ - ["transform-react-jsx", { "pragma": "h" }], - ["@babel/plugin-proposal-class-properties"] - ] -} diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 000000000..8994ed321 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,4 @@ +module.exports = { + presets: ["@babel/preset-env"], + plugins: [["transform-react-jsx", { pragma: "h" }], ["@babel/plugin-proposal-class-properties"]] +} diff --git a/dist/bundle.js b/dist/bundle.js index 45d94e6c5..abbdaa110 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -1,8 +1,8 @@ -!function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=134)}([function(t,e){var n,r,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(t){if(n===setTimeout)return setTimeout(t,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(t){n=o}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(t){r=s}}();var c,u=[],l=!1,h=-1;function f(){l&&c&&(l=!1,c.length?u=c.concat(u):h=-1,u.length&&p())}function p(){if(!l){var t=a(f);l=!0;for(var e=u.length;e;){for(c=u,u=[];++h1)for(var n=1;n0&&this._events[t].length>s&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace()),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){if(!r(e))throw TypeError("listener must be a function");var n=!1;function i(){this.removeListener(t,i),n||(n=!0,e.apply(this,arguments))}return i.listener=e,this.on(t,i),this},n.prototype.removeListener=function(t,e){var n,o,s,a;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(s=(n=this._events[t]).length,o=-1,n===e||r(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(i(n)){for(a=s;a-- >0;)if(n[a]===e||n[a].listener&&n[a].listener===e){o=a;break}if(o<0)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(o,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(r(n=this._events[t]))this.removeListener(t,n);else if(n)for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){return this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(r(e))return 1;if(e)return e.length}return 0},n.listenerCount=function(t,e){return t.listenerCount(e)}},function(t,e,n){"use strict";(function(e){!e.version||0===e.version.indexOf("v0.")||0===e.version.indexOf("v1.")&&0!==e.version.indexOf("v1.8.")?t.exports={nextTick:function(t,n,r,i){if("function"!=typeof t)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return e.nextTick(t);case 2:return e.nextTick(function(){t.call(null,n)});case 3:return e.nextTick(function(){t.call(null,n,r)});case 4:return e.nextTick(function(){t.call(null,n,r,i)});default:for(o=new Array(a-1),s=0;s1)for(var n=1;n0&&this._events[t].length>s&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace()),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){if(!r(e))throw TypeError("listener must be a function");var n=!1;function i(){this.removeListener(t,i),n||(n=!0,e.apply(this,arguments))}return i.listener=e,this.on(t,i),this},n.prototype.removeListener=function(t,e){var n,o,s,a;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(s=(n=this._events[t]).length,o=-1,n===e||r(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(i(n)){for(a=s;a-- >0;)if(n[a]===e||n[a].listener&&n[a].listener===e){o=a;break}if(o<0)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(o,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(r(n=this._events[t]))this.removeListener(t,n);else if(n)for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){return this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(r(e))return 1;if(e)return e.length}return 0},n.listenerCount=function(t,e){return t.listenerCount(e)}},function(t,e,n){"use strict";(function(e){!e.version||0===e.version.indexOf("v0.")||0===e.version.indexOf("v1.")&&0!==e.version.indexOf("v1.8.")?t.exports={nextTick:function(t,n,r,i){if("function"!=typeof t)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return e.nextTick(t);case 2:return e.nextTick(function(){t.call(null,n)});case 3:return e.nextTick(function(){t.call(null,n,r)});case 4:return e.nextTick(function(){t.call(null,n,r,i)});default:for(o=new Array(a-1),s=0;s * @license MIT */ -var r=n(48),i=n(49),o=n(24);function s(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(t,e){if(s()=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|t}function d(t,e){if(c.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return H(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return G(t).length;default:if(r)return H(t).length;e=(""+e).toLowerCase(),r=!0}}function _(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function g(t,e,n,r,i){if(0===t.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:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof e&&(e=c.from(e,r)),c.isBuffer(e))return 0===e.length?-1:m(t,e,n,r,i);if("number"==typeof e)return e&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):m(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,n,r,i){var o,s=1,a=t.length,c=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,c/=2,n/=2}function u(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){var l=-1;for(o=n;oa&&(n=a-c),o=n;o>=0;o--){for(var h=!0,f=0;fi&&(r=i):r=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;s>8,i=n%256,o.push(i),o.push(r);return o}(e,t.length-n),t,n,r)}function R(t,e,n){return 0===e&&n===t.length?r.fromByteArray(t):r.fromByteArray(t.slice(e,n))}function A(t,e,n){n=Math.min(t.length,n);for(var r=[],i=e;i239?4:u>223?3:u>191?2:1;if(i+h<=n)switch(h){case 1:u<128&&(l=u);break;case 2:128==(192&(o=t[i+1]))&&(c=(31&u)<<6|63&o)>127&&(l=c);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(c=(15&u)<<12|(63&o)<<6|63&s)>2047&&(c<55296||c>57343)&&(l=c);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(c=(15&u)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(l=c)}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(t){var e=t.length;if(e<=T)return String.fromCharCode.apply(String,t);var n="",r=0;for(;rthis.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return x(this,e,n);case"utf8":case"utf-8":return A(this,e,n);case"ascii":return I(this,e,n);case"latin1":case"binary":return O(this,e,n);case"base64":return R(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}.apply(this,arguments)},c.prototype.equals=function(t){if(!c.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===c.compare(this,t)},c.prototype.inspect=function(){var t="",n=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),""},c.prototype.compare=function(t,e,n,r,i){if(!c.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),e<0||n>t.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&e>=n)return 0;if(r>=i)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,i>>>=0,this===t)return 0;for(var o=i-r,s=n-e,a=Math.min(o,s),u=this.slice(r,i),l=t.slice(e,n),h=0;hi)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return y(this,t,e,n);case"utf8":case"utf-8":return v(this,t,e,n);case"ascii":return b(this,t,e,n);case"latin1":case"binary":return w(this,t,e,n);case"base64":return E(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,t,e,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var T=4096;function I(t,e,n){var r="";n=Math.min(t.length,n);for(var i=e;ir)&&(n=r);for(var i="",o=e;on)throw new RangeError("Trying to access beyond buffer length")}function N(t,e,n,r,i,o){if(!c.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function P(t,e,n,r){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-n,2);i>>8*(r?i:1-i)}function L(t,e,n,r){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-n,4);i>>8*(r?i:3-i)&255}function M(t,e,n,r,i,o){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function j(t,e,n,r,o){return o||M(t,0,n,4),i.write(t,e,n,r,23,4),n+4}function U(t,e,n,r,o){return o||M(t,0,n,8),i.write(t,e,n,r,52,8),n+8}c.prototype.slice=function(t,e){var n,r=this.length;if(t=~~t,e=void 0===e?r:~~e,t<0?(t+=r)<0&&(t=0):t>r&&(t=r),e<0?(e+=r)<0&&(e=0):e>r&&(e=r),e0&&(i*=256);)r+=this[t+--e]*i;return r},c.prototype.readUInt8=function(t,e){return e||k(t,1,this.length),this[t]},c.prototype.readUInt16LE=function(t,e){return e||k(t,2,this.length),this[t]|this[t+1]<<8},c.prototype.readUInt16BE=function(t,e){return e||k(t,2,this.length),this[t]<<8|this[t+1]},c.prototype.readUInt32LE=function(t,e){return e||k(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},c.prototype.readUInt32BE=function(t,e){return e||k(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},c.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=this[t],i=1,o=0;++o=(i*=128)&&(r-=Math.pow(2,8*e)),r},c.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=e,i=1,o=this[t+--r];r>0&&(i*=256);)o+=this[t+--r]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},c.prototype.readInt8=function(t,e){return e||k(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},c.prototype.readInt16LE=function(t,e){e||k(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt16BE=function(t,e){e||k(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt32LE=function(t,e){return e||k(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},c.prototype.readInt32BE=function(t,e){return e||k(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},c.prototype.readFloatLE=function(t,e){return e||k(t,4,this.length),i.read(this,t,!0,23,4)},c.prototype.readFloatBE=function(t,e){return e||k(t,4,this.length),i.read(this,t,!1,23,4)},c.prototype.readDoubleLE=function(t,e){return e||k(t,8,this.length),i.read(this,t,!0,52,8)},c.prototype.readDoubleBE=function(t,e){return e||k(t,8,this.length),i.read(this,t,!1,52,8)},c.prototype.writeUIntLE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||N(this,t,e,n,Math.pow(2,8*n)-1,0);var i=1,o=0;for(this[e]=255&t;++o=0&&(o*=256);)this[e+i]=t/o&255;return e+n},c.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,1,255,0),c.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},c.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):P(this,t,e,!0),e+2},c.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):P(this,t,e,!1),e+2},c.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):L(this,t,e,!0),e+4},c.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):L(this,t,e,!1),e+4},c.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);N(this,t,e,n,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o>0)-a&255;return e+n},c.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);N(this,t,e,n,i-1,-i)}var o=n-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+n},c.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,1,127,-128),c.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},c.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):P(this,t,e,!0),e+2},c.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):P(this,t,e,!1),e+2},c.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):L(this,t,e,!0),e+4},c.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):L(this,t,e,!1),e+4},c.prototype.writeFloatLE=function(t,e,n){return j(this,t,e,!0,n)},c.prototype.writeFloatBE=function(t,e,n){return j(this,t,e,!1,n)},c.prototype.writeDoubleLE=function(t,e,n){return U(this,t,e,!0,n)},c.prototype.writeDoubleBE=function(t,e,n){return U(this,t,e,!1,n)},c.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r=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),t.length-e=0;--i)t[i+e]=this[i+n];else if(o<1e3||!c.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(o=e;o55295&&n<57344){if(!i){if(n>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(e-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((e-=1)<0)break;o.push(n)}else if(n<2048){if((e-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=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((e-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function G(t){return r.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(D,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function q(t,e,n,r){for(var i=0;i=e.length||i>=t.length);++i)e[i+n]=t[i];return i}}).call(this,n(1))},function(t,e,n){"use strict";t.exports=n(70)()?Object.assign:n(71)},function(t,e,n){"use strict";var r,i=n(30),o=n(19),s=n(5),a=n(4),c=n(8),u=n(87),l=n(6),h=Object.defineProperty,f=Object.defineProperties;t.exports=r=function(t,e){if(!(this instanceof r))throw new TypeError("Constructor requires 'new'");f(this,{__list__:c("w",a(t)),__context__:c("w",e),__nextIndex__:c("w",0)}),e&&(s(e.on),e.on("_add",this._onAdd),e.on("_delete",this._onDelete),e.on("_clear",this._onClear))},delete r.prototype.constructor,f(r.prototype,o({_next:c(function(){var t;if(this.__list__)return this.__redo__&&void 0!==(t=this.__redo__.shift())?t:this.__nextIndex__=this.__nextIndex__||(++this.__nextIndex__,this.__redo__?(this.__redo__.forEach(function(e,n){e>=t&&(this.__redo__[n]=++e)},this),this.__redo__.push(t)):h(this,"__redo__",c("c",[t])))}),_onDelete:c(function(t){var e;t>=this.__nextIndex__||(--this.__nextIndex__,this.__redo__&&(-1!==(e=this.__redo__.indexOf(t))&&this.__redo__.splice(e,1),this.__redo__.forEach(function(e,n){e>t&&(this.__redo__[n]=--e)},this)))}),_onClear:c(function(){this.__redo__&&i.call(this.__redo__),this.__nextIndex__=0})}))),h(r.prototype,l.iterator,c(function(){return this}))},function(t,e,n){"use strict";var r=n(121);t.exports=function(t,e){var n;function i(r){e.rejectUnauthorized&&t.emit("error",r),n.end()}return e.port=e.port||8883,e.host=e.hostname||e.host||"localhost",e.rejectUnauthorized=!1!==e.rejectUnauthorized,delete e.path,(n=r.connect(e)).on("secureConnect",function(){e.rejectUnauthorized&&!n.authorized?n.emit("error",new Error("TLS not authorized")):n.removeListener("error",i)}),n.on("error",i),n}},function(t,e,n){"use strict";(function(e){var r=n(17),i=n(13).Readable,o={objectMode:!0},s={clean:!0},a=n(57);function c(t){if(!(this instanceof c))return new c(t);this.options=t||{},this.options=r(s,t),this._inflights=new a}c.prototype.put=function(t,e){return this._inflights.set(t.messageId,t),e&&e(),this},c.prototype.createStream=function(){var t=new i(o),n=!1,r=[],s=0;return this._inflights.forEach(function(t,e){r.push(t)}),t._read=function(){!n&&s0?("string"==typeof e||s.objectMode||Object.getPrototypeOf(e)===u.prototype||(e=function(t){return u.from(t)}(e)),r?s.endEmitted?t.emit("error",new Error("stream.unshift() after end event")):w(t,s,e,!0):s.ended?t.emit("error",new Error("stream.push() after EOF")):(s.reading=!1,s.decoder&&!n?(e=s.decoder.write(e),s.objectMode||0!==e.length?w(t,s,e,!1):T(t,s)):w(t,s,e,!1))):r||(s.reading=!1));return function(t){return!t.ended&&(t.needReadable||t.lengthe.highWaterMark&&(e.highWaterMark=function(t){return t>=E?t=E:(t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++),t}(t)),t<=e.length?t:e.ended?e.length:(e.needReadable=!0,0))}function R(t){var e=t._readableState;e.needReadable=!1,e.emittedReadable||(p("emitReadable",e.flowing),e.emittedReadable=!0,e.sync?i.nextTick(A,t):A(t))}function A(t){p("emit readable"),t.emit("readable"),C(t)}function T(t,e){e.readingMore||(e.readingMore=!0,i.nextTick(I,t,e))}function I(t,e){for(var n=e.length;!e.reading&&!e.flowing&&!e.ended&&e.length=e.length?(n=e.decoder?e.buffer.join(""):1===e.buffer.length?e.buffer.head.data:e.buffer.concat(e.length),e.buffer.clear()):n=function(t,e,n){var r;to.length?o.length:t;if(s===o.length?i+=o:i+=o.slice(0,t),0===(t-=s)){s===o.length?(++r,n.next?e.head=n.next:e.head=e.tail=null):(e.head=n,n.data=o.slice(s));break}++r}return e.length-=r,i}(t,e):function(t,e){var n=u.allocUnsafe(t),r=e.head,i=1;r.data.copy(n),t-=r.data.length;for(;r=r.next;){var o=r.data,s=t>o.length?o.length:t;if(o.copy(n,n.length-t,0,s),0===(t-=s)){s===o.length?(++i,r.next?e.head=r.next:e.head=e.tail=null):(e.head=r,r.data=o.slice(s));break}++i}return e.length-=i,n}(t,e);return r}(t,e.buffer,e.decoder),n);var n}function N(t){var e=t._readableState;if(e.length>0)throw new Error('"endReadable()" called on non-empty stream');e.endEmitted||(e.ended=!0,i.nextTick(P,e,t))}function P(t,e){t.endEmitted||0!==t.length||(t.endEmitted=!0,e.readable=!1,e.emit("end"))}function L(t,e){for(var n=0,r=t.length;n=e.highWaterMark||e.ended))return p("read: emitReadable",e.length,e.ended),0===e.length&&e.ended?N(this):R(this),null;if(0===(t=S(t,e))&&e.ended)return 0===e.length&&N(this),null;var r,i=e.needReadable;return p("need readable",i),(0===e.length||e.length-t0?k(t,e):null)?(e.needReadable=!0,t=0):e.length-=t,0===e.length&&(e.ended||(e.needReadable=!0),n!==t&&e.ended&&N(this)),null!==r&&this.emit("data",r),r},v.prototype._read=function(t){this.emit("error",new Error("_read() is not implemented"))},v.prototype.pipe=function(t,e){var n=this,o=this._readableState;switch(o.pipesCount){case 0:o.pipes=t;break;case 1:o.pipes=[o.pipes,t];break;default:o.pipes.push(t)}o.pipesCount+=1,p("pipe count=%d opts=%j",o.pipesCount,e);var c=(!e||!1!==e.end)&&t!==r.stdout&&t!==r.stderr?l:v;function u(e,r){p("onunpipe"),e===n&&r&&!1===r.hasUnpiped&&(r.hasUnpiped=!0,p("cleanup"),t.removeListener("close",m),t.removeListener("finish",y),t.removeListener("drain",h),t.removeListener("error",g),t.removeListener("unpipe",u),n.removeListener("end",l),n.removeListener("end",v),n.removeListener("data",_),f=!0,!o.awaitDrain||t._writableState&&!t._writableState.needDrain||h())}function l(){p("onend"),t.end()}o.endEmitted?i.nextTick(c):n.once("end",c),t.on("unpipe",u);var h=function(t){return function(){var e=t._readableState;p("pipeOnDrain",e.awaitDrain),e.awaitDrain&&e.awaitDrain--,0===e.awaitDrain&&a(t,"data")&&(e.flowing=!0,C(t))}}(n);t.on("drain",h);var f=!1;var d=!1;function _(e){p("ondata"),d=!1,!1!==t.write(e)||d||((1===o.pipesCount&&o.pipes===t||o.pipesCount>1&&-1!==L(o.pipes,t))&&!f&&(p("false write response, pause",n._readableState.awaitDrain),n._readableState.awaitDrain++,d=!0),n.pause())}function g(e){p("onerror",e),v(),t.removeListener("error",g),0===a(t,"error")&&t.emit("error",e)}function m(){t.removeListener("finish",y),v()}function y(){p("onfinish"),t.removeListener("close",m),v()}function v(){p("unpipe"),n.unpipe(t)}return n.on("data",_),function(t,e,n){if("function"==typeof t.prependListener)return t.prependListener(e,n);t._events&&t._events[e]?s(t._events[e])?t._events[e].unshift(n):t._events[e]=[n,t._events[e]]:t.on(e,n)}(t,"error",g),t.once("close",m),t.once("finish",y),t.emit("pipe",n),o.flowing||(p("pipe resume"),n.resume()),t},v.prototype.unpipe=function(t){var e=this._readableState,n={hasUnpiped:!1};if(0===e.pipesCount)return this;if(1===e.pipesCount)return t&&t!==e.pipes?this:(t||(t=e.pipes),e.pipes=null,e.pipesCount=0,e.flowing=!1,t&&t.emit("unpipe",this,n),this);if(!t){var r=e.pipes,i=e.pipesCount;e.pipes=null,e.pipesCount=0,e.flowing=!1;for(var o=0;o-1?r:o.nextTick;y.WritableState=m;var u=n(12);u.inherits=n(3);var l={deprecate:n(55)},h=n(25),f=n(2).Buffer,p=i.Uint8Array||function(){};var d,_=n(26);function g(){}function m(t,e){a=a||n(7),t=t||{};var r=e instanceof a;this.objectMode=!!t.objectMode,r&&(this.objectMode=this.objectMode||!!t.writableObjectMode);var i=t.highWaterMark,u=t.writableHighWaterMark,l=this.objectMode?16:16384;this.highWaterMark=i||0===i?i:r&&(u||0===u)?u: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===t.decodeStrings;this.decodeStrings=!h,this.defaultEncoding=t.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(t){!function(t,e){var n=t._writableState,r=n.sync,i=n.writecb;if(function(t){t.writing=!1,t.writecb=null,t.length-=t.writelen,t.writelen=0}(n),e)!function(t,e,n,r,i){--e.pendingcb,n?(o.nextTick(i,r),o.nextTick(R,t,e),t._writableState.errorEmitted=!0,t.emit("error",r)):(i(r),t._writableState.errorEmitted=!0,t.emit("error",r),R(t,e))}(t,n,r,e,i);else{var s=E(n);s||n.corked||n.bufferProcessing||!n.bufferedRequest||w(t,n),r?c(b,t,n,s,i):b(t,n,s,i)}}(e,t)},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(t){if(a=a||n(7),!(d.call(y,this)||this instanceof a))return new y(t);this._writableState=new m(t,this),this.writable=!0,t&&("function"==typeof t.write&&(this._write=t.write),"function"==typeof t.writev&&(this._writev=t.writev),"function"==typeof t.destroy&&(this._destroy=t.destroy),"function"==typeof t.final&&(this._final=t.final)),h.call(this)}function v(t,e,n,r,i,o,s){e.writelen=r,e.writecb=s,e.writing=!0,e.sync=!0,n?t._writev(i,e.onwrite):t._write(i,o,e.onwrite),e.sync=!1}function b(t,e,n,r){n||function(t,e){0===e.length&&e.needDrain&&(e.needDrain=!1,t.emit("drain"))}(t,e),e.pendingcb--,r(),R(t,e)}function w(t,e){e.bufferProcessing=!0;var n=e.bufferedRequest;if(t._writev&&n&&n.next){var r=e.bufferedRequestCount,i=new Array(r),o=e.corkedRequestsFree;o.entry=n;for(var a=0,c=!0;n;)i[a]=n,n.isBuf||(c=!1),n=n.next,a+=1;i.allBuffers=c,v(t,e,!0,e.length,i,"",o.finish),e.pendingcb++,e.lastBufferedRequest=null,o.next?(e.corkedRequestsFree=o.next,o.next=null):e.corkedRequestsFree=new s(e),e.bufferedRequestCount=0}else{for(;n;){var u=n.chunk,l=n.encoding,h=n.callback;if(v(t,e,!1,e.objectMode?1:u.length,u,l,h),n=n.next,e.bufferedRequestCount--,e.writing)break}null===n&&(e.lastBufferedRequest=null)}e.bufferedRequest=n,e.bufferProcessing=!1}function E(t){return t.ending&&0===t.length&&null===t.bufferedRequest&&!t.finished&&!t.writing}function S(t,e){t._final(function(n){e.pendingcb--,n&&t.emit("error",n),e.prefinished=!0,t.emit("prefinish"),R(t,e)})}function R(t,e){var n=E(e);return n&&(!function(t,e){e.prefinished||e.finalCalled||("function"==typeof t._final?(e.pendingcb++,e.finalCalled=!0,o.nextTick(S,t,e)):(e.prefinished=!0,t.emit("prefinish")))}(t,e),0===e.pendingcb&&(e.finished=!0,t.emit("finish"))),n}u.inherits(y,h),m.prototype.getBuffer=function(){for(var t=this.bufferedRequest,e=[];t;)e.push(t),t=t.next;return e},function(){try{Object.defineProperty(m.prototype,"buffer",{get:l.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(t){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(d=Function.prototype[Symbol.hasInstance],Object.defineProperty(y,Symbol.hasInstance,{value:function(t){return!!d.call(this,t)||this===y&&(t&&t._writableState instanceof m)}})):d=function(t){return t instanceof this},y.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},y.prototype.write=function(t,e,n){var r=this._writableState,i=!1,s=!r.objectMode&&function(t){return f.isBuffer(t)||t instanceof p}(t);return s&&!f.isBuffer(t)&&(t=function(t){return f.from(t)}(t)),"function"==typeof e&&(n=e,e=null),s?e="buffer":e||(e=r.defaultEncoding),"function"!=typeof n&&(n=g),r.ended?function(t,e){var n=new Error("write after end");t.emit("error",n),o.nextTick(e,n)}(this,n):(s||function(t,e,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||e.objectMode||(s=new TypeError("Invalid non-string/buffer chunk")),s&&(t.emit("error",s),o.nextTick(r,s),i=!1),i}(this,r,t,n))&&(r.pendingcb++,i=function(t,e,n,r,i,o){if(!n){var s=function(t,e,n){t.objectMode||!1===t.decodeStrings||"string"!=typeof e||(e=f.from(e,n));return e}(e,r,i);r!==s&&(n=!0,i="buffer",r=s)}var a=e.objectMode?1:r.length;e.length+=a;var c=e.length-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this},Object.defineProperty(y.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),y.prototype._write=function(t,e,n){n(new Error("_write() is not implemented"))},y.prototype._writev=null,y.prototype.end=function(t,e,n){var r=this._writableState;"function"==typeof t?(n=t,t=null,e=null):"function"==typeof e&&(n=e,e=null),null!==t&&void 0!==t&&this.write(t,e),r.corked&&(r.corked=1,this.uncork()),r.ending||r.finished||function(t,e,n){e.ending=!0,R(t,e),n&&(e.finished?o.nextTick(n):t.once("finish",n));e.ended=!0,t.writable=!1}(this,r,n)},Object.defineProperty(y.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(t){this._writableState&&(this._writableState.destroyed=t)}}),y.prototype.destroy=_.destroy,y.prototype._undestroy=_.undestroy,y.prototype._destroy=function(t,e){this.end(),e(t)}}).call(this,n(0),n(53).setImmediate,n(1))},function(t,e,n){"use strict";var r=n(2).Buffer,i=r.isEncoding||function(t){switch((t=""+t)&&t.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(t){var e;switch(this.encoding=function(t){var e=function(t){if(!t)return"utf8";for(var e;;)switch(t){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 t;default:if(e)return;t=(""+t).toLowerCase(),e=!0}}(t);if("string"!=typeof e&&(r.isEncoding===i||!i(t)))throw new Error("Unknown encoding: "+t);return e||t}(t),this.encoding){case"utf16le":this.text=c,this.end=u,e=4;break;case"utf8":this.fillLast=a,e=4;break;case"base64":this.text=l,this.end=h,e=3;break;default:return this.write=f,void(this.end=p)}this.lastNeed=0,this.lastTotal=0,this.lastChar=r.allocUnsafe(e)}function s(t){return t<=127?0:t>>5==6?2:t>>4==14?3:t>>3==30?4:t>>6==2?-1:-2}function a(t){var e=this.lastTotal-this.lastNeed,n=function(t,e,n){if(128!=(192&e[0]))return t.lastNeed=0,"�";if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�";if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�"}}(this,t);return void 0!==n?n:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),void(this.lastNeed-=t.length))}function c(t,e){if((t.length-e)%2==0){var n=t.toString("utf16le",e);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function u(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,n)}return e}function l(t,e){var n=(t.length-e)%3;return 0===n?t.toString("base64",e):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-n))}function h(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function f(t){return t.toString(this.encoding)}function p(t){return t&&t.length?this.write(t):""}e.StringDecoder=o,o.prototype.write=function(t){if(0===t.length)return"";var e,n;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n=0)return i>0&&(t.lastNeed=i-1),i;if(--r=0)return i>0&&(t.lastNeed=i-2),i;if(--r=0)return i>0&&(2===i?i=0:t.lastNeed=i-3),i;return 0}(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=n;var r=t.length-(n-this.lastNeed);return t.copy(this.lastChar,0,r),t.toString("utf8",e,r)},o.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length}},function(t,e,n){"use strict";t.exports=o;var r=n(7),i=n(12);function o(t){if(!(this instanceof o))return new o(t);r.call(this,t),this._transformState={afterTransform:function(t,e){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!=e&&this.push(e),r(t);var i=this._readableState;i.reading=!1,(i.needReadable||i.length65535||u%1!=0)return e.emit("error",new Error("Invalid keepalive")),!1;d+=2;if(d+=1,a){if("object"!=typeof a)return e.emit("error",new Error("Invalid will")),!1;if(!a.topic||"string"!=typeof a.topic)return e.emit("error",new Error("Invalid will topic")),!1;if(d+=i.byteLength(a.topic)+2,a.payload&&a.payload){if(!(a.payload.length>=0))return e.emit("error",new Error("Invalid will payload")),!1;"string"==typeof a.payload?d+=i.byteLength(a.payload)+2:d+=a.payload.length+2}else d+=2}var _=!1;if(null!=h){if(!S(h))return e.emit("error",new Error("Invalid username")),!1;_=!0,d+=i.byteLength(h)+2}if(null!=p){if(!_)return e.emit("error",new Error("Username is required to use password")),!1;if(!S(p))return e.emit("error",new Error("Invalid password")),!1;d+=E(p)+2}e.write(r.CONNECT_HEADER),m(e,d),w(e,o),e.write(4===s?r.VERSION4:r.VERSION3);var g=0;g|=null!=h?r.USERNAME_MASK:0,g|=null!=p?r.PASSWORD_MASK:0,g|=a&&a.retain?r.WILL_RETAIN_MASK:0,g|=a&&a.qos?a.qos<0&&f(e,l);return e.write(u)}(t,e);case"puback":case"pubrec":case"pubrel":case"pubcomp":case"unsuback":return function(t,e){var n=t||{},i=n.cmd||"puback",o=n.messageId,s=n.dup&&"pubrel"===i?r.DUP_MASK:0,a=0;"pubrel"===i&&(a=1);if("number"!=typeof o)return e.emit("error",new Error("Invalid messageId")),!1;return e.write(r.ACKS[i][a][s][0]),m(e,2),f(e,o)}(t,e);case"subscribe":return function(t,e){var n=t||{},o=n.dup?r.DUP_MASK:0,s=n.messageId,a=n.subscriptions,c=0;if("number"!=typeof s)return e.emit("error",new Error("Invalid messageId")),!1;c+=2;if("object"!=typeof a||!a.length)return e.emit("error",new Error("Invalid subscriptions")),!1;for(var u=0;u=0&&t<128?1:t>=128&&t<16384?2:t>=16384&&t<2097152?3:t>=2097152&&t<268435456?4:0}(t));do{e=t%128|0,(t=t/128|0)>0&&(e|=128),r.writeUInt8(e,n++)}while(t>0);return r}(e),e<16384&&(g[e]=n)),t.write(n)}function y(t,e){var n=i.byteLength(e);f(t,n),t.write(e,"utf8")}function v(t,e){return t.write(u[e])}function b(t,e){return t.write(l(e))}function w(t,e){"string"==typeof e?y(t,e):e?(f(t,e.length),t.write(e)):f(t,0)}function E(t){return t?t instanceof i?t.length:i.byteLength(t):0}function S(t){return"string"==typeof t||t instanceof i}t.exports=d},function(t,e,n){"use strict";var r=n(114),i=n(116);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}e.parse=v,e.resolve=function(t,e){return v(t,!1,!0).resolve(e)},e.resolveObject=function(t,e){return t?v(t,!1,!0).resolveObject(e):e},e.format=function(t){i.isString(t)&&(t=v(t));return t instanceof o?t.format():o.prototype.format.call(t)},e.Url=o;var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,u=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),l=["'"].concat(u),h=["%","/","?",";","#"].concat(l),f=["/","?","#"],p=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,_={javascript:!0,"javascript:":!0},g={javascript:!0,"javascript:":!0},m={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},y=n(117);function v(t,e,n){if(t&&i.isObject(t)&&t instanceof o)return t;var r=new o;return r.parse(t,e,n),r}o.prototype.parse=function(t,e,n){if(!i.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var o=t.indexOf("?"),a=-1!==o&&o127?P+="x":P+=N[L];if(!P.match(p)){var j=C.slice(0,I),U=C.slice(I+1),D=N.match(d);D&&(j.push(D[1]),U.unshift(D[2])),U.length&&(v="/"+U.join(".")+v),this.hostname=j.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),x||(this.hostname=r.toASCII(this.hostname));var B=this.port?":"+this.port:"",H=this.hostname||"";this.host=H+B,this.href+=this.host,x&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==v[0]&&(v="/"+v))}if(!_[E])for(I=0,k=l.length;I0)&&n.host.split("@"))&&(n.auth=x.shift(),n.host=n.hostname=x.shift());return n.search=t.search,n.query=t.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 A=S.slice(-1)[0],T=(n.host||t.host||S.length>1)&&("."===A||".."===A)||""===A,I=0,O=S.length;O>=0;O--)"."===(A=S[O])?S.splice(O,1):".."===A?(S.splice(O,1),I++):I&&(S.splice(O,1),I--);if(!w&&!E)for(;I--;I)S.unshift("..");!w||""===S[0]||S[0]&&"/"===S[0].charAt(0)||S.unshift(""),T&&"/"!==S.join("/").substr(-1)&&S.push("");var x,C=""===S[0]||S[0]&&"/"===S[0].charAt(0);R&&(n.hostname=n.host=C?"":S.length?S.shift():"",(x=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=x.shift(),n.host=n.hostname=x.shift()));return(w=w||n.host&&S.length)&&!C&&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=t.auth||n.auth,n.slashes=n.slashes||t.slashes,n.href=n.format(),n},o.prototype.parseHost=function(){var t=this.host,e=a.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},function(t,e,n){"use strict";var r=n(120);t.exports=function(t,e){var n,i;return e.port=e.port||1883,e.hostname=e.hostname||e.host||"localhost",n=e.port,i=e.hostname,r.createConnection(n,i)}},function(t,e,n){"use strict";var r=!1,i=[];function o(t){r?wx.sendSocketMessage({data:t.buffer||t}):i.push(t)}var s=n(44);function a(t,e){var n="MQIsdp"===e.protocolId&&3===e.protocolVersion?"mqttv3.1":"mqtt";!function(t){t.hostname||(t.hostname="localhost"),t.path||(t.path="/"),t.wsOptions||(t.wsOptions={})}(e);var a=function(t,e){var n="wxs"===t.protocol?"wss":"ws",r=n+"://"+t.hostname+t.path;return t.port&&80!==t.port&&443!==t.port&&(r=n+"://"+t.hostname+":"+t.port+t.path),"function"==typeof t.transformWsUrl&&(r=t.transformWsUrl(r,t,e)),r}(e,t);return s(function(t,e){var n={OPEN:1,CLOSING:2,CLOSED:3,readyState:r?1:0,send:o,close:wx.closeSocket,onopen:null,onmessage:null,onclose:null,onerror:null};return wx.connectSocket({url:t,protocols:e}),wx.onSocketOpen(function(t){n.readyState=n.OPEN,r=!0;for(var e=0;e_)return void setTimeout(t,g,e,n,r);m&&"string"==typeof e&&(e=a.from(e,"utf8"));try{l.send(e)}catch(t){return r(t)}r()}:function(t,e,n){if(l.readyState!==l.OPEN)return void n();m&&"string"==typeof t&&(t=a.from(t,"utf8"));l.send(t,n)};n&&!Array.isArray(n)&&"object"==typeof n&&(c=n,n=null,("string"==typeof c.protocol||Array.isArray(c.protocol))&&(n=c.protocol));c||(c={});void 0===c.objectMode&&(c.objectMode=!(!0===c.binary||void 0===c.binary));var d=function(t,e,n){var r=new i({objectMode:t.objectMode});return r._write=e,r._flush=n,r}(c,p,function(t){l.close(),t()});c.objectMode||(d._writev=function(t,e){for(var n=new Array(t.length),r=0;r0&&(this.options.resubscribe?(this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics)):this._resubscribeTopics={}),s=!1}),this.on("close",function(){null!==r.pingTimer&&(r.pingTimer.clear(),r.pingTimer=null)}),this.on("close",this._setupReconnect),i.EventEmitter.call(this),this._setupStream()}u(y,i.EventEmitter),y.prototype._setupStream=function(){var t,e=this,n=new c,i=a.parser(this.options),o=null,u=[];function l(){r.nextTick(h)}function h(){var t=u.shift(),n=o;t?e._handlePacket(t,l):(o=null,n())}this._clearReconnect(),this.stream=this.streamBuilder(this),i.on("packet",function(t){u.push(t)}),n._write=function(t,e,n){o=n,i.parse(t),h()},this.stream.pipe(n),this.stream.on("error",m),s(this.stream,this.emit.bind(this,"close")),(t=Object.create(this.options)).cmd="connect",_(this,t),i.on("error",this.emit.bind(this,"error")),this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout(function(){e._cleanUp(!0)},this.options.connectTimeout)},y.prototype._handlePacket=function(t,e){switch(this.emit("packetreceive",t),t.cmd){case"publish":this._handlePublish(t,e);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(t),e();break;case"pubrel":this._handlePubrel(t,e);break;case"connack":this._handleConnack(t),e();break;case"pingresp":this._handlePingresp(t),e()}},y.prototype._checkDisconnecting=function(t){return this.disconnecting&&(t?t(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting},y.prototype.publish=function(t,e,n,r){var i;"function"==typeof n&&(r=n,n=null);if(n=f({qos:0,retain:!1,dup:!1},n),this._checkDisconnecting(r))return this;switch(i={cmd:"publish",topic:t,payload:e,qos:n.qos,retain:n.retain,messageId:this._nextId(),dup:n.dup},n.qos){case 1:case 2:this.outgoing[i.messageId]=r||m,this._sendPacket(i);break;default:this._sendPacket(i,r)}return this},y.prototype.subscribe=function(){var t,e,n=Array.prototype.slice.call(arguments),r=[],i=n.shift(),o=i.resubscribe,s=n.pop()||m,a=n.pop(),c=this;if(delete i.resubscribe,"string"==typeof i&&(i=[i]),"function"!=typeof s&&(a=s,s=m),null!==(e=h.validateTopics(i)))return p(s,new Error("Invalid topic "+e)),this;if(this._checkDisconnecting(s))return this;if(a=f({qos:0},a),Array.isArray(i)?i.forEach(function(t){(c._resubscribeTopics[t]0&&(c._resubscribeTopics[t.topic]=t.qos,u.push(t.topic))}),c.messageIdToTopic[t.messageId]=u}return this.outgoing[t.messageId]=function(t,e){if(!t)for(var n=e.granted,i=0;i0?this.once("outgoingEmpty",setTimeout.bind(null,i,10)):i(),this)},y.prototype.removeOutgoingMessage=function(t){var e=this.outgoing[t];return delete this.outgoing[t],this.outgoingStore.del({messageId:t},function(){e(new Error("Message removed"))}),this},y.prototype.reconnect=function(t){var e=this,n=function(){t?(e.options.incomingStore=t.incomingStore,e.options.outgoingStore=t.outgoingStore):(e.options.incomingStore=null,e.options.outgoingStore=null),e.incomingStore=e.options.incomingStore||new o,e.outgoingStore=e.options.outgoingStore||new o,e.disconnecting=!1,e.disconnected=!1,e._deferredReconnect=null,e._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=n:n(),this},y.prototype._reconnect=function(){this.emit("reconnect"),this._setupStream()},y.prototype._setupReconnect=function(){var t=this;!t.disconnecting&&!t.reconnectTimer&&t.options.reconnectPeriod>0&&(this.reconnecting||(this.emit("offline"),this.reconnecting=!0),t.reconnectTimer=setInterval(function(){t._reconnect()},t.options.reconnectPeriod))},y.prototype._clearReconnect=function(){this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},y.prototype._cleanUp=function(t,e){e&&this.stream.on("close",e),t?(0===this.options.reconnectPeriod&&this.options.clean&&function(t){t&&Object.keys(t).forEach(function(e){"function"==typeof t[e]&&(t[e](new Error("Connection closed")),delete t[e])})}(this.outgoing),this.stream.destroy()):this._sendPacket({cmd:"disconnect"},p.bind(null,this.stream.end.bind(this.stream))),this.disconnecting||(this._clearReconnect(),this._setupReconnect()),null!==this.pingTimer&&(this.pingTimer.clear(),this.pingTimer=null),e&&!this.connected&&(this.stream.removeListener("close",e),e())},y.prototype._sendPacket=function(t,e){if(this.connected){switch(this._shiftPingInterval(),t.cmd){case"publish":break;case"pubrel":return void g(this,t,e);default:return void _(this,t,e)}switch(t.qos){case 2:case 1:g(this,t,e);break;case 0:default:_(this,t,e)}}else 0===(t.qos||0)&&this.queueQoSZero||"publish"!==t.cmd?this.queue.push({packet:t,cb:e}):t.qos>0?(e=this.outgoing[t.messageId],this.outgoingStore.put(t,function(t){if(t)return e&&e(t)})):e&&e(new Error("No connection to broker"))},y.prototype._setupPingTimer=function(){var t=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=l(function(){t._checkPing()},1e3*this.options.keepalive))},y.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},y.prototype._checkPing=function(){this.pingResp?(this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):this._cleanUp(!0)},y.prototype._handlePingresp=function(){this.pingResp=!0},y.prototype._handleConnack=function(t){var e=t.returnCode;if(clearTimeout(this.connackTimer),0===e)this.reconnecting=!1,this.emit("connect",t);else if(e>0){var n=new Error("Connection refused: "+["","Unacceptable protocol version","Identifier rejected","Server unavailable","Bad username or password","Not authorized"][e]);n.code=e,this.emit("error",n)}},y.prototype._handlePublish=function(t,e){e=void 0!==e?e:m;var n=t.topic.toString(),r=t.payload,i=t.qos,o=t.messageId,s=this;switch(i){case 2:this.incomingStore.put(t,function(t){if(t)return e(t);s._sendPacket({cmd:"pubrec",messageId:o},e)});break;case 1:this.emit("message",n,r,t),this.handleMessage(t,function(t){if(t)return e(t);s._sendPacket({cmd:"puback",messageId:o},e)});break;case 0:this.emit("message",n,r,t),this.handleMessage(t,e)}},y.prototype.handleMessage=function(t,e){e()},y.prototype._handleAck=function(t){var e=t.messageId,n=t.cmd,r=null,i=this.outgoing[e],o=this;if(i){switch(n){case"pubcomp":case"puback":delete this.outgoing[e],this.outgoingStore.del(t,i);break;case"pubrec":r={cmd:"pubrel",qos:2,messageId:e},this._sendPacket(r);break;case"suback":if(delete this.outgoing[e],1===t.granted.length&&0!=(128&t.granted[0])){var s=this.messageIdToTopic[e];s&&s.forEach(function(t){delete o._resubscribeTopics[t]})}i(null,t);break;case"unsuback":delete this.outgoing[e],i(null);break;default:o.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&0===Object.keys(this.outgoing).length&&this.emit("outgoingEmpty")}},y.prototype._handlePubrel=function(t,e){e=void 0!==e?e:m;var n=this,r={cmd:"pubcomp",messageId:t.messageId};n.incomingStore.get(t,function(i,o){i||"pubrel"===o.cmd?n._sendPacket(r,e):(n.emit("message",o.topic,o.payload,o),n.incomingStore.put(t,function(t){if(t)return e(t);n.handleMessage(o,function(t){if(t)return e(t);n._sendPacket(r,e)})}))})},y.prototype._nextId=function(){var t=this.nextId++;return 65536===this.nextId&&(this.nextId=1),t},y.prototype.getLastMessageId=function(){return 1===this.nextId?65535:this.nextId-1},t.exports=y}).call(this,n(1),n(0))},function(t,e,n){"use strict";e.byteLength=function(t){var e=u(t),n=e[0],r=e[1];return 3*(n+r)/4-r},e.toByteArray=function(t){for(var e,n=u(t),r=n[0],s=n[1],a=new o(function(t,e,n){return 3*(e+n)/4-n}(0,r,s)),c=0,l=s>0?r-4:r,h=0;h>16&255,a[c++]=e>>8&255,a[c++]=255&e;2===s&&(e=i[t.charCodeAt(h)]<<2|i[t.charCodeAt(h+1)]>>4,a[c++]=255&e);1===s&&(e=i[t.charCodeAt(h)]<<10|i[t.charCodeAt(h+1)]<<4|i[t.charCodeAt(h+2)]>>2,a[c++]=e>>8&255,a[c++]=255&e);return a},e.fromByteArray=function(t){for(var e,n=t.length,i=n%3,o=[],s=0,a=n-i;sa?a:s+16383));1===i?(e=t[n-1],o.push(r[e>>2]+r[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],o.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"="));return o.join("")};for(var r=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=s.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function l(t){return r[t>>18&63]+r[t>>12&63]+r[t>>6&63]+r[63&t]}function h(t,e,n){for(var r,i=[],o=e;o>1,l=-7,h=n?i-1:0,f=n?-1:1,p=t[e+h];for(h+=f,o=p&(1<<-l)-1,p>>=-l,l+=a;l>0;o=256*o+t[e+h],h+=f,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=r;l>0;s=256*s+t[e+h],h+=f,l-=8);if(0===o)o=1-u;else{if(o===c)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,r),o-=u}return(p?-1:1)*s*Math.pow(2,o-r)},e.write=function(t,e,n,r,i,o){var s,a,c,u=8*o-i-1,l=(1<>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:o-1,d=r?1:-1,_=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),(e+=s+h>=1?f/c:f*Math.pow(2,1-h))*c>=2&&(s++,c/=2),s+h>=l?(a=0,s=l):s+h>=1?(a=(e*c-1)*Math.pow(2,i),s+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;t[n+p]=255&a,p+=d,a/=256,i-=8);for(s=s<0;t[n+p]=255&s,p+=d,s/=256,u-=8);t[n+p-d]|=128*_}},function(t,e){},function(t,e,n){"use strict";var r=n(2).Buffer,i=n(52);function o(t,e,n){t.copy(e,n)}t.exports=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.head=null,this.tail=null,this.length=0}return t.prototype.push=function(t){var e={data:t,next:null};this.length>0?this.tail.next=e:this.head=e,this.tail=e,++this.length},t.prototype.unshift=function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length},t.prototype.shift=function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}},t.prototype.clear=function(){this.head=this.tail=null,this.length=0},t.prototype.join=function(t){if(0===this.length)return"";for(var e=this.head,n=""+e.data;e=e.next;)n+=t+e.data;return n},t.prototype.concat=function(t){if(0===this.length)return r.alloc(0);if(1===this.length)return this.head.data;for(var e=r.allocUnsafe(t>>>0),n=this.head,i=0;n;)o(n.data,e,i),i+=n.data.length,n=n.next;return e},t}(),i&&i.inspect&&i.inspect.custom&&(t.exports.prototype[i.inspect.custom]=function(){var t=i.inspect({length:this.length});return this.constructor.name+" "+t})},function(t,e){},function(t,e,n){(function(t){var r=void 0!==t&&t||"undefined"!=typeof self&&self||window,i=Function.prototype.apply;function o(t,e){this._id=t,this._clearFn=e}e.setTimeout=function(){return new o(i.call(setTimeout,r,arguments),clearTimeout)},e.setInterval=function(){return new o(i.call(setInterval,r,arguments),clearInterval)},e.clearTimeout=e.clearInterval=function(t){t&&t.close()},o.prototype.unref=o.prototype.ref=function(){},o.prototype.close=function(){this._clearFn.call(r,this._id)},e.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},e.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},e._unrefActive=e.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;e>=0&&(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},e))},n(54),e.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==t&&t.setImmediate||this&&this.setImmediate,e.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==t&&t.clearImmediate||this&&this.clearImmediate}).call(this,n(1))},function(t,e,n){(function(t,e){!function(t,n){"use strict";if(!t.setImmediate){var r,i=1,o={},s=!1,a=t.document,c=Object.getPrototypeOf&&Object.getPrototypeOf(t);c=c&&c.setTimeout?c:t,"[object process]"==={}.toString.call(t.process)?r=function(t){e.nextTick(function(){l(t)})}:function(){if(t.postMessage&&!t.importScripts){var e=!0,n=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=n,e}}()?function(){var e="setImmediate$"+Math.random()+"$",n=function(n){n.source===t&&"string"==typeof n.data&&0===n.data.indexOf(e)&&l(+n.data.slice(e.length))};t.addEventListener?t.addEventListener("message",n,!1):t.attachEvent("onmessage",n),r=function(n){t.postMessage(e+n,"*")}}():t.MessageChannel?function(){var t=new MessageChannel;t.port1.onmessage=function(t){l(t.data)},r=function(e){t.port2.postMessage(e)}}():a&&"onreadystatechange"in a.createElement("script")?function(){var t=a.documentElement;r=function(e){var n=a.createElement("script");n.onreadystatechange=function(){l(e),n.onreadystatechange=null,t.removeChild(n),n=null},t.appendChild(n)}}():r=function(t){setTimeout(l,0,t)},c.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),n=0;n=0?u(l):i(this.length)-u(c(l));e0?1:-1}},function(t,e,n){"use strict";var r=n(9),i={function:!0,object:!0};t.exports=function(t){return r(t)&&i[typeof t]||!1}},function(t,e,n){"use strict";var r,i=Object.create;n(33)()||(r=n(34)),t.exports=function(){var t,e,n;return r?1!==r.level?i:(t={},e={},n={configurable:!1,enumerable:!1,writable:!0,value:void 0},Object.getOwnPropertyNames(Object.prototype).forEach(function(t){e[t]="__proto__"!==t?n:{configurable:!0,enumerable:!1,writable:!0,value:void 0}}),Object.defineProperties(t,e),Object.defineProperty(r,"nullPolyfill",{configurable:!1,enumerable:!1,writable:!1,value:t}),function(e,n){return i(null===e?t:e,n)}):i}()},function(t,e,n){"use strict";t.exports=function(){var t,e=Object.assign;return"function"==typeof e&&(e(t={foo:"raz"},{bar:"dwa"},{trzy:"trzy"}),t.foo+t.bar+t.trzy==="razdwatrzy")}},function(t,e,n){"use strict";var r=n(72),i=n(4),o=Math.max;t.exports=function(t,e){var n,s,a,c=o(arguments.length,2);for(t=Object(i(t)),a=function(r){try{t[r]=e[r]}catch(t){n||(n=t)}},s=1;s-1}},function(t,e,n){"use strict";var r,i,o,s,a,c,u,l=n(8),h=n(5),f=Function.prototype.apply,p=Function.prototype.call,d=Object.create,_=Object.defineProperty,g=Object.defineProperties,m=Object.prototype.hasOwnProperty,y={configurable:!0,enumerable:!1,writable:!0};a={on:r=function(t,e){var n;return h(e),m.call(this,"__ee__")?n=this.__ee__:(n=y.value=d(null),_(this,"__ee__",y),y.value=null),n[t]?"object"==typeof n[t]?n[t].push(e):n[t]=[n[t],e]:n[t]=e,this},once:i=function(t,e){var n,i;return h(e),i=this,r.call(this,t,n=function(){o.call(i,t,n),f.call(e,this,arguments)}),n.__eeOnceListener__=e,this},off:o=function(t,e){var n,r,i,o;if(h(e),!m.call(this,"__ee__"))return this;if(!(n=this.__ee__)[t])return this;if("object"==typeof(r=n[t]))for(o=0;i=r[o];++o)i!==e&&i.__eeOnceListener__!==e||(2===r.length?n[t]=r[o?0:1]:r.splice(o,1));else r!==e&&r.__eeOnceListener__!==e||delete n[t];return this},emit:s=function(t){var e,n,r,i,o;if(m.call(this,"__ee__")&&(i=this.__ee__[t]))if("object"==typeof i){for(n=arguments.length,o=new Array(n-1),e=1;e=55296&&g<=56319&&(_+=t[++p]),c.call(e,m,_,h),!f);++p);else u.call(t,function(t){return c.call(e,m,t,h),f})}},function(t,e,n){"use strict";var r=n(15),i=n(16),o=n(86),s=n(96),a=n(37),c=n(6).iterator;t.exports=function(t){return"function"==typeof a(t)[c]?t[c]():r(t)?new o(t):i(t)?new s(t):new o(t)}},function(t,e,n){"use strict";var r,i=n(14),o=n(36),s=n(8),a=n(6),c=n(20),u=Object.defineProperty;r=t.exports=function(t,e){if(!(this instanceof r))throw new TypeError("Constructor requires 'new'");c.call(this,t),e=e?o.call(e,"key+value")?"key+value":o.call(e,"key")?"key":"value":"value",u(this,"__kind__",s("",e))},i&&i(r,c),delete r.prototype.constructor,r.prototype=Object.create(c.prototype,{_resolve:s(function(t){return"value"===this.__kind__?this.__list__[t]:"key+value"===this.__kind__?[t,this.__list__[t]]:t})}),u(r.prototype,a.toStringTag,s("c","Array Iterator"))},function(t,e,n){"use strict";var r,i=n(88),o=n(35),s=n(5),a=n(93),c=n(5),u=n(4),l=Function.prototype.bind,h=Object.defineProperty,f=Object.prototype.hasOwnProperty;r=function(t,e,n){var r,o=u(e)&&c(e.value);return delete(r=i(e)).writable,delete r.value,r.get=function(){return!n.overwriteDefinition&&f.call(this,t)?o:(e.value=l.call(o,n.resolveContext?n.resolveContext(this):this),h(this,t,e),this[t])},r},t.exports=function(t){var e=o(arguments[1]);return null!=e.resolveContext&&s(e.resolveContext),a(t,function(t,n){return r(n,t,e)})}},function(t,e,n){"use strict";var r=n(89),i=n(19),o=n(4);t.exports=function(t){var e=Object(o(t)),n=arguments[1],s=Object(arguments[2]);if(e!==t&&!n)return e;var a={};return n?r(n,function(e){(s.ensure||e in t)&&(a[e]=t[e])}):i(a,t),a}},function(t,e,n){"use strict";t.exports=n(90)()?Array.from:n(91)},function(t,e,n){"use strict";t.exports=function(){var t,e,n=Array.from;return"function"==typeof n&&(e=n(t=["raz","dwa"]),Boolean(e&&e!==t&&"dwa"===e[1]))}},function(t,e,n){"use strict";var r=n(6).iterator,i=n(15),o=n(92),s=n(32),a=n(5),c=n(4),u=n(9),l=n(16),h=Array.isArray,f=Function.prototype.call,p={configurable:!0,enumerable:!0,writable:!0,value:null},d=Object.defineProperty;t.exports=function(t){var e,n,_,g,m,y,v,b,w,E,S=arguments[1],R=arguments[2];if(t=Object(c(t)),u(S)&&a(S),this&&this!==Array&&o(this))e=this;else{if(!S){if(i(t))return 1!==(m=t.length)?Array.apply(null,t):((g=new Array(1))[0]=t[0],g);if(h(t)){for(g=new Array(m=t.length),n=0;n=55296&&y<=56319&&(E+=t[++n]),E=S?f.call(S,R,E,_):E,e?(p.value=E,d(g,_,p)):g[_]=E,++_;m=_}if(void 0===m)for(m=s(t.length),e&&(g=new e(m)),n=0;n=55296&&e<=56319?n+this.__list__[this.__nextIndex__++]:n})}),c(r.prototype,s.toStringTag,o("c","String Iterator"))},function(t,e,n){"use strict";var r,i=n(14),o=n(8),s=n(20),a=n(6).toStringTag,c=n(98),u=Object.defineProperties,l=s.prototype._unBind;r=t.exports=function(t,e){if(!(this instanceof r))return new r(t,e);s.call(this,t.__mapKeysData__,t),e&&c[e]||(e="key+value"),u(this,{__kind__:o("",e),__values__:o("w",t.__mapValuesData__)})},i&&i(r,s),r.prototype=Object.create(s.prototype,{constructor:o(r),_resolve:o(function(t){return"value"===this.__kind__?this.__values__[t]:"key"===this.__kind__?this.__list__[t]:[this.__list__[t],this.__values__[t]]}),_unBind:o(function(){this.__values__=null,l.call(this)}),toString:o(function(){return"[object Map Iterator]"})}),Object.defineProperty(r.prototype,a,o("c","Map Iterator"))},function(t,e,n){"use strict";t.exports=n(99)("key","value","key+value")},function(t,e,n){"use strict";var r=Array.prototype.forEach,i=Object.create;t.exports=function(t){var e=i(null);return r.call(arguments,function(t){e[t]=!0}),e}},function(t,e,n){"use strict";t.exports="undefined"!=typeof Map&&"[object Map]"===Object.prototype.toString.call(new Map)},function(t,e,n){var r=n(102);function i(t){var e=function(){return e.called?e.value:(e.called=!0,e.value=t.apply(this,arguments))};return e.called=!1,e}function o(t){var e=function(){if(e.called)throw new Error(e.onceError);return e.called=!0,e.value=t.apply(this,arguments)},n=t.name||"Function wrapped with `once`";return e.onceError=n+" shouldn't be called more than once",e.called=!1,e}t.exports=r(i),t.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(t,e){t.exports=function t(e,n){if(e&&n)return t(e)(n);if("function"!=typeof e)throw new TypeError("need wrapper function");Object.keys(e).forEach(function(t){r[t]=e[t]});return r;function r(){for(var t=new Array(arguments.length),n=0;n0)&&this[this._states[this._stateCounter]]()&&!this.error;)this._stateCounter++,this._stateCounter>=this._states.length&&(this._stateCounter=0);return this._list.length},c.prototype._parseHeader=function(){var t=this._list.readUInt8(0);return this.packet.cmd=a.types[t>>a.CMD_SHIFT],this.packet.retain=0!=(t&a.RETAIN_MASK),this.packet.qos=t>>a.QOS_SHIFT&a.QOS_MASK,this.packet.dup=0!=(t&a.DUP_MASK),this._list.consume(1),!0},c.prototype._parseLength=function(){for(var t,e=0,n=1,r=0,i=!0;e<5&&(r+=n*((t=this._list.readUInt8(e++))&a.LENGTH_MASK),n*=128,0!=(t&a.LENGTH_FIN_MASK));)if(this._list.length<=e){i=!1;break}return i&&(this.packet.length=r,this._list.consume(e)),i},c.prototype._parsePayload=function(){var t=!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._parseMessageId();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":case"disconnect":break;default:this._emitError(new Error("Not supported"))}t=!0}return t},c.prototype._parseConnect=function(){var t,e,n,r,i,o,s={},c=this.packet;if(null===(t=this._parseString()))return this._emitError(new Error("Cannot parse protocolId"));if("MQTT"!==t&&"MQIsdp"!==t)return this._emitError(new Error("Invalid protocolId"));if(c.protocolId=t,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(c.protocolVersion=this._list.readUInt8(this._pos),3!==c.protocolVersion&&4!==c.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(s.username=this._list.readUInt8(this._pos)&a.USERNAME_MASK,s.password=this._list.readUInt8(this._pos)&a.PASSWORD_MASK,s.will=this._list.readUInt8(this._pos)&a.WILL_FLAG_MASK,s.will&&(c.will={},c.will.retain=0!=(this._list.readUInt8(this._pos)&a.WILL_RETAIN_MASK),c.will.qos=(this._list.readUInt8(this._pos)&a.WILL_QOS_MASK)>>a.WILL_QOS_SHIFT),c.clean=0!=(this._list.readUInt8(this._pos)&a.CLEAN_SESSION_MASK),this._pos++,c.keepalive=this._parseNum(),-1===c.keepalive)return this._emitError(new Error("Packet too short"));if(null===(e=this._parseString()))return this._emitError(new Error("Packet too short"));if(c.clientId=e,s.will){if(null===(n=this._parseString()))return this._emitError(new Error("Cannot parse will topic"));if(c.will.topic=n,null===(r=this._parseBuffer()))return this._emitError(new Error("Cannot parse will payload"));c.will.payload=r}if(s.username){if(null===(o=this._parseString()))return this._emitError(new Error("Cannot parse username"));c.username=o}if(s.password){if(null===(i=this._parseBuffer()))return this._emitError(new Error("Cannot parse password"));c.password=i}return c},c.prototype._parseConnack=function(){var t=this.packet;return this._list.length<2?null:(t.sessionPresent=!!(this._list.readUInt8(this._pos++)&a.SESSIONPRESENT_MASK),t.returnCode=this._list.readUInt8(this._pos),-1===t.returnCode?this._emitError(new Error("Cannot parse return code")):void 0)},c.prototype._parsePublish=function(){var t=this.packet;if(t.topic=this._parseString(),null===t.topic)return this._emitError(new Error("Cannot parse topic"));t.qos>0&&!this._parseMessageId()||(t.payload=this._list.slice(this._pos,t.length))},c.prototype._parseSubscribe=function(){var t,e,n=this.packet;if(1!==n.qos)return this._emitError(new Error("Wrong subscribe header"));if(n.subscriptions=[],this._parseMessageId())for(;this._posthis._list.length||r>this.packet.length?null:(e=this._list.toString("utf8",this._pos,r),this._pos+=n,e)},c.prototype._parseBuffer=function(){var t,e=this._parseNum(),n=e+this._pos;return-1===e||n>this._list.length||n>this.packet.length?null:(t=this._list.slice(this._pos,n),this._pos+=e,t)},c.prototype._parseNum=function(){if(this._list.length-this._pos<2)return-1;var t=this._list.readUInt16BE(this._pos);return this._pos+=2,t},c.prototype._newPacket=function(){return this.packet&&(this._list.consume(this.packet.length),this.emit("packet",this.packet)),this.packet=new s,!0},c.prototype._emitError=function(t){this.error=t,this.emit("error",t)},t.exports=c},function(t,e,n){var r=n(106),i=n(107),o=n(2).Buffer;function s(t){if(!(this instanceof s))return new s(t);if(this._bufs=[],this.length=0,"function"==typeof t){this._callback=t;var e=function(t){this._callback&&(this._callback(t),this._callback=null)}.bind(this);this.on("pipe",function(t){t.on("error",e)}),this.on("unpipe",function(t){t.removeListener("error",e)})}else this.append(t);r.call(this)}i.inherits(s,r),s.prototype._offset=function(t){var e,n=0,r=0;if(0===t)return[0,0];for(;rthis.length)&&(r=this.length),n>=this.length)return t||o.alloc(0);if(r<=0)return t||o.alloc(0);var i,s,a=!!t,c=this._offset(n),u=r-n,l=u,h=a&&e||0,f=c[1];if(0===n&&r==this.length){if(!a)return 1===this._bufs.length?this._bufs[0]:o.concat(this._bufs,this.length);for(s=0;s(i=this._bufs[s].length-f))){this._bufs[s].copy(t,h,f,f+l);break}this._bufs[s].copy(t,h,f),h+=i,l-=i,f&&(f=0)}return t},s.prototype.shallowSlice=function(t,e){t=t||0,e=e||this.length,t<0&&(t+=this.length),e<0&&(e+=this.length);var n=this._offset(t),r=this._offset(e),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])),new s(i)},s.prototype.toString=function(t,e,n){return this.slice(e,n).toString(t)},s.prototype.consume=function(t){for(;this._bufs.length;){if(!(t>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(t),this.length-=t;break}t-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},s.prototype.duplicate=function(){for(var t=0,e=new s;t=o)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return t}}),c=r[n];n=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),d(n)?r.showHidden=n:n&&e._extend(r,n),y(r.showHidden)&&(r.showHidden=!1),y(r.depth)&&(r.depth=2),y(r.colors)&&(r.colors=!1),y(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=c),l(r,t,r.depth)}function c(t,e){var n=a.styles[e];return n?"["+a.colors[n][0]+"m"+t+"["+a.colors[n][1]+"m":t}function u(t,e){return t}function l(t,n,r){if(t.customInspect&&n&&S(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,t);return m(i)||(i=l(t,i,r)),i}var o=function(t,e){if(y(e))return t.stylize("undefined","undefined");if(m(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}if(g(e))return t.stylize(""+e,"number");if(d(e))return t.stylize(""+e,"boolean");if(_(e))return t.stylize("null","null")}(t,n);if(o)return o;var s=Object.keys(n),a=function(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(n)),E(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return h(n);if(0===s.length){if(S(n)){var c=n.name?": "+n.name:"";return t.stylize("[Function"+c+"]","special")}if(v(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(w(n))return t.stylize(Date.prototype.toString.call(n),"date");if(E(n))return h(n)}var u,b="",R=!1,A=["{","}"];(p(n)&&(R=!0,A=["[","]"]),S(n))&&(b=" [Function"+(n.name?": "+n.name:"")+"]");return v(n)&&(b=" "+RegExp.prototype.toString.call(n)),w(n)&&(b=" "+Date.prototype.toUTCString.call(n)),E(n)&&(b=" "+h(n)),0!==s.length||R&&0!=n.length?r<0?v(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special"):(t.seen.push(n),u=R?function(t,e,n,r,i){for(var o=[],s=0,a=e.length;s=0&&0,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60)return n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1];return n[0]+e+" "+t.join(", ")+" "+n[1]}(u,b,A)):A[0]+b+A[1]}function h(t){return"["+Error.prototype.toString.call(t)+"]"}function f(t,e,n,r,i,o){var s,a,c;if((c=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]}).get?a=c.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):c.set&&(a=t.stylize("[Setter]","special")),I(r,i)||(s="["+i+"]"),a||(t.seen.indexOf(c.value)<0?(a=_(n)?l(t,c.value,null):l(t,c.value,n-1)).indexOf("\n")>-1&&(a=o?a.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+a.split("\n").map(function(t){return" "+t}).join("\n")):a=t.stylize("[Circular]","special")),y(s)){if(o&&i.match(/^\d+$/))return a;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+a}function p(t){return Array.isArray(t)}function d(t){return"boolean"==typeof t}function _(t){return null===t}function g(t){return"number"==typeof t}function m(t){return"string"==typeof t}function y(t){return void 0===t}function v(t){return b(t)&&"[object RegExp]"===R(t)}function b(t){return"object"==typeof t&&null!==t}function w(t){return b(t)&&"[object Date]"===R(t)}function E(t){return b(t)&&("[object Error]"===R(t)||t instanceof Error)}function S(t){return"function"==typeof t}function R(t){return Object.prototype.toString.call(t)}function A(t){return t<10?"0"+t.toString(10):t.toString(10)}e.debuglog=function(t){if(y(o)&&(o=r.env.NODE_DEBUG||""),t=t.toUpperCase(),!s[t])if(new RegExp("\\b"+t+"\\b","i").test(o)){var n=r.pid;s[t]=function(){var r=e.format.apply(e,arguments);console.error("%s %d: %s",t,n,r)}}else s[t]=function(){};return s[t]},e.inspect=a,a.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},a.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},e.isArray=p,e.isBoolean=d,e.isNull=_,e.isNullOrUndefined=function(t){return null==t},e.isNumber=g,e.isString=m,e.isSymbol=function(t){return"symbol"==typeof t},e.isUndefined=y,e.isRegExp=v,e.isObject=b,e.isDate=w,e.isError=E,e.isFunction=S,e.isPrimitive=function(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t},e.isBuffer=n(108);var T=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function I(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.log=function(){console.log("%s - %s",function(){var t=new Date,e=[A(t.getHours()),A(t.getMinutes()),A(t.getSeconds())].join(":");return[t.getDate(),T[t.getMonth()],e].join(" ")}(),e.format.apply(e,arguments))},e.inherits=n(3),e._extend=function(t,e){if(!e||!b(e))return t;for(var n=Object.keys(e),r=n.length;r--;)t[n[r]]=e[n[r]];return t}}).call(this,n(1),n(0))},function(t,e){t.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},function(t,e){t.exports=function(){this.cmd=null,this.retain=!1,this.qos=0,this.dup=!1,this.length=-1,this.topic=null,this.payload=null}},function(t,e,n){"use strict";var r=n(2).Buffer,i=n(40),o=n(10).EventEmitter;function s(){this._array=new Array(20),this._i=0}n(3)(s,o),s.prototype.write=function(t){return this._array[this._i++]=t,!0},s.prototype.concat=function(){var t,e,n=0,i=new Array(this._array.length),o=this._array,s=0;for(t=0;t>8,0),e.writeUInt8(255&t,1),e}t.exports={cache:o,generateCache:function(){for(var t=0;t0){t=new Array(arguments.length-2);for(var e=0;e= 0x80 (not a basic code point)","invalid-input":"Invalid input"},w=u-l,E=Math.floor,S=String.fromCharCode;function R(t){throw new RangeError(b[t])}function A(t,e){for(var n=t.length,r=[];n--;)r[n]=e(t[n]);return r}function T(t,e){var n=t.split("@"),r="";return n.length>1&&(r=n[0]+"@",t=n[1]),r+A((t=t.replace(v,".")).split("."),e).join(".")}function I(t){for(var e,n,r=[],i=0,o=t.length;i=55296&&e<=56319&&i65535&&(e+=S((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=S(t)}).join("")}function x(t){return t-48<10?t-22:t-65<26?t-65:t-97<26?t-97:u}function C(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function k(t,e,n){var r=0;for(t=n?E(t/p):t>>1,t+=E(t/e);t>w*h>>1;r+=u)t=E(t/w);return E(r+(w+1)*t/(t+f))}function N(t){var e,n,r,i,o,s,a,f,p,m,y=[],v=t.length,b=0,w=_,S=d;for((n=t.lastIndexOf(g))<0&&(n=0),r=0;r=128&&R("not-basic"),y.push(t.charCodeAt(r));for(i=n>0?n+1:0;i=v&&R("invalid-input"),((f=x(t.charCodeAt(i++)))>=u||f>E((c-b)/s))&&R("overflow"),b+=f*s,!(f<(p=a<=S?l:a>=S+h?h:a-S));a+=u)s>E(c/(m=u-p))&&R("overflow"),s*=m;S=k(b-o,e=y.length+1,0==o),E(b/e)>c-w&&R("overflow"),w+=E(b/e),b%=e,y.splice(b++,0,w)}return O(y)}function P(t){var e,n,r,i,o,s,a,f,p,m,y,v,b,w,A,T=[];for(v=(t=I(t)).length,e=_,n=0,o=d,s=0;s=e&&yE((c-n)/(b=r+1))&&R("overflow"),n+=(a-e)*b,e=a,s=0;sc&&R("overflow"),y==e){for(f=n,p=u;!(f<(m=p<=o?l:p>=o+h?h:p-o));p+=u)A=f-m,w=u-m,T.push(S(C(m+A%w,0))),f=E(A/w);T.push(S(C(f,0))),o=k(n,b,r==i),n=0,++r}++n,++e}return T.join("")}a={version:"1.4.1",ucs2:{decode:I,encode:O},decode:N,encode:P,toASCII:function(t){return T(t,function(t){return y.test(t)?"xn--"+P(t):t})},toUnicode:function(t){return T(t,function(t){return m.test(t)?N(t.slice(4).toLowerCase()):t})}},void 0===(i=function(){return a}.call(e,n,e,t))||(t.exports=i)}()}).call(this,n(115)(t),n(1))},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,n){"use strict";t.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},function(t,e,n){"use strict";e.decode=e.parse=n(118),e.encode=e.stringify=n(119)},function(t,e,n){"use strict";function r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.exports=function(t,e,n,o){e=e||"&",n=n||"=";var s={};if("string"!=typeof t||0===t.length)return s;var a=/\+/g;t=t.split(e);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var u=t.length;c>0&&u>c&&(u=c);for(var l=0;l=0?(h=_.substr(0,g),f=_.substr(g+1)):(h=_,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(t){return"[object Array]"===Object.prototype.toString.call(t)}},function(t,e,n){"use strict";var r=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};t.exports=function(t,e,n,a){return e=e||"&",n=n||"=",null===t&&(t=void 0),"object"==typeof t?o(s(t),function(s){var a=encodeURIComponent(r(s))+n;return i(t[s])?o(t[s],function(t){return a+encodeURIComponent(r(t))}).join(e):a+encodeURIComponent(r(t[s]))}).join(e):a?encodeURIComponent(r(a))+n+encodeURIComponent(r(t)):""};var i=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function o(t,e){if(t.map)return t.map(e);for(var n=[],r=0;r p {\n line-height: 1; }\n",""])},function(t,e){t.exports=function(t){return"string"!=typeof t?t:(/^['"].*['"]$/.test(t)&&(t=t.slice(1,-1)),/["'() \t\n]/.test(t)?'"'+t.replace(/"/g,'\\"').replace(/\n/g,"\\n")+'"':t)}},function(t,e){t.exports=function(t){var e=[];return e.toString=function(){return this.map(function(e){var n=function(t,e){var n=t[1]||"",r=t[3];if(!r)return n;if(e&&"function"==typeof btoa){var i=function(t){return"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(t))))+" */"}(r),o=r.sources.map(function(t){return"/*# sourceURL="+r.sourceRoot+t+" */"});return[n].concat(o).concat([i]).join("\n")}return[n].join("\n")}(e,t);return e[2]?"@media "+e[2]+"{"+n+"}":n}).join("")},e.i=function(t,n){"string"==typeof t&&(t=[[null,t,""]]);for(var r={},i=0;i=0&&c.splice(e,1)}function d(t){var e=document.createElement("style");if(void 0===t.attrs.type&&(t.attrs.type="text/css"),void 0===t.attrs.nonce){var r=function(){0;return n.nc}();r&&(t.attrs.nonce=r)}return _(e,t.attrs),f(t,e),e}function _(t,e){Object.keys(e).forEach(function(n){t.setAttribute(n,e[n])})}function g(t,e){var n,r,i,o;if(e.transform&&t.css){if(!(o="function"==typeof e.transform?e.transform(t.css):e.transform.default(t.css)))return function(){};t.css=o}if(e.singleton){var c=a++;n=s||(s=d(e)),r=y.bind(null,n,c,!1),i=y.bind(null,n,c,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(t){var e=document.createElement("link");return void 0===t.attrs.type&&(t.attrs.type="text/css"),t.attrs.rel="stylesheet",_(e,t.attrs),f(t,e),e}(e),r=function(t,e,n){var r=n.css,i=n.sourceMap,o=void 0===e.convertToAbsoluteUrls&&i;(e.convertToAbsoluteUrls||o)&&(r=u(r));i&&(r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(i))))+" */");var s=new Blob([r],{type:"text/css"}),a=t.href;t.href=URL.createObjectURL(s),a&&URL.revokeObjectURL(a)}.bind(null,n,e),i=function(){p(n),n.href&&URL.revokeObjectURL(n.href)}):(n=d(e),r=function(t,e){var n=e.css,r=e.media;r&&t.setAttribute("media",r);if(t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}.bind(null,n),i=function(){p(n)});return r(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;r(t=e)}else i()}}t.exports=function(t,e){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(e=e||{}).attrs="object"==typeof e.attrs?e.attrs:{},e.singleton||"boolean"==typeof e.singleton||(e.singleton=i()),e.insertInto||(e.insertInto="head"),e.insertAt||(e.insertAt="bottom");var n=h(t,e);return l(n,e),function(t){for(var i=[],o=0;o2;)o.push(arguments[u]);for(e&&null!=e.children&&(o.length||o.push(e.children),delete e.children);o.length;)if((a=o.pop())&&void 0!==a.pop)for(u=a.length;u--;)o.push(a[u]);else"boolean"==typeof a&&(a=null),(c="function"!=typeof t)&&(null==a?a="":"number"==typeof a?a=String(a):"string"!=typeof a&&(c=!1)),c&&n?l[l.length-1]+=a:l===s?l=[a]:l.push(a),n=c;var h=new r;return h.nodeName=t,h.children=l,h.attributes=null==e?void 0:e,h.key=null==e?void 0:e.key,void 0!==i.vnode&&i.vnode(h),h}function c(t,e){for(var n in e)t[n]=e[n];return t}var u="function"==typeof Promise?Promise.resolve().then.bind(Promise.resolve()):setTimeout;var l=/acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,h=[];function f(t){!t._dirty&&(t._dirty=!0)&&1==h.push(t)&&(i.debounceRendering||u)(p)}function p(){var t,e=h;for(h=[];t=e.pop();)t._dirty&&P(t)}function d(t,e,n){return"string"==typeof e||"number"==typeof e?void 0!==t.splitText:"string"==typeof e.nodeName?!t._componentConstructor&&_(t,e.nodeName):n||t._componentConstructor===e.nodeName}function _(t,e){return t.normalizedNodeName===e||t.nodeName.toLowerCase()===e.toLowerCase()}function g(t){var e=c({},t.attributes);e.children=t.children;var n=t.nodeName.defaultProps;if(void 0!==n)for(var r in n)void 0===e[r]&&(e[r]=n[r]);return e}function m(t){var e=t.parentNode;e&&e.removeChild(t)}function y(t,e,n,r,i){if("className"===e&&(e="class"),"key"===e);else if("ref"===e)n&&n(null),r&&r(t);else if("class"!==e||i)if("style"===e){if(r&&"string"!=typeof r&&"string"!=typeof n||(t.style.cssText=r||""),r&&"object"==typeof r){if("string"!=typeof n)for(var o in n)o in r||(t.style[o]="");for(var o in r)t.style[o]="number"==typeof r[o]&&!1===l.test(o)?r[o]+"px":r[o]}}else if("dangerouslySetInnerHTML"===e)r&&(t.innerHTML=r.__html||"");else if("o"==e[0]&&"n"==e[1]){var s=e!==(e=e.replace(/Capture$/,""));e=e.toLowerCase().substring(2),r?n||t.addEventListener(e,v,s):t.removeEventListener(e,v,s),(t._listeners||(t._listeners={}))[e]=r}else if("list"!==e&&"type"!==e&&!i&&e in t){try{t[e]=null==r?"":r}catch(t){}null!=r&&!1!==r||"spellcheck"==e||t.removeAttribute(e)}else{var a=i&&e!==(e=e.replace(/^xlink:?/,""));null==r||!1===r?a?t.removeAttributeNS("http://www.w3.org/1999/xlink",e.toLowerCase()):t.removeAttribute(e):"function"!=typeof r&&(a?t.setAttributeNS("http://www.w3.org/1999/xlink",e.toLowerCase(),r):t.setAttribute(e,r))}else t.className=r||""}function v(t){return this._listeners[t.type](i.event&&i.event(t)||t)}var b=[],w=0,E=!1,S=!1;function R(){for(var t;t=b.pop();)i.afterMount&&i.afterMount(t),t.componentDidMount&&t.componentDidMount()}function A(t,e,n,r,i,o){w++||(E=null!=i&&void 0!==i.ownerSVGElement,S=null!=t&&!("__preactattr_"in t));var s=T(t,e,n,r,o);return i&&s.parentNode!==i&&i.appendChild(s),--w||(S=!1,o||R()),s}function T(t,e,n,r,i){var o=t,s=E;if(null!=e&&"boolean"!=typeof e||(e=""),"string"==typeof e||"number"==typeof e)return t&&void 0!==t.splitText&&t.parentNode&&(!t._component||i)?t.nodeValue!=e&&(t.nodeValue=e):(o=document.createTextNode(e),t&&(t.parentNode&&t.parentNode.replaceChild(o,t),I(t,!0))),o.__preactattr_=!0,o;var a=e.nodeName;if("function"==typeof a)return function(t,e,n,r){var i=t&&t._component,o=i,s=t,a=i&&t._componentConstructor===e.nodeName,c=a,u=g(e);for(;i&&!c&&(i=i._parentComponent);)c=i.constructor===e.nodeName;i&&c&&(!r||i._component)?(N(i,u,3,n,r),t=i.base):(o&&!a&&(L(o),t=s=null),i=C(e.nodeName,u,n),t&&!i.nextBase&&(i.nextBase=t,s=null),N(i,u,1,n,r),t=i.base,s&&t!==s&&(s._component=null,I(s,!1)));return t}(t,e,n,r);if(E="svg"===a||"foreignObject"!==a&&E,a=String(a),(!t||!_(t,a))&&(o=function(t,e){var n=e?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t);return n.normalizedNodeName=t,n}(a,E),t)){for(;t.firstChild;)o.appendChild(t.firstChild);t.parentNode&&t.parentNode.replaceChild(o,t),I(t,!0)}var c=o.firstChild,u=o.__preactattr_,l=e.children;if(null==u){u=o.__preactattr_={};for(var h=o.attributes,f=h.length;f--;)u[h[f].name]=h[f].value}return!S&&l&&1===l.length&&"string"==typeof l[0]&&null!=c&&void 0!==c.splitText&&null==c.nextSibling?c.nodeValue!=l[0]&&(c.nodeValue=l[0]):(l&&l.length||null!=c)&&function(t,e,n,r,i){var o,s,a,c,u,l=t.childNodes,h=[],f={},p=0,_=0,g=l.length,y=0,v=e?e.length:0;if(0!==g)for(var b=0;b{if(!r)return n;let i=Number(r)*e;return void 0===t?i.toString():i.toFixed(t)}}const D={GENERAL:{SERIAL:"/Serial",DEVICE_INSTANCE:"/DeviceInstance"},BATTERY:{CURRENT:"/Dc/Battery/Current",POWER:"/Dc/Battery/Power",VOLTAGE:"/Dc/Battery/Voltage",SOC:"/Dc/Battery/Soc",CIRCUIT_BREAKER_ALARM:"/Dc/Battery/Alarms/CircuitBreakerTripped",CONSUMED_AMP_HOURRS:"/Dc/Battery/ConsumedAmphours",STATE:"/Dc/Battery/State",TIME_TO_GO:"/Dc/Battery/TimeToGo"},SOLAR_CHARGERS:{CURRENT:"/Dc/Pv/Current",POWER:"/Dc/Pv/Power"},INVERTER_CHARGER:{DC_LOADS:{CURRENT:"/Dc/Vebus/Current",POWER:"/Dc/Vebus/Power"},AC_LOADS:{CURRENT:"/Ac/Out/L1/I",POWER:"/Ac/Out/L1/V",VOLTAGE:"/Ac/Out/L1/P",CONSUMPTION_OUTPUT_L1_POWER:"/Ac/ConsumptionOnOutput/L1/Power",CONSUMPTION_OUTPUT_L2_POWER:"/Ac/ConsumptionOnOutput/L2/Power",CONSUMPTION_OUTPUT_L3_POWER:"/Ac/ConsumptionOnOutput/L3/Power"},AC_SOURCE:"/Ac/ActiveIn/Source",SHORE_POWER:{IS_CONNECTED:"/Ac/ActiveIn/Connected",VOLTAGE:"/Ac/ActiveIn/L1/V",CURRENT:"/Ac/ActiveIn/L1/I",POWER:"/Ac/ActiveIn/L1/P",CURRENT_LIMIT:"/Ac/ActiveIn/CurrentLimit",AC_GRID_L1_POWER:"/Ac/Grid/L1/Power",AC_GRID_L2_POWER:"/Ac/Grid/L2/Power",AC_GRID_L3_POWER:"/Ac/Grid/L3/Power"},GENERATOR:{AC_GENSET_L1_POWER:"/Ac/Genset/L1/Power",AC_GENSET_L2_POWER:"/Ac/Genset/L2/Power",AC_GENSET_L3_POWER:"/Ac/Genset/L3/Power"},SYSTEM:{STATE:"/SystemState/State",MODE:"/Mode",STATES:{CHARGER_ONLY:1,INVERTER_ONLY:2,ON:3,OFF:4},AC_NUMBER_OF_PHASES:"/Ac/Consumption/NumberOfPhases",VEBUS_SERVICE:"/VebusService"}}};var B={[D.BATTERY.VOLTAGE]:{description:"Voltage",unit:"V",formatter:U(1),timeout:0},[D.BATTERY.CURRENT]:{description:"Current",unit:"A",formatter:U(1),timeout:0},[D.BATTERY.POWER]:{description:"Power",unit:"W",formatter:U(),timeout:0},[D.BATTERY.SOC]:{description:"State of charge",unit:"%",formatter:U(),timeout:0},[D.INVERTER_CHARGER.DC_LOADS.CURRENT]:{description:"DC loads current",unit:"A",formatter:U(1),timeout:0},[D.INVERTER_CHARGER.DC_LOADS.POWER]:{description:"DC loads power",unit:"W",formatter:U(),timeout:0},[D.INVERTER_CHARGER.AC_LOADS.VOLTAGE]:{description:"AC loads voltage",unit:"V",formatter:U(),timeout:0},[D.INVERTER_CHARGER.AC_LOADS.CURRENT]:{description:"AC loads current",unit:"A",formatter:U(1),timeout:0},[D.INVERTER_CHARGER.AC_LOADS.POWER]:{description:"AC loads power",unit:"W",formatter:U(),timeout:0},[D.INVERTER_CHARGER.SHORE_POWER.IS_CONNECTED]:{description:"Grid is connected",formatter:U()},[D.INVERTER_CHARGER.SHORE_POWER.VOLTAGE]:{description:"Grid voltage",unit:"V",formatter:U(),timeout:0},[D.INVERTER_CHARGER.SHORE_POWER.CURRENT]:{description:"Grid current",unit:"A",formatter:U(1),timeout:0},[D.INVERTER_CHARGER.SHORE_POWER.CURRENT_LIMIT]:{description:"Grid input limit",unit:"A",formatter:U(),timeout:0,write:!0},[D.INVERTER_CHARGER.SHORE_POWER.POWER]:{description:"Grid power",unit:"W",formatter:U(),timeout:0},[D.INVERTER_CHARGER.SYSTEM.STATE]:{description:"System state",unit:"",formatter:function(t){return 0==t?"Off":1==t?"Low power":2==t?"VE.Bus Fault condition":3==t?"Bulk charging":4==t?"Absorption charging":5==t?"Float charging":6==t?"Storage mode":7==t?"Equalisation charging":8==t?"Passthru":9==t?"Inverting":10==t?"Assisting":256==t?"Discharging":257==t?"Sustain":"--"},timeout:0},[D.INVERTER_CHARGER.SYSTEM.MODE]:{description:"System mode",unit:"",formatter:function(t){return 1==t?"Charger only":2==t?"Inverter only":3==t?"ON":4==t?"OFF":"--"},timeout:0,write:!0},[D.INVERTER_CHARGER.AC_SOURCE]:{unit:"",formatter:function(t){return 0==t?"Not Available":1==t?"Grid Input":2==t?"Generator":3==t?"Shore Power":240==t?"Inverting":"Ac Input Mode"},timeout:0}},H=n(46);const G=t=>{const e=t.split("/");return{type:e[0],portalId:e[1],serviceType:e[2],deviceInstance:parseInt(e[3]),dbusPath:"/"+e.splice(4).join("/")}},q=(t,e)=>{let n;try{n=JSON.parse(e.toString())}catch(r){n={},console.error(t,`[${e.toString()}]`,r)}const{dbusPath:r}=G(t);return{path:r,value:n.value||null}};function V(t){return Object.keys(t).map(e=>t[e])}const W=(t,e)=>{return-1!==V(e).indexOf(t)},F=t=>t.reduce((t,e)=>(t[e]=0,t),{}),Y={SYSTEM:V(D.GENERAL).concat(V(D.BATTERY)).concat(V(D.SOLAR_CHARGERS)).concat(V(D.INVERTER_CHARGER.DC_LOADS)).concat(D.INVERTER_CHARGER.SYSTEM.STATE).concat(D.INVERTER_CHARGER.SYSTEM.VEBUS_SERVICE).concat(D.INVERTER_CHARGER.AC_SOURCE),VEBUS:V(D.INVERTER_CHARGER.AC_LOADS).concat(V(D.INVERTER_CHARGER.SHORE_POWER)).concat(D.INVERTER_CHARGER.SYSTEM.MODE).concat(V(D.INVERTER_CHARGER.GENERATOR)).concat([D.INVERTER_CHARGER.SYSTEM.AC_NUMBER_OF_PHASES])};let z,K,$,Q;!function(t){t[t.IDLE=0]="IDLE",t[t.CHARGING=1]="CHARGING",t[t.DISCHARGING=2]="DISCHARGING"}(z||(z={})),function(t){t[t.OFF=0]="OFF",t[t.LOW_POWER=1]="LOW_POWER",t[t.FAULT_CONDITION=2]="FAULT_CONDITION",t[t.BULK_CHARGING=3]="BULK_CHARGING",t[t.ABSORPTION_CHARGINNG=4]="ABSORPTION_CHARGINNG",t[t.FLOAT_CHARGING=5]="FLOAT_CHARGING",t[t.STORAGE_MODE=6]="STORAGE_MODE",t[t.EQUALISATION_CHARGING=7]="EQUALISATION_CHARGING",t[t.PASSTHRU=8]="PASSTHRU",t[t.INVERTING=9]="INVERTING",t[t.ASSISTING=10]="ASSISTING",t[t.DISCHARGING=256]="DISCHARGING",t[t.SUSTAIN=257]="SUSTAIN"}(K||(K={})),function(t){t[t.NOT_AVAILABLE=0]="NOT_AVAILABLE",t[t.GRID=1]="GRID",t[t.GENSET=2]="GENSET",t[t.SHORE=3]="SHORE",t[t.INVERTING_ISLAND_MODE=240]="INVERTING_ISLAND_MODE"}($||($={})),function(t){t[t.CHARGER_ONLY=1]="CHARGER_ONLY",t[t.INVERTER_ONLY=2]="INVERTER_ONLY",t[t.ON=3]="ON",t[t.OFF=4]="OFF"}(Q||(Q={}));const J={ALL:"N/#",SERIAL:"N/+/system/0/Serial",ALL_DEVICES_CONNECTED:"N/+/+/+/ProductId",ALL_DEVICE_INSTANCES:"N/+/+/+/DeviceInstance"};function Z(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var X=class{constructor(){Z(this,"portalId",null),Z(this,"vebusInstanceId",null),Z(this,"systemInstanceId",null),Z(this,"equipment",void 0),Z(this,"isInitialized",()=>this.portalId&&this.vebusInstanceId&&null!==this.systemInstanceId),Z(this,"getTopicFromDbusPath",(t,e)=>Y.SYSTEM.includes(e)?`${t}/${this.portalId}/system/${this.systemInstanceId}${e}`:Y.VEBUS.includes(e)?`${t}/${this.portalId}/vebus/${this.vebusInstanceId}${e}`:(console.error(`Could not create path for type ${t} path ${e}`),"")),this.equipment={battery:null,inverterCharger:{dcLoads:null,acLoads:null,shorePower:null,system:null}}}handleSystemMessage(t,e){const n=G(t);this.handlePortalIdMessage(n,e)||this.handleBaterryInfoMessages(n,e)||this.handleDCLoads(n,e)||this.handleACLoads(n,e)||this.handleShorePower(n,e)||this.handleSystemState(n,e)||this.handleDeviceIds(n,e)}handlePortalIdMessage(t,e){return t.dbusPath===D.GENERAL.SERIAL&&(this.portalId=e.value,!0)}handleDeviceIds(t,e){if(t.dbusPath===D.GENERAL.DEVICE_INSTANCE){switch(console.log(`DEVICE ${t.serviceType} AVAILABLE WITH ID ${t.deviceInstance}`),t.serviceType){case"vebus":this.vebusInstanceId=t.deviceInstance;break;case"system":this.systemInstanceId=t.deviceInstance}return!0}return!1}handleBaterryInfoMessages(t,e){return!!W(t.dbusPath,D.BATTERY)&&(this.equipment.battery||(this.equipment.battery={}),this.equipment.battery[t.dbusPath]=e.value,!0)}handleDCLoads(t,e){return!!W(t.dbusPath,D.INVERTER_CHARGER.DC_LOADS)&&(this.equipment.inverterCharger.dcLoads||(this.equipment.inverterCharger.dcLoads={}),this.equipment.inverterCharger.dcLoads[t.dbusPath]=e.value,!0)}handleACLoads(t,e){return!!W(t.dbusPath,D.INVERTER_CHARGER.AC_LOADS)&&(this.equipment.inverterCharger.acLoads||(this.equipment.inverterCharger.acLoads={}),this.equipment.inverterCharger.acLoads[t.dbusPath]=e.value,!0)}handleShorePower(t,e){return!!W(t.dbusPath,D.INVERTER_CHARGER.SHORE_POWER)&&(this.equipment.inverterCharger.shorePower||(this.equipment.inverterCharger.shorePower={}),this.equipment.inverterCharger.shorePower[t.dbusPath]=e.value,!0)}handleSystemState(t,e){return!!W(t.dbusPath,D.INVERTER_CHARGER.SYSTEM)&&(this.equipment.inverterCharger.system||(this.equipment.inverterCharger.system={}),this.equipment.inverterCharger.system[t.dbusPath]=e.value,!0)}};function tt(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}const et=[J.SERIAL,J.ALL_DEVICE_INSTANCES],nt=(t,e)=>{t?console.log("Error connecting to topic",t):e.forEach(t=>{console.log(`Subscribed to ${t.topic} with qos ${t.qos}...`)})};var rt=class{constructor(t){tt(this,"mqttClient",void 0),tt(this,"venusSystem",void 0),tt(this,"keepAliveHandlerRef",null),tt(this,"onMessage",()=>{}),tt(this,"onConnectionChanged",()=>{}),tt(this,"connect",()=>new Promise((t,e)=>{this.mqttClient.once("connect",()=>{const t=F(et);this.mqttClient.subscribe(t,(t,n)=>{nt(t,n),t&&e(t)})}),this.mqttClient.on("connect",()=>{this.setupKeepAlive(),this.onConnectionChanged({connected:!0})}),this.mqttClient.on("disconnect",()=>{clearInterval(this.keepAliveHandlerRef),this.onConnectionChanged({connected:!1})}),this.mqttClient.on("reconnect",()=>{this.onConnectionChanged({connected:!1})}),this.mqttClient.on("message",(e,n)=>{const r=q(e,n);this.venusSystem.handleSystemMessage(e,r),this.venusSystem.isInitialized()&&(this.mqttClient.removeAllListeners("message"),t())})})),tt(this,"subscribe",t=>{this.mqttClient.on("message",(t,e)=>{const n=q(t,e);this.onMessage(n)});const e=t.map(t=>this.venusSystem.getTopicFromDbusPath("N",t)),n=F(e);this.mqttClient.subscribe(n,nt)}),this.mqttClient=H.connect(t),this.venusSystem=new X,window.onunload=(()=>{this.mqttClient.end()})}write(t,e){const n=this.venusSystem.getTopicFromDbusPath("W",t);let r=JSON.stringify({value:e});console.log(n,r),this.mqttClient.publish(n,r)}setupKeepAlive(){clearInterval(this.keepAliveHandlerRef),this.keepAliveHandlerRef=setInterval(()=>{const t=this.venusSystem.getTopicFromDbusPath("R",D.GENERAL.SERIAL);this.mqttClient.publish(t,"")},5e4)}};n(125);function it(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}const ot=(t,e)=>{e||(e=window.location.href),t=t.replace(/[\[\]]/g,"\\$&");var n=new RegExp("[?&]"+t+"(=([^&#]*)|&|#|$)").exec(e);return n?n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):"":null},st=[10,15,20,30,50,100],at=[6,10,13,16,25,32,63],ct=ot("host")||window.location.hostname||"localhost",ut=parseInt(ot("port"))||9001,lt=`mqtt://${ct}:${ut}`;class ht extends M{render(t,e){return a("p",{className:"value"},t.value)}}class ft extends M{render(t,e){return a("div",{className:"metric-component metric-component--small"},a("img",{src:"./images/icons/icon_ShorePower.svg",className:"metric-icon"}),a("div",{className:"metrics-container"},a("p",null,t.acInput),a("div",{className:"metrics"},a(ht,{value:t.voltage,connected:t.connected}),a(ht,{value:t.current,connected:t.connected}),a(ht,{value:t.power,connected:t.connected}))))}}class pt extends M{constructor(...t){super(...t),it(this,"state",{selectorVisible:!1}),it(this,"toggleSelector",()=>{this.setState({selectorVisible:!this.state.selectorVisible})}),it(this,"setAmperage",t=>{this.props.deviceInterface.write(D.INVERTER_CHARGER.SHORE_POWER.CURRENT_LIMIT,t),this.toggleSelector()})}render(t,e){const n=parseInt(t.shoreVoltage),r=!n||n>150?at:st;return a("div",{className:"metric-component metric-component--small"},e.selectorVisible?r.map(e=>a("button",{className:"metrics-selector-button amperage-selector-button"+(parseInt(t.currentLimit)==e?" metrics-selector-button--active":""),href:"#",onClick:()=>this.setAmperage(e)},e)):a("button",{className:"metrics-selector-button amperage-selector-button",onclick:this.toggleSelector},a("span",{className:"select-shore-input-limit"},"Select shore input limit:"),t.currentLimit))}}class dt extends M{constructor(...t){super(...t),it(this,"setMode",t=>{this.props.deviceInterface.write(D.INVERTER_CHARGER.SYSTEM.MODE,t)})}render(t,e){return a("div",{className:"metric-component"},a("div",{className:"metrics-left-container"},a("img",{src:"./images/icons/icon_multiplus.png",className:"metric-icon"}),a("div",{className:"metrics-container"},a("p",null,"MultiPlus"),a("div",{className:"metrics"},a("p",null,t.state)))),a("div",{className:"metrics-selector"},a("button",{href:"#",className:"metrics-selector-button"+("ON"==t.activeMode?" metrics-selector-button--active":""),onClick:()=>this.setMode(D.INVERTER_CHARGER.SYSTEM.STATES.ON)},"On"),a("button",{href:"#",className:"metrics-selector-button"+("OFF"==t.activeMode?" metrics-selector-button--active":""),onClick:()=>this.setMode(D.INVERTER_CHARGER.SYSTEM.STATES.OFF)},"Off"),a("button",{href:"#",className:"metrics-selector-button"+("Charger only"==t.activeMode?" metrics-selector-button--active":""),onClick:()=>this.setMode(D.INVERTER_CHARGER.SYSTEM.STATES.CHARGER_ONLY)},"Charger only")))}}class _t extends M{render(t,e){const n=parseInt(t.current)>0?"Charging":"Draining";return a("div",{className:"metric-component battery-component"},a("div",{className:"metrics-left-container"},a("img",{src:"./images/icons/icon_battery.svg",className:"metric-icon"}),a("div",{className:"metrics-container"},a("p",null,"Battery"),a("div",{className:"metrics"},a(ht,{value:t.voltage,connected:t.connected}),a(ht,{value:t.current,connected:t.connected}),a(ht,{value:t.power,connected:t.connected})))),a("div",{className:"battery-level-container"},a("div",{className:"text-bottom-align"},a("p",{className:"battery-level"},parseInt(t.soc)),a("p",{className:"charging-state"},"% ",n))))}}class gt extends M{render(t,e){return a("div",{className:"metric-component metric-component--small"},a("img",{src:"./images/icons/icon_ac.svg",className:"metric-icon"}),a("div",{className:"metrics-container"},a("p",null,"AC Loads"),a("div",{className:"metrics"},a(ht,{value:t.voltage,connected:t.connected}),a(ht,{value:t.current,connected:t.connected}),a(ht,{value:t.power,connected:t.connected}))))}}class mt extends M{render(t,e){return a("div",{className:"metric-component metric-component--small"},a("img",{src:"./images/icons/icon_dc@1x.svg",className:"metric-icon"}),a("div",{className:"metrics-container"},a("p",null,"DC Loads"),a("div",{className:"metrics"},a(ht,{value:t.current,connected:t.connected}),a(ht,{value:t.power,connected:t.connected}))))}}j(a(class extends M{constructor(...t){super(...t),it(this,"state",{[D.BATTERY.VOLTAGE]:"--",[D.BATTERY.CURRENT]:"--",[D.BATTERY.POWER]:"--",[D.BATTERY.SOC]:"--",[D.INVERTER_CHARGER.DC_LOADS.CURRENT]:"--",[D.INVERTER_CHARGER.DC_LOADS.POWER]:"--",[D.INVERTER_CHARGER.AC_LOADS.VOLTAGE]:"--",[D.INVERTER_CHARGER.AC_LOADS.CURRENT]:"--",[D.INVERTER_CHARGER.AC_LOADS.POWER]:"--",[D.INVERTER_CHARGER.SHORE_POWER.IS_CONNECTED]:"--",[D.INVERTER_CHARGER.SHORE_POWER.VOLTAGE]:"--",[D.INVERTER_CHARGER.SHORE_POWER.CURRENT]:"--",[D.INVERTER_CHARGER.SHORE_POWER.CURRENT_LIMIT]:"--",[D.INVERTER_CHARGER.SHORE_POWER.POWER]:"--",[D.INVERTER_CHARGER.SYSTEM.STATE]:"--",[D.INVERTER_CHARGER.SYSTEM.MODE]:"--",[D.INVERTER_CHARGER.AC_SOURCE]:"Ac Input Mode",connected:!1}),it(this,"componentDidMount",()=>{const t=new rt(lt);t.connect().then(()=>{const e=Object.keys(B);t.subscribe(e)}),t.onMessage=(({path:t,value:e})=>{console.log(t,e);const n=B[t];if(!n)return void console.error(`Metric not found for path ${t}`);const r=n.formatter(e);this.setState({[t]:r+n.unit})}),t.onConnectionChanged=(({connected:t})=>{this.setState({connected:t})}),this.setState({deviceInterface:t})})}render(t,e){return a("main",null,a("div",{className:"bg"}),a("header",null,a("div",{className:"connection-container"},a("p",{className:"connection-state"},this.state.connected?"Connected":"Disconnected"),a("a",{href:"http://"+ct,className:"remote-console",target:"_blank"},"Remote Console"))),a("div",null,a("div",{className:"multi-metric-container"},a(ft,{acInput:this.state[D.INVERTER_CHARGER.AC_SOURCE],voltage:this.state[D.INVERTER_CHARGER.SHORE_POWER.VOLTAGE],current:this.state[D.INVERTER_CHARGER.SHORE_POWER.CURRENT],power:this.state[D.INVERTER_CHARGER.SHORE_POWER.POWER],connected:this.state.connected}),a(pt,{currentLimit:this.state[D.INVERTER_CHARGER.SHORE_POWER.CURRENT_LIMIT],shoreVoltage:this.state[D.INVERTER_CHARGER.SHORE_POWER.VOLTAGE],deviceInterface:this.state.deviceInterface,connected:this.state.connected})),a(dt,{state:this.state[D.INVERTER_CHARGER.SYSTEM.STATE],mode:this.state[D.INVERTER_CHARGER.SYSTEM.MODE],connected:this.state.connected,activeMode:this.state[D.INVERTER_CHARGER.SYSTEM.MODE],deviceInterface:this.state.deviceInterface}),a(_t,{soc:this.state[D.BATTERY.SOC],voltage:this.state[D.BATTERY.VOLTAGE],current:this.state[D.BATTERY.CURRENT],power:this.state[D.BATTERY.POWER],connected:this.state.connected}),a("div",{className:"multi-metric-container"},a(gt,{voltage:this.state[D.INVERTER_CHARGER.AC_LOADS.VOLTAGE],current:this.state[D.INVERTER_CHARGER.AC_LOADS.CURRENT],power:this.state[D.INVERTER_CHARGER.AC_LOADS.POWER],connected:this.state.connected}),a(mt,{current:this.state[D.INVERTER_CHARGER.DC_LOADS.CURRENT],power:this.state[D.INVERTER_CHARGER.DC_LOADS.POWER],connected:this.state.connected}))))}},null),document.body)}]); \ No newline at end of file +var r=n(48),i=n(49),o=n(25);function s(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(t,e){if(s()=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|t}function d(t,e){if(c.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return H(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return q(t).length;default:if(r)return H(t).length;e=(""+e).toLowerCase(),r=!0}}function g(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function _(t,e,n,r,i){if(0===t.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:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof e&&(e=c.from(e,r)),c.isBuffer(e))return 0===e.length?-1:m(t,e,n,r,i);if("number"==typeof e)return e&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):m(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,n,r,i){var o,s=1,a=t.length,c=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,c/=2,n/=2}function u(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){var l=-1;for(o=n;oa&&(n=a-c),o=n;o>=0;o--){for(var f=!0,h=0;hi&&(r=i):r=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;s>8,i=n%256,o.push(i),o.push(r);return o}(e,t.length-n),t,n,r)}function R(t,e,n){return 0===e&&n===t.length?r.fromByteArray(t):r.fromByteArray(t.slice(e,n))}function A(t,e,n){n=Math.min(t.length,n);for(var r=[],i=e;i239?4:u>223?3:u>191?2:1;if(i+f<=n)switch(f){case 1:u<128&&(l=u);break;case 2:128==(192&(o=t[i+1]))&&(c=(31&u)<<6|63&o)>127&&(l=c);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(c=(15&u)<<12|(63&o)<<6|63&s)>2047&&(c<55296||c>57343)&&(l=c);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(c=(15&u)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(l=c)}null===l?(l=65533,f=1):l>65535&&(l-=65536,r.push(l>>>10&1023|55296),l=56320|1023&l),r.push(l),i+=f}return function(t){var e=t.length;if(e<=T)return String.fromCharCode.apply(String,t);var n="",r=0;for(;rthis.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return C(this,e,n);case"utf8":case"utf-8":return A(this,e,n);case"ascii":return I(this,e,n);case"latin1":case"binary":return O(this,e,n);case"base64":return R(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}.apply(this,arguments)},c.prototype.equals=function(t){if(!c.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===c.compare(this,t)},c.prototype.inspect=function(){var t="",n=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),""},c.prototype.compare=function(t,e,n,r,i){if(!c.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),e<0||n>t.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&e>=n)return 0;if(r>=i)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,i>>>=0,this===t)return 0;for(var o=i-r,s=n-e,a=Math.min(o,s),u=this.slice(r,i),l=t.slice(e,n),f=0;fi)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return y(this,t,e,n);case"utf8":case"utf-8":return v(this,t,e,n);case"ascii":return b(this,t,e,n);case"latin1":case"binary":return w(this,t,e,n);case"base64":return E(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,t,e,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var T=4096;function I(t,e,n){var r="";n=Math.min(t.length,n);for(var i=e;ir)&&(n=r);for(var i="",o=e;on)throw new RangeError("Trying to access beyond buffer length")}function N(t,e,n,r,i,o){if(!c.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function P(t,e,n,r){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-n,2);i>>8*(r?i:1-i)}function M(t,e,n,r){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-n,4);i>>8*(r?i:3-i)&255}function L(t,e,n,r,i,o){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function j(t,e,n,r,o){return o||L(t,0,n,4),i.write(t,e,n,r,23,4),n+4}function U(t,e,n,r,o){return o||L(t,0,n,8),i.write(t,e,n,r,52,8),n+8}c.prototype.slice=function(t,e){var n,r=this.length;if(t=~~t,e=void 0===e?r:~~e,t<0?(t+=r)<0&&(t=0):t>r&&(t=r),e<0?(e+=r)<0&&(e=0):e>r&&(e=r),e0&&(i*=256);)r+=this[t+--e]*i;return r},c.prototype.readUInt8=function(t,e){return e||k(t,1,this.length),this[t]},c.prototype.readUInt16LE=function(t,e){return e||k(t,2,this.length),this[t]|this[t+1]<<8},c.prototype.readUInt16BE=function(t,e){return e||k(t,2,this.length),this[t]<<8|this[t+1]},c.prototype.readUInt32LE=function(t,e){return e||k(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},c.prototype.readUInt32BE=function(t,e){return e||k(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},c.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=this[t],i=1,o=0;++o=(i*=128)&&(r-=Math.pow(2,8*e)),r},c.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=e,i=1,o=this[t+--r];r>0&&(i*=256);)o+=this[t+--r]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},c.prototype.readInt8=function(t,e){return e||k(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},c.prototype.readInt16LE=function(t,e){e||k(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt16BE=function(t,e){e||k(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt32LE=function(t,e){return e||k(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},c.prototype.readInt32BE=function(t,e){return e||k(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},c.prototype.readFloatLE=function(t,e){return e||k(t,4,this.length),i.read(this,t,!0,23,4)},c.prototype.readFloatBE=function(t,e){return e||k(t,4,this.length),i.read(this,t,!1,23,4)},c.prototype.readDoubleLE=function(t,e){return e||k(t,8,this.length),i.read(this,t,!0,52,8)},c.prototype.readDoubleBE=function(t,e){return e||k(t,8,this.length),i.read(this,t,!1,52,8)},c.prototype.writeUIntLE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||N(this,t,e,n,Math.pow(2,8*n)-1,0);var i=1,o=0;for(this[e]=255&t;++o=0&&(o*=256);)this[e+i]=t/o&255;return e+n},c.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,1,255,0),c.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},c.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):P(this,t,e,!0),e+2},c.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):P(this,t,e,!1),e+2},c.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):M(this,t,e,!0),e+4},c.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},c.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);N(this,t,e,n,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o>0)-a&255;return e+n},c.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);N(this,t,e,n,i-1,-i)}var o=n-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+n},c.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,1,127,-128),c.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},c.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):P(this,t,e,!0),e+2},c.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):P(this,t,e,!1),e+2},c.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):M(this,t,e,!0),e+4},c.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},c.prototype.writeFloatLE=function(t,e,n){return j(this,t,e,!0,n)},c.prototype.writeFloatBE=function(t,e,n){return j(this,t,e,!1,n)},c.prototype.writeDoubleLE=function(t,e,n){return U(this,t,e,!0,n)},c.prototype.writeDoubleBE=function(t,e,n){return U(this,t,e,!1,n)},c.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r=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),t.length-e=0;--i)t[i+e]=this[i+n];else if(o<1e3||!c.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(o=e;o55295&&n<57344){if(!i){if(n>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(e-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((e-=1)<0)break;o.push(n)}else if(n<2048){if((e-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=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((e-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function q(t){return r.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(D,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function V(t,e,n,r){for(var i=0;i=e.length||i>=t.length);++i)e[i+n]=t[i];return i}}).call(this,n(1))},function(t,e,n){"use strict";t.exports=n(70)()?Object.assign:n(71)},function(t,e,n){"use strict";var r,i=n(31),o=n(20),s=n(5),a=n(4),c=n(8),u=n(87),l=n(6),f=Object.defineProperty,h=Object.defineProperties;t.exports=r=function(t,e){if(!(this instanceof r))throw new TypeError("Constructor requires 'new'");h(this,{__list__:c("w",a(t)),__context__:c("w",e),__nextIndex__:c("w",0)}),e&&(s(e.on),e.on("_add",this._onAdd),e.on("_delete",this._onDelete),e.on("_clear",this._onClear))},delete r.prototype.constructor,h(r.prototype,o({_next:c(function(){var t;if(this.__list__)return this.__redo__&&void 0!==(t=this.__redo__.shift())?t:this.__nextIndex__=this.__nextIndex__||(++this.__nextIndex__,this.__redo__?(this.__redo__.forEach(function(e,n){e>=t&&(this.__redo__[n]=++e)},this),this.__redo__.push(t)):f(this,"__redo__",c("c",[t])))}),_onDelete:c(function(t){var e;t>=this.__nextIndex__||(--this.__nextIndex__,this.__redo__&&(-1!==(e=this.__redo__.indexOf(t))&&this.__redo__.splice(e,1),this.__redo__.forEach(function(e,n){e>t&&(this.__redo__[n]=--e)},this)))}),_onClear:c(function(){this.__redo__&&i.call(this.__redo__),this.__nextIndex__=0})}))),f(r.prototype,l.iterator,c(function(){return this}))},function(t,e,n){"use strict";var r=n(121);t.exports=function(t,e){var n;function i(r){e.rejectUnauthorized&&t.emit("error",r),n.end()}return e.port=e.port||8883,e.host=e.hostname||e.host||"localhost",e.rejectUnauthorized=!1!==e.rejectUnauthorized,delete e.path,(n=r.connect(e)).on("secureConnect",function(){e.rejectUnauthorized&&!n.authorized?n.emit("error",new Error("TLS not authorized")):n.removeListener("error",i)}),n.on("error",i),n}},function(t,e,n){"use strict";(function(e){var r=n(18),i=n(13).Readable,o={objectMode:!0},s={clean:!0},a=n(57);function c(t){if(!(this instanceof c))return new c(t);this.options=t||{},this.options=r(s,t),this._inflights=new a}c.prototype.put=function(t,e){return this._inflights.set(t.messageId,t),e&&e(),this},c.prototype.createStream=function(){var t=new i(o),n=!1,r=[],s=0;return this._inflights.forEach(function(t,e){r.push(t)}),t._read=function(){!n&&s0?("string"==typeof e||s.objectMode||Object.getPrototypeOf(e)===u.prototype||(e=function(t){return u.from(t)}(e)),r?s.endEmitted?t.emit("error",new Error("stream.unshift() after end event")):w(t,s,e,!0):s.ended?t.emit("error",new Error("stream.push() after EOF")):(s.reading=!1,s.decoder&&!n?(e=s.decoder.write(e),s.objectMode||0!==e.length?w(t,s,e,!1):T(t,s)):w(t,s,e,!1))):r||(s.reading=!1));return function(t){return!t.ended&&(t.needReadable||t.lengthe.highWaterMark&&(e.highWaterMark=function(t){return t>=E?t=E:(t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++),t}(t)),t<=e.length?t:e.ended?e.length:(e.needReadable=!0,0))}function R(t){var e=t._readableState;e.needReadable=!1,e.emittedReadable||(p("emitReadable",e.flowing),e.emittedReadable=!0,e.sync?i.nextTick(A,t):A(t))}function A(t){p("emit readable"),t.emit("readable"),x(t)}function T(t,e){e.readingMore||(e.readingMore=!0,i.nextTick(I,t,e))}function I(t,e){for(var n=e.length;!e.reading&&!e.flowing&&!e.ended&&e.length=e.length?(n=e.decoder?e.buffer.join(""):1===e.buffer.length?e.buffer.head.data:e.buffer.concat(e.length),e.buffer.clear()):n=function(t,e,n){var r;to.length?o.length:t;if(s===o.length?i+=o:i+=o.slice(0,t),0===(t-=s)){s===o.length?(++r,n.next?e.head=n.next:e.head=e.tail=null):(e.head=n,n.data=o.slice(s));break}++r}return e.length-=r,i}(t,e):function(t,e){var n=u.allocUnsafe(t),r=e.head,i=1;r.data.copy(n),t-=r.data.length;for(;r=r.next;){var o=r.data,s=t>o.length?o.length:t;if(o.copy(n,n.length-t,0,s),0===(t-=s)){s===o.length?(++i,r.next?e.head=r.next:e.head=e.tail=null):(e.head=r,r.data=o.slice(s));break}++i}return e.length-=i,n}(t,e);return r}(t,e.buffer,e.decoder),n);var n}function N(t){var e=t._readableState;if(e.length>0)throw new Error('"endReadable()" called on non-empty stream');e.endEmitted||(e.ended=!0,i.nextTick(P,e,t))}function P(t,e){t.endEmitted||0!==t.length||(t.endEmitted=!0,e.readable=!1,e.emit("end"))}function M(t,e){for(var n=0,r=t.length;n=e.highWaterMark||e.ended))return p("read: emitReadable",e.length,e.ended),0===e.length&&e.ended?N(this):R(this),null;if(0===(t=S(t,e))&&e.ended)return 0===e.length&&N(this),null;var r,i=e.needReadable;return p("need readable",i),(0===e.length||e.length-t0?k(t,e):null)?(e.needReadable=!0,t=0):e.length-=t,0===e.length&&(e.ended||(e.needReadable=!0),n!==t&&e.ended&&N(this)),null!==r&&this.emit("data",r),r},v.prototype._read=function(t){this.emit("error",new Error("_read() is not implemented"))},v.prototype.pipe=function(t,e){var n=this,o=this._readableState;switch(o.pipesCount){case 0:o.pipes=t;break;case 1:o.pipes=[o.pipes,t];break;default:o.pipes.push(t)}o.pipesCount+=1,p("pipe count=%d opts=%j",o.pipesCount,e);var c=(!e||!1!==e.end)&&t!==r.stdout&&t!==r.stderr?l:v;function u(e,r){p("onunpipe"),e===n&&r&&!1===r.hasUnpiped&&(r.hasUnpiped=!0,p("cleanup"),t.removeListener("close",m),t.removeListener("finish",y),t.removeListener("drain",f),t.removeListener("error",_),t.removeListener("unpipe",u),n.removeListener("end",l),n.removeListener("end",v),n.removeListener("data",g),h=!0,!o.awaitDrain||t._writableState&&!t._writableState.needDrain||f())}function l(){p("onend"),t.end()}o.endEmitted?i.nextTick(c):n.once("end",c),t.on("unpipe",u);var f=function(t){return function(){var e=t._readableState;p("pipeOnDrain",e.awaitDrain),e.awaitDrain&&e.awaitDrain--,0===e.awaitDrain&&a(t,"data")&&(e.flowing=!0,x(t))}}(n);t.on("drain",f);var h=!1;var d=!1;function g(e){p("ondata"),d=!1,!1!==t.write(e)||d||((1===o.pipesCount&&o.pipes===t||o.pipesCount>1&&-1!==M(o.pipes,t))&&!h&&(p("false write response, pause",n._readableState.awaitDrain),n._readableState.awaitDrain++,d=!0),n.pause())}function _(e){p("onerror",e),v(),t.removeListener("error",_),0===a(t,"error")&&t.emit("error",e)}function m(){t.removeListener("finish",y),v()}function y(){p("onfinish"),t.removeListener("close",m),v()}function v(){p("unpipe"),n.unpipe(t)}return n.on("data",g),function(t,e,n){if("function"==typeof t.prependListener)return t.prependListener(e,n);t._events&&t._events[e]?s(t._events[e])?t._events[e].unshift(n):t._events[e]=[n,t._events[e]]:t.on(e,n)}(t,"error",_),t.once("close",m),t.once("finish",y),t.emit("pipe",n),o.flowing||(p("pipe resume"),n.resume()),t},v.prototype.unpipe=function(t){var e=this._readableState,n={hasUnpiped:!1};if(0===e.pipesCount)return this;if(1===e.pipesCount)return t&&t!==e.pipes?this:(t||(t=e.pipes),e.pipes=null,e.pipesCount=0,e.flowing=!1,t&&t.emit("unpipe",this,n),this);if(!t){var r=e.pipes,i=e.pipesCount;e.pipes=null,e.pipesCount=0,e.flowing=!1;for(var o=0;o-1?r:o.nextTick;y.WritableState=m;var u=n(12);u.inherits=n(3);var l={deprecate:n(55)},f=n(26),h=n(2).Buffer,p=i.Uint8Array||function(){};var d,g=n(27);function _(){}function m(t,e){a=a||n(7),t=t||{};var r=e instanceof a;this.objectMode=!!t.objectMode,r&&(this.objectMode=this.objectMode||!!t.writableObjectMode);var i=t.highWaterMark,u=t.writableHighWaterMark,l=this.objectMode?16:16384;this.highWaterMark=i||0===i?i:r&&(u||0===u)?u: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 f=!1===t.decodeStrings;this.decodeStrings=!f,this.defaultEncoding=t.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(t){!function(t,e){var n=t._writableState,r=n.sync,i=n.writecb;if(function(t){t.writing=!1,t.writecb=null,t.length-=t.writelen,t.writelen=0}(n),e)!function(t,e,n,r,i){--e.pendingcb,n?(o.nextTick(i,r),o.nextTick(R,t,e),t._writableState.errorEmitted=!0,t.emit("error",r)):(i(r),t._writableState.errorEmitted=!0,t.emit("error",r),R(t,e))}(t,n,r,e,i);else{var s=E(n);s||n.corked||n.bufferProcessing||!n.bufferedRequest||w(t,n),r?c(b,t,n,s,i):b(t,n,s,i)}}(e,t)},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(t){if(a=a||n(7),!(d.call(y,this)||this instanceof a))return new y(t);this._writableState=new m(t,this),this.writable=!0,t&&("function"==typeof t.write&&(this._write=t.write),"function"==typeof t.writev&&(this._writev=t.writev),"function"==typeof t.destroy&&(this._destroy=t.destroy),"function"==typeof t.final&&(this._final=t.final)),f.call(this)}function v(t,e,n,r,i,o,s){e.writelen=r,e.writecb=s,e.writing=!0,e.sync=!0,n?t._writev(i,e.onwrite):t._write(i,o,e.onwrite),e.sync=!1}function b(t,e,n,r){n||function(t,e){0===e.length&&e.needDrain&&(e.needDrain=!1,t.emit("drain"))}(t,e),e.pendingcb--,r(),R(t,e)}function w(t,e){e.bufferProcessing=!0;var n=e.bufferedRequest;if(t._writev&&n&&n.next){var r=e.bufferedRequestCount,i=new Array(r),o=e.corkedRequestsFree;o.entry=n;for(var a=0,c=!0;n;)i[a]=n,n.isBuf||(c=!1),n=n.next,a+=1;i.allBuffers=c,v(t,e,!0,e.length,i,"",o.finish),e.pendingcb++,e.lastBufferedRequest=null,o.next?(e.corkedRequestsFree=o.next,o.next=null):e.corkedRequestsFree=new s(e),e.bufferedRequestCount=0}else{for(;n;){var u=n.chunk,l=n.encoding,f=n.callback;if(v(t,e,!1,e.objectMode?1:u.length,u,l,f),n=n.next,e.bufferedRequestCount--,e.writing)break}null===n&&(e.lastBufferedRequest=null)}e.bufferedRequest=n,e.bufferProcessing=!1}function E(t){return t.ending&&0===t.length&&null===t.bufferedRequest&&!t.finished&&!t.writing}function S(t,e){t._final(function(n){e.pendingcb--,n&&t.emit("error",n),e.prefinished=!0,t.emit("prefinish"),R(t,e)})}function R(t,e){var n=E(e);return n&&(!function(t,e){e.prefinished||e.finalCalled||("function"==typeof t._final?(e.pendingcb++,e.finalCalled=!0,o.nextTick(S,t,e)):(e.prefinished=!0,t.emit("prefinish")))}(t,e),0===e.pendingcb&&(e.finished=!0,t.emit("finish"))),n}u.inherits(y,f),m.prototype.getBuffer=function(){for(var t=this.bufferedRequest,e=[];t;)e.push(t),t=t.next;return e},function(){try{Object.defineProperty(m.prototype,"buffer",{get:l.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(t){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(d=Function.prototype[Symbol.hasInstance],Object.defineProperty(y,Symbol.hasInstance,{value:function(t){return!!d.call(this,t)||this===y&&(t&&t._writableState instanceof m)}})):d=function(t){return t instanceof this},y.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},y.prototype.write=function(t,e,n){var r=this._writableState,i=!1,s=!r.objectMode&&function(t){return h.isBuffer(t)||t instanceof p}(t);return s&&!h.isBuffer(t)&&(t=function(t){return h.from(t)}(t)),"function"==typeof e&&(n=e,e=null),s?e="buffer":e||(e=r.defaultEncoding),"function"!=typeof n&&(n=_),r.ended?function(t,e){var n=new Error("write after end");t.emit("error",n),o.nextTick(e,n)}(this,n):(s||function(t,e,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||e.objectMode||(s=new TypeError("Invalid non-string/buffer chunk")),s&&(t.emit("error",s),o.nextTick(r,s),i=!1),i}(this,r,t,n))&&(r.pendingcb++,i=function(t,e,n,r,i,o){if(!n){var s=function(t,e,n){t.objectMode||!1===t.decodeStrings||"string"!=typeof e||(e=h.from(e,n));return e}(e,r,i);r!==s&&(n=!0,i="buffer",r=s)}var a=e.objectMode?1:r.length;e.length+=a;var c=e.length-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this},Object.defineProperty(y.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),y.prototype._write=function(t,e,n){n(new Error("_write() is not implemented"))},y.prototype._writev=null,y.prototype.end=function(t,e,n){var r=this._writableState;"function"==typeof t?(n=t,t=null,e=null):"function"==typeof e&&(n=e,e=null),null!==t&&void 0!==t&&this.write(t,e),r.corked&&(r.corked=1,this.uncork()),r.ending||r.finished||function(t,e,n){e.ending=!0,R(t,e),n&&(e.finished?o.nextTick(n):t.once("finish",n));e.ended=!0,t.writable=!1}(this,r,n)},Object.defineProperty(y.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(t){this._writableState&&(this._writableState.destroyed=t)}}),y.prototype.destroy=g.destroy,y.prototype._undestroy=g.undestroy,y.prototype._destroy=function(t,e){this.end(),e(t)}}).call(this,n(0),n(53).setImmediate,n(1))},function(t,e,n){"use strict";var r=n(2).Buffer,i=r.isEncoding||function(t){switch((t=""+t)&&t.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(t){var e;switch(this.encoding=function(t){var e=function(t){if(!t)return"utf8";for(var e;;)switch(t){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 t;default:if(e)return;t=(""+t).toLowerCase(),e=!0}}(t);if("string"!=typeof e&&(r.isEncoding===i||!i(t)))throw new Error("Unknown encoding: "+t);return e||t}(t),this.encoding){case"utf16le":this.text=c,this.end=u,e=4;break;case"utf8":this.fillLast=a,e=4;break;case"base64":this.text=l,this.end=f,e=3;break;default:return this.write=h,void(this.end=p)}this.lastNeed=0,this.lastTotal=0,this.lastChar=r.allocUnsafe(e)}function s(t){return t<=127?0:t>>5==6?2:t>>4==14?3:t>>3==30?4:t>>6==2?-1:-2}function a(t){var e=this.lastTotal-this.lastNeed,n=function(t,e,n){if(128!=(192&e[0]))return t.lastNeed=0,"�";if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�";if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�"}}(this,t);return void 0!==n?n:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),void(this.lastNeed-=t.length))}function c(t,e){if((t.length-e)%2==0){var n=t.toString("utf16le",e);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function u(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,n)}return e}function l(t,e){var n=(t.length-e)%3;return 0===n?t.toString("base64",e):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-n))}function f(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function h(t){return t.toString(this.encoding)}function p(t){return t&&t.length?this.write(t):""}e.StringDecoder=o,o.prototype.write=function(t){if(0===t.length)return"";var e,n;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n=0)return i>0&&(t.lastNeed=i-1),i;if(--r=0)return i>0&&(t.lastNeed=i-2),i;if(--r=0)return i>0&&(2===i?i=0:t.lastNeed=i-3),i;return 0}(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=n;var r=t.length-(n-this.lastNeed);return t.copy(this.lastChar,0,r),t.toString("utf8",e,r)},o.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length}},function(t,e,n){"use strict";t.exports=o;var r=n(7),i=n(12);function o(t){if(!(this instanceof o))return new o(t);r.call(this,t),this._transformState={afterTransform:function(t,e){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!=e&&this.push(e),r(t);var i=this._readableState;i.reading=!1,(i.needReadable||i.length65535||u%1!=0)return e.emit("error",new Error("Invalid keepalive")),!1;d+=2;if(d+=1,a){if("object"!=typeof a)return e.emit("error",new Error("Invalid will")),!1;if(!a.topic||"string"!=typeof a.topic)return e.emit("error",new Error("Invalid will topic")),!1;if(d+=i.byteLength(a.topic)+2,a.payload&&a.payload){if(!(a.payload.length>=0))return e.emit("error",new Error("Invalid will payload")),!1;"string"==typeof a.payload?d+=i.byteLength(a.payload)+2:d+=a.payload.length+2}else d+=2}var g=!1;if(null!=f){if(!S(f))return e.emit("error",new Error("Invalid username")),!1;g=!0,d+=i.byteLength(f)+2}if(null!=p){if(!g)return e.emit("error",new Error("Username is required to use password")),!1;if(!S(p))return e.emit("error",new Error("Invalid password")),!1;d+=E(p)+2}e.write(r.CONNECT_HEADER),m(e,d),w(e,o),e.write(4===s?r.VERSION4:r.VERSION3);var _=0;_|=null!=f?r.USERNAME_MASK:0,_|=null!=p?r.PASSWORD_MASK:0,_|=a&&a.retain?r.WILL_RETAIN_MASK:0,_|=a&&a.qos?a.qos<0&&h(e,l);return e.write(u)}(t,e);case"puback":case"pubrec":case"pubrel":case"pubcomp":case"unsuback":return function(t,e){var n=t||{},i=n.cmd||"puback",o=n.messageId,s=n.dup&&"pubrel"===i?r.DUP_MASK:0,a=0;"pubrel"===i&&(a=1);if("number"!=typeof o)return e.emit("error",new Error("Invalid messageId")),!1;return e.write(r.ACKS[i][a][s][0]),m(e,2),h(e,o)}(t,e);case"subscribe":return function(t,e){var n=t||{},o=n.dup?r.DUP_MASK:0,s=n.messageId,a=n.subscriptions,c=0;if("number"!=typeof s)return e.emit("error",new Error("Invalid messageId")),!1;c+=2;if("object"!=typeof a||!a.length)return e.emit("error",new Error("Invalid subscriptions")),!1;for(var u=0;u=0&&t<128?1:t>=128&&t<16384?2:t>=16384&&t<2097152?3:t>=2097152&&t<268435456?4:0}(t));do{e=t%128|0,(t=t/128|0)>0&&(e|=128),r.writeUInt8(e,n++)}while(t>0);return r}(e),e<16384&&(_[e]=n)),t.write(n)}function y(t,e){var n=i.byteLength(e);h(t,n),t.write(e,"utf8")}function v(t,e){return t.write(u[e])}function b(t,e){return t.write(l(e))}function w(t,e){"string"==typeof e?y(t,e):e?(h(t,e.length),t.write(e)):h(t,0)}function E(t){return t?t instanceof i?t.length:i.byteLength(t):0}function S(t){return"string"==typeof t||t instanceof i}t.exports=d},function(t,e,n){"use strict";var r=n(114),i=n(116);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}e.parse=v,e.resolve=function(t,e){return v(t,!1,!0).resolve(e)},e.resolveObject=function(t,e){return t?v(t,!1,!0).resolveObject(e):e},e.format=function(t){i.isString(t)&&(t=v(t));return t instanceof o?t.format():o.prototype.format.call(t)},e.Url=o;var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,u=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),l=["'"].concat(u),f=["%","/","?",";","#"].concat(l),h=["/","?","#"],p=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,g={javascript:!0,"javascript:":!0},_={javascript:!0,"javascript:":!0},m={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},y=n(117);function v(t,e,n){if(t&&i.isObject(t)&&t instanceof o)return t;var r=new o;return r.parse(t,e,n),r}o.prototype.parse=function(t,e,n){if(!i.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var o=t.indexOf("?"),a=-1!==o&&o127?P+="x":P+=N[M];if(!P.match(p)){var j=x.slice(0,I),U=x.slice(I+1),D=N.match(d);D&&(j.push(D[1]),U.unshift(D[2])),U.length&&(v="/"+U.join(".")+v),this.hostname=j.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),C||(this.hostname=r.toASCII(this.hostname));var B=this.port?":"+this.port:"",H=this.hostname||"";this.host=H+B,this.href+=this.host,C&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==v[0]&&(v="/"+v))}if(!g[E])for(I=0,k=l.length;I0)&&n.host.split("@"))&&(n.auth=C.shift(),n.host=n.hostname=C.shift());return n.search=t.search,n.query=t.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 A=S.slice(-1)[0],T=(n.host||t.host||S.length>1)&&("."===A||".."===A)||""===A,I=0,O=S.length;O>=0;O--)"."===(A=S[O])?S.splice(O,1):".."===A?(S.splice(O,1),I++):I&&(S.splice(O,1),I--);if(!w&&!E)for(;I--;I)S.unshift("..");!w||""===S[0]||S[0]&&"/"===S[0].charAt(0)||S.unshift(""),T&&"/"!==S.join("/").substr(-1)&&S.push("");var C,x=""===S[0]||S[0]&&"/"===S[0].charAt(0);R&&(n.hostname=n.host=x?"":S.length?S.shift():"",(C=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=C.shift(),n.host=n.hostname=C.shift()));return(w=w||n.host&&S.length)&&!x&&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=t.auth||n.auth,n.slashes=n.slashes||t.slashes,n.href=n.format(),n},o.prototype.parseHost=function(){var t=this.host,e=a.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},function(t,e,n){"use strict";var r=n(120);t.exports=function(t,e){var n,i;return e.port=e.port||1883,e.hostname=e.hostname||e.host||"localhost",n=e.port,i=e.hostname,r.createConnection(n,i)}},function(t,e,n){"use strict";var r=!1,i=[];function o(t){r?wx.sendSocketMessage({data:t.buffer||t}):i.push(t)}var s=n(45);function a(t,e){var n="MQIsdp"===e.protocolId&&3===e.protocolVersion?"mqttv3.1":"mqtt";!function(t){t.hostname||(t.hostname="localhost"),t.path||(t.path="/"),t.wsOptions||(t.wsOptions={})}(e);var a=function(t,e){var n="wxs"===t.protocol?"wss":"ws",r=n+"://"+t.hostname+t.path;return t.port&&80!==t.port&&443!==t.port&&(r=n+"://"+t.hostname+":"+t.port+t.path),"function"==typeof t.transformWsUrl&&(r=t.transformWsUrl(r,t,e)),r}(e,t);return s(function(t,e){var n={OPEN:1,CLOSING:2,CLOSED:3,readyState:r?1:0,send:o,close:wx.closeSocket,onopen:null,onmessage:null,onclose:null,onerror:null};return wx.connectSocket({url:t,protocols:e}),wx.onSocketOpen(function(t){n.readyState=n.OPEN,r=!0;for(var e=0;eg)return void setTimeout(t,_,e,n,r);m&&"string"==typeof e&&(e=a.from(e,"utf8"));try{l.send(e)}catch(t){return r(t)}r()}:function(t,e,n){if(l.readyState!==l.OPEN)return void n();m&&"string"==typeof t&&(t=a.from(t,"utf8"));l.send(t,n)};n&&!Array.isArray(n)&&"object"==typeof n&&(c=n,n=null,("string"==typeof c.protocol||Array.isArray(c.protocol))&&(n=c.protocol));c||(c={});void 0===c.objectMode&&(c.objectMode=!(!0===c.binary||void 0===c.binary));var d=function(t,e,n){var r=new i({objectMode:t.objectMode});return r._write=e,r._flush=n,r}(c,p,function(t){l.close(),t()});c.objectMode||(d._writev=function(t,e){for(var n=new Array(t.length),r=0;r0&&(this.options.resubscribe?(this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics)):this._resubscribeTopics={}),s=!1}),this.on("close",function(){null!==r.pingTimer&&(r.pingTimer.clear(),r.pingTimer=null)}),this.on("close",this._setupReconnect),i.EventEmitter.call(this),this._setupStream()}u(y,i.EventEmitter),y.prototype._setupStream=function(){var t,e=this,n=new c,i=a.parser(this.options),o=null,u=[];function l(){r.nextTick(f)}function f(){var t=u.shift(),n=o;t?e._handlePacket(t,l):(o=null,n())}this._clearReconnect(),this.stream=this.streamBuilder(this),i.on("packet",function(t){u.push(t)}),n._write=function(t,e,n){o=n,i.parse(t),f()},this.stream.pipe(n),this.stream.on("error",m),s(this.stream,this.emit.bind(this,"close")),(t=Object.create(this.options)).cmd="connect",g(this,t),i.on("error",this.emit.bind(this,"error")),this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout(function(){e._cleanUp(!0)},this.options.connectTimeout)},y.prototype._handlePacket=function(t,e){switch(this.emit("packetreceive",t),t.cmd){case"publish":this._handlePublish(t,e);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(t),e();break;case"pubrel":this._handlePubrel(t,e);break;case"connack":this._handleConnack(t),e();break;case"pingresp":this._handlePingresp(t),e()}},y.prototype._checkDisconnecting=function(t){return this.disconnecting&&(t?t(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting},y.prototype.publish=function(t,e,n,r){var i;"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:t,payload:e,qos:n.qos,retain:n.retain,messageId:this._nextId(),dup:n.dup},n.qos){case 1:case 2:this.outgoing[i.messageId]=r||m,this._sendPacket(i);break;default:this._sendPacket(i,r)}return this},y.prototype.subscribe=function(){var t,e,n=Array.prototype.slice.call(arguments),r=[],i=n.shift(),o=i.resubscribe,s=n.pop()||m,a=n.pop(),c=this;if(delete i.resubscribe,"string"==typeof i&&(i=[i]),"function"!=typeof s&&(a=s,s=m),null!==(e=f.validateTopics(i)))return p(s,new Error("Invalid topic "+e)),this;if(this._checkDisconnecting(s))return this;if(a=h({qos:0},a),Array.isArray(i)?i.forEach(function(t){(c._resubscribeTopics[t]0&&(c._resubscribeTopics[t.topic]=t.qos,u.push(t.topic))}),c.messageIdToTopic[t.messageId]=u}return this.outgoing[t.messageId]=function(t,e){if(!t)for(var n=e.granted,i=0;i0?this.once("outgoingEmpty",setTimeout.bind(null,i,10)):i(),this)},y.prototype.removeOutgoingMessage=function(t){var e=this.outgoing[t];return delete this.outgoing[t],this.outgoingStore.del({messageId:t},function(){e(new Error("Message removed"))}),this},y.prototype.reconnect=function(t){var e=this,n=function(){t?(e.options.incomingStore=t.incomingStore,e.options.outgoingStore=t.outgoingStore):(e.options.incomingStore=null,e.options.outgoingStore=null),e.incomingStore=e.options.incomingStore||new o,e.outgoingStore=e.options.outgoingStore||new o,e.disconnecting=!1,e.disconnected=!1,e._deferredReconnect=null,e._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=n:n(),this},y.prototype._reconnect=function(){this.emit("reconnect"),this._setupStream()},y.prototype._setupReconnect=function(){var t=this;!t.disconnecting&&!t.reconnectTimer&&t.options.reconnectPeriod>0&&(this.reconnecting||(this.emit("offline"),this.reconnecting=!0),t.reconnectTimer=setInterval(function(){t._reconnect()},t.options.reconnectPeriod))},y.prototype._clearReconnect=function(){this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},y.prototype._cleanUp=function(t,e){e&&this.stream.on("close",e),t?(0===this.options.reconnectPeriod&&this.options.clean&&function(t){t&&Object.keys(t).forEach(function(e){"function"==typeof t[e]&&(t[e](new Error("Connection closed")),delete t[e])})}(this.outgoing),this.stream.destroy()):this._sendPacket({cmd:"disconnect"},p.bind(null,this.stream.end.bind(this.stream))),this.disconnecting||(this._clearReconnect(),this._setupReconnect()),null!==this.pingTimer&&(this.pingTimer.clear(),this.pingTimer=null),e&&!this.connected&&(this.stream.removeListener("close",e),e())},y.prototype._sendPacket=function(t,e){if(this.connected){switch(this._shiftPingInterval(),t.cmd){case"publish":break;case"pubrel":return void _(this,t,e);default:return void g(this,t,e)}switch(t.qos){case 2:case 1:_(this,t,e);break;case 0:default:g(this,t,e)}}else 0===(t.qos||0)&&this.queueQoSZero||"publish"!==t.cmd?this.queue.push({packet:t,cb:e}):t.qos>0?(e=this.outgoing[t.messageId],this.outgoingStore.put(t,function(t){if(t)return e&&e(t)})):e&&e(new Error("No connection to broker"))},y.prototype._setupPingTimer=function(){var t=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=l(function(){t._checkPing()},1e3*this.options.keepalive))},y.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},y.prototype._checkPing=function(){this.pingResp?(this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):this._cleanUp(!0)},y.prototype._handlePingresp=function(){this.pingResp=!0},y.prototype._handleConnack=function(t){var e=t.returnCode;if(clearTimeout(this.connackTimer),0===e)this.reconnecting=!1,this.emit("connect",t);else if(e>0){var n=new Error("Connection refused: "+["","Unacceptable protocol version","Identifier rejected","Server unavailable","Bad username or password","Not authorized"][e]);n.code=e,this.emit("error",n)}},y.prototype._handlePublish=function(t,e){e=void 0!==e?e:m;var n=t.topic.toString(),r=t.payload,i=t.qos,o=t.messageId,s=this;switch(i){case 2:this.incomingStore.put(t,function(t){if(t)return e(t);s._sendPacket({cmd:"pubrec",messageId:o},e)});break;case 1:this.emit("message",n,r,t),this.handleMessage(t,function(t){if(t)return e(t);s._sendPacket({cmd:"puback",messageId:o},e)});break;case 0:this.emit("message",n,r,t),this.handleMessage(t,e)}},y.prototype.handleMessage=function(t,e){e()},y.prototype._handleAck=function(t){var e=t.messageId,n=t.cmd,r=null,i=this.outgoing[e],o=this;if(i){switch(n){case"pubcomp":case"puback":delete this.outgoing[e],this.outgoingStore.del(t,i);break;case"pubrec":r={cmd:"pubrel",qos:2,messageId:e},this._sendPacket(r);break;case"suback":if(delete this.outgoing[e],1===t.granted.length&&0!=(128&t.granted[0])){var s=this.messageIdToTopic[e];s&&s.forEach(function(t){delete o._resubscribeTopics[t]})}i(null,t);break;case"unsuback":delete this.outgoing[e],i(null);break;default:o.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&0===Object.keys(this.outgoing).length&&this.emit("outgoingEmpty")}},y.prototype._handlePubrel=function(t,e){e=void 0!==e?e:m;var n=this,r={cmd:"pubcomp",messageId:t.messageId};n.incomingStore.get(t,function(i,o){i||"pubrel"===o.cmd?n._sendPacket(r,e):(n.emit("message",o.topic,o.payload,o),n.incomingStore.put(t,function(t){if(t)return e(t);n.handleMessage(o,function(t){if(t)return e(t);n._sendPacket(r,e)})}))})},y.prototype._nextId=function(){var t=this.nextId++;return 65536===this.nextId&&(this.nextId=1),t},y.prototype.getLastMessageId=function(){return 1===this.nextId?65535:this.nextId-1},t.exports=y}).call(this,n(1),n(0))},function(t,e,n){"use strict";e.byteLength=function(t){var e=u(t),n=e[0],r=e[1];return 3*(n+r)/4-r},e.toByteArray=function(t){for(var e,n=u(t),r=n[0],s=n[1],a=new o(function(t,e,n){return 3*(e+n)/4-n}(0,r,s)),c=0,l=s>0?r-4:r,f=0;f>16&255,a[c++]=e>>8&255,a[c++]=255&e;2===s&&(e=i[t.charCodeAt(f)]<<2|i[t.charCodeAt(f+1)]>>4,a[c++]=255&e);1===s&&(e=i[t.charCodeAt(f)]<<10|i[t.charCodeAt(f+1)]<<4|i[t.charCodeAt(f+2)]>>2,a[c++]=e>>8&255,a[c++]=255&e);return a},e.fromByteArray=function(t){for(var e,n=t.length,i=n%3,o=[],s=0,a=n-i;sa?a:s+16383));1===i?(e=t[n-1],o.push(r[e>>2]+r[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],o.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"="));return o.join("")};for(var r=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=s.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function l(t){return r[t>>18&63]+r[t>>12&63]+r[t>>6&63]+r[63&t]}function f(t,e,n){for(var r,i=[],o=e;o>1,l=-7,f=n?i-1:0,h=n?-1:1,p=t[e+f];for(f+=h,o=p&(1<<-l)-1,p>>=-l,l+=a;l>0;o=256*o+t[e+f],f+=h,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=r;l>0;s=256*s+t[e+f],f+=h,l-=8);if(0===o)o=1-u;else{if(o===c)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,r),o-=u}return(p?-1:1)*s*Math.pow(2,o-r)},e.write=function(t,e,n,r,i,o){var s,a,c,u=8*o-i-1,l=(1<>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:o-1,d=r?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),(e+=s+f>=1?h/c:h*Math.pow(2,1-f))*c>=2&&(s++,c/=2),s+f>=l?(a=0,s=l):s+f>=1?(a=(e*c-1)*Math.pow(2,i),s+=f):(a=e*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;t[n+p]=255&a,p+=d,a/=256,i-=8);for(s=s<0;t[n+p]=255&s,p+=d,s/=256,u-=8);t[n+p-d]|=128*g}},function(t,e){},function(t,e,n){"use strict";var r=n(2).Buffer,i=n(52);function o(t,e,n){t.copy(e,n)}t.exports=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.head=null,this.tail=null,this.length=0}return t.prototype.push=function(t){var e={data:t,next:null};this.length>0?this.tail.next=e:this.head=e,this.tail=e,++this.length},t.prototype.unshift=function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length},t.prototype.shift=function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}},t.prototype.clear=function(){this.head=this.tail=null,this.length=0},t.prototype.join=function(t){if(0===this.length)return"";for(var e=this.head,n=""+e.data;e=e.next;)n+=t+e.data;return n},t.prototype.concat=function(t){if(0===this.length)return r.alloc(0);if(1===this.length)return this.head.data;for(var e=r.allocUnsafe(t>>>0),n=this.head,i=0;n;)o(n.data,e,i),i+=n.data.length,n=n.next;return e},t}(),i&&i.inspect&&i.inspect.custom&&(t.exports.prototype[i.inspect.custom]=function(){var t=i.inspect({length:this.length});return this.constructor.name+" "+t})},function(t,e){},function(t,e,n){(function(t){var r=void 0!==t&&t||"undefined"!=typeof self&&self||window,i=Function.prototype.apply;function o(t,e){this._id=t,this._clearFn=e}e.setTimeout=function(){return new o(i.call(setTimeout,r,arguments),clearTimeout)},e.setInterval=function(){return new o(i.call(setInterval,r,arguments),clearInterval)},e.clearTimeout=e.clearInterval=function(t){t&&t.close()},o.prototype.unref=o.prototype.ref=function(){},o.prototype.close=function(){this._clearFn.call(r,this._id)},e.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},e.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},e._unrefActive=e.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;e>=0&&(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},e))},n(54),e.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==t&&t.setImmediate||this&&this.setImmediate,e.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==t&&t.clearImmediate||this&&this.clearImmediate}).call(this,n(1))},function(t,e,n){(function(t,e){!function(t,n){"use strict";if(!t.setImmediate){var r,i=1,o={},s=!1,a=t.document,c=Object.getPrototypeOf&&Object.getPrototypeOf(t);c=c&&c.setTimeout?c:t,"[object process]"==={}.toString.call(t.process)?r=function(t){e.nextTick(function(){l(t)})}:function(){if(t.postMessage&&!t.importScripts){var e=!0,n=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=n,e}}()?function(){var e="setImmediate$"+Math.random()+"$",n=function(n){n.source===t&&"string"==typeof n.data&&0===n.data.indexOf(e)&&l(+n.data.slice(e.length))};t.addEventListener?t.addEventListener("message",n,!1):t.attachEvent("onmessage",n),r=function(n){t.postMessage(e+n,"*")}}():t.MessageChannel?function(){var t=new MessageChannel;t.port1.onmessage=function(t){l(t.data)},r=function(e){t.port2.postMessage(e)}}():a&&"onreadystatechange"in a.createElement("script")?function(){var t=a.documentElement;r=function(e){var n=a.createElement("script");n.onreadystatechange=function(){l(e),n.onreadystatechange=null,t.removeChild(n),n=null},t.appendChild(n)}}():r=function(t){setTimeout(l,0,t)},c.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),n=0;n=0?u(l):i(this.length)-u(c(l));e0?1:-1}},function(t,e,n){"use strict";var r=n(9),i={function:!0,object:!0};t.exports=function(t){return r(t)&&i[typeof t]||!1}},function(t,e,n){"use strict";var r,i=Object.create;n(34)()||(r=n(35)),t.exports=function(){var t,e,n;return r?1!==r.level?i:(t={},e={},n={configurable:!1,enumerable:!1,writable:!0,value:void 0},Object.getOwnPropertyNames(Object.prototype).forEach(function(t){e[t]="__proto__"!==t?n:{configurable:!0,enumerable:!1,writable:!0,value:void 0}}),Object.defineProperties(t,e),Object.defineProperty(r,"nullPolyfill",{configurable:!1,enumerable:!1,writable:!1,value:t}),function(e,n){return i(null===e?t:e,n)}):i}()},function(t,e,n){"use strict";t.exports=function(){var t,e=Object.assign;return"function"==typeof e&&(e(t={foo:"raz"},{bar:"dwa"},{trzy:"trzy"}),t.foo+t.bar+t.trzy==="razdwatrzy")}},function(t,e,n){"use strict";var r=n(72),i=n(4),o=Math.max;t.exports=function(t,e){var n,s,a,c=o(arguments.length,2);for(t=Object(i(t)),a=function(r){try{t[r]=e[r]}catch(t){n||(n=t)}},s=1;s-1}},function(t,e,n){"use strict";var r,i,o,s,a,c,u,l=n(8),f=n(5),h=Function.prototype.apply,p=Function.prototype.call,d=Object.create,g=Object.defineProperty,_=Object.defineProperties,m=Object.prototype.hasOwnProperty,y={configurable:!0,enumerable:!1,writable:!0};a={on:r=function(t,e){var n;return f(e),m.call(this,"__ee__")?n=this.__ee__:(n=y.value=d(null),g(this,"__ee__",y),y.value=null),n[t]?"object"==typeof n[t]?n[t].push(e):n[t]=[n[t],e]:n[t]=e,this},once:i=function(t,e){var n,i;return f(e),i=this,r.call(this,t,n=function(){o.call(i,t,n),h.call(e,this,arguments)}),n.__eeOnceListener__=e,this},off:o=function(t,e){var n,r,i,o;if(f(e),!m.call(this,"__ee__"))return this;if(!(n=this.__ee__)[t])return this;if("object"==typeof(r=n[t]))for(o=0;i=r[o];++o)i!==e&&i.__eeOnceListener__!==e||(2===r.length?n[t]=r[o?0:1]:r.splice(o,1));else r!==e&&r.__eeOnceListener__!==e||delete n[t];return this},emit:s=function(t){var e,n,r,i,o;if(m.call(this,"__ee__")&&(i=this.__ee__[t]))if("object"==typeof i){for(n=arguments.length,o=new Array(n-1),e=1;e=55296&&_<=56319&&(g+=t[++p]),c.call(e,m,g,f),!h);++p);else u.call(t,function(t){return c.call(e,m,t,f),h})}},function(t,e,n){"use strict";var r=n(15),i=n(16),o=n(86),s=n(96),a=n(38),c=n(6).iterator;t.exports=function(t){return"function"==typeof a(t)[c]?t[c]():r(t)?new o(t):i(t)?new s(t):new o(t)}},function(t,e,n){"use strict";var r,i=n(14),o=n(37),s=n(8),a=n(6),c=n(21),u=Object.defineProperty;r=t.exports=function(t,e){if(!(this instanceof r))throw new TypeError("Constructor requires 'new'");c.call(this,t),e=e?o.call(e,"key+value")?"key+value":o.call(e,"key")?"key":"value":"value",u(this,"__kind__",s("",e))},i&&i(r,c),delete r.prototype.constructor,r.prototype=Object.create(c.prototype,{_resolve:s(function(t){return"value"===this.__kind__?this.__list__[t]:"key+value"===this.__kind__?[t,this.__list__[t]]:t})}),u(r.prototype,a.toStringTag,s("c","Array Iterator"))},function(t,e,n){"use strict";var r,i=n(88),o=n(36),s=n(5),a=n(93),c=n(5),u=n(4),l=Function.prototype.bind,f=Object.defineProperty,h=Object.prototype.hasOwnProperty;r=function(t,e,n){var r,o=u(e)&&c(e.value);return delete(r=i(e)).writable,delete r.value,r.get=function(){return!n.overwriteDefinition&&h.call(this,t)?o:(e.value=l.call(o,n.resolveContext?n.resolveContext(this):this),f(this,t,e),this[t])},r},t.exports=function(t){var e=o(arguments[1]);return null!=e.resolveContext&&s(e.resolveContext),a(t,function(t,n){return r(n,t,e)})}},function(t,e,n){"use strict";var r=n(89),i=n(20),o=n(4);t.exports=function(t){var e=Object(o(t)),n=arguments[1],s=Object(arguments[2]);if(e!==t&&!n)return e;var a={};return n?r(n,function(e){(s.ensure||e in t)&&(a[e]=t[e])}):i(a,t),a}},function(t,e,n){"use strict";t.exports=n(90)()?Array.from:n(91)},function(t,e,n){"use strict";t.exports=function(){var t,e,n=Array.from;return"function"==typeof n&&(e=n(t=["raz","dwa"]),Boolean(e&&e!==t&&"dwa"===e[1]))}},function(t,e,n){"use strict";var r=n(6).iterator,i=n(15),o=n(92),s=n(33),a=n(5),c=n(4),u=n(9),l=n(16),f=Array.isArray,h=Function.prototype.call,p={configurable:!0,enumerable:!0,writable:!0,value:null},d=Object.defineProperty;t.exports=function(t){var e,n,g,_,m,y,v,b,w,E,S=arguments[1],R=arguments[2];if(t=Object(c(t)),u(S)&&a(S),this&&this!==Array&&o(this))e=this;else{if(!S){if(i(t))return 1!==(m=t.length)?Array.apply(null,t):((_=new Array(1))[0]=t[0],_);if(f(t)){for(_=new Array(m=t.length),n=0;n=55296&&y<=56319&&(E+=t[++n]),E=S?h.call(S,R,E,g):E,e?(p.value=E,d(_,g,p)):_[g]=E,++g;m=g}if(void 0===m)for(m=s(t.length),e&&(_=new e(m)),n=0;n=55296&&e<=56319?n+this.__list__[this.__nextIndex__++]:n})}),c(r.prototype,s.toStringTag,o("c","String Iterator"))},function(t,e,n){"use strict";var r,i=n(14),o=n(8),s=n(21),a=n(6).toStringTag,c=n(98),u=Object.defineProperties,l=s.prototype._unBind;r=t.exports=function(t,e){if(!(this instanceof r))return new r(t,e);s.call(this,t.__mapKeysData__,t),e&&c[e]||(e="key+value"),u(this,{__kind__:o("",e),__values__:o("w",t.__mapValuesData__)})},i&&i(r,s),r.prototype=Object.create(s.prototype,{constructor:o(r),_resolve:o(function(t){return"value"===this.__kind__?this.__values__[t]:"key"===this.__kind__?this.__list__[t]:[this.__list__[t],this.__values__[t]]}),_unBind:o(function(){this.__values__=null,l.call(this)}),toString:o(function(){return"[object Map Iterator]"})}),Object.defineProperty(r.prototype,a,o("c","Map Iterator"))},function(t,e,n){"use strict";t.exports=n(99)("key","value","key+value")},function(t,e,n){"use strict";var r=Array.prototype.forEach,i=Object.create;t.exports=function(t){var e=i(null);return r.call(arguments,function(t){e[t]=!0}),e}},function(t,e,n){"use strict";t.exports="undefined"!=typeof Map&&"[object Map]"===Object.prototype.toString.call(new Map)},function(t,e,n){var r=n(102);function i(t){var e=function(){return e.called?e.value:(e.called=!0,e.value=t.apply(this,arguments))};return e.called=!1,e}function o(t){var e=function(){if(e.called)throw new Error(e.onceError);return e.called=!0,e.value=t.apply(this,arguments)},n=t.name||"Function wrapped with `once`";return e.onceError=n+" shouldn't be called more than once",e.called=!1,e}t.exports=r(i),t.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(t,e){t.exports=function t(e,n){if(e&&n)return t(e)(n);if("function"!=typeof e)throw new TypeError("need wrapper function");Object.keys(e).forEach(function(t){r[t]=e[t]});return r;function r(){for(var t=new Array(arguments.length),n=0;n0)&&this[this._states[this._stateCounter]]()&&!this.error;)this._stateCounter++,this._stateCounter>=this._states.length&&(this._stateCounter=0);return this._list.length},c.prototype._parseHeader=function(){var t=this._list.readUInt8(0);return this.packet.cmd=a.types[t>>a.CMD_SHIFT],this.packet.retain=0!=(t&a.RETAIN_MASK),this.packet.qos=t>>a.QOS_SHIFT&a.QOS_MASK,this.packet.dup=0!=(t&a.DUP_MASK),this._list.consume(1),!0},c.prototype._parseLength=function(){for(var t,e=0,n=1,r=0,i=!0;e<5&&(r+=n*((t=this._list.readUInt8(e++))&a.LENGTH_MASK),n*=128,0!=(t&a.LENGTH_FIN_MASK));)if(this._list.length<=e){i=!1;break}return i&&(this.packet.length=r,this._list.consume(e)),i},c.prototype._parsePayload=function(){var t=!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._parseMessageId();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":case"disconnect":break;default:this._emitError(new Error("Not supported"))}t=!0}return t},c.prototype._parseConnect=function(){var t,e,n,r,i,o,s={},c=this.packet;if(null===(t=this._parseString()))return this._emitError(new Error("Cannot parse protocolId"));if("MQTT"!==t&&"MQIsdp"!==t)return this._emitError(new Error("Invalid protocolId"));if(c.protocolId=t,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(c.protocolVersion=this._list.readUInt8(this._pos),3!==c.protocolVersion&&4!==c.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(s.username=this._list.readUInt8(this._pos)&a.USERNAME_MASK,s.password=this._list.readUInt8(this._pos)&a.PASSWORD_MASK,s.will=this._list.readUInt8(this._pos)&a.WILL_FLAG_MASK,s.will&&(c.will={},c.will.retain=0!=(this._list.readUInt8(this._pos)&a.WILL_RETAIN_MASK),c.will.qos=(this._list.readUInt8(this._pos)&a.WILL_QOS_MASK)>>a.WILL_QOS_SHIFT),c.clean=0!=(this._list.readUInt8(this._pos)&a.CLEAN_SESSION_MASK),this._pos++,c.keepalive=this._parseNum(),-1===c.keepalive)return this._emitError(new Error("Packet too short"));if(null===(e=this._parseString()))return this._emitError(new Error("Packet too short"));if(c.clientId=e,s.will){if(null===(n=this._parseString()))return this._emitError(new Error("Cannot parse will topic"));if(c.will.topic=n,null===(r=this._parseBuffer()))return this._emitError(new Error("Cannot parse will payload"));c.will.payload=r}if(s.username){if(null===(o=this._parseString()))return this._emitError(new Error("Cannot parse username"));c.username=o}if(s.password){if(null===(i=this._parseBuffer()))return this._emitError(new Error("Cannot parse password"));c.password=i}return c},c.prototype._parseConnack=function(){var t=this.packet;return this._list.length<2?null:(t.sessionPresent=!!(this._list.readUInt8(this._pos++)&a.SESSIONPRESENT_MASK),t.returnCode=this._list.readUInt8(this._pos),-1===t.returnCode?this._emitError(new Error("Cannot parse return code")):void 0)},c.prototype._parsePublish=function(){var t=this.packet;if(t.topic=this._parseString(),null===t.topic)return this._emitError(new Error("Cannot parse topic"));t.qos>0&&!this._parseMessageId()||(t.payload=this._list.slice(this._pos,t.length))},c.prototype._parseSubscribe=function(){var t,e,n=this.packet;if(1!==n.qos)return this._emitError(new Error("Wrong subscribe header"));if(n.subscriptions=[],this._parseMessageId())for(;this._posthis._list.length||r>this.packet.length?null:(e=this._list.toString("utf8",this._pos,r),this._pos+=n,e)},c.prototype._parseBuffer=function(){var t,e=this._parseNum(),n=e+this._pos;return-1===e||n>this._list.length||n>this.packet.length?null:(t=this._list.slice(this._pos,n),this._pos+=e,t)},c.prototype._parseNum=function(){if(this._list.length-this._pos<2)return-1;var t=this._list.readUInt16BE(this._pos);return this._pos+=2,t},c.prototype._newPacket=function(){return this.packet&&(this._list.consume(this.packet.length),this.emit("packet",this.packet)),this.packet=new s,!0},c.prototype._emitError=function(t){this.error=t,this.emit("error",t)},t.exports=c},function(t,e,n){var r=n(106),i=n(107),o=n(2).Buffer;function s(t){if(!(this instanceof s))return new s(t);if(this._bufs=[],this.length=0,"function"==typeof t){this._callback=t;var e=function(t){this._callback&&(this._callback(t),this._callback=null)}.bind(this);this.on("pipe",function(t){t.on("error",e)}),this.on("unpipe",function(t){t.removeListener("error",e)})}else this.append(t);r.call(this)}i.inherits(s,r),s.prototype._offset=function(t){var e,n=0,r=0;if(0===t)return[0,0];for(;rthis.length)&&(r=this.length),n>=this.length)return t||o.alloc(0);if(r<=0)return t||o.alloc(0);var i,s,a=!!t,c=this._offset(n),u=r-n,l=u,f=a&&e||0,h=c[1];if(0===n&&r==this.length){if(!a)return 1===this._bufs.length?this._bufs[0]:o.concat(this._bufs,this.length);for(s=0;s(i=this._bufs[s].length-h))){this._bufs[s].copy(t,f,h,h+l);break}this._bufs[s].copy(t,f,h),f+=i,l-=i,h&&(h=0)}return t},s.prototype.shallowSlice=function(t,e){t=t||0,e=e||this.length,t<0&&(t+=this.length),e<0&&(e+=this.length);var n=this._offset(t),r=this._offset(e),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])),new s(i)},s.prototype.toString=function(t,e,n){return this.slice(e,n).toString(t)},s.prototype.consume=function(t){for(;this._bufs.length;){if(!(t>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(t),this.length-=t;break}t-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},s.prototype.duplicate=function(){for(var t=0,e=new s;t=o)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return t}}),c=r[n];n=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),d(n)?r.showHidden=n:n&&e._extend(r,n),y(r.showHidden)&&(r.showHidden=!1),y(r.depth)&&(r.depth=2),y(r.colors)&&(r.colors=!1),y(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=c),l(r,t,r.depth)}function c(t,e){var n=a.styles[e];return n?"["+a.colors[n][0]+"m"+t+"["+a.colors[n][1]+"m":t}function u(t,e){return t}function l(t,n,r){if(t.customInspect&&n&&S(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,t);return m(i)||(i=l(t,i,r)),i}var o=function(t,e){if(y(e))return t.stylize("undefined","undefined");if(m(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}if(_(e))return t.stylize(""+e,"number");if(d(e))return t.stylize(""+e,"boolean");if(g(e))return t.stylize("null","null")}(t,n);if(o)return o;var s=Object.keys(n),a=function(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(n)),E(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return f(n);if(0===s.length){if(S(n)){var c=n.name?": "+n.name:"";return t.stylize("[Function"+c+"]","special")}if(v(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(w(n))return t.stylize(Date.prototype.toString.call(n),"date");if(E(n))return f(n)}var u,b="",R=!1,A=["{","}"];(p(n)&&(R=!0,A=["[","]"]),S(n))&&(b=" [Function"+(n.name?": "+n.name:"")+"]");return v(n)&&(b=" "+RegExp.prototype.toString.call(n)),w(n)&&(b=" "+Date.prototype.toUTCString.call(n)),E(n)&&(b=" "+f(n)),0!==s.length||R&&0!=n.length?r<0?v(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special"):(t.seen.push(n),u=R?function(t,e,n,r,i){for(var o=[],s=0,a=e.length;s=0&&0,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60)return n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1];return n[0]+e+" "+t.join(", ")+" "+n[1]}(u,b,A)):A[0]+b+A[1]}function f(t){return"["+Error.prototype.toString.call(t)+"]"}function h(t,e,n,r,i,o){var s,a,c;if((c=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]}).get?a=c.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):c.set&&(a=t.stylize("[Setter]","special")),I(r,i)||(s="["+i+"]"),a||(t.seen.indexOf(c.value)<0?(a=g(n)?l(t,c.value,null):l(t,c.value,n-1)).indexOf("\n")>-1&&(a=o?a.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+a.split("\n").map(function(t){return" "+t}).join("\n")):a=t.stylize("[Circular]","special")),y(s)){if(o&&i.match(/^\d+$/))return a;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+a}function p(t){return Array.isArray(t)}function d(t){return"boolean"==typeof t}function g(t){return null===t}function _(t){return"number"==typeof t}function m(t){return"string"==typeof t}function y(t){return void 0===t}function v(t){return b(t)&&"[object RegExp]"===R(t)}function b(t){return"object"==typeof t&&null!==t}function w(t){return b(t)&&"[object Date]"===R(t)}function E(t){return b(t)&&("[object Error]"===R(t)||t instanceof Error)}function S(t){return"function"==typeof t}function R(t){return Object.prototype.toString.call(t)}function A(t){return t<10?"0"+t.toString(10):t.toString(10)}e.debuglog=function(t){if(y(o)&&(o=r.env.NODE_DEBUG||""),t=t.toUpperCase(),!s[t])if(new RegExp("\\b"+t+"\\b","i").test(o)){var n=r.pid;s[t]=function(){var r=e.format.apply(e,arguments);console.error("%s %d: %s",t,n,r)}}else s[t]=function(){};return s[t]},e.inspect=a,a.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},a.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},e.isArray=p,e.isBoolean=d,e.isNull=g,e.isNullOrUndefined=function(t){return null==t},e.isNumber=_,e.isString=m,e.isSymbol=function(t){return"symbol"==typeof t},e.isUndefined=y,e.isRegExp=v,e.isObject=b,e.isDate=w,e.isError=E,e.isFunction=S,e.isPrimitive=function(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t},e.isBuffer=n(108);var T=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function I(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.log=function(){console.log("%s - %s",function(){var t=new Date,e=[A(t.getHours()),A(t.getMinutes()),A(t.getSeconds())].join(":");return[t.getDate(),T[t.getMonth()],e].join(" ")}(),e.format.apply(e,arguments))},e.inherits=n(3),e._extend=function(t,e){if(!e||!b(e))return t;for(var n=Object.keys(e),r=n.length;r--;)t[n[r]]=e[n[r]];return t}}).call(this,n(1),n(0))},function(t,e){t.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},function(t,e){t.exports=function(){this.cmd=null,this.retain=!1,this.qos=0,this.dup=!1,this.length=-1,this.topic=null,this.payload=null}},function(t,e,n){"use strict";var r=n(2).Buffer,i=n(41),o=n(10).EventEmitter;function s(){this._array=new Array(20),this._i=0}n(3)(s,o),s.prototype.write=function(t){return this._array[this._i++]=t,!0},s.prototype.concat=function(){var t,e,n=0,i=new Array(this._array.length),o=this._array,s=0;for(t=0;t>8,0),e.writeUInt8(255&t,1),e}t.exports={cache:o,generateCache:function(){for(var t=0;t0){t=new Array(arguments.length-2);for(var e=0;e= 0x80 (not a basic code point)","invalid-input":"Invalid input"},w=u-l,E=Math.floor,S=String.fromCharCode;function R(t){throw new RangeError(b[t])}function A(t,e){for(var n=t.length,r=[];n--;)r[n]=e(t[n]);return r}function T(t,e){var n=t.split("@"),r="";return n.length>1&&(r=n[0]+"@",t=n[1]),r+A((t=t.replace(v,".")).split("."),e).join(".")}function I(t){for(var e,n,r=[],i=0,o=t.length;i=55296&&e<=56319&&i65535&&(e+=S((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=S(t)}).join("")}function C(t){return t-48<10?t-22:t-65<26?t-65:t-97<26?t-97:u}function x(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function k(t,e,n){var r=0;for(t=n?E(t/p):t>>1,t+=E(t/e);t>w*f>>1;r+=u)t=E(t/w);return E(r+(w+1)*t/(t+h))}function N(t){var e,n,r,i,o,s,a,h,p,m,y=[],v=t.length,b=0,w=g,S=d;for((n=t.lastIndexOf(_))<0&&(n=0),r=0;r=128&&R("not-basic"),y.push(t.charCodeAt(r));for(i=n>0?n+1:0;i=v&&R("invalid-input"),((h=C(t.charCodeAt(i++)))>=u||h>E((c-b)/s))&&R("overflow"),b+=h*s,!(h<(p=a<=S?l:a>=S+f?f:a-S));a+=u)s>E(c/(m=u-p))&&R("overflow"),s*=m;S=k(b-o,e=y.length+1,0==o),E(b/e)>c-w&&R("overflow"),w+=E(b/e),b%=e,y.splice(b++,0,w)}return O(y)}function P(t){var e,n,r,i,o,s,a,h,p,m,y,v,b,w,A,T=[];for(v=(t=I(t)).length,e=g,n=0,o=d,s=0;s=e&&yE((c-n)/(b=r+1))&&R("overflow"),n+=(a-e)*b,e=a,s=0;sc&&R("overflow"),y==e){for(h=n,p=u;!(h<(m=p<=o?l:p>=o+f?f:p-o));p+=u)A=h-m,w=u-m,T.push(S(x(m+A%w,0))),h=E(A/w);T.push(S(x(h,0))),o=k(n,b,r==i),n=0,++r}++n,++e}return T.join("")}a={version:"1.4.1",ucs2:{decode:I,encode:O},decode:N,encode:P,toASCII:function(t){return T(t,function(t){return y.test(t)?"xn--"+P(t):t})},toUnicode:function(t){return T(t,function(t){return m.test(t)?N(t.slice(4).toLowerCase()):t})}},void 0===(i=function(){return a}.call(e,n,e,t))||(t.exports=i)}()}).call(this,n(115)(t),n(1))},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,n){"use strict";t.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},function(t,e,n){"use strict";e.decode=e.parse=n(118),e.encode=e.stringify=n(119)},function(t,e,n){"use strict";function r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.exports=function(t,e,n,o){e=e||"&",n=n||"=";var s={};if("string"!=typeof t||0===t.length)return s;var a=/\+/g;t=t.split(e);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var u=t.length;c>0&&u>c&&(u=c);for(var l=0;l=0?(f=g.substr(0,_),h=g.substr(_+1)):(f=g,h=""),p=decodeURIComponent(f),d=decodeURIComponent(h),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(t){return"[object Array]"===Object.prototype.toString.call(t)}},function(t,e,n){"use strict";var r=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};t.exports=function(t,e,n,a){return e=e||"&",n=n||"=",null===t&&(t=void 0),"object"==typeof t?o(s(t),function(s){var a=encodeURIComponent(r(s))+n;return i(t[s])?o(t[s],function(t){return a+encodeURIComponent(r(t))}).join(e):a+encodeURIComponent(r(t[s]))}).join(e):a?encodeURIComponent(r(a))+n+encodeURIComponent(r(t)):""};var i=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function o(t,e){if(t.map)return t.map(e);for(var n=[],r=0;r p {\n line-height: 1; }\n",""])},function(t,e){t.exports=function(t){return"string"!=typeof t?t:(/^['"].*['"]$/.test(t)&&(t=t.slice(1,-1)),/["'() \t\n]/.test(t)?'"'+t.replace(/"/g,'\\"').replace(/\n/g,"\\n")+'"':t)}},function(t,e){t.exports=function(t){var e=[];return e.toString=function(){return this.map(function(e){var n=function(t,e){var n=t[1]||"",r=t[3];if(!r)return n;if(e&&"function"==typeof btoa){var i=function(t){return"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(t))))+" */"}(r),o=r.sources.map(function(t){return"/*# sourceURL="+r.sourceRoot+t+" */"});return[n].concat(o).concat([i]).join("\n")}return[n].join("\n")}(e,t);return e[2]?"@media "+e[2]+"{"+n+"}":n}).join("")},e.i=function(t,n){"string"==typeof t&&(t=[[null,t,""]]);for(var r={},i=0;i=0&&c.splice(e,1)}function d(t){var e=document.createElement("style");if(void 0===t.attrs.type&&(t.attrs.type="text/css"),void 0===t.attrs.nonce){var r=function(){0;return n.nc}();r&&(t.attrs.nonce=r)}return g(e,t.attrs),h(t,e),e}function g(t,e){Object.keys(e).forEach(function(n){t.setAttribute(n,e[n])})}function _(t,e){var n,r,i,o;if(e.transform&&t.css){if(!(o="function"==typeof e.transform?e.transform(t.css):e.transform.default(t.css)))return function(){};t.css=o}if(e.singleton){var c=a++;n=s||(s=d(e)),r=y.bind(null,n,c,!1),i=y.bind(null,n,c,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(t){var e=document.createElement("link");return void 0===t.attrs.type&&(t.attrs.type="text/css"),t.attrs.rel="stylesheet",g(e,t.attrs),h(t,e),e}(e),r=function(t,e,n){var r=n.css,i=n.sourceMap,o=void 0===e.convertToAbsoluteUrls&&i;(e.convertToAbsoluteUrls||o)&&(r=u(r));i&&(r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(i))))+" */");var s=new Blob([r],{type:"text/css"}),a=t.href;t.href=URL.createObjectURL(s),a&&URL.revokeObjectURL(a)}.bind(null,n,e),i=function(){p(n),n.href&&URL.revokeObjectURL(n.href)}):(n=d(e),r=function(t,e){var n=e.css,r=e.media;r&&t.setAttribute("media",r);if(t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}.bind(null,n),i=function(){p(n)});return r(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;r(t=e)}else i()}}t.exports=function(t,e){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(e=e||{}).attrs="object"==typeof e.attrs?e.attrs:{},e.singleton||"boolean"==typeof e.singleton||(e.singleton=i()),e.insertInto||(e.insertInto="head"),e.insertAt||(e.insertAt="bottom");var n=f(t,e);return l(n,e),function(t){for(var i=[],o=0;o2;)o.push(arguments[u]);for(e&&null!=e.children&&(o.length||o.push(e.children),delete e.children);o.length;)if((a=o.pop())&&void 0!==a.pop)for(u=a.length;u--;)o.push(a[u]);else"boolean"==typeof a&&(a=null),(c="function"!=typeof t)&&(null==a?a="":"number"==typeof a?a=String(a):"string"!=typeof a&&(c=!1)),c&&n?l[l.length-1]+=a:l===s?l=[a]:l.push(a),n=c;var f=new r;return f.nodeName=t,f.children=l,f.attributes=null==e?void 0:e,f.key=null==e?void 0:e.key,void 0!==i.vnode&&i.vnode(f),f}function c(t,e){for(var n in e)t[n]=e[n];return t}var u="function"==typeof Promise?Promise.resolve().then.bind(Promise.resolve()):setTimeout;var l=/acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,f=[];function h(t){!t._dirty&&(t._dirty=!0)&&1==f.push(t)&&(i.debounceRendering||u)(p)}function p(){var t,e=f;for(f=[];t=e.pop();)t._dirty&&P(t)}function d(t,e,n){return"string"==typeof e||"number"==typeof e?void 0!==t.splitText:"string"==typeof e.nodeName?!t._componentConstructor&&g(t,e.nodeName):n||t._componentConstructor===e.nodeName}function g(t,e){return t.normalizedNodeName===e||t.nodeName.toLowerCase()===e.toLowerCase()}function _(t){var e=c({},t.attributes);e.children=t.children;var n=t.nodeName.defaultProps;if(void 0!==n)for(var r in n)void 0===e[r]&&(e[r]=n[r]);return e}function m(t){var e=t.parentNode;e&&e.removeChild(t)}function y(t,e,n,r,i){if("className"===e&&(e="class"),"key"===e);else if("ref"===e)n&&n(null),r&&r(t);else if("class"!==e||i)if("style"===e){if(r&&"string"!=typeof r&&"string"!=typeof n||(t.style.cssText=r||""),r&&"object"==typeof r){if("string"!=typeof n)for(var o in n)o in r||(t.style[o]="");for(var o in r)t.style[o]="number"==typeof r[o]&&!1===l.test(o)?r[o]+"px":r[o]}}else if("dangerouslySetInnerHTML"===e)r&&(t.innerHTML=r.__html||"");else if("o"==e[0]&&"n"==e[1]){var s=e!==(e=e.replace(/Capture$/,""));e=e.toLowerCase().substring(2),r?n||t.addEventListener(e,v,s):t.removeEventListener(e,v,s),(t._listeners||(t._listeners={}))[e]=r}else if("list"!==e&&"type"!==e&&!i&&e in t){try{t[e]=null==r?"":r}catch(t){}null!=r&&!1!==r||"spellcheck"==e||t.removeAttribute(e)}else{var a=i&&e!==(e=e.replace(/^xlink:?/,""));null==r||!1===r?a?t.removeAttributeNS("http://www.w3.org/1999/xlink",e.toLowerCase()):t.removeAttribute(e):"function"!=typeof r&&(a?t.setAttributeNS("http://www.w3.org/1999/xlink",e.toLowerCase(),r):t.setAttribute(e,r))}else t.className=r||""}function v(t){return this._listeners[t.type](i.event&&i.event(t)||t)}var b=[],w=0,E=!1,S=!1;function R(){for(var t;t=b.pop();)i.afterMount&&i.afterMount(t),t.componentDidMount&&t.componentDidMount()}function A(t,e,n,r,i,o){w++||(E=null!=i&&void 0!==i.ownerSVGElement,S=null!=t&&!("__preactattr_"in t));var s=T(t,e,n,r,o);return i&&s.parentNode!==i&&i.appendChild(s),--w||(S=!1,o||R()),s}function T(t,e,n,r,i){var o=t,s=E;if(null!=e&&"boolean"!=typeof e||(e=""),"string"==typeof e||"number"==typeof e)return t&&void 0!==t.splitText&&t.parentNode&&(!t._component||i)?t.nodeValue!=e&&(t.nodeValue=e):(o=document.createTextNode(e),t&&(t.parentNode&&t.parentNode.replaceChild(o,t),I(t,!0))),o.__preactattr_=!0,o;var a=e.nodeName;if("function"==typeof a)return function(t,e,n,r){var i=t&&t._component,o=i,s=t,a=i&&t._componentConstructor===e.nodeName,c=a,u=_(e);for(;i&&!c&&(i=i._parentComponent);)c=i.constructor===e.nodeName;i&&c&&(!r||i._component)?(N(i,u,3,n,r),t=i.base):(o&&!a&&(M(o),t=s=null),i=x(e.nodeName,u,n),t&&!i.nextBase&&(i.nextBase=t,s=null),N(i,u,1,n,r),t=i.base,s&&t!==s&&(s._component=null,I(s,!1)));return t}(t,e,n,r);if(E="svg"===a||"foreignObject"!==a&&E,a=String(a),(!t||!g(t,a))&&(o=function(t,e){var n=e?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t);return n.normalizedNodeName=t,n}(a,E),t)){for(;t.firstChild;)o.appendChild(t.firstChild);t.parentNode&&t.parentNode.replaceChild(o,t),I(t,!0)}var c=o.firstChild,u=o.__preactattr_,l=e.children;if(null==u){u=o.__preactattr_={};for(var f=o.attributes,h=f.length;h--;)u[f[h].name]=f[h].value}return!S&&l&&1===l.length&&"string"==typeof l[0]&&null!=c&&void 0!==c.splitText&&null==c.nextSibling?c.nodeValue!=l[0]&&(c.nodeValue=l[0]):(l&&l.length||null!=c)&&function(t,e,n,r,i){var o,s,a,c,u,l=t.childNodes,f=[],h={},p=0,g=0,_=l.length,y=0,v=e?e.length:0;if(0!==_)for(var b=0;b<_;b++){var w=l[b],E=w.__preactattr_,S=v&&E?w._component?w._component.__key:E.key:null;null!=S?(p++,h[S]=w):(E||(void 0!==w.splitText?!i||w.nodeValue.trim():i))&&(f[y++]=w)}if(0!==v)for(var b=0;b0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"--";return function(r){if(!r)return n;var i=Number(r)*e;return void 0===t?i.toString():i.toFixed(t)}}var D,B={GENERAL:{SERIAL:"/Serial",DEVICE_INSTANCE:"/DeviceInstance"},BATTERY:{CURRENT:"/Dc/Battery/Current",POWER:"/Dc/Battery/Power",VOLTAGE:"/Dc/Battery/Voltage",SOC:"/Dc/Battery/Soc",CIRCUIT_BREAKER_ALARM:"/Dc/Battery/Alarms/CircuitBreakerTripped",CONSUMED_AMP_HOURRS:"/Dc/Battery/ConsumedAmphours",STATE:"/Dc/Battery/State",TIME_TO_GO:"/Dc/Battery/TimeToGo"},SOLAR_CHARGERS:{CURRENT:"/Dc/Pv/Current",POWER:"/Dc/Pv/Power"},INVERTER_CHARGER:{DC_LOADS:{CURRENT:"/Dc/Vebus/Current",POWER:"/Dc/Vebus/Power"},AC_LOADS:{CURRENT:"/Ac/Out/L1/I",POWER:"/Ac/Out/L1/V",VOLTAGE:"/Ac/Out/L1/P",CONSUMPTION_OUTPUT_L1_POWER:"/Ac/ConsumptionOnOutput/L1/Power",CONSUMPTION_OUTPUT_L2_POWER:"/Ac/ConsumptionOnOutput/L2/Power",CONSUMPTION_OUTPUT_L3_POWER:"/Ac/ConsumptionOnOutput/L3/Power"},AC_SOURCE:"/Ac/ActiveIn/Source",SHORE_POWER:{IS_CONNECTED:"/Ac/ActiveIn/Connected",VOLTAGE:"/Ac/ActiveIn/L1/V",CURRENT:"/Ac/ActiveIn/L1/I",POWER:"/Ac/ActiveIn/L1/P",CURRENT_LIMIT:"/Ac/ActiveIn/CurrentLimit",AC_GRID_L1_POWER:"/Ac/Grid/L1/Power",AC_GRID_L2_POWER:"/Ac/Grid/L2/Power",AC_GRID_L3_POWER:"/Ac/Grid/L3/Power"},GENERATOR:{AC_GENSET_L1_POWER:"/Ac/Genset/L1/Power",AC_GENSET_L2_POWER:"/Ac/Genset/L2/Power",AC_GENSET_L3_POWER:"/Ac/Genset/L3/Power"},SYSTEM:{STATE:"/SystemState/State",MODE:"/Mode",STATES:{CHARGER_ONLY:1,INVERTER_ONLY:2,ON:3,OFF:4},AC_NUMBER_OF_PHASES:"/Ac/Consumption/NumberOfPhases",VEBUS_SERVICE:"/VebusService"}}};function H(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var q=(H(D={},B.BATTERY.VOLTAGE,{description:"Voltage",unit:"V",formatter:U(1),timeout:0}),H(D,B.BATTERY.CURRENT,{description:"Current",unit:"A",formatter:U(1),timeout:0}),H(D,B.BATTERY.POWER,{description:"Power",unit:"W",formatter:U(),timeout:0}),H(D,B.BATTERY.SOC,{description:"State of charge",unit:"%",formatter:U(),timeout:0}),H(D,B.INVERTER_CHARGER.DC_LOADS.CURRENT,{description:"DC loads current",unit:"A",formatter:U(1),timeout:0}),H(D,B.INVERTER_CHARGER.DC_LOADS.POWER,{description:"DC loads power",unit:"W",formatter:U(),timeout:0}),H(D,B.INVERTER_CHARGER.AC_LOADS.VOLTAGE,{description:"AC loads voltage",unit:"V",formatter:U(),timeout:0}),H(D,B.INVERTER_CHARGER.AC_LOADS.CURRENT,{description:"AC loads current",unit:"A",formatter:U(1),timeout:0}),H(D,B.INVERTER_CHARGER.AC_LOADS.POWER,{description:"AC loads power",unit:"W",formatter:U(),timeout:0}),H(D,B.INVERTER_CHARGER.SHORE_POWER.IS_CONNECTED,{description:"Grid is connected",formatter:U()}),H(D,B.INVERTER_CHARGER.SHORE_POWER.VOLTAGE,{description:"Grid voltage",unit:"V",formatter:U(),timeout:0}),H(D,B.INVERTER_CHARGER.SHORE_POWER.CURRENT,{description:"Grid current",unit:"A",formatter:U(1),timeout:0}),H(D,B.INVERTER_CHARGER.SHORE_POWER.CURRENT_LIMIT,{description:"Grid input limit",unit:"A",formatter:U(),timeout:0,write:!0}),H(D,B.INVERTER_CHARGER.SHORE_POWER.POWER,{description:"Grid power",unit:"W",formatter:U(),timeout:0}),H(D,B.INVERTER_CHARGER.SYSTEM.STATE,{description:"System state",unit:"",formatter:function(t){return 0==t?"Off":1==t?"Low power":2==t?"VE.Bus Fault condition":3==t?"Bulk charging":4==t?"Absorption charging":5==t?"Float charging":6==t?"Storage mode":7==t?"Equalisation charging":8==t?"Passthru":9==t?"Inverting":10==t?"Assisting":256==t?"Discharging":257==t?"Sustain":"--"},timeout:0}),H(D,B.INVERTER_CHARGER.SYSTEM.MODE,{description:"System mode",unit:"",formatter:function(t){return 1==t?"Charger only":2==t?"Inverter only":3==t?"ON":4==t?"OFF":"--"},timeout:0,write:!0}),H(D,B.INVERTER_CHARGER.AC_SOURCE,{unit:"",formatter:function(t){return 0==t?"Not Available":1==t?"Grid Input":2==t?"Generator":3==t?"Shore Power":240==t?"Inverting":"Ac Input Mode"},timeout:0}),D),V=n(17),G=function(t){var e=t.split("/");return{type:e[0],portalId:e[1],serviceType:e[2],deviceInstance:parseInt(e[3]),dbusPath:"/"+e.splice(4).join("/")}},W=function(t,e){var n;try{n=JSON.parse(e.toString())}catch(r){n={},console.error(t,"[".concat(e.toString(),"]"),r)}return{path:G(t).dbusPath,value:n.value||null}};function Y(t){return Object.keys(t).map(function(e){return t[e]})}var F=function(t,e){return-1!==Y(e).indexOf(t)},z=function(t){return t.reduce(function(t,e){return t[e]=0,t},{})},K={SYSTEM:Y(B.GENERAL).concat(Y(B.BATTERY)).concat(Y(B.SOLAR_CHARGERS)).concat(Y(B.INVERTER_CHARGER.DC_LOADS)).concat(B.INVERTER_CHARGER.SYSTEM.STATE).concat(B.INVERTER_CHARGER.SYSTEM.VEBUS_SERVICE).concat(B.INVERTER_CHARGER.AC_SOURCE),VEBUS:Y(B.INVERTER_CHARGER.AC_LOADS).concat(Y(B.INVERTER_CHARGER.SHORE_POWER)).concat(B.INVERTER_CHARGER.SYSTEM.MODE).concat(Y(B.INVERTER_CHARGER.GENERATOR)).concat([B.INVERTER_CHARGER.SYSTEM.AC_NUMBER_OF_PHASES])},J={ALL:"N/#",SERIAL:"N/+/system/0/Serial",ALL_DEVICES_CONNECTED:"N/+/+/+/ProductId",ALL_DEVICE_INSTANCES:"N/+/+/+/DeviceInstance"};function Q(t,e){for(var n=0;n150?bt:vt;return a("div",{className:"metric-component metric-component--small"},e.selectorVisible?i.map(function(e){return a("button",{className:"metrics-selector-button amperage-selector-button"+(parseInt(t.currentLimit)==e?" metrics-selector-button--active":""),href:"#",onClick:function(){return n.setAmperage(e)}},e)}):a("button",{className:"metrics-selector-button amperage-selector-button",onclick:this.toggleSelector},a("span",{className:"select-shore-input-limit"},"Select shore input limit:"),t.currentLimit))}}]),e}(),Ot=function(t){function e(){var t,n;ut(this,e);for(var r=arguments.length,i=new Array(r),o=0;o0?"Charging":"Draining";return a("div",{className:"metric-component battery-component"},a("div",{className:"metrics-left-container"},a("img",{src:"./images/icons/icon_battery.svg",className:"metric-icon"}),a("div",{className:"metrics-container"},a("p",null,"Battery"),a("div",{className:"metrics"},a(At,{value:t.voltage,connected:t.connected}),a(At,{value:t.current,connected:t.connected}),a(At,{value:t.power,connected:t.connected})))),a("div",{className:"battery-level-container"},a("div",{className:"text-bottom-align"},a("p",{className:"battery-level"},parseInt(t.soc)),a("p",{className:"charging-state"},"% ",n))))}}]),e}(),xt=function(t){function e(){return ut(this,e),ht(this,pt(e).apply(this,arguments))}return dt(e,L),ft(e,[{key:"render",value:function(t,e){return a("div",{className:"metric-component metric-component--small"},a("img",{src:"./images/icons/icon_ac.svg",className:"metric-icon"}),a("div",{className:"metrics-container"},a("p",null,"AC Loads"),a("div",{className:"metrics"},a(At,{value:t.voltage,connected:t.connected}),a(At,{value:t.current,connected:t.connected}),a(At,{value:t.power,connected:t.connected}))))}}]),e}(),kt=function(t){function e(){return ut(this,e),ht(this,pt(e).apply(this,arguments))}return dt(e,L),ft(e,[{key:"render",value:function(t,e){return a("div",{className:"metric-component metric-component--small"},a("img",{src:"./images/icons/icon_dc@1x.svg",className:"metric-icon"}),a("div",{className:"metrics-container"},a("p",null,"DC Loads"),a("div",{className:"metrics"},a(At,{value:t.current,connected:t.connected}),a(At,{value:t.power,connected:t.connected}))))}}]),e}();j(a(Rt,null),document.body)}]); \ No newline at end of file diff --git a/jestconfig.json b/jestconfig.json index e1bb70c17..7120ea982 100644 --- a/jestconfig.json +++ b/jestconfig.json @@ -1,7 +1,4 @@ { - "transform": { - "^.+\\.(t|j)sx?$": "ts-jest" - }, - "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", - "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"] + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?)$", + "moduleFileExtensions": ["js", "jsx", "json", "node"] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 30246a507..42cde9384 100644 --- a/package-lock.json +++ b/package-lock.json @@ -396,15 +396,6 @@ "@babel/helper-plugin-utils": "^7.0.0" } }, - "@babel/plugin-syntax-typescript": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.0.0.tgz", - "integrity": "sha512-5fxmdqiAQVQTIS+KSvYeZuTt91wKtBTYi6JlIkvbQ6hmO+9fZE81ezxmMiFMIsxE7CdRSgzn7nQ1BChcvK9OpA==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, "@babel/plugin-transform-arrow-functions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.0.0.tgz", @@ -663,16 +654,6 @@ "@babel/helper-plugin-utils": "^7.0.0" } }, - "@babel/plugin-transform-typescript": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.1.0.tgz", - "integrity": "sha512-TOTtVeT+fekAesiCHnPz+PSkYSdOSLyLn42DI45nxg6iCdlQY6LIj/tYqpMB0y+YicoTUiYiXqF8rG6SKfhw6Q==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/plugin-syntax-typescript": "^7.0.0" - } - }, "@babel/plugin-transform-unicode-regex": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.0.0.tgz", @@ -733,16 +714,6 @@ "semver": "^5.3.0" } }, - "@babel/preset-typescript": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.1.0.tgz", - "integrity": "sha512-LYveByuF9AOM8WrsNne5+N79k1YxjNB6gmpCQsnuSBAcV8QUeB+ZUxQzL7Rz7HksPbahymKkq2qBR+o36ggFZA==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/plugin-transform-typescript": "^7.1.0" - } - }, "@babel/template": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.1.2.tgz", @@ -799,27 +770,6 @@ "to-fast-properties": "^2.0.0" } }, - "@types/jest": { - "version": "23.3.5", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-23.3.5.tgz", - "integrity": "sha512-3LI+vUC3Wju28vbjIjsTKakhMB8HC4l+tMz+Z8WRzVK+kmvezE5jcOvKtBpznWSI5KDLFo+FouUhpTKoekadCA==", - "dev": true - }, - "@types/mqtt": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/@types/mqtt/-/mqtt-2.5.0.tgz", - "integrity": "sha512-n+0/ErBin30j+UbhcHGK/STjHjh65k85WNR6NlUjRG0g9yctpF12pS+SOkwz0wmp+7momAo9Cyi4Wmvy8UsCQg==", - "dev": true, - "requires": { - "mqtt": "*" - } - }, - "@types/node": { - "version": "10.12.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.0.tgz", - "integrity": "sha512-3TUHC3jsBAB7qVRGxT6lWyYo2v96BMmD2PTcl47H25Lu7UXtFH/2qqmKiVrnel6Ne//0TFYf6uvNX+HW2FRkLQ==", - "dev": true - }, "@webassemblyjs/ast": { "version": "1.7.8", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.7.8.tgz", @@ -1401,31 +1351,10 @@ } }, "babel-core": { - "version": "6.26.3", - "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.3.tgz", - "integrity": "sha512-6jyFLuDmeidKmUEb3NM+/yawG0M2bDZ9Z1qbZP59cyHLz8kYGKYwpJP0UwUKKUiTRNvxfLesJnTedqczP7cTDA==", - "dev": true, - "requires": { - "babel-code-frame": "^6.26.0", - "babel-generator": "^6.26.0", - "babel-helpers": "^6.24.1", - "babel-messages": "^6.23.0", - "babel-register": "^6.26.0", - "babel-runtime": "^6.26.0", - "babel-template": "^6.26.0", - "babel-traverse": "^6.26.0", - "babel-types": "^6.26.0", - "babylon": "^6.18.0", - "convert-source-map": "^1.5.1", - "debug": "^2.6.9", - "json5": "^0.5.1", - "lodash": "^4.17.4", - "minimatch": "^3.0.4", - "path-is-absolute": "^1.0.1", - "private": "^0.1.8", - "slash": "^1.0.0", - "source-map": "^0.5.7" - } + "version": "7.0.0-bridge.0", + "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz", + "integrity": "sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==", + "dev": true }, "babel-generator": { "version": "6.26.1", @@ -1567,6 +1496,35 @@ "lodash": "^4.17.4", "mkdirp": "^0.5.1", "source-map-support": "^0.4.15" + }, + "dependencies": { + "babel-core": { + "version": "6.26.3", + "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.3.tgz", + "integrity": "sha512-6jyFLuDmeidKmUEb3NM+/yawG0M2bDZ9Z1qbZP59cyHLz8kYGKYwpJP0UwUKKUiTRNvxfLesJnTedqczP7cTDA==", + "dev": true, + "requires": { + "babel-code-frame": "^6.26.0", + "babel-generator": "^6.26.0", + "babel-helpers": "^6.24.1", + "babel-messages": "^6.23.0", + "babel-register": "^6.26.0", + "babel-runtime": "^6.26.0", + "babel-template": "^6.26.0", + "babel-traverse": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "convert-source-map": "^1.5.1", + "debug": "^2.6.9", + "json5": "^0.5.1", + "lodash": "^4.17.4", + "minimatch": "^3.0.4", + "path-is-absolute": "^1.0.1", + "private": "^0.1.8", + "slash": "^1.0.0", + "source-map": "^0.5.7" + } + } } }, "babel-runtime": { @@ -1577,6 +1535,14 @@ "requires": { "core-js": "^2.4.0", "regenerator-runtime": "^0.11.0" + }, + "dependencies": { + "regenerator-runtime": { + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==", + "dev": true + } } }, "babel-template": { @@ -1927,15 +1893,6 @@ "node-releases": "^1.0.0-alpha.14" } }, - "bs-logger": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.5.tgz", - "integrity": "sha512-uFLE0LFMxrH8Z5Hd9QgivvRbrl/NFkOTHzGhlqQxsnmx5JBLrp4bc249afLL+GccyY/8hkcGi2LpVaOzaEY0nQ==", - "dev": true, - "requires": { - "fast-json-stable-stringify": "^2.0.0" - } - }, "bser": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/bser/-/bser-2.0.0.tgz", @@ -5407,6 +5364,35 @@ "jest-validate": "^23.6.0", "micromatch": "^2.3.11", "pretty-format": "^23.6.0" + }, + "dependencies": { + "babel-core": { + "version": "6.26.3", + "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.3.tgz", + "integrity": "sha512-6jyFLuDmeidKmUEb3NM+/yawG0M2bDZ9Z1qbZP59cyHLz8kYGKYwpJP0UwUKKUiTRNvxfLesJnTedqczP7cTDA==", + "dev": true, + "requires": { + "babel-code-frame": "^6.26.0", + "babel-generator": "^6.26.0", + "babel-helpers": "^6.24.1", + "babel-messages": "^6.23.0", + "babel-register": "^6.26.0", + "babel-runtime": "^6.26.0", + "babel-template": "^6.26.0", + "babel-traverse": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "convert-source-map": "^1.5.1", + "debug": "^2.6.9", + "json5": "^0.5.1", + "lodash": "^4.17.4", + "minimatch": "^3.0.4", + "path-is-absolute": "^1.0.1", + "private": "^0.1.8", + "slash": "^1.0.0", + "source-map": "^0.5.7" + } + } } }, "jest-diff": { @@ -5637,6 +5623,33 @@ "yargs": "^11.0.0" }, "dependencies": { + "babel-core": { + "version": "6.26.3", + "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.3.tgz", + "integrity": "sha512-6jyFLuDmeidKmUEb3NM+/yawG0M2bDZ9Z1qbZP59cyHLz8kYGKYwpJP0UwUKKUiTRNvxfLesJnTedqczP7cTDA==", + "dev": true, + "requires": { + "babel-code-frame": "^6.26.0", + "babel-generator": "^6.26.0", + "babel-helpers": "^6.24.1", + "babel-messages": "^6.23.0", + "babel-register": "^6.26.0", + "babel-runtime": "^6.26.0", + "babel-template": "^6.26.0", + "babel-traverse": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "convert-source-map": "^1.5.1", + "debug": "^2.6.9", + "json5": "^0.5.1", + "lodash": "^4.17.4", + "minimatch": "^3.0.4", + "path-is-absolute": "^1.0.1", + "private": "^0.1.8", + "slash": "^1.0.0", + "source-map": "^0.5.7" + } + }, "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", @@ -6178,12 +6191,6 @@ "pify": "^3.0.0" } }, - "make-error": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", - "integrity": "sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==", - "dev": true - }, "makeerror": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.11.tgz", @@ -7973,9 +7980,9 @@ } }, "regenerator-runtime": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==", + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz", + "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==", "dev": true }, "regenerator-transform": { @@ -9515,80 +9522,12 @@ "glob": "^7.1.2" } }, - "ts-jest": { - "version": "23.10.4", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-23.10.4.tgz", - "integrity": "sha512-oV/wBwGUS7olSk/9yWMiSIJWbz5xO4zhftnY3gwv6s4SMg6WHF1m8XZNBvQOKQRiTAexZ9754Z13dxBq3Zgssw==", - "dev": true, - "requires": { - "bs-logger": "0.x", - "buffer-from": "1.x", - "fast-json-stable-stringify": "2.x", - "json5": "2.x", - "make-error": "1.x", - "mkdirp": "0.x", - "semver": "^5.5", - "yargs-parser": "10.x" - }, - "dependencies": { - "json5": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.0.tgz", - "integrity": "sha512-8Mh9h6xViijj36g7Dxi+Y4S6hNGV96vcJZr/SrlHh1LR/pEn/8j/+qIBbs44YKl69Lrfctp4QD+AdWLTMqEZAQ==", - "dev": true, - "requires": { - "minimist": "^1.2.0" - } - }, - "minimist": { - "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - } - } - }, "tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", "dev": true }, - "tslint": { - "version": "5.11.0", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.11.0.tgz", - "integrity": "sha1-mPMMAurjzecAYgHkwzywi0hYHu0=", - "dev": true, - "requires": { - "babel-code-frame": "^6.22.0", - "builtin-modules": "^1.1.1", - "chalk": "^2.3.0", - "commander": "^2.12.1", - "diff": "^3.2.0", - "glob": "^7.1.1", - "js-yaml": "^3.7.0", - "minimatch": "^3.0.4", - "resolve": "^1.3.2", - "semver": "^5.3.0", - "tslib": "^1.8.0", - "tsutils": "^2.27.2" - } - }, - "tslint-config-prettier": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/tslint-config-prettier/-/tslint-config-prettier-1.15.0.tgz", - "integrity": "sha512-06CgrHJxJmNYVgsmeMoa1KXzQRoOdvfkqnJth6XUkNeOz707qxN0WfxfhYwhL5kXHHbYJRby2bqAPKwThlZPhw==", - "dev": true - }, - "tsutils": { - "version": "2.29.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", - "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } - }, "tty-browserify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", @@ -9625,12 +9564,6 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, - "typescript": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.1.3.tgz", - "integrity": "sha512-+81MUSyX+BaSo+u2RbozuQk/UWx6hfG0a5gHu4ANEM4sU96XbuIyAB+rWBW1u70c6a5QuZfuYICn3s2UjuHUpA==", - "dev": true - }, "uglify-es": { "version": "3.3.9", "resolved": "https://registry.npmjs.org/uglify-es/-/uglify-es-3.3.9.tgz", diff --git a/package.json b/package.json index ff4664d9f..9b0e1d663 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ "clean": "rm -rf dist", "compile": "npm run clean && npx webpack", "test": "jest --config jestconfig.json", - "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\" \"test/**/*.ts\" \"test/**/*.js\"", - "lint": "tslint -p tsconfig.json" + "format": "prettier --write \"src/**/*.js\" \"test/**/*.js\"" }, "author": "", "license": "ISC", @@ -19,10 +18,8 @@ "@babel/core": "^7.1.2", "@babel/plugin-proposal-class-properties": "^7.1.0", "@babel/preset-env": "^7.1.0", - "@babel/preset-typescript": "^7.1.0", - "@types/jest": "^23.3.5", - "@types/mqtt": "^2.5.0", - "@types/node": "^10.11.7", + "babel-core": "^7.0.0-bridge.0", + "babel-jest": "^23.6.0", "babel-loader": "^8.0.4", "babel-plugin-transform-react-jsx": "^6.24.1", "copy-webpack-plugin": "^4.5.3", @@ -34,13 +31,11 @@ "node-sass": "^4.9.4", "preact": "^8.3.1", "prettier": "^1.14.3", + "regenerator-runtime": "^0.12.1", "sass-loader": "^7.1.0", "style-loader": "^0.23.1", - "ts-jest": "^23.10.4", - "tslint": "^5.11.0", - "tslint-config-prettier": "^1.15.0", - "typescript": "^3.1.3", "webpack": "^4.22.0", "webpack-cli": "^3.1.2" - } + }, + "dependencies": {} } diff --git a/src/service/MockMqttClient.ts b/src/service/MockMqttClient.js similarity index 89% rename from src/service/MockMqttClient.ts rename to src/service/MockMqttClient.js index 756174210..1b0f440a2 100644 --- a/src/service/MockMqttClient.ts +++ b/src/service/MockMqttClient.js @@ -2,8 +2,8 @@ import { DBUS_PATHS } from "../config/dbusPaths" import { ClientSubscribeCallback, ISubscriptionMap } from "mqtt" export default class FakeMqttClient { - private onMessage: Function = null // this is the function that 'sends data to the ui' - private initialized = false + onMessage = null // this is the function that 'sends data to the ui' + initialized = false initService(callbackFn) { callbackFn("N/mockPortalId/system/0/Serial", JSON.stringify({ value: "mockPortalId" })) @@ -68,21 +68,21 @@ export default class FakeMqttClient { console.log("end") } - once(action: string, callback: Function) { + once(action, callback) { console.log(`once: ${action}`) callback() } - subscribe(sub: string | string[] | ISubscriptionMap, callback: ClientSubscribeCallback) { + subscribe(sub, callback) { console.log("subscribe:", sub) } - removeAllListeners(event?: string | symbol) { + removeAllListeners(event) { console.log("Remove all listeners") this.initialized = true } - on(action: string, callback: Function) { + on(action, callback) { console.log(`on: ${action}`) if (action === "connect" || action === "disconnect" || action === "reconnect") { callback() @@ -95,7 +95,7 @@ export default class FakeMqttClient { } else console.log(action) } - publish(topic: string, data: string | Buffer) { + publish(topic, data) { console.log(`publish: ${JSON.stringify(data)}`) } } diff --git a/src/service/VenusClient.ts b/src/service/VenusClient.js similarity index 82% rename from src/service/VenusClient.ts rename to src/service/VenusClient.js index c736b1ff4..7fd13c732 100644 --- a/src/service/VenusClient.ts +++ b/src/service/VenusClient.js @@ -1,5 +1,5 @@ import * as mqtt from "mqtt" -import { MqttClient, ClientSubscribeCallback } from "mqtt" +import { MqttClient } from "mqtt" import { TOPICS } from "./topics" import { DBUS_PATHS } from "../config/dbusPaths" import { parseMessage, arrayToSubscriptionMap } from "./util" @@ -9,16 +9,18 @@ import VenusSystem from "./venusSystem" // we can use this mock mqtt client that mocks the mqtt server responses to // the ui. Implemented using webpack define plugin to define whether or not // we are in prod or dev mode. -declare const DEV: string +// TODO Check if this still works +let DEV + import MockMqttClient from "./MockMqttClient" /** * Default quality of service when subscribing - best effort * {@link https://www.npmjs.com/package/mqtt#qos} */ -const TOPICS_TO_SUBSCRIBE_ON_INIT: string[] = [TOPICS.NOTIFICATION.SERIAL, TOPICS.NOTIFICATION.ALL_DEVICE_INSTANCES] +const TOPICS_TO_SUBSCRIBE_ON_INIT = [TOPICS.NOTIFICATION.SERIAL, TOPICS.NOTIFICATION.ALL_DEVICE_INSTANCES] -const subscribeCallback: ClientSubscribeCallback = (err, granted) => { +const subscribeCallback = (err, granted) => { if (err) { console.log("Error connecting to topic", err) } else { @@ -29,13 +31,20 @@ const subscribeCallback: ClientSubscribeCallback = (err, granted) => { } class VenusClient { - public mqttClient: MqttClient | MockMqttClient - private venusSystem: VenusSystem - private keepAliveHandlerRef: any = null - public onMessage: Function = () => {} - public onConnectionChanged: Function = () => {} + /** + * @type {MockMqttClient|MqttClient} + */ + mqttClient + /** + * @type {VenusSystem} + * @private + */ + venusSystem + keepAliveHandlerRef = null + onMessage = () => {} + onConnectionChanged = () => {} - constructor(host: string) { + constructor(host) { this.mqttClient = DEV ? new MockMqttClient() : mqtt.connect(host) this.venusSystem = new VenusSystem() window.onunload = () => { @@ -43,7 +52,7 @@ class VenusClient { } } - public connect = () => { + connect = () => { return new Promise((resolve, reject) => { this.mqttClient.once("connect", () => { const initialSubs = arrayToSubscriptionMap(TOPICS_TO_SUBSCRIBE_ON_INIT) @@ -83,7 +92,7 @@ class VenusClient { }) } - public write(dbusPath: string, value: number | string) { + write(dbusPath, value) { const topic = this.venusSystem.getTopicFromDbusPath("W", dbusPath) let data = JSON.stringify({ value: value }) console.log(topic, data) @@ -93,7 +102,7 @@ class VenusClient { /** * Send a read message every 50s to keep the MQTT broker alive */ - private setupKeepAlive() { + setupKeepAlive() { clearInterval(this.keepAliveHandlerRef) this.keepAliveHandlerRef = setInterval(() => { const topic = this.venusSystem.getTopicFromDbusPath("R", DBUS_PATHS.GENERAL.SERIAL) @@ -101,7 +110,7 @@ class VenusClient { }, 50000) } - public subscribe = (dbusPaths: string[]) => { + subscribe = dbusPaths => { this.mqttClient.on("message", (topic, message) => { const clientMessage = parseMessage(topic, message) this.onMessage(clientMessage) diff --git a/src/service/index.ts b/src/service/index.js similarity index 100% rename from src/service/index.ts rename to src/service/index.js diff --git a/src/service/topics.ts b/src/service/topics.js similarity index 67% rename from src/service/topics.ts rename to src/service/topics.js index 93345cf7e..ba1886746 100644 --- a/src/service/topics.ts +++ b/src/service/topics.js @@ -16,41 +16,41 @@ export const SERVICES = { .concat([DBUS_PATHS.INVERTER_CHARGER.SYSTEM.AC_NUMBER_OF_PHASES]) } -export enum BATTERY_STATE { - IDLE = 0, - CHARGING = 1, - DISCHARGING = 2 +export const BATTERY_STATE = { + IDLE: 0, + CHARGING: 1, + DISCHARGING: 2 } -export enum VEBUS_SYSTEM_STATE { - OFF = 0, - LOW_POWER = 1, - FAULT_CONDITION = 2, - BULK_CHARGING = 3, - ABSORPTION_CHARGINNG = 4, - FLOAT_CHARGING = 5, - STORAGE_MODE = 6, - EQUALISATION_CHARGING = 7, - PASSTHRU = 8, - INVERTING = 9, - ASSISTING = 10, - DISCHARGING = 256, - SUSTAIN = 257 +export const VEBUS_SYSTEM_STATE = { + OFF: 0, + LOW_POWER: 1, + FAULT_CONDITION: 2, + BULK_CHARGING: 3, + ABSORPTION_CHARGINNG: 4, + FLOAT_CHARGING: 5, + STORAGE_MODE: 6, + EQUALISATION_CHARGING: 7, + PASSTHRU: 8, + INVERTING: 9, + ASSISTING: 10, + DISCHARGING: 256, + SUSTAIN: 257 } -export enum AC_SOURCE { - NOT_AVAILABLE = 0, - GRID = 1, - GENSET = 2, - SHORE = 3, - INVERTING_ISLAND_MODE = 240 +export const AC_SOURCE = { + NOT_AVAILABLE: 0, + GRID: 1, + GENSET: 2, + SHORE: 3, + INVERTING_ISLAND_MODE: 240 } -export enum SYSTEM_MODE { - CHARGER_ONLY = 1, - INVERTER_ONLY = 2, - ON = 3, - OFF = 4 +export const SYSTEM_MODE = { + CHARGER_ONLY: 1, + INVERTER_ONLY: 2, + ON: 3, + OFF: 4 } export const TOPICS = { diff --git a/src/service/util.ts b/src/service/util.js similarity index 57% rename from src/service/util.ts rename to src/service/util.js index 08b291dfb..da8aafea9 100644 --- a/src/service/util.ts +++ b/src/service/util.js @@ -1,12 +1,12 @@ -import { ISubscriptionMap } from "mqtt" - -export type Topic = { - type: "N" | "R" | "W" - portalId: string - serviceType: string - deviceInstance: number | null - dbusPath: string -} +/** + * @typedef {object} Topic + * + * @prop {"N" | "R" | "W"} type + * @prop {string} portalId + * @prop {string} serviceType + * @prop {string} deviceInstance + * @prop {string} dbusPath + */ /** * Splits a topic string into an object with properties for each "part" @@ -15,8 +15,9 @@ export type Topic = { * N//// * * See details at https://github.com/victronenergy/dbus-mqtt + * @returns {Topic} */ -export const parseTopic = (topic: string) => { +export const parseTopic = topic => { const parts = topic.split("/") return { type: parts[0], @@ -24,10 +25,10 @@ export const parseTopic = (topic: string) => { serviceType: parts[2], deviceInstance: parseInt(parts[3]), dbusPath: "/" + parts.splice(4).join("/") - } as Topic + } } -export const parseMessage = (topic: string, message: Buffer) => { +export const parseMessage = (topic, message) => { let data try { data = JSON.parse(message.toString()) @@ -44,21 +45,18 @@ export const parseMessage = (topic: string, message: Buffer) => { } } -export function objectValues(data: any) { +export function objectValues(data) { return Object.keys(data).map(key => data[key]) } -export const isPathOfType = (dbusPath: string, enumObject: any) => { +export const isPathOfType = (dbusPath, enumObject) => { const paths = objectValues(enumObject) return paths.indexOf(dbusPath) !== -1 } -export const arrayToSubscriptionMap = (toSubscribe: string[]) => { - return toSubscribe.reduce( - (acc, value) => { - acc[value] = 0 - return acc - }, - {} as ISubscriptionMap - ) +export const arrayToSubscriptionMap = toSubscribe => { + return toSubscribe.reduce((acc, value) => { + acc[value] = 0 + return acc + }, {}) } diff --git a/src/service/venusSystem.ts b/src/service/venusSystem.js similarity index 79% rename from src/service/venusSystem.ts rename to src/service/venusSystem.js index e0dd49eb1..27c358432 100644 --- a/src/service/venusSystem.ts +++ b/src/service/venusSystem.js @@ -2,21 +2,21 @@ import { isPathOfType, parseTopic, Topic } from "./util" import { SERVICES } from "./topics" import { DBUS_PATHS } from "../config/dbusPaths" -type Equipment = { - battery: any - inverterCharger: { - dcLoads?: any - acLoads?: any - shorePower?: any - system?: any - } -} +/** + * @typedef {object} Equipment + * @prop {object} battery + * @prop {object} inverterCharger + * @prop {object} inverterCharger.dcLoads + * @prop {object} inverterCharger.acLoads + * @prop {object} inverterCharger.shorePower + * @prop {object} inverterCharger.system + */ class VenusSystem { - public portalId: string | null = null - public vebusInstanceId: number | null = null - public systemInstanceId: number | null = null - public equipment: Equipment + portalId = null + vebusInstanceId = null + systemInstanceId = null + equipment constructor() { this.equipment = { @@ -30,11 +30,17 @@ class VenusSystem { } } - public isInitialized = () => { + isInitialized = () => { return this.portalId && this.vebusInstanceId && this.systemInstanceId !== null } - public getTopicFromDbusPath = (type: "N" | "R" | "W", dbusPath: string) => { + /** + * + * @param {"N" | "R" | "W"} type + * @param dbusPath + * @returns {string} + */ + getTopicFromDbusPath = (type, dbusPath) => { if (SERVICES.SYSTEM.includes(dbusPath)) { return `${type}/${this.portalId}/system/${this.systemInstanceId}${dbusPath}` } else if (SERVICES.VEBUS.includes(dbusPath)) { @@ -46,8 +52,8 @@ class VenusSystem { } // Handling of the system components and their IDs below - public handleSystemMessage(topic: string, message: any) { - const topicDetails: Topic = parseTopic(topic) + handleSystemMessage(topic, message) { + const topicDetails = parseTopic(topic) this.handlePortalIdMessage(topicDetails, message) || this.handleBaterryInfoMessages(topicDetails, message) || this.handleDCLoads(topicDetails, message) || @@ -57,7 +63,7 @@ class VenusSystem { this.handleDeviceIds(topicDetails, message) } - private handlePortalIdMessage(topic: Topic, data: any) { + handlePortalIdMessage(topic, data) { if (topic.dbusPath === DBUS_PATHS.GENERAL.SERIAL) { this.portalId = data.value return true @@ -65,7 +71,7 @@ class VenusSystem { return false } - private handleDeviceIds(topic: Topic, data: any) { + handleDeviceIds(topic, data) { if (topic.dbusPath === DBUS_PATHS.GENERAL.DEVICE_INSTANCE) { console.log(`DEVICE ${topic.serviceType} AVAILABLE WITH ID ${topic.deviceInstance}`) switch (topic.serviceType) { @@ -89,7 +95,7 @@ class VenusSystem { return false } - private handleBaterryInfoMessages(topic: Topic, data: any) { + handleBaterryInfoMessages(topic, data) { if (isPathOfType(topic.dbusPath, DBUS_PATHS.BATTERY)) { if (!this.equipment.battery) { this.equipment.battery = {} @@ -100,7 +106,7 @@ class VenusSystem { return false } - private handleDCLoads(topic: Topic, data: any) { + handleDCLoads(topic, data) { if (isPathOfType(topic.dbusPath, DBUS_PATHS.INVERTER_CHARGER.DC_LOADS)) { if (!this.equipment.inverterCharger.dcLoads) { this.equipment.inverterCharger.dcLoads = {} @@ -111,7 +117,7 @@ class VenusSystem { return false } - private handleACLoads(topic: Topic, data: any) { + handleACLoads(topic, data) { if (isPathOfType(topic.dbusPath, DBUS_PATHS.INVERTER_CHARGER.AC_LOADS)) { if (!this.equipment.inverterCharger.acLoads) { this.equipment.inverterCharger.acLoads = {} @@ -122,7 +128,7 @@ class VenusSystem { return false } - private handleShorePower(topic: Topic, data: any) { + handleShorePower(topic, data) { if (isPathOfType(topic.dbusPath, DBUS_PATHS.INVERTER_CHARGER.SHORE_POWER)) { if (!this.equipment.inverterCharger.shorePower) { this.equipment.inverterCharger.shorePower = {} @@ -133,7 +139,7 @@ class VenusSystem { return false } - private handleSystemState(topic: Topic, data: any) { + handleSystemState(topic, data) { if (isPathOfType(topic.dbusPath, DBUS_PATHS.INVERTER_CHARGER.SYSTEM)) { if (!this.equipment.inverterCharger.system) { this.equipment.inverterCharger.system = {} diff --git a/test/PowerSupplySystem.test.ts b/test/PowerSupplySystem.test.ts deleted file mode 100644 index f16645311..000000000 --- a/test/PowerSupplySystem.test.ts +++ /dev/null @@ -1,57 +0,0 @@ -import PowerSupplySystem from "../src/service/PowerSupplySystem" -import { DBUS_PATHS } from "../src/config/dbusPaths" - -describe("initialization", () => { - test("starts with no portal id", () => { - const system = new PowerSupplySystem() - expect(system.portalId).toBe(null) - }) - - test("starts as not initialized", () => { - const system = new PowerSupplySystem() - expect(system.isInitialized()).toBe(false) - }) - - test("initializes portal id after first `/Serial` notification received", () => { - const system = new PowerSupplySystem() - system.handleNotification("N/985dadd0c9e4/system/0/Serial", Buffer.from('{"value": "985dadd0c9e4"}')) - expect(system.portalId).toBe("985dadd0c9e4") - expect(system.isInitialized()).toBe(false) - }) - - test("initializes vebus device id after `/DeviceInstance` notification received", () => { - const system = new PowerSupplySystem() - system.handleNotification("N/985dadd0c9e4/vebus/257/DeviceInstance", Buffer.from('{"value": 257}')) - expect(system.vebusInstanceId).toBe(257) - expect(system.isInitialized()).toBe(false) - }) - - test("is initialized after portal id and vebus device id are set", () => { - const system = new PowerSupplySystem() - system.handleNotification("N/985dadd0c9e4/system/0/Serial", Buffer.from('{"value": "985dadd0c9e4"}')) - system.handleNotification("N/985dadd0c9e4/vebus/257/DeviceInstance", Buffer.from('{"value": 257}')) - expect(system.isInitialized()).toBe(true) - }) -}) - -describe("return topic based on dbus path", () => { - let system: PowerSupplySystem - - beforeEach(() => { - system = new PowerSupplySystem() - system.handleNotification("N/985dadd0c9e4/system/0/Serial", Buffer.from('{"value": "985dadd0c9e4"}')) - system.handleNotification("N/985dadd0c9e4/vebus/257/DeviceInstance", Buffer.from('{"value": 257}')) - }) - - test("correctly initializes system paths", () => { - expect(system.getTopicFromDbusPath("N", DBUS_PATHS.BATTERY.VOLTAGE)).toBe( - `N/985dadd0c9e4/system/0/Dc/Battery/Voltage` - ) - }) - - test("correctly initializes vebus paths", () => { - expect(system.getTopicFromDbusPath("N", DBUS_PATHS.INVERTER_CHARGER.AC_LOADS.CURRENT)).toBe( - `N/985dadd0c9e4/vebus/257/Ac/Out/L1/V` - ) - }) -}) diff --git a/test/VenusClient.test.ts b/test/VenusClient.test.js similarity index 76% rename from test/VenusClient.test.ts rename to test/VenusClient.test.js index ab54e027b..62d104981 100644 --- a/test/VenusClient.test.ts +++ b/test/VenusClient.test.js @@ -1,20 +1,15 @@ import * as mqtt from "mqtt" import VenusClient from "../src/service/VenusClient" -import Mock = jest.Mock -jest.mock("mqtt", "connect") - -interface CallbackMap { - [event: string]: Function[] -} class MockClient { - public callbacks: CallbackMap = {} + callbacks = {} notifyClientConnected() { this.callbacks["connect"].forEach(cb => cb(null, [{ topic: "x", ops: 0 }])) } - public once = (event: string, callback: Function) => { + on = () => {} + once = (event, callback) => { if (!this.callbacks[event]) { this.callbacks[event] = [callback] } else { @@ -22,7 +17,7 @@ class MockClient { } } - public subscribe: Mock = jest.fn() + subscribe = jest.fn() } const mockClient = new MockClient() diff --git a/test/util.test.ts b/test/util.test.js similarity index 100% rename from test/util.test.ts rename to test/util.test.js diff --git a/test/venusSystem.test.js b/test/venusSystem.test.js new file mode 100644 index 000000000..6e75d2d66 --- /dev/null +++ b/test/venusSystem.test.js @@ -0,0 +1,58 @@ +import VenusSystem from "../src/service/venusSystem" +import { DBUS_PATHS } from "../src/config/dbusPaths" + +describe("initialization", () => { + test("starts with no portal id", () => { + const system = new VenusSystem() + expect(system.portalId).toBe(null) + }) + + test("starts as not initialized", () => { + const system = new VenusSystem() + expect(system.isInitialized()).toBeFalsy() + }) + + test("initializes portal id after first `/Serial` notification received", () => { + const system = new VenusSystem() + system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" }) + expect(system.portalId).toBe("985dadd0c9e4") + expect(system.isInitialized()).toBeFalsy() + }) + + test("initializes vebus device id after `/DeviceInstance` notification received", () => { + const system = new VenusSystem() + system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 }) + expect(system.vebusInstanceId).toBe(257) + expect(system.isInitialized()).toBeFalsy() + }) + + test("is initialized after portal id and vebus device id are set", () => { + const system = new VenusSystem() + system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" }) + system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 }) + expect(system.isInitialized()).toBeFalsy() + }) +}) + +describe("return topic based on dbus path", () => { + let system + + beforeEach(() => { + system = new VenusSystem() + system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" }) + system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 }) + system.handleSystemMessage("N/985dadd0c9e4/system/0/DeviceInstance", { value: 0 }) + }) + + test("correctly initializes system paths", () => { + expect(system.getTopicFromDbusPath("N", DBUS_PATHS.BATTERY.VOLTAGE)).toBe( + `N/985dadd0c9e4/system/0/Dc/Battery/Voltage` + ) + }) + + test("correctly initializes vebus paths", () => { + expect(system.getTopicFromDbusPath("N", DBUS_PATHS.INVERTER_CHARGER.AC_LOADS.CURRENT)).toBe( + `N/985dadd0c9e4/vebus/257/Ac/Out/L1/I` + ) + }) +}) diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 536cda5ba..000000000 --- a/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "lib": ["es6"], - "target": "es5", - "module": "commonjs", - "declaration": true, - "outDir": "./lib", - "strict": true - }, - "include": ["service"], - "exclude": ["node_modules", "**/__tests__/*"] -} \ No newline at end of file diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 70fdbab29..000000000 --- a/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": ["tslint:recommended", "tslint-config-prettier"] -} \ No newline at end of file