mini_program_gizwits_sdk 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/src/sdk.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module.exports=function(e){var t={};function i(s){if(t[s])return t[s].exports;var r=t[s]={i:s,l:!1,exports:{}};return e[s].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=e,i.c=t,i.d=function(e,t,s){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(s,r,function(t){return e[t]}.bind(null,r));return s},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=16)}([function(e,t,i){(function(t){var s;e.exports=(s=s||function(e,s){var r;if("undefined"!=typeof window&&window.crypto&&(r=window.crypto),"undefined"!=typeof self&&self.crypto&&(r=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(r=globalThis.crypto),!r&&"undefined"!=typeof window&&window.msCrypto&&(r=window.msCrypto),!r&&void 0!==t&&t.crypto&&(r=t.crypto),!r)try{r=i(35)}catch(e){}var n=function(){if(r){if("function"==typeof r.getRandomValues)try{return r.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof r.randomBytes)try{return r.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),o={},c=o.lib={},l=c.Base={extend:function(e){var t=a(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},d=c.WordArray=l.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,i=e.words,s=this.sigBytes,r=e.sigBytes;if(this.clamp(),s%4)for(var n=0;n<r;n++){var a=i[n>>>2]>>>24-n%4*8&255;t[s+n>>>2]|=a<<24-(s+n)%4*8}else for(var o=0;o<r;o+=4)t[s+o>>>2]=i[o>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=l.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],i=0;i<e;i+=4)t.push(n());return new d.init(t,e)}}),u=o.enc={},h=u.Hex={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],r=0;r<i;r++){var n=t[r>>>2]>>>24-r%4*8&255;s.push((n>>>4).toString(16)),s.push((15&n).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s+=2)i[s>>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new d.init(i,t/2)}},f=u.Latin1={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],r=0;r<i;r++){var n=t[r>>>2]>>>24-r%4*8&255;s.push(String.fromCharCode(n))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s++)i[s>>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new d.init(i,t)}},p=u.Utf8={stringify:function(e){try{return decodeURIComponent(escape(f.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return f.parse(unescape(encodeURIComponent(e)))}},g=c.BufferedBlockAlgorithm=l.extend({reset:function(){this._data=new d.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=p.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var i,s=this._data,r=s.words,n=s.sigBytes,a=this.blockSize,o=n/(4*a),c=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,l=e.min(4*c,n);if(c){for(var u=0;u<c;u+=a)this._doProcessBlock(r,u);i=r.splice(0,c),s.sigBytes-=l}return new d.init(i,l)},clone:function(){var e=l.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),v=(c.Hasher=g.extend({cfg:l.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){g.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,i){return new e.init(i).finalize(t)}},_createHmacHelper:function(e){return function(t,i){return new v.HMAC.init(e,i).finalize(t)}}}),o.algo={});return o}(Math),s)}).call(this,i(34))},function(e,t,i){var s,r,n,a,o,c,l,d,u,h,f,p,g,v,_,y,D,m,b;e.exports=(s=i(0),i(3),void(s.lib.Cipher||(r=s,n=r.lib,a=n.Base,o=n.WordArray,c=n.BufferedBlockAlgorithm,l=r.enc,l.Utf8,d=l.Base64,u=r.algo.EvpKDF,h=n.Cipher=c.extend({cfg:a.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,i){this.cfg=this.cfg.extend(i),this._xformMode=e,this._key=t,this.reset()},reset:function(){c.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?b:D}return function(t){return{encrypt:function(i,s,r){return e(s).encrypt(t,i,s,r)},decrypt:function(i,s,r){return e(s).decrypt(t,i,s,r)}}}}()}),n.StreamCipher=h.extend({_doFinalize:function(){return this._process(!0)},blockSize:1}),f=r.mode={},p=n.BlockCipherMode=a.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),g=f.CBC=function(){var e=p.extend();function t(e,t,i){var s,r=this._iv;r?(s=r,this._iv=void 0):s=this._prevBlock;for(var n=0;n<i;n++)e[t+n]^=s[n]}return e.Encryptor=e.extend({processBlock:function(e,i){var s=this._cipher,r=s.blockSize;t.call(this,e,i,r),s.encryptBlock(e,i),this._prevBlock=e.slice(i,i+r)}}),e.Decryptor=e.extend({processBlock:function(e,i){var s=this._cipher,r=s.blockSize,n=e.slice(i,i+r);s.decryptBlock(e,i),t.call(this,e,i,r),this._prevBlock=n}}),e}(),v=(r.pad={}).Pkcs7={pad:function(e,t){for(var i=4*t,s=i-e.sigBytes%i,r=s<<24|s<<16|s<<8|s,n=[],a=0;a<s;a+=4)n.push(r);var c=o.create(n,s);e.concat(c)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},n.BlockCipher=h.extend({cfg:h.cfg.extend({mode:g,padding:v}),reset:function(){var e;h.reset.call(this);var t=this.cfg,i=t.iv,s=t.mode;this._xformMode==this._ENC_XFORM_MODE?e=s.createEncryptor:(e=s.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==e?this._mode.init(this,i&&i.words):(this._mode=e.call(s,this,i&&i.words),this._mode.__creator=e)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e,t=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e},blockSize:4}),_=n.CipherParams=a.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),y=(r.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,i=e.salt;return(i?o.create([1398893684,1701076831]).concat(i).concat(t):t).toString(d)},parse:function(e){var t,i=d.parse(e),s=i.words;return 1398893684==s[0]&&1701076831==s[1]&&(t=o.create(s.slice(2,4)),s.splice(0,4),i.sigBytes-=16),_.create({ciphertext:i,salt:t})}},D=n.SerializableCipher=a.extend({cfg:a.extend({format:y}),encrypt:function(e,t,i,s){s=this.cfg.extend(s);var r=e.createEncryptor(i,s),n=r.finalize(t),a=r.cfg;return _.create({ciphertext:n,key:i,iv:a.iv,algorithm:e,mode:a.mode,padding:a.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,i,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(i,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),m=(r.kdf={}).OpenSSL={execute:function(e,t,i,s){s||(s=o.random(8));var r=u.create({keySize:t+i}).compute(e,s),n=o.create(r.words.slice(t),4*i);return r.sigBytes=4*t,_.create({key:r,iv:n,salt:s})}},b=n.PasswordBasedCipher=D.extend({cfg:D.cfg.extend({kdf:m}),encrypt:function(e,t,i,s){var r=(s=this.cfg.extend(s)).kdf.execute(i,e.keySize,e.ivSize);s.iv=r.iv;var n=D.encrypt.call(this,e,t,r.key,s);return n.mixIn(r),n},decrypt:function(e,t,i,s){s=this.cfg.extend(s),t=this._parse(t,s.format);var r=s.kdf.execute(i,e.keySize,e.ivSize,t.salt);return s.iv=r.iv,D.decrypt.call(this,e,t,r.key,s)}}))))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.checkHeader=e=>{let t=0;return 0===e[0]&&0===e[1]&&0===e[2]&&3===e[3]&&(t=4,4)};t.getProtocolLen=e=>{let t=0;for(;t<e.length&&"1"===s(e[t].toString(2),8)[0];t++);return t+1},t.arrayToString=function(e){let t="";return e.map(e=>(t+=s(e.toString(16),2),null)),t};const s=(e,t,i=!1)=>{const s=t-e.length,r=new Array(s).fill(0).join("");return i?e+=r:e=r+e,e};t.fillString=s;t.string2Bytes=e=>{const t=[];for(let i=0;i<e.length;i++)t.push(e.charCodeAt(i));return t};t.hexStrint2byte=e=>{const t=Math.ceil(e.length/2),i=[];for(let s=0;s<t;s++){const t=2*s,r=t+2,n=e.substring(t,r);i.push(parseInt(n,16))}return i};const r=e=>{const t=encodeURI(e);return-1!==t.indexOf("%")&&"%"!==e?t.split("%").filter(e=>""!==e).map(e=>parseInt(e,16)):[t.charCodeAt(0)]};t.formatCode=r;t.formatCodesFromStr=e=>{const t=[0,0];let i=[];for(let s=0;s<e.length;s++){const n=r(e[s]);t[1]+=n.length,i=i.concat(n)}return[i,t]}},function(e,t,i){var s,r,n,a,o,c,l,d;e.exports=(d=i(0),i(14),i(15),r=(s=d).lib,n=r.Base,a=r.WordArray,o=s.algo,c=o.MD5,l=o.EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:c,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i,s=this.cfg,r=s.hasher.create(),n=a.create(),o=n.words,c=s.keySize,l=s.iterations;o.length<c;){i&&r.update(i),i=r.update(e).finalize(t),r.reset();for(var d=1;d<l;d++)i=r.finalize(i),r.reset();n.concat(i)}return n.sigBytes=4*c,n}}),s.EvpKDF=function(e,t,i){return l.create(i).compute(e,t)},d.EvpKDF)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default={GIZ_OPENAPI_DEVICE_NOT_BOUND:{errorCode:9017,errorMessage:"not bind"},GIZ_SDK_HTTP_REQUEST_FAILED:{errorCode:8099,errorMessage:"网络请求失败"},GIZ_SDK_SDK_NOT_INITIALIZED:{errorCode:8300,errorMessage:"not init"},CONFIG_TIME_OUT:{errorCode:8023,errorMessage:"Config Timeout"},WECHAT_ERROR:{errorCode:1e4,errorMessage:"wechat error"},GIZ_SDK_ONBOARDING_STOPPED:{errorCode:8318,errorMessage:"配网中断"},GIZ_SDK_DEVICE_CONFIG_IS_RUNNING:{errorCode:8022,errorMessage:"配置正在进行中"},GIZ_OPENAPI_TOKEN_INVALID:{errorCode:9004,errorMessage:"token 失效"},GIZ_SDK_BIND_DEVICE_FAILED:{errorCode:8039,errorMessage:"设备绑定失败"},GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON:{errorCode:8281,errorMessage:"蓝牙未启用"},GIZ_SDK_OTHERWISE:{errorCode:8100,errorMessage:""},GIZ_SDK_DEVICE_NOT_SUBSCRIBED:{errorCode:8029,errorMessage:"设备还未订阅"},GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY:{errorCode:8250,errorMessage:"产品类型不在指定范围内"}}},function(e,t,i){var s,r,n;e.exports=(n=i(0),r=(s=n).lib.WordArray,s.enc.Base64={stringify:function(e){var t=e.words,i=e.sigBytes,s=this._map;e.clamp();for(var r=[],n=0;n<i;n+=3)for(var a=(t[n>>>2]>>>24-n%4*8&255)<<16|(t[n+1>>>2]>>>24-(n+1)%4*8&255)<<8|t[n+2>>>2]>>>24-(n+2)%4*8&255,o=0;o<4&&n+.75*o<i;o++)r.push(s.charAt(a>>>6*(3-o)&63));var c=s.charAt(64);if(c)for(;r.length%4;)r.push(c);return r.join("")},parse:function(e){var t=e.length,i=this._map,s=this._reverseMap;if(!s){s=this._reverseMap=[];for(var n=0;n<i.length;n++)s[i.charCodeAt(n)]=n}var a=i.charAt(64);if(a){var o=e.indexOf(a);-1!==o&&(t=o)}return function(e,t,i){for(var s=[],n=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,l=o|c;s[n>>>2]|=l<<24-n%4*8,n++}return r.create(s,n)}(e,t,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},n.enc.Base64)},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,r=i.WordArray,n=i.Hasher,a=t.algo,o=[];!function(){for(var t=0;t<64;t++)o[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=a.MD5=n.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var s=t+i,r=e[s];e[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8)}var n=this._hash.words,a=e[t+0],c=e[t+1],f=e[t+2],p=e[t+3],g=e[t+4],v=e[t+5],_=e[t+6],y=e[t+7],D=e[t+8],m=e[t+9],b=e[t+10],w=e[t+11],S=e[t+12],B=e[t+13],I=e[t+14],k=e[t+15],C=n[0],A=n[1],x=n[2],E=n[3];C=l(C,A,x,E,a,7,o[0]),E=l(E,C,A,x,c,12,o[1]),x=l(x,E,C,A,f,17,o[2]),A=l(A,x,E,C,p,22,o[3]),C=l(C,A,x,E,g,7,o[4]),E=l(E,C,A,x,v,12,o[5]),x=l(x,E,C,A,_,17,o[6]),A=l(A,x,E,C,y,22,o[7]),C=l(C,A,x,E,D,7,o[8]),E=l(E,C,A,x,m,12,o[9]),x=l(x,E,C,A,b,17,o[10]),A=l(A,x,E,C,w,22,o[11]),C=l(C,A,x,E,S,7,o[12]),E=l(E,C,A,x,B,12,o[13]),x=l(x,E,C,A,I,17,o[14]),C=d(C,A=l(A,x,E,C,k,22,o[15]),x,E,c,5,o[16]),E=d(E,C,A,x,_,9,o[17]),x=d(x,E,C,A,w,14,o[18]),A=d(A,x,E,C,a,20,o[19]),C=d(C,A,x,E,v,5,o[20]),E=d(E,C,A,x,b,9,o[21]),x=d(x,E,C,A,k,14,o[22]),A=d(A,x,E,C,g,20,o[23]),C=d(C,A,x,E,m,5,o[24]),E=d(E,C,A,x,I,9,o[25]),x=d(x,E,C,A,p,14,o[26]),A=d(A,x,E,C,D,20,o[27]),C=d(C,A,x,E,B,5,o[28]),E=d(E,C,A,x,f,9,o[29]),x=d(x,E,C,A,y,14,o[30]),C=u(C,A=d(A,x,E,C,S,20,o[31]),x,E,v,4,o[32]),E=u(E,C,A,x,D,11,o[33]),x=u(x,E,C,A,w,16,o[34]),A=u(A,x,E,C,I,23,o[35]),C=u(C,A,x,E,c,4,o[36]),E=u(E,C,A,x,g,11,o[37]),x=u(x,E,C,A,y,16,o[38]),A=u(A,x,E,C,b,23,o[39]),C=u(C,A,x,E,B,4,o[40]),E=u(E,C,A,x,a,11,o[41]),x=u(x,E,C,A,p,16,o[42]),A=u(A,x,E,C,_,23,o[43]),C=u(C,A,x,E,m,4,o[44]),E=u(E,C,A,x,S,11,o[45]),x=u(x,E,C,A,k,16,o[46]),C=h(C,A=u(A,x,E,C,f,23,o[47]),x,E,a,6,o[48]),E=h(E,C,A,x,y,10,o[49]),x=h(x,E,C,A,I,15,o[50]),A=h(A,x,E,C,v,21,o[51]),C=h(C,A,x,E,S,6,o[52]),E=h(E,C,A,x,p,10,o[53]),x=h(x,E,C,A,b,15,o[54]),A=h(A,x,E,C,c,21,o[55]),C=h(C,A,x,E,D,6,o[56]),E=h(E,C,A,x,k,10,o[57]),x=h(x,E,C,A,_,15,o[58]),A=h(A,x,E,C,B,21,o[59]),C=h(C,A,x,E,g,6,o[60]),E=h(E,C,A,x,w,10,o[61]),x=h(x,E,C,A,f,15,o[62]),A=h(A,x,E,C,m,21,o[63]),n[0]=n[0]+C|0,n[1]=n[1]+A|0,n[2]=n[2]+x|0,n[3]=n[3]+E|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;i[r>>>5]|=128<<24-r%32;var n=e.floor(s/4294967296),a=s;i[15+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),i[14+(r+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),t.sigBytes=4*(i.length+1),this._process();for(var o=this._hash,c=o.words,l=0;l<4;l++){var d=c[l];c[l]=16711935&(d<<8|d>>>24)|4278255360&(d<<24|d>>>8)}return o},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});function l(e,t,i,s,r,n,a){var o=e+(t&i|~t&s)+r+a;return(o<<n|o>>>32-n)+t}function d(e,t,i,s,r,n,a){var o=e+(t&s|i&~s)+r+a;return(o<<n|o>>>32-n)+t}function u(e,t,i,s,r,n,a){var o=e+(t^i^s)+r+a;return(o<<n|o>>>32-n)+t}function h(e,t,i,s,r,n,a){var o=e+(i^(t|~s))+r+a;return(o<<n|o>>>32-n)+t}t.MD5=n._createHelper(c),t.HmacMD5=n._createHmacHelper(c)}(Math),s.MD5)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(2);class r{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=s.checkHeader(e);if(!1===t)throw new Error("Header Error");this.header=s.arrayToString(e.slice(0,t));const i=e.slice(t,e.length),n=s.getProtocolLen(i);this.len=r.decodeLen(i.slice(0,n)),t+=n,this.flag=e.slice(t,t+1),t+=1,this.cmd=s.arrayToString(e.slice(t,t+2)),t+=2,this.content=e.slice(t,e.length)},e&&e.length>0&&this.formatP0(e)}}r.decodeLen=e=>{let t=1,i=0,s=0,r=0;do{s=e[r],i+=(127&s)*t,t*=128,r+=1}while(0!=(128&s));return i},t.default=r},function(e,t,i){"use strict";function s(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}Object.defineProperty(t,"__esModule",{value:!0}),t.ab2hex=s,t.compareWXSDKVersion=function(e,t){const i=e.split("."),s=t.split("."),r=Math.max(e.length,t.length);for(;i.length<r;)i.push("0");for(;s.length<r;)s.push("0");for(let i=0;i<r;i++){const s=parseInt(e[i]),r=parseInt(t[i]);if(s>r)return 1;if(s<r)return-1}return 0},t.isError=e=>null!=e&&"symbol"==typeof e.errorCode,t.wrapErrorInfo=e=>({errorCode:e,errorMessage:e}),t.unionBy=(e,t)=>e.reduce((e,i)=>{const s=i[t];return e.some(e=>e[t]===s)||e.push(i),e},[]),t.isWXDevicesResult=function(e){return e.success&&"[object Array]"===Object.prototype.toString.call(e.bleDevices)},t.str2Buf=function(e){var t=e.length,i=new ArrayBuffer(t+2),s=new DataView(i);for(let i=0;i<t;i++)s.setUint8(i,parseInt(e[i],16));return i},t.numberArray2Uint8Array=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i},t.advertisData2PkAndMac=(e,t)=>{let i=e.slice(e.byteLength-16),r=e.slice(0,e.byteLength-16),n=s(i);if(t.find(e=>e===n)){const e=s(r);return{productKey:n,mac:e}}{i=e.slice(0,16),r=e.slice(16),n=s(i);const t=s(r);return{productKey:n,mac:t}}},t.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey,t.merageBleLocalDevices=(e,i)=>(i.map(i=>{const s=e.find(e=>t.isSameDevice(e,i));s?(s.isBleOnline=!0,s.bleDeviceID=i.bleDeviceID):e.push(i)}),e),t.merageLanLocalDevices=(e,i)=>(i.map(i=>{const s=e.find(e=>t.isSameDevice(e,i));s?s.isLanOnline=!0:e.push(i)}),e),t.BTDevice2GDevice=(e,i)=>{const{productKey:s,mac:r}=t.advertisData2PkAndMac(e.advertisData,i);return{mac:r,did:"",connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,productKey:s,name:e.name,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime()}},t.getFirstConnectType=(e,t)=>{if(!t)return e.isLanOnline?"LAN":e.isBleOnline?"BLE":"WAN";if("WAN"===t)return"WAN";switch(t){case"BLE":return e.isBleOnline?"BLE":"NONE";case"LAN":return e.isLanOnline?"LAN":"NONE"}return"WAN"},t.getProductInfoThroughPK=(e,t)=>t.find(t=>t.productKey===e),t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2ab=function(e){const t=[];for(let s=0;s<e.length;s+=2){var i=e.slice(s,s+2);t.push(parseInt(i,16))}return new Uint8Array(t)}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(30),r=i(17),n=i(4);t.siteApiRequest=async(e,t)=>{const i=Object.assign({},t);i.header=Object.assign(Object.assign({},{"Content-Type":"application/json"}),t.headers),delete i.headers;const a=(r.getGlobalData("cloudServiceInfo")||{}).siteInfo||"site.gizwits.com",o=await s.default("http://"+a+e,i);if(o.statusCode>=200&&o.statusCode<300)return{success:!0,data:o.data};let c={success:!1,err:{errorCode:n.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{c={success:!1,err:{errorCode:o.data.error_code,errorMessage:o.data.error_message}}}catch(e){}return c},t.default=async(e,t,i=!0)=>{const a=Object.assign({},t),o={"Content-Type":"application/json","X-Gizwits-Application-Id":r.getGlobalData("appID")};i&&(o["X-Gizwits-User-token"]=r.getGlobalData("token")),a.header=Object.assign(Object.assign({},o),t.headers),delete a.headers;const c=r.getGlobalData("cloudServiceInfo").openAPIInfo,l=await s.default("https://"+c+e,a);if(l.statusCode>=200&&l.statusCode<300)return{success:!0,data:l.data};let d={success:!1,err:{errorCode:n.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{d={success:!1,err:{errorCode:l.data.error_code,errorMessage:l.data.error_message}}}catch(e){}return d}},function(e,t,i){var s,r,n,a,o,c;e.exports=(c=i(0),r=(s=c).lib,n=r.Base,a=r.WordArray,(o=s.x64={}).Word=n.extend({init:function(e,t){this.high=e,this.low=t}}),o.WordArray=n.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:8*e.length},toX32:function(){for(var e=this.words,t=e.length,i=[],s=0;s<t;s++){var r=e[s];i.push(r.high),i.push(r.low)}return a.create(i,this.sigBytes)},clone:function(){for(var e=n.clone.call(this),t=e.words=this.words.slice(0),i=t.length,s=0;s<i;s++)t[s]=t[s].clone();return e}}),c)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=e=>new Promise(t=>setTimeout(()=>t(),e))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(9);const r=new class{constructor(){this.data={},this.key="dataPointConfig",this.init=async()=>{const e=await wx.getStorageSync(this.key)||"{}";let t={};try{t=JSON.parse(e)}catch(e){}this.data=t},this.getConfigFile=async e=>{var t;if(!this.data[e]){const i=`/app/datapoint?product_key=${e}`,r=await s.default(`${i}`,{method:"GET"});if(!r.success||!(null===(t=r.data)||void 0===t?void 0:t.entities))return null;this.data[e]=r.data,wx.setStorageSync(this.key,JSON.stringify(this.data))}return this.data[e]}}};r.init(),t.default=r},function(e,t,i){var s;e.exports=(s=i(0),i(10),i(36),i(37),i(5),i(38),i(6),i(14),i(23),i(39),i(24),i(40),i(41),i(42),i(15),i(43),i(3),i(1),i(44),i(45),i(46),i(47),i(48),i(49),i(50),i(51),i(52),i(53),i(54),i(55),i(56),i(57),i(58),i(59),s)},function(e,t,i){var s,r,n,a,o,c,l,d;e.exports=(d=i(0),r=(s=d).lib,n=r.WordArray,a=r.Hasher,o=s.algo,c=[],l=o.SHA1=a.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],r=i[1],n=i[2],a=i[3],o=i[4],l=0;l<80;l++){if(l<16)c[l]=0|e[t+l];else{var d=c[l-3]^c[l-8]^c[l-14]^c[l-16];c[l]=d<<1|d>>>31}var u=(s<<5|s>>>27)+o+c[l];u+=l<20?1518500249+(r&n|~r&a):l<40?1859775393+(r^n^a):l<60?(r&n|r&a|n&a)-1894007588:(r^n^a)-899497514,o=a,a=n,n=r<<30|r>>>2,r=s,s=u}i[0]=i[0]+s|0,i[1]=i[1]+r|0,i[2]=i[2]+n|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[14+(s+64>>>9<<4)]=Math.floor(i/4294967296),t[15+(s+64>>>9<<4)]=i,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),s.SHA1=a._createHelper(l),s.HmacSHA1=a._createHmacHelper(l),d.SHA1)},function(e,t,i){var s,r,n,a;e.exports=(s=i(0),n=(r=s).lib.Base,a=r.enc.Utf8,void(r.algo.HMAC=n.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var i=e.blockSize,s=4*i;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),n=this._iKey=t.clone(),o=r.words,c=n.words,l=0;l<i;l++)o[l]^=1549556828,c[l]^=909522486;r.sigBytes=n.sigBytes=s,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(i))}})))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),i(25);const s=i(26),r=i(4);t.errorCode=r.default;const n=i(18);t.BleHandle=n.BleHandle,t.default=s.default},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s={};t.setGlobalData=function(e,t){s[e]=t},t.getGlobalData=function(e){return s[e]}},function(e,t,i){"use strict";var s=this&&this.__rest||function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(i[s[r]]=e[s[r]])}return i};Object.defineProperty(t,"__esModule",{value:!0});const r=i(8),n=i(19),a=i(27),o=i(2),c=i(7),l=i(28),d=i(29);t.BleHandle=class{constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"abf0",characteristicUUIDSuffix:"abf7"},globalListenerMap:i,gizSdk:u,offlineThreshold:h}){this.connectedList=[],this.pks=[],this.tmpBleData="",this.tmpDataNum=0,this.listenerMap={},this.globalListenerMap={},this.scanList=[],this.listenDevOffline=e=>{setInterval(()=>{const t=(new Date).getTime(),i=this.scanList.filter(i=>t-i.ctime<e);i.length!==this.scanList.length&&(this.scanList=i,this.gizSdk.bleDevices=i)},500)},this.openBluetoothAdapter=()=>new Promise((e,t)=>{wx.openBluetoothAdapter({success:()=>{console.log("openBluetoothAdapter success"),e({success:!0}),wx.onBLECharacteristicValueChange(this.handleOnBLECharacteristicValueChange)},fail:e=>{console.log("openBluetoothAdapter fail",e),this.notifyError({errMsg:e.errMsg,errCode:-1}),t(e)}})}),this.handleOnBLECharacteristicValueChange=e=>{const t=r.ab2hex(e.value);try{const i=new c.default(o.hexStrint2byte(t));console.log("ProtocolBase",i.len,e.value.byteLength,i),this.tmpBleData=t,this.tmpDataNum=i.len-e.value.byteLength+4+Math.ceil(i.len.toString(2).length/8)}catch(i){this.tmpBleData&&(this.tmpBleData+=t,this.tmpDataNum-=e.value.byteLength)}this.tmpDataNum>0||!this.tmpBleData||(console.log("ProtocolBase141",this.tmpBleData,this.tmpDataNum),this.listenerMap[e.deviceId]&&this.listenerMap[e.deviceId].map(t=>{t(e,this.tmpBleData)}),this.listenerMap.ALL&&(console.log("ProtocolBase1"),this.listenerMap.ALL.map(t=>{console.log("ProtocolBase2"),t(e,this.tmpBleData)})),this.tmpBleData="",this.tmpDataNum=0)},this.notifyError=e=>{var t;null===(t=this.globalListenerMap.onBleHandleError)||void 0===t||t.map(t=>{t(e)})},this.listenConnection=e=>{wx.onBLEConnectionStateChange(t=>{const i=this.connectedList.map(e=>e.deviceId).includes(e)&&t.deviceId===e&&!1===t.connected;console.log("蓝牙状态变化",{connectedList:this.connectedList,res:t,deviceId:e}),i&&this.connectDevice(e)})},this.checkPermission=async()=>{if((await wx.getSetting()).authSetting["scope.bluetooth"]){return await this.openBluetoothAdapter(),await this.getBluetoothAdapterState()}try{return await wx.authorize({scope:"scope.bluetooth"}),await this.openBluetoothAdapter(),await this.getBluetoothAdapterState()}catch(e){console.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1})}},this.getBluetoothAdapterState=async()=>{const e=await wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,n=s(e,["errMsg","available"]);return{data:Object.assign({},n),err:r.wrapErrorInfo(t),success:i}},this.getDeviceStatus=async(e,t,i,s)=>{const n=await d.default.pack(t,i,s);return n?await this.write(e,r.numberArray2Uint8Array(n).buffer):{success:!1}},this.handleBluetoothDeviceFound=(e,t)=>{const i=r.unionBy(e.devices,"deviceId").filter(e=>{const{advertisData:t,deviceId:i,name:s,localName:n}=e,a=r.ab2hex(t),o=this.scanList.find(e=>e.bleDeviceID===i);if(o)return this.gizSdk.setDeviceMeta(o,"ctime",Date.now()),!1;return this.pks.some(e=>a.includes(e))});if(i.length>0){const e=i.map(e=>r.BTDevice2GDevice(e,this.pks));this.scanList.push(...e),t(this.scanList)}},this.startScan=async(e,t=5e3)=>new Promise(async i=>{wx.onBluetoothDeviceFound(t=>{this.handleBluetoothDeviceFound(t,e)}),await wx.startBluetoothDevicesDiscovery({powerLevel:"high",allowDuplicatesKey:!0,interval:500}),setTimeout(()=>{this.stopScan(),i({scanList:this.scanList})},t)}),this.stopScan=async()=>{const{errMsg:e,errCode:t}=await wx.stopBluetoothDevicesDiscovery();return{errMsg:e,errCode:t}},this.connectDevice=async e=>{var t;const i=await wx.createBLEConnection({deviceId:e}).catch(t=>{this.removeDevById(e),this.notifyError(t)});if("createBLEConnection:ok"!==i.errMsg)return{success:!1,message:null==i?void 0:i.errMsg};this.listenConnection(e);const s=await wx.getBLEDeviceServices({deviceId:e}).catch(e=>this.notifyError(e)),n=null===(t=null==s?void 0:s.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)))||void 0===t?void 0:t.uuid;if(!n)return{message:"can not find valid serviceId",success:!1};const o=await wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:n}).catch(e=>this.notifyError(e));console.log({getCharRes:o});const c=null==o?void 0:o.characteristics[0].uuid;this.connectedList.every(t=>t.deviceId!==e)&&this.connectedList.push({deviceId:e,serviceId:n,characteristicId:c});await wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:n,characteristicId:c,state:!0,type:"notification"}).catch(e=>this.notifyError(e));this.write(e,r.numberArray2Uint8Array(a.default.pack()).buffer);const d=await this.handleBindReq(e);if(console.log("handleBindReq",d),d.success){this.write(e,r.numberArray2Uint8Array(l.default.pack({passcode:d.data})).buffer);const t=await this.handleLoginReq(e).catch(e=>this.notifyError(e));if(console.log("loginData",t),null==t?void 0:t.success)return{success:!0,message:"ok"}}return{success:!1,message:"ok"}},this.handleBindReq=e=>new Promise(t=>{console.log("handleBindReq");const i=(s,r)=>{console.log("监听蓝牙特征值发生变化");const n=new a.default(o.hexStrint2byte(r));this.removeDeviceListener(e,i),n.passcode?t({success:!0,data:n.passcode}):t({success:!1,data:""})};this.addDeviceListener(e,i)}),this.handleLoginReq=e=>new Promise(t=>{const i=(s,r)=>{console.log("设备回复LoginReq",r);const n=new l.default(o.hexStrint2byte(r));this.removeDeviceListener(e,i),!0===n.result?t({success:!0,data:n.did}):t({success:!1,data:""})};this.addDeviceListener(e,i)}),this.removeDeviceListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{message:"ok",success:!0}}return{message:"invalid function",success:!1}},this.addDeviceListener=async(e,t)=>{"ALL"===e&&(this.listenerMap.ALL||(this.listenerMap.ALL=[]),this.listenerMap.ALL.push(t));const{serviceId:i,characteristicId:s,errMsg:r}=this.getTargetDevice(e);return r?{success:!1,message:r}:(this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),await wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:s,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),console.log(`监听设备 ${e} 成功!`),{message:"ok",success:!0})},this.write=async(e,t)=>{console.log("app => dev:",r.ab2hex(t));const{serviceId:i,characteristicId:s}=this.getTargetDevice(e);if(i&&s){return await n.unpackWriteBLECharacteristicValue(e,i,s,t)}return{success:!1,message:"serviceId or characteristicId is unvalid!",errbody:{serviceId:i,characteristicId:s}}},this.disConnectDevice=async e=>{this.removeDevById(e);const{errMsg:t}=await wx.closeBLEConnection({deviceId:e});return"closeBLEConnection:ok"===t?{err:t,success:!0}:{err:t,success:!1}},this.removeDevById=e=>{const t=this.connectedList.findIndex(t=>t.deviceId===e);this.connectedList.splice(t,1)},this.getTargetDevice=e=>{const t=this.connectedList.find(t=>e===t.deviceId);return t||{errMsg:"Unable get this device,maybe you forgot to connect it."}};const{serviceUUIDSuffix:f}=t;this.serviceUUIDSuffix=f,this.pks=e,this.globalListenerMap=i,this.gizSdk=u}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(11);function r(e,t,i,s){return new Promise(r=>{console.log("writeBLECharacteristicValue"),wx.writeBLECharacteristicValue({deviceId:e,serviceId:t,characteristicId:i,value:s,complete:r})})}t.openBluetoothAdapter=function(){return new Promise((e,t)=>{wx.openBluetoothAdapter({success:e,fail:t})})},t.closeBluetoothAdapter=function(){return new Promise((e,t)=>{wx.closeBluetoothAdapter({success:e,fail:t})})},t.getBluetoothAdapterState=function(){return new Promise((e,t)=>{wx.getBluetoothAdapterState({success:e,fail:t})})},t.startBluetoothDevicesDiscovery=function(){return new Promise((e,t)=>{wx.startBluetoothDevicesDiscovery({success:e,fail:t,interval:100})})},t.getBluetoothDevices=function(){return new Promise((e,t)=>{wx.getBluetoothDevices({success:({devices:t})=>e(t),fail:t})})},t.createBLEConnection=function(e,t){return new Promise((i,s)=>{wx.createBLEConnection({deviceId:e,timeout:t,success:e=>i(e),fail:e=>{-1===e.errCode?i(e):s(e)}})})},t.getBLEDeviceServices=function(e){return new Promise((t,i)=>{wx.getBLEDeviceServices({deviceId:e,success:({services:e})=>t(e),fail:i})})},t.getBLEDeviceCharacteristics=function(e,t){return new Promise((i,s)=>{wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:t,success:({characteristics:e})=>i(e),fail:s})})},t.notifyBLECharacteristicValueChange=function(e,t,i,s=!0){return new Promise((r,n)=>{wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:t,characteristicId:i,state:s,success:r,fail:n})})},t.writeBLECharacteristicValue=r,t.unpackWriteBLECharacteristicValue=function(e,t,i,n){if(0===n.byteLength)throw new Error("value is not empty");return new Promise(async(a,o)=>{let c,l=0,d=n.byteLength;for(;d>0;){await s.default(30);const a=n.slice(l,l+20);if(l+=20,d-=20,c=await r(e,t,i,a),console.log("unpackWriteBLECharacteristicValue",l/20,c),0!==c.errCode)break}0!==c.errCode?o(c):a(c)})}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(7),r=i(2);class n extends s.default{constructor(e){super(e)}}n.pack=(e,t)=>{const i=[],[s,n]=r.formatCodesFromStr(e),[a,o]=r.formatCodesFromStr(t),c=[0].concat([0,1],n,s,o,a);let l=c.length;for(;l>0;)i.push(l),l-=255;const d=[0,0,0,3].concat(i).concat(c),u=new ArrayBuffer(d.length),h=new Uint8Array(u);for(let e=0;e<u.byteLength;e++)h[e]=d[e];return h},t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(11),r=i(4),n=i(22);t.default=class{constructor(e,t,i,a){this.ssid="",this.password="",this.specialProductKeys=[],this.disableSearchDevice=!1,this.specialProductKeySecrets=[],this.timeoutHandler=null,this.setDeviceOnboardingDeployRej=()=>{},this.cleanTimeout=()=>{this.disableSearchDevice=!0,this.timeoutHandler&&clearTimeout(this.timeoutHandler),this.timeoutHandler=null,console.log("this.timeoutHandler",this.timeoutHandler)},this.stopDeviceOnboardingDeploy=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:r.default.GIZ_SDK_ONBOARDING_STOPPED}),this.cleanTimeout()},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:r.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:r.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,a)=>{console.debug("GIZ_SDK: 开始大循环搜索设备");const o=async()=>{var c;if(this.hasTimeoutHandler())try{const l=await n.checkDeviceRegister({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(c=l.err)||void 0===c?void 0:c.errorCode)===r.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void a({success:!1,err:r.default.GIZ_OPENAPI_TOKEN_INVALID});l.err||0===l.data.length?(console.debug("GIZ_SDK: 大循环没有发现设备"),await s.default(1500),!this.disableSearchDevice&&o()):(console.debug("GIZ_SDK: 大循环搜索到设备",l),i({success:!0,data:l.data}))}catch(e){await s.default(3e3),!this.disableSearchDevice&&o()}};o()}),this.initDeviceOnboardingDeploy=(e,t)=>{this.setDeviceOnboardingDeployRej=t,this.disableSearchDevice=!1},this.startTimeoutTimer=e=>{this.timeoutHandler=setTimeout(this.handleTimeout,1e3*e)},this.bindDevices=e=>(console.log("GIZ_SDK: start bind device"),new Promise(async(t,i)=>{const s=e.map(e=>{const t=this.specialProductKeys.findIndex(t=>e.productKey===t);if(-1===t)return;const i=this.specialProductKeySecrets[t];return n.bindMac({mac:e.mac,productKey:e.productKey,productSecret:i})});try{const n=await Promise.all(s),a=e.filter((e,t)=>{const i=n[t];return i&&i.success});a.length>0?(console.log("GIZ_SDK: bind device success",a),t({success:!0,data:a})):(console.log("GIZ_SDK: bind device error",n),i({success:!1,data:e,err:r.default.GIZ_SDK_BIND_DEVICE_FAILED}))}catch(e){i(e)}})),this.ssid=e,this.password=t,this.specialProductKeys=i,this.specialProductKeySecrets=a}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(9),r=i(33),n=i(60),a=i(13);t.getBindingList=async()=>{const e=await s.default("/app/bindings?show_disabled=0&limit=1000&skip=0",{method:"GET"});if(e.success){return{success:!0,data:e.data.devices.map(e=>({productKey:e.product_key,mac:e.mac,did:e.did,host:e.host,port_s:e.port_s,port:e.port,ws_port:e.ws_port,wss_port:e.wss_port,isBleOnline:!1,isLanOnline:!1,connectType:"NONE",name:e.dev_alias,isBind:!0,isOnline:e.is_online}))}}return{success:!1,err:e.err}},t.bindMac=async function({mac:e,productKey:t,productSecret:i,alias:r,beOwner:a}){const o={mac:e,product_key:t,dev_alias:r,set_owner:a},{Signature:c,timestamp:l}=n.psKeySign(i);return await s.default("/app/bind_mac",{method:"POST",data:o,headers:{"X-Gizwits-Signature":c,"X-Gizwits-Timestamp":l}})},t.unbindDevice=async function({devices:e}){return await s.default("/app/bindings",{method:"DELETE",data:{devices:e.map(e=>({did:e.did}))}})},t.checkDeviceRegister=async function({SSID:e,password:t,productKeys:i}){const n=r.default({SSID:e,password:t,pks:i});let a="";return n.map(e=>{a+=`${e},`}),a=a.substring(0,a.length-1),await s.default(`/app/device_register?random_codes=${a}`,{method:"get"})},t.safeRegister=async function({productKey:e,productSecret:t,mac:i,passcode:r,gwDid:n,isReset:o}){let c=`is_reset=${o?1:0}&mac=${i}&passcode=${r}`;n&&(c+=`&gw_did=${n}`);const l=a.enc.Hex.parse(t),d=a.enc.Hex.parse(""),u=a.enc.Utf8.parse(c),h=a.AES.encrypt(u,l,{iv:d,mode:a.mode.ECB,padding:a.pad.Pkcs7}).ciphertext.toString().toUpperCase(),f=await s.default(`/dev/${e}/device`,{method:"POST",data:{data:h},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);return f.success?{success:!0,data:{successDevices:[],failedDevices:[]}}:{success:!1,err:f.err}}},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,r=i.WordArray,n=i.Hasher,a=t.algo,o=[],c=[];!function(){function t(t){for(var i=e.sqrt(t),s=2;s<=i;s++)if(!(t%s))return!1;return!0}function i(e){return 4294967296*(e-(0|e))|0}for(var s=2,r=0;r<64;)t(s)&&(r<8&&(o[r]=i(e.pow(s,.5))),c[r]=i(e.pow(s,1/3)),r++),s++}();var l=[],d=a.SHA256=n.extend({_doReset:function(){this._hash=new r.init(o.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],r=i[1],n=i[2],a=i[3],o=i[4],d=i[5],u=i[6],h=i[7],f=0;f<64;f++){if(f<16)l[f]=0|e[t+f];else{var p=l[f-15],g=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,v=l[f-2],_=(v<<15|v>>>17)^(v<<13|v>>>19)^v>>>10;l[f]=g+l[f-7]+_+l[f-16]}var y=s&r^s&n^r&n,D=(s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22),m=h+((o<<26|o>>>6)^(o<<21|o>>>11)^(o<<7|o>>>25))+(o&d^~o&u)+c[f]+l[f];h=u,u=d,d=o,o=a+m|0,a=n,n=r,r=s,s=m+(D+y)|0}i[0]=i[0]+s|0,i[1]=i[1]+r|0,i[2]=i[2]+n|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0,i[5]=i[5]+d|0,i[6]=i[6]+u|0,i[7]=i[7]+h|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=e.floor(s/4294967296),i[15+(r+64>>>9<<4)]=s,t.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(d),t.HmacSHA256=n._createHmacHelper(d)}(Math),s.SHA256)},function(e,t,i){var s;e.exports=(s=i(0),i(10),function(){var e=s,t=e.lib.Hasher,i=e.x64,r=i.Word,n=i.WordArray,a=e.algo;function o(){return r.create.apply(r,arguments)}var c=[o(1116352408,3609767458),o(1899447441,602891725),o(3049323471,3964484399),o(3921009573,2173295548),o(961987163,4081628472),o(1508970993,3053834265),o(2453635748,2937671579),o(2870763221,3664609560),o(3624381080,2734883394),o(310598401,1164996542),o(607225278,1323610764),o(1426881987,3590304994),o(1925078388,4068182383),o(2162078206,991336113),o(2614888103,633803317),o(3248222580,3479774868),o(3835390401,2666613458),o(4022224774,944711139),o(264347078,2341262773),o(604807628,2007800933),o(770255983,1495990901),o(1249150122,1856431235),o(1555081692,3175218132),o(1996064986,2198950837),o(2554220882,3999719339),o(2821834349,766784016),o(2952996808,2566594879),o(3210313671,3203337956),o(3336571891,1034457026),o(3584528711,2466948901),o(113926993,3758326383),o(338241895,168717936),o(666307205,1188179964),o(773529912,1546045734),o(1294757372,1522805485),o(1396182291,2643833823),o(1695183700,2343527390),o(1986661051,1014477480),o(2177026350,1206759142),o(2456956037,344077627),o(2730485921,1290863460),o(2820302411,3158454273),o(3259730800,3505952657),o(3345764771,106217008),o(3516065817,3606008344),o(3600352804,1432725776),o(4094571909,1467031594),o(275423344,851169720),o(430227734,3100823752),o(506948616,1363258195),o(659060556,3750685593),o(883997877,3785050280),o(958139571,3318307427),o(1322822218,3812723403),o(1537002063,2003034995),o(1747873779,3602036899),o(1955562222,1575990012),o(2024104815,1125592928),o(2227730452,2716904306),o(2361852424,442776044),o(2428436474,593698344),o(2756734187,3733110249),o(3204031479,2999351573),o(3329325298,3815920427),o(3391569614,3928383900),o(3515267271,566280711),o(3940187606,3454069534),o(4118630271,4000239992),o(116418474,1914138554),o(174292421,2731055270),o(289380356,3203993006),o(460393269,320620315),o(685471733,587496836),o(852142971,1086792851),o(1017036298,365543100),o(1126000580,2618297676),o(1288033470,3409855158),o(1501505948,4234509866),o(1607167915,987167468),o(1816402316,1246189591)],l=[];!function(){for(var e=0;e<80;e++)l[e]=o()}();var d=a.SHA512=t.extend({_doReset:function(){this._hash=new n.init([new r.init(1779033703,4089235720),new r.init(3144134277,2227873595),new r.init(1013904242,4271175723),new r.init(2773480762,1595750129),new r.init(1359893119,2917565137),new r.init(2600822924,725511199),new r.init(528734635,4215389547),new r.init(1541459225,327033209)])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],r=i[1],n=i[2],a=i[3],o=i[4],d=i[5],u=i[6],h=i[7],f=s.high,p=s.low,g=r.high,v=r.low,_=n.high,y=n.low,D=a.high,m=a.low,b=o.high,w=o.low,S=d.high,B=d.low,I=u.high,k=u.low,C=h.high,A=h.low,x=f,E=p,L=g,O=v,P=_,M=y,T=D,H=m,K=b,R=w,N=S,G=B,z=I,U=k,j=C,Z=A,F=0;F<80;F++){var W,V,$=l[F];if(F<16)V=$.high=0|e[t+2*F],W=$.low=0|e[t+2*F+1];else{var X=l[F-15],q=X.high,J=X.low,Y=(q>>>1|J<<31)^(q>>>8|J<<24)^q>>>7,Q=(J>>>1|q<<31)^(J>>>8|q<<24)^(J>>>7|q<<25),ee=l[F-2],te=ee.high,ie=ee.low,se=(te>>>19|ie<<13)^(te<<3|ie>>>29)^te>>>6,re=(ie>>>19|te<<13)^(ie<<3|te>>>29)^(ie>>>6|te<<26),ne=l[F-7],ae=ne.high,oe=ne.low,ce=l[F-16],le=ce.high,de=ce.low;V=(V=(V=Y+ae+((W=Q+oe)>>>0<Q>>>0?1:0))+se+((W+=re)>>>0<re>>>0?1:0))+le+((W+=de)>>>0<de>>>0?1:0),$.high=V,$.low=W}var ue,he=K&N^~K&z,fe=R&G^~R&U,pe=x&L^x&P^L&P,ge=E&O^E&M^O&M,ve=(x>>>28|E<<4)^(x<<30|E>>>2)^(x<<25|E>>>7),_e=(E>>>28|x<<4)^(E<<30|x>>>2)^(E<<25|x>>>7),ye=(K>>>14|R<<18)^(K>>>18|R<<14)^(K<<23|R>>>9),De=(R>>>14|K<<18)^(R>>>18|K<<14)^(R<<23|K>>>9),me=c[F],be=me.high,we=me.low,Se=j+ye+((ue=Z+De)>>>0<Z>>>0?1:0),Be=_e+ge;j=z,Z=U,z=N,U=G,N=K,G=R,K=T+(Se=(Se=(Se=Se+he+((ue+=fe)>>>0<fe>>>0?1:0))+be+((ue+=we)>>>0<we>>>0?1:0))+V+((ue+=W)>>>0<W>>>0?1:0))+((R=H+ue|0)>>>0<H>>>0?1:0)|0,T=P,H=M,P=L,M=O,L=x,O=E,x=Se+(ve+pe+(Be>>>0<_e>>>0?1:0))+((E=ue+Be|0)>>>0<ue>>>0?1:0)|0}p=s.low=p+E,s.high=f+x+(p>>>0<E>>>0?1:0),v=r.low=v+O,r.high=g+L+(v>>>0<O>>>0?1:0),y=n.low=y+M,n.high=_+P+(y>>>0<M>>>0?1:0),m=a.low=m+H,a.high=D+T+(m>>>0<H>>>0?1:0),w=o.low=w+R,o.high=b+K+(w>>>0<R>>>0?1:0),B=d.low=B+G,d.high=S+N+(B>>>0<G>>>0?1:0),k=u.low=k+U,u.high=I+z+(k>>>0<U>>>0?1:0),A=h.low=A+Z,h.high=C+j+(A>>>0<Z>>>0?1:0)},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[30+(s+128>>>10<<5)]=Math.floor(i/4294967296),t[31+(s+128>>>10<<5)]=i,e.sigBytes=4*t.length,this._process(),this._hash.toX32()},clone:function(){var e=t.clone.call(this);return e._hash=this._hash.clone(),e},blockSize:32});e.SHA512=t._createHelper(d),e.HmacSHA512=t._createHmacHelper(d)}(),s.SHA512)},function(e,t){},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(17),r=i(18),n=i(31),a=i(32),o=i(61),c=i(16),l=i(62),d=i(22),u=i(8),h=i(12),f=i(63),p=i(2);t.default=class{constructor({appID:e,appSecret:t,productInfo:i,cloudServiceInfo:r,token:n,uid:g,offlineThreshold:v}){this.version="3.0.7",this.listenerMap={},this._deviceList=[],this._bleDevices=[],this._udpDevices=[],this.productInfo=[],this.autoScanInterval=null,this.handleBleDeviceData=async(e,t)=>{const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){const e=await f.unpack(p.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})})}},this.handleSockerDeviceData=e=>{const t=this.allDevices.find(t=>t.did===e.did);t&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(i=>{i(Object.assign({device:t},"attrs"in e?{data:e.attrs}:{raw:e.raw}))})},this.notiDeviveList=()=>{var e,t;null===(e=this.listenerMap.GizDeviceListNotifications)||void 0===e||e.map(e=>{e(this.allDevices)}),null===(t=this.listenerMap.onScanListChange)||void 0===t||t.map(e=>{e(this.bleScanDevice)})},this.startAutoScan=()=>{this.autoScanInterval&&clearInterval(this.autoScanInterval),this.autoScanInterval=setInterval(async()=>{const e=await this.bleHandle.startScan(e=>{this.bleDevices=e},6e3);console.log("auto scan result",e),this.bleDevices=e.scanList},1e3)},this.stopAutoScan=()=>{this.autoScanInterval&&clearInterval(this.autoScanInterval)},this.setDeviceMeta=(e,t,i)=>{const s=this.allDevices.find(t=>t.mac===e.mac);s&&0!==this.allDevices.length&&(s[t]=i,console.log("setDeviceMeta",this.allDevices),this.notiDeviveList())},this.getVersion=()=>({success:!0,data:this.version}),this.initBle=async()=>{const e=await this.bleHandle.checkPermission();return e.success?(this.bleHandle.addDeviceListener("ALL",this.handleBleDeviceData),console.debug("init BLE succcess",e),{success:!0}):(console.error("init BLE Error",e),{success:!1,err:c.errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON})},this.scanBleDevice=async e=>{console.log("start scanBleDevice"),this.bleHandle.scanList=[];const t=await this.bleHandle.startScan(e=>{this.bleDevices=e},e);return console.debug("scanBleDevice",t),{success:!0,data:t.scanList}},this.write=async(e,t)=>{console.log("待发送指令:",e,t);const i=this.allDevices.find(t=>u.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType)switch(i.connectType){case"BLE":{const e=await f.pack(t,i.productKey);e&&(console.log("write cmd",e,t),this.bleHandle.write(i.bleDeviceID,u.numberArray2Uint8Array(e).buffer));break}case"WAN":this.socketHandle.writeData(i,t)}},this.getProductConfig=async e=>{const t=await h.default.getConfigFile(e);return t?{success:!0,data:t}:{success:!1}},this.stopScanBleDevice=()=>{this.bleHandle.stopScan()},this.login=async e=>{var t,i;const r=await l.AnonymousLogin({uid:e});return r.success&&(s.setGlobalData("token",null===(t=r.data)||void 0===t?void 0:t.token),s.setGlobalData("uid",null===(i=r.data)||void 0===i?void 0:i.uid)),r},this.getDeviceStatus=async(e,t)=>{const i=this.allDevices.find(t=>u.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE":return await this.bleHandle.getDeviceStatus(i.bleDeviceID,i.productKey,i.rootDeviceId,t);case"WAN":return this.socketHandle.readStatus(i,t);default:return{success:!1,message:"Device connectType is unsupported"}}},this.subscribe=async(e,t,i=!0)=>{switch(u.getFirstConnectType(e,t)){case"BLE":{const t=this.bleDevices.find(t=>u.isSameDevice(t,e));if(!t)return{success:!1};const i=await this.bleHandle.connectDevice(t.bleDeviceID);return i.success?(this.setDeviceMeta(t,"connectType","BLE"),setTimeout(()=>{this.getDeviceStatus(t)},500)):this.bleHandle.disConnectDevice(t.bleDeviceID),i}case"WAN":{const t=this.socketHandle.connectDevice(e);return t.success&&this.setDeviceMeta(e,"connectType","WAN"),t}}return{success:!1}},this.unSubscribe=async e=>{switch(e.connectType){case"BLE":{const t=await this.bleHandle.disConnectDevice(e.bleDeviceID);return t.success&&this.setDeviceMeta(e,"connectType","NONE"),t}}return{success:!1}},this.bindRemoteDevice=async({mac:e,productKey:t,alias:i,beOwner:s})=>{const r=u.getProductInfoThroughPK(t,this.productInfo);if(r){const n=await d.bindMac({mac:e,productKey:t,productSecret:r.productSecret,alias:i,beOwner:s});return this.getBindingList(),n}return{success:!1,err:c.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}},this.unbindDevice=async({devices:e})=>{const t=await d.unbindDevice({devices:e});return t.success&&this.getBindingList(),t},this.deviceSafetyRegister=async({mac:e,productKey:t})=>await this.deviceSafetyApi({mac:e,productKey:t,isReset:!1}),this.deviceSafetyUnbind=async({mac:e,productKey:t})=>await this.deviceSafetyApi({mac:e,productKey:t,isReset:!0}),this.setDeviceOnboardingDeploy=async({ssid:e,password:t,mode:i=0,timeout:s,isBind:r=!0,softAPSSIDPrefix:n})=>{if(this.currentWifiConfigHandle)return{success:!1,err:c.errorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const l=(new Date).getTime();console.debug("GIZ_SDK: 配网开始时间:"+l);try{switch(i){case 0:{this.currentWifiConfigHandle=new a.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=await this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:n});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return console.debug("GIZ_SDK: 配网结束时间:"+o),console.debug("GIZ_SDK: 配网用时:"+(o-l)),i}case 3:{this.currentWifiConfigHandle=new o.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=await this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:n});this.currentWifiConfigHandle=null;const a=(new Date).getTime();return console.debug("GIZ_SDK: 配网结束时间:"+a),console.debug("GIZ_SDK: 配网用时:"+(a-l)),i}}}catch(e){return console.error(e),e.err&&e.err.errorCode?e:{success:!1,err:c.errorCode.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}},this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=e&&e.siteInfo||"site.gizwits.com",r=Object.assign(Object.assign({},e||{}),{openAPIInfo:t,siteInfo:i});s.setGlobalData("cloudServiceInfo",r)},this.deviceSafetyApi=async({mac:e,productKey:t,isReset:i})=>{const s=u.getProductInfoThroughPK(t,this.productInfo);return s?await d.safeRegister({productKey:t,productSecret:s.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:c.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}},this.getBindingList=async()=>{const e=await d.getBindingList();this.devieList=e.data||[]},this.getDevices=async()=>(await this.getBindingList(),{success:!0,data:this.allDevices}),this.stopDeviceOnboardingDeploy=()=>{this.currentWifiConfigHandle&&(this.currentWifiConfigHandle.stopDeviceOnboardingDeploy(),this.currentWifiConfigHandle=null)},this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}},this.addEventListener=async(e,t)=>(this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}),this.productInfo=i,s.setGlobalData("appID",e),s.setGlobalData("appSecret",t),s.setGlobalData("productInfo",i),s.setGlobalData("token",n),s.setGlobalData("uid",g),this.setDomain(r),this.offlineThreshold=v,console.debug(`init sdk success, current version: ${this.version}`)}get devieList(){return this._deviceList}set devieList(e){this._deviceList=e,this.notiDeviveList()}get bleDevices(){return this._bleDevices}set bleDevices(e){this._bleDevices=e,this.notiDeviveList()}get udpDevices(){return this._udpDevices}set udpDevices(e){this._udpDevices=e,this.notiDeviveList()}get allDevices(){let e=u.merageBleLocalDevices([...this.devieList],this.bleDevices);return e=u.merageLanLocalDevices(e,this.udpDevices),this.bleHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.bleDeviceID===t.deviceId);-1!==i&&(e[i].connectType="BLE")}),e}set allDevice(e){this.allDevice=e,this.notiDeviveList()}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}get bleHandle(){return this._bleHandle||(this._bleHandle=new r.BleHandle({pks:this.specialProductKeys,globalListenerMap:this.listenerMap,gizSdk:this,offlineThreshold:this.offlineThreshold})),this._bleHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new n.default({appID:s.getGlobalData("appID"),token:s.getGlobalData("token"),uid:s.getGlobalData("uid")}),this._gizSocket.subscribeDeviceStatus(this.handleSockerDeviceData)),this._gizSocket}get specialProductKeys(){return this.productInfo.map(e=>{var t;return null!==(t=e.productKey)&&void 0!==t?t:""})}get specialProductKeySecrets(){return this.productInfo.map(e=>{var t;return null!==(t=e.productSecret)&&void 0!==t?t:""})}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(7),r=i(2);class n extends s.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt(r.arrayToString(this.content.slice(t,t+2)),16);t+=2;let s="";this.content.slice(t,t+i).map(e=>{s+=String.fromCharCode(e)}),this.passcode=s}}n.pack=()=>[0,0,0,3,3,0,0,6],t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(7),r=i(2);class n extends s.default{constructor(e){super(e),this.result=!1,this.didLength=0,this.did="";let t=0;if(this.result=0===this.content[0],t++,1===this.flag[0]){this.didLength=parseInt(r.arrayToString(this.content.slice(t,t+2)),16),t+=2;let e="";this.content.slice(t,this.content.length).map(t=>{e+=String.fromCharCode(t)}),this.did=e}}}n.pack=({passcode:e})=>{let t=[0];const i=r.hexStrint2byte(r.fillString(e.length.toString(16),4)),s=r.string2Bytes(e),n=[0].concat([0,8]).concat(i).concat(s);return t=r.hexStrint2byte(n.length.toString(16)),[0,0,0,3].concat(t).concat(n)},t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(12),r=i(7),n=i(2);class a extends r.default{}a.pack=async(e,t,i)=>{const r=await s.default.getConfigFile(e);if(r){const e="var_len"===r.protocolType,s=[0,0,0,3],a=[0];let o=[0];const c=[0,147];let l=[0,0,0,0],d=[2];if(t){o=[1];const e=n.fillString(t.length.toString(16),4),i=n.hexStrint2byte(e),s=n.string2Bytes(t);l=l.concat(i).concat(s)}if(e){d=[18];let e="";if(i){const t=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:1}),{});r.entities[0].attrs.map(i=>{e=t[i.name]?`1${e}`:`0${e}`})}else r.entities[0].attrs.map(()=>{e=`1${e}`});e=n.fillString(e,8*Math.ceil(e.length/8)),d=d.concat(n.hexStrint2byte(parseInt(e,2).toString(16)))}const u=o.concat(c).concat(l).concat(d);return a[0]=u.length,s.concat(a).concat(u)}return null},t.default=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise((i,s)=>{wx.request(Object.assign(Object.assign({url:e,timeout:3e3},t),{success:e=>{i(e)},fail:e=>{s(e)}}))})}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),r=i(9),n=i(8);t.default=class{constructor({appID:e,token:t,uid:i,limitSocketNum:o=!0}){this._bindingDevices=null,this._connections={},this._getDevice=e=>{if(null===this._bindingDevices)return s.default.GIZ_SDK_SDK_NOT_INITIALIZED;const t=this._bindingDevices[e];return null==t?s.default.GIZ_OPENAPI_DEVICE_NOT_BOUND:t},this._getConnect=e=>{const t=this._getWebsocketConnInfo(e);return this._connections[t]},this._getDeviceAndConnect=e=>{const t=this._getDevice(e);if(n.isError(t))return t;const i=this._getConnect(t);return null==i?s.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED:[t,i]},this.connectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];if(null==i){const e=Object.keys(this._connections).length;if(0!==this._maxSocketNum&&e>=this._maxSocketNum)return{success:!1,errorCode:s.default.MAX_CONNECT};i=new a({appID:this.appID,token:this.token,uid:this.uid,wsInfo:t,onDeviceStatusChanged:this._handleDeviceStatusChanged}),this._connections[t]=i}return i._addSubDid(e.did),null==i._websocket?i._connectWS():i.ready&&i._subDevices([e.did]),{success:!0}},this.connect=e=>{const t=this._getDevice(e);if(n.isError(t))return t;const i=this.connectDevice(t);return i.success?null:i.errorCode},this.send=(e,t)=>{const i=this._getDeviceAndConnect(e);return n.isError(i)?i:i[1]._send({cmd:"c2s_raw",data:{did:e,raw:t}})},this.writeData=(e,t)=>{const i=this._getConnect(e),s=null!=i;return s&&i._send({cmd:"c2s_write",data:{did:e.did,attrs:t}}),{success:s}},this.write=(e,t)=>{const i=this._getDeviceAndConnect(e);return n.isError(i)?i:i[1]._send({cmd:"c2s_write",data:{did:e,attrs:t}})},this.readStatus=(e,t)=>{const i=this._getConnect(e),s=null!=i;return s&&i._send({cmd:"c2s_read",data:{did:e.did,names:t}}),{success:s}},this.read=(e,t)=>{const i=this._getDeviceAndConnect(e);return n.isError(i)?i:i[1]._send({cmd:"c2s_read",data:{did:e,names:t}})},this.close=()=>{Object.values(this._connections).forEach(e=>e.close())},this.subscribeDeviceStatus=e=>{this._onDeviceStatusChanged=e},this._handleDeviceStatusChanged=e=>{const t=this._getDevice(e.did);n.isError(t)||this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._getBindingList=async(e=20,t=0,i=[])=>{const s=`/app/bindings?show_disabled=0&limit=${e}&skip=${t}`,{err:n,data:a}=await r.default(`${s}`,{method:"GET"});if(n)return{err:n};const o=[...i,...(null==a?void 0:a.devices)||[]];return a&&a.devices.length===e?await this._getBindingList(e,e+t,o):o},this._getWebsocketConnInfo=e=>e.host.includes("stage")?"wss://wxstage.gizwits.com":"wss://wxm2m.gizwits.com",this.appID=e,this.token=t,this.uid=i;const c=wx.getSystemInfoSync().SDKVersion;this._maxSocketNum=o?-1===n.compareWXSDKVersion(c,"1.7.0")?1:5:0}async init(){var e,t;try{const i=await this._getBindingList();return(null===(e=i.err)||void 0===e?void 0:e.errorCode)?{errorCode:null===(t=i.err)||void 0===t?void 0:t.errorCode,errorMessage:"getting binding list failed"}:(this._bindingDevices=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t.did]:t}),{}),null)}catch(e){return s.default.GIZ_SDK_OTHERWISE}}};class a{constructor({appID:e,token:t,uid:i,wsInfo:s,onDeviceStatusChanged:r}){this.ready=!1,this.commType="attrs_v4",this._heartbeatInterval=60,this._keepaliveTime=180,this._loginIntveral=5e3,this.autoSubscribe=!1,this._websocket=null,this._loginFailedTimes=0,this._subDids=new Set,this._socketRespHandleMap={},this._addSubDid=e=>{this._subDids.add(e)},this._connectWS=()=>{this._websocket=wx.connectSocket({url:this._wsUrl}),this._websocket.onClose(this.handleClose),this._websocket.onOpen(this.handleOpen),this._websocket.onError(this.handleError),this._websocket.onMessage(this.handleMessage)},this._subDevices=e=>{const t={cmd:"subscribe_req",data:e.map(e=>({did:e}))};this._send(t)},this._send=(e,t=!1)=>(console.log("Socket send",e,t),new Promise(i=>{this._websocket&&(t||this.ready)&&this._websocket.send({data:JSON.stringify(e),complete:e=>{console.debug("GIZ_SDK: socket send res",e),["sendSocketMessage:fail debug invoke no active session","sendSocketMessage:fail wcwss taskID not exist"].includes(e&&e.errMsg)&&(this._websocket&&this._websocket.close({}),this._connectWS()),i(e)}})})),this.close=()=>{this.ready=!1,this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._websocket&&(this._websocket.close({}),this._websocket=null)},this.handleClose=e=>{console.log("socket close",e),this.close(),this._stopPing()},this.handleOpen=()=>{console.log(" socket open"),this._login()},this.handleMessage=({data:e})=>{console.log("message",e);const t=JSON.parse(e),i=this._socketRespHandleMap[t.cmd];i&&i(t.data)},this.handleError=e=>{console.debug("GIZ_SDK: socket error",e)},this._login=()=>{const e={cmd:"login_req",data:{appid:this.appID,uid:this.uid,token:this.token,p0_type:this.commType,heartbeat_interval:this._keepaliveTime,auto_subscribe:this.autoSubscribe}};this._send(e,!0)},this._tryLoginAgain=()=>{this._loginFailedTimes+=1,setTimeout(()=>{this._login()},this._loginFailedTimes*this._loginIntveral)},this._startPing=()=>{this._heartbeatTimerId=setInterval(()=>{this._send({cmd:"ping"})},1e3*this._heartbeatInterval)},this._stopPing=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId)},this.pongResp=()=>{},this._loginResp=e=>{1==e.success?(this._loginFailedTimes=0,this.ready=!0,this._startPing(),this._subDevices([...this._subDids])):this._loginFailedTimes<3?(console.debug("GIZ_SDK: Login failed, will try again, please wait..."),this._tryLoginAgain()):(console.debug("GIZ_SDK: Login failed"),this.close())},this._subscribeResp=e=>{console.log("GIZ_SDK: subscribe_res",e),e&&e.success&&e.success.forEach(e=>this._send({cmd:"c2s_read",data:{did:e.did}})),console.debug("GIZ_SDK: subscribe_res",e)},this._onlineResp=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged({did:e.did,attrs:Object.assign({is_online:e.online},e)})},this._rawChangedResp=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._statusChangedResp=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._invalidMsgResp=e=>{1003===e.error_code&&this._login(),console.debug("GIZ_SDK: s2c_invalid_msg",e)},this.appID=e,this.token=t,this.uid=i,this._wsUrl=`${s}/ws/app/v1`,this._heartbeatTimerId=void 0,this._loginFailedTimes=0,this._onDeviceStatusChanged=r,this._socketRespHandleMap={pong:this.pongResp,login_res:this._loginResp,subscribe_res:this._subscribeResp,s2c_online_status:this._onlineResp,s2c_raw:this._rawChangedResp,s2c_noti:this._statusChangedResp,s2c_invalid_msg:this._invalidMsgResp}}}t.Connection=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),r=i(20),n=i(21);class a extends n.default{constructor(){super(...arguments),this.disableSendUDP=!1,this.sendMessageInterval=null,this.UDPSocketHandler=null,this.destroy=()=>{this.cleanTimeout(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.sendMessageInterval=null,this.UDPSocketHandler&&(this.UDPSocketHandler.offError(),this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.close())},this.configDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((n,a)=>{console.debug("GIZ_SDK: start config device");let o=!1,c=0;const l=r.default.pack(e,t);this.UDPSocketHandler=wx.createUDPSocket(),this.UDPSocketHandler.bind(),this.disableSendUDP=!1;const d=()=>{try{!this.disableSendUDP&&this.UDPSocketHandler.send({address:"10.10.100.254",port:12414,message:l,offset:0,length:l.byteLength})}catch(e){}};this.sendMessageInterval=setInterval(()=>{d()},2e3),this.UDPSocketHandler.onError(e=>{c+=1,c>2&&(this.destroy(),a({success:!1,err:{errorCode:s.default.WECHAT_ERROR.errorCode,errorMessage:e.errMsg}}))});const u=async()=>{if(!o){this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.offError(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.disableSendUDP=!0,o=!0;try{const i=await this.searchDevice({ssid:e,password:t});n(i)}catch(e){a(e)}}};this.UDPSocketHandler.onMessage(e=>{u()}),wx.onNetworkStatusChange(async()=>{!o&&wx.getConnectedWifi({success:async e=>{-1===e.wifi.SSID.indexOf(i)&&u()}})})}),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>{const s=this.ssid,r=this.password;return new Promise(async(n,a)=>{this.destroy(),this.initDeviceOnboardingDeploy(n,a),this.startTimeoutTimer(e);try{const e=((await this.configDevice({ssid:s,password:r,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));if(t)try{n(await this.bindDevices(e))}catch(e){a(e)}else n({success:!0,data:e})}catch(e){a(e)}finally{this.destroy()}})}}}t.default=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(13),r=({SSID:e,password:t,pk:i})=>{let r=s.MD5(e+t).toString();r=s.enc.Hex.parse(r);let n=s.enc.Utf8.parse(i),a=s.AES.encrypt(n,r,{iv:r,mode:s.mode.ECB,padding:s.pad.ZeroPadding});return s.MD5(a.ciphertext).toString()};t.default=({SSID:e,password:t,pks:i})=>{const s=[];return i.map(i=>{const n=r({SSID:e,password:t,pk:i});s.push(n)}),s}},function(e,t){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t){},function(e,t,i){var s;e.exports=(s=i(0),function(){if("function"==typeof ArrayBuffer){var e=s.lib.WordArray,t=e.init;(e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var i=e.byteLength,s=[],r=0;r<i;r++)s[r>>>2]|=e[r]<<24-r%4*8;t.call(this,s,i)}else t.apply(this,arguments)}).prototype=e}}(),s.lib.WordArray)},function(e,t,i){var s;e.exports=(s=i(0),function(){var e=s,t=e.lib.WordArray,i=e.enc;function r(e){return e<<8&4278255360|e>>>8&16711935}i.Utf16=i.Utf16BE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],r=0;r<i;r+=2){var n=t[r>>>2]>>>16-r%4*8&65535;s.push(String.fromCharCode(n))}return s.join("")},parse:function(e){for(var i=e.length,s=[],r=0;r<i;r++)s[r>>>1]|=e.charCodeAt(r)<<16-r%2*16;return t.create(s,2*i)}},i.Utf16LE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n+=2){var a=r(t[n>>>2]>>>16-n%4*8&65535);s.push(String.fromCharCode(a))}return s.join("")},parse:function(e){for(var i=e.length,s=[],n=0;n<i;n++)s[n>>>1]|=r(e.charCodeAt(n)<<16-n%2*16);return t.create(s,2*i)}}}(),s.enc.Utf16)},function(e,t,i){var s,r,n;e.exports=(n=i(0),r=(s=n).lib.WordArray,s.enc.Base64url={stringify:function(e,t=!0){var i=e.words,s=e.sigBytes,r=t?this._safe_map:this._map;e.clamp();for(var n=[],a=0;a<s;a+=3)for(var o=(i[a>>>2]>>>24-a%4*8&255)<<16|(i[a+1>>>2]>>>24-(a+1)%4*8&255)<<8|i[a+2>>>2]>>>24-(a+2)%4*8&255,c=0;c<4&&a+.75*c<s;c++)n.push(r.charAt(o>>>6*(3-c)&63));var l=r.charAt(64);if(l)for(;n.length%4;)n.push(l);return n.join("")},parse:function(e,t=!0){var i=e.length,s=t?this._safe_map:this._map,n=this._reverseMap;if(!n){n=this._reverseMap=[];for(var a=0;a<s.length;a++)n[s.charCodeAt(a)]=a}var o=s.charAt(64);if(o){var c=e.indexOf(o);-1!==c&&(i=c)}return function(e,t,i){for(var s=[],n=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,l=o|c;s[n>>>2]|=l<<24-n%4*8,n++}return r.create(s,n)}(e,i,n)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},n.enc.Base64url)},function(e,t,i){var s,r,n,a,o,c;e.exports=(c=i(0),i(23),r=(s=c).lib.WordArray,n=s.algo,a=n.SHA256,o=n.SHA224=a.extend({_doReset:function(){this._hash=new r.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var e=a._doFinalize.call(this);return e.sigBytes-=4,e}}),s.SHA224=a._createHelper(o),s.HmacSHA224=a._createHmacHelper(o),c.SHA224)},function(e,t,i){var s,r,n,a,o,c,l,d;e.exports=(d=i(0),i(10),i(24),r=(s=d).x64,n=r.Word,a=r.WordArray,o=s.algo,c=o.SHA512,l=o.SHA384=c.extend({_doReset:function(){this._hash=new a.init([new n.init(3418070365,3238371032),new n.init(1654270250,914150663),new n.init(2438529370,812702999),new n.init(355462360,4144912697),new n.init(1731405415,4290775857),new n.init(2394180231,1750603025),new n.init(3675008525,1694076839),new n.init(1203062813,3204075428)])},_doFinalize:function(){var e=c._doFinalize.call(this);return e.sigBytes-=16,e}}),s.SHA384=c._createHelper(l),s.HmacSHA384=c._createHmacHelper(l),d.SHA384)},function(e,t,i){var s;e.exports=(s=i(0),i(10),function(e){var t=s,i=t.lib,r=i.WordArray,n=i.Hasher,a=t.x64.Word,o=t.algo,c=[],l=[],d=[];!function(){for(var e=1,t=0,i=0;i<24;i++){c[e+5*t]=(i+1)*(i+2)/2%64;var s=(2*e+3*t)%5;e=t%5,t=s}for(e=0;e<5;e++)for(t=0;t<5;t++)l[e+5*t]=t+(2*e+3*t)%5*5;for(var r=1,n=0;n<24;n++){for(var o=0,u=0,h=0;h<7;h++){if(1&r){var f=(1<<h)-1;f<32?u^=1<<f:o^=1<<f-32}128&r?r=r<<1^113:r<<=1}d[n]=a.create(o,u)}}();var u=[];!function(){for(var e=0;e<25;e++)u[e]=a.create()}();var h=o.SHA3=n.extend({cfg:n.cfg.extend({outputLength:512}),_doReset:function(){for(var e=this._state=[],t=0;t<25;t++)e[t]=new a.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(e,t){for(var i=this._state,s=this.blockSize/2,r=0;r<s;r++){var n=e[t+2*r],a=e[t+2*r+1];n=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),a=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),(A=i[r]).high^=a,A.low^=n}for(var o=0;o<24;o++){for(var h=0;h<5;h++){for(var f=0,p=0,g=0;g<5;g++)f^=(A=i[h+5*g]).high,p^=A.low;var v=u[h];v.high=f,v.low=p}for(h=0;h<5;h++){var _=u[(h+4)%5],y=u[(h+1)%5],D=y.high,m=y.low;for(f=_.high^(D<<1|m>>>31),p=_.low^(m<<1|D>>>31),g=0;g<5;g++)(A=i[h+5*g]).high^=f,A.low^=p}for(var b=1;b<25;b++){var w=(A=i[b]).high,S=A.low,B=c[b];B<32?(f=w<<B|S>>>32-B,p=S<<B|w>>>32-B):(f=S<<B-32|w>>>64-B,p=w<<B-32|S>>>64-B);var I=u[l[b]];I.high=f,I.low=p}var k=u[0],C=i[0];for(k.high=C.high,k.low=C.low,h=0;h<5;h++)for(g=0;g<5;g++){var A=i[b=h+5*g],x=u[b],E=u[(h+1)%5+5*g],L=u[(h+2)%5+5*g];A.high=x.high^~E.high&L.high,A.low=x.low^~E.low&L.low}A=i[0];var O=d[o];A.high^=O.high,A.low^=O.low}},_doFinalize:function(){var t=this._data,i=t.words,s=(this._nDataBytes,8*t.sigBytes),n=32*this.blockSize;i[s>>>5]|=1<<24-s%32,i[(e.ceil((s+1)/n)*n>>>5)-1]|=128,t.sigBytes=4*i.length,this._process();for(var a=this._state,o=this.cfg.outputLength/8,c=o/8,l=[],d=0;d<c;d++){var u=a[d],h=u.high,f=u.low;h=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8),f=16711935&(f<<8|f>>>24)|4278255360&(f<<24|f>>>8),l.push(f),l.push(h)}return new r.init(l,o)},clone:function(){for(var e=n.clone.call(this),t=e._state=this._state.slice(0),i=0;i<25;i++)t[i]=t[i].clone();return e}});t.SHA3=n._createHelper(h),t.HmacSHA3=n._createHmacHelper(h)}(Math),s.SHA3)},function(e,t,i){var s;e.exports=(s=i(0),
|
|
1
|
+
module.exports=function(e){var t={};function i(s){if(t[s])return t[s].exports;var r=t[s]={i:s,l:!1,exports:{}};return e[s].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=e,i.c=t,i.d=function(e,t,s){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(s,r,function(t){return e[t]}.bind(null,r));return s},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=16)}([function(e,t,i){(function(t){var s;e.exports=(s=s||function(e,s){var r;if("undefined"!=typeof window&&window.crypto&&(r=window.crypto),"undefined"!=typeof self&&self.crypto&&(r=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(r=globalThis.crypto),!r&&"undefined"!=typeof window&&window.msCrypto&&(r=window.msCrypto),!r&&void 0!==t&&t.crypto&&(r=t.crypto),!r)try{r=i(35)}catch(e){}var n=function(){if(r){if("function"==typeof r.getRandomValues)try{return r.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof r.randomBytes)try{return r.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),o={},c=o.lib={},l=c.Base={extend:function(e){var t=a(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},d=c.WordArray=l.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,i=e.words,s=this.sigBytes,r=e.sigBytes;if(this.clamp(),s%4)for(var n=0;n<r;n++){var a=i[n>>>2]>>>24-n%4*8&255;t[s+n>>>2]|=a<<24-(s+n)%4*8}else for(var o=0;o<r;o+=4)t[s+o>>>2]=i[o>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=l.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],i=0;i<e;i+=4)t.push(n());return new d.init(t,e)}}),u=o.enc={},h=u.Hex={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],r=0;r<i;r++){var n=t[r>>>2]>>>24-r%4*8&255;s.push((n>>>4).toString(16)),s.push((15&n).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s+=2)i[s>>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new d.init(i,t/2)}},f=u.Latin1={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],r=0;r<i;r++){var n=t[r>>>2]>>>24-r%4*8&255;s.push(String.fromCharCode(n))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s++)i[s>>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new d.init(i,t)}},p=u.Utf8={stringify:function(e){try{return decodeURIComponent(escape(f.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return f.parse(unescape(encodeURIComponent(e)))}},g=c.BufferedBlockAlgorithm=l.extend({reset:function(){this._data=new d.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=p.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var i,s=this._data,r=s.words,n=s.sigBytes,a=this.blockSize,o=n/(4*a),c=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,l=e.min(4*c,n);if(c){for(var u=0;u<c;u+=a)this._doProcessBlock(r,u);i=r.splice(0,c),s.sigBytes-=l}return new d.init(i,l)},clone:function(){var e=l.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),v=(c.Hasher=g.extend({cfg:l.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){g.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,i){return new e.init(i).finalize(t)}},_createHmacHelper:function(e){return function(t,i){return new v.HMAC.init(e,i).finalize(t)}}}),o.algo={});return o}(Math),s)}).call(this,i(34))},function(e,t,i){var s,r,n,a,o,c,l,d,u,h,f,p,g,v,_,y,D,m,b;e.exports=(s=i(0),i(3),void(s.lib.Cipher||(r=s,n=r.lib,a=n.Base,o=n.WordArray,c=n.BufferedBlockAlgorithm,l=r.enc,l.Utf8,d=l.Base64,u=r.algo.EvpKDF,h=n.Cipher=c.extend({cfg:a.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,i){this.cfg=this.cfg.extend(i),this._xformMode=e,this._key=t,this.reset()},reset:function(){c.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?b:D}return function(t){return{encrypt:function(i,s,r){return e(s).encrypt(t,i,s,r)},decrypt:function(i,s,r){return e(s).decrypt(t,i,s,r)}}}}()}),n.StreamCipher=h.extend({_doFinalize:function(){return this._process(!0)},blockSize:1}),f=r.mode={},p=n.BlockCipherMode=a.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),g=f.CBC=function(){var e=p.extend();function t(e,t,i){var s,r=this._iv;r?(s=r,this._iv=void 0):s=this._prevBlock;for(var n=0;n<i;n++)e[t+n]^=s[n]}return e.Encryptor=e.extend({processBlock:function(e,i){var s=this._cipher,r=s.blockSize;t.call(this,e,i,r),s.encryptBlock(e,i),this._prevBlock=e.slice(i,i+r)}}),e.Decryptor=e.extend({processBlock:function(e,i){var s=this._cipher,r=s.blockSize,n=e.slice(i,i+r);s.decryptBlock(e,i),t.call(this,e,i,r),this._prevBlock=n}}),e}(),v=(r.pad={}).Pkcs7={pad:function(e,t){for(var i=4*t,s=i-e.sigBytes%i,r=s<<24|s<<16|s<<8|s,n=[],a=0;a<s;a+=4)n.push(r);var c=o.create(n,s);e.concat(c)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},n.BlockCipher=h.extend({cfg:h.cfg.extend({mode:g,padding:v}),reset:function(){var e;h.reset.call(this);var t=this.cfg,i=t.iv,s=t.mode;this._xformMode==this._ENC_XFORM_MODE?e=s.createEncryptor:(e=s.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==e?this._mode.init(this,i&&i.words):(this._mode=e.call(s,this,i&&i.words),this._mode.__creator=e)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e,t=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e},blockSize:4}),_=n.CipherParams=a.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),y=(r.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,i=e.salt;return(i?o.create([1398893684,1701076831]).concat(i).concat(t):t).toString(d)},parse:function(e){var t,i=d.parse(e),s=i.words;return 1398893684==s[0]&&1701076831==s[1]&&(t=o.create(s.slice(2,4)),s.splice(0,4),i.sigBytes-=16),_.create({ciphertext:i,salt:t})}},D=n.SerializableCipher=a.extend({cfg:a.extend({format:y}),encrypt:function(e,t,i,s){s=this.cfg.extend(s);var r=e.createEncryptor(i,s),n=r.finalize(t),a=r.cfg;return _.create({ciphertext:n,key:i,iv:a.iv,algorithm:e,mode:a.mode,padding:a.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,i,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(i,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),m=(r.kdf={}).OpenSSL={execute:function(e,t,i,s){s||(s=o.random(8));var r=u.create({keySize:t+i}).compute(e,s),n=o.create(r.words.slice(t),4*i);return r.sigBytes=4*t,_.create({key:r,iv:n,salt:s})}},b=n.PasswordBasedCipher=D.extend({cfg:D.cfg.extend({kdf:m}),encrypt:function(e,t,i,s){var r=(s=this.cfg.extend(s)).kdf.execute(i,e.keySize,e.ivSize);s.iv=r.iv;var n=D.encrypt.call(this,e,t,r.key,s);return n.mixIn(r),n},decrypt:function(e,t,i,s){s=this.cfg.extend(s),t=this._parse(t,s.format);var r=s.kdf.execute(i,e.keySize,e.ivSize,t.salt);return s.iv=r.iv,D.decrypt.call(this,e,t,r.key,s)}}))))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.checkHeader=e=>{let t=0;return 0===e[0]&&0===e[1]&&0===e[2]&&3===e[3]&&(t=4,4)};t.getProtocolLen=e=>{let t=0;for(;t<e.length&&"1"===s(e[t].toString(2),8)[0];t++);return t+1},t.arrayToString=function(e){let t="";return e.map(e=>(t+=s(e.toString(16),2),null)),t};const s=(e,t,i=!1)=>{const s=t-e.length,r=new Array(s).fill(0).join("");return i?e+=r:e=r+e,e};t.fillString=s;t.string2Bytes=e=>{const t=[];for(let i=0;i<e.length;i++)t.push(e.charCodeAt(i));return t};t.hexStrint2byte=e=>{const t=Math.ceil(e.length/2),i=[];for(let s=0;s<t;s++){const t=2*s,r=t+2,n=e.substring(t,r);i.push(parseInt(n,16))}return i};const r=e=>{const t=encodeURI(e);return-1!==t.indexOf("%")&&"%"!==e?t.split("%").filter(e=>""!==e).map(e=>parseInt(e,16)):[t.charCodeAt(0)]};t.formatCode=r;t.formatCodesFromStr=e=>{const t=[0,0];let i=[];for(let s=0;s<e.length;s++){const n=r(e[s]);t[1]+=n.length,i=i.concat(n)}return[i,t]}},function(e,t,i){var s,r,n,a,o,c,l,d;e.exports=(d=i(0),i(14),i(15),r=(s=d).lib,n=r.Base,a=r.WordArray,o=s.algo,c=o.MD5,l=o.EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:c,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i,s=this.cfg,r=s.hasher.create(),n=a.create(),o=n.words,c=s.keySize,l=s.iterations;o.length<c;){i&&r.update(i),i=r.update(e).finalize(t),r.reset();for(var d=1;d<l;d++)i=r.finalize(i),r.reset();n.concat(i)}return n.sigBytes=4*c,n}}),s.EvpKDF=function(e,t,i){return l.create(i).compute(e,t)},d.EvpKDF)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default={GIZ_OPENAPI_DEVICE_NOT_BOUND:{errorCode:9017,errorMessage:"not bind"},GIZ_SDK_HTTP_REQUEST_FAILED:{errorCode:8099,errorMessage:"网络请求失败"},GIZ_SDK_SDK_NOT_INITIALIZED:{errorCode:8300,errorMessage:"not init"},CONFIG_TIME_OUT:{errorCode:8023,errorMessage:"Config Timeout"},WECHAT_ERROR:{errorCode:1e4,errorMessage:"wechat error"},GIZ_SDK_ONBOARDING_STOPPED:{errorCode:8318,errorMessage:"配网中断"},GIZ_SDK_DEVICE_CONFIG_IS_RUNNING:{errorCode:8022,errorMessage:"配置正在进行中"},GIZ_OPENAPI_TOKEN_INVALID:{errorCode:9004,errorMessage:"token 失效"},GIZ_SDK_BIND_DEVICE_FAILED:{errorCode:8039,errorMessage:"设备绑定失败"},GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON:{errorCode:8281,errorMessage:"蓝牙未启用"},GIZ_SDK_OTHERWISE:{errorCode:8100,errorMessage:""},GIZ_SDK_DEVICE_NOT_SUBSCRIBED:{errorCode:8029,errorMessage:"设备还未订阅"},GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY:{errorCode:8250,errorMessage:"产品类型不在指定范围内"}}},function(e,t,i){var s,r,n;e.exports=(n=i(0),r=(s=n).lib.WordArray,s.enc.Base64={stringify:function(e){var t=e.words,i=e.sigBytes,s=this._map;e.clamp();for(var r=[],n=0;n<i;n+=3)for(var a=(t[n>>>2]>>>24-n%4*8&255)<<16|(t[n+1>>>2]>>>24-(n+1)%4*8&255)<<8|t[n+2>>>2]>>>24-(n+2)%4*8&255,o=0;o<4&&n+.75*o<i;o++)r.push(s.charAt(a>>>6*(3-o)&63));var c=s.charAt(64);if(c)for(;r.length%4;)r.push(c);return r.join("")},parse:function(e){var t=e.length,i=this._map,s=this._reverseMap;if(!s){s=this._reverseMap=[];for(var n=0;n<i.length;n++)s[i.charCodeAt(n)]=n}var a=i.charAt(64);if(a){var o=e.indexOf(a);-1!==o&&(t=o)}return function(e,t,i){for(var s=[],n=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,l=o|c;s[n>>>2]|=l<<24-n%4*8,n++}return r.create(s,n)}(e,t,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},n.enc.Base64)},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,r=i.WordArray,n=i.Hasher,a=t.algo,o=[];!function(){for(var t=0;t<64;t++)o[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=a.MD5=n.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var s=t+i,r=e[s];e[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8)}var n=this._hash.words,a=e[t+0],c=e[t+1],f=e[t+2],p=e[t+3],g=e[t+4],v=e[t+5],_=e[t+6],y=e[t+7],D=e[t+8],m=e[t+9],b=e[t+10],w=e[t+11],S=e[t+12],B=e[t+13],I=e[t+14],k=e[t+15],C=n[0],A=n[1],x=n[2],E=n[3];C=l(C,A,x,E,a,7,o[0]),E=l(E,C,A,x,c,12,o[1]),x=l(x,E,C,A,f,17,o[2]),A=l(A,x,E,C,p,22,o[3]),C=l(C,A,x,E,g,7,o[4]),E=l(E,C,A,x,v,12,o[5]),x=l(x,E,C,A,_,17,o[6]),A=l(A,x,E,C,y,22,o[7]),C=l(C,A,x,E,D,7,o[8]),E=l(E,C,A,x,m,12,o[9]),x=l(x,E,C,A,b,17,o[10]),A=l(A,x,E,C,w,22,o[11]),C=l(C,A,x,E,S,7,o[12]),E=l(E,C,A,x,B,12,o[13]),x=l(x,E,C,A,I,17,o[14]),C=d(C,A=l(A,x,E,C,k,22,o[15]),x,E,c,5,o[16]),E=d(E,C,A,x,_,9,o[17]),x=d(x,E,C,A,w,14,o[18]),A=d(A,x,E,C,a,20,o[19]),C=d(C,A,x,E,v,5,o[20]),E=d(E,C,A,x,b,9,o[21]),x=d(x,E,C,A,k,14,o[22]),A=d(A,x,E,C,g,20,o[23]),C=d(C,A,x,E,m,5,o[24]),E=d(E,C,A,x,I,9,o[25]),x=d(x,E,C,A,p,14,o[26]),A=d(A,x,E,C,D,20,o[27]),C=d(C,A,x,E,B,5,o[28]),E=d(E,C,A,x,f,9,o[29]),x=d(x,E,C,A,y,14,o[30]),C=u(C,A=d(A,x,E,C,S,20,o[31]),x,E,v,4,o[32]),E=u(E,C,A,x,D,11,o[33]),x=u(x,E,C,A,w,16,o[34]),A=u(A,x,E,C,I,23,o[35]),C=u(C,A,x,E,c,4,o[36]),E=u(E,C,A,x,g,11,o[37]),x=u(x,E,C,A,y,16,o[38]),A=u(A,x,E,C,b,23,o[39]),C=u(C,A,x,E,B,4,o[40]),E=u(E,C,A,x,a,11,o[41]),x=u(x,E,C,A,p,16,o[42]),A=u(A,x,E,C,_,23,o[43]),C=u(C,A,x,E,m,4,o[44]),E=u(E,C,A,x,S,11,o[45]),x=u(x,E,C,A,k,16,o[46]),C=h(C,A=u(A,x,E,C,f,23,o[47]),x,E,a,6,o[48]),E=h(E,C,A,x,y,10,o[49]),x=h(x,E,C,A,I,15,o[50]),A=h(A,x,E,C,v,21,o[51]),C=h(C,A,x,E,S,6,o[52]),E=h(E,C,A,x,p,10,o[53]),x=h(x,E,C,A,b,15,o[54]),A=h(A,x,E,C,c,21,o[55]),C=h(C,A,x,E,D,6,o[56]),E=h(E,C,A,x,k,10,o[57]),x=h(x,E,C,A,_,15,o[58]),A=h(A,x,E,C,B,21,o[59]),C=h(C,A,x,E,g,6,o[60]),E=h(E,C,A,x,w,10,o[61]),x=h(x,E,C,A,f,15,o[62]),A=h(A,x,E,C,m,21,o[63]),n[0]=n[0]+C|0,n[1]=n[1]+A|0,n[2]=n[2]+x|0,n[3]=n[3]+E|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;i[r>>>5]|=128<<24-r%32;var n=e.floor(s/4294967296),a=s;i[15+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),i[14+(r+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),t.sigBytes=4*(i.length+1),this._process();for(var o=this._hash,c=o.words,l=0;l<4;l++){var d=c[l];c[l]=16711935&(d<<8|d>>>24)|4278255360&(d<<24|d>>>8)}return o},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});function l(e,t,i,s,r,n,a){var o=e+(t&i|~t&s)+r+a;return(o<<n|o>>>32-n)+t}function d(e,t,i,s,r,n,a){var o=e+(t&s|i&~s)+r+a;return(o<<n|o>>>32-n)+t}function u(e,t,i,s,r,n,a){var o=e+(t^i^s)+r+a;return(o<<n|o>>>32-n)+t}function h(e,t,i,s,r,n,a){var o=e+(i^(t|~s))+r+a;return(o<<n|o>>>32-n)+t}t.MD5=n._createHelper(c),t.HmacMD5=n._createHmacHelper(c)}(Math),s.MD5)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(2);class r{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=s.checkHeader(e);if(!1===t)throw new Error("Header Error");this.header=s.arrayToString(e.slice(0,t));const i=e.slice(t,e.length),n=s.getProtocolLen(i);this.len=r.decodeLen(i.slice(0,n)),t+=n,this.flag=e.slice(t,t+1),t+=1,this.cmd=s.arrayToString(e.slice(t,t+2)),t+=2,this.content=e.slice(t,e.length)},e&&e.length>0&&this.formatP0(e)}}r.decodeLen=e=>{let t=1,i=0,s=0,r=0;do{s=e[r],i+=(127&s)*t,t*=128,r+=1}while(0!=(128&s));return i},t.default=r},function(e,t,i){"use strict";function s(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}Object.defineProperty(t,"__esModule",{value:!0}),t.ab2hex=s,t.compareWXSDKVersion=function(e,t){const i=e.split("."),s=t.split("."),r=Math.max(e.length,t.length);for(;i.length<r;)i.push("0");for(;s.length<r;)s.push("0");for(let i=0;i<r;i++){const s=parseInt(e[i]),r=parseInt(t[i]);if(s>r)return 1;if(s<r)return-1}return 0},t.isError=e=>null!=e&&"symbol"==typeof e.errorCode,t.wrapErrorInfo=e=>({errorCode:e,errorMessage:e}),t.unionBy=(e,t)=>e.reduce((e,i)=>{const s=i[t];return e.some(e=>e[t]===s)||e.push(i),e},[]),t.isWXDevicesResult=function(e){return e.success&&"[object Array]"===Object.prototype.toString.call(e.bleDevices)},t.str2Buf=function(e){var t=e.length,i=new ArrayBuffer(t+2),s=new DataView(i);for(let i=0;i<t;i++)s.setUint8(i,parseInt(e[i],16));return i},t.numberArray2Uint8Array=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i},t.advertisData2PkAndMac=(e,t)=>{let i=e.slice(e.byteLength-16),r=e.slice(0,e.byteLength-16),n=s(i);if(t.find(e=>e===n)){const e=s(r);return{productKey:n,mac:e}}{i=e.slice(0,16),r=e.slice(16),n=s(i);const t=s(r);return{productKey:n,mac:t}}},t.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey,t.merageBleLocalDevices=(e,i)=>(i.map(i=>{const s=e.find(e=>t.isSameDevice(e,i));s?(s.isBleOnline=!0,s.bleDeviceID=i.bleDeviceID):e.push(i)}),e),t.merageLanLocalDevices=(e,i)=>(i.map(i=>{const s=e.find(e=>t.isSameDevice(e,i));s?s.isLanOnline=!0:e.push(i)}),e),t.BTDevice2GDevice=(e,i)=>{const{productKey:s,mac:r}=t.advertisData2PkAndMac(e.advertisData,i);return{mac:r,did:"",connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,productKey:s,name:e.name,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime()}},t.getFirstConnectType=(e,t)=>{if(!t)return e.isLanOnline?"LAN":e.isBleOnline?"BLE":"WAN";if("WAN"===t)return"WAN";switch(t){case"BLE":return e.isBleOnline?"BLE":"NONE";case"LAN":return e.isLanOnline?"LAN":"NONE"}return"WAN"},t.getProductInfoThroughPK=(e,t)=>t.find(t=>t.productKey===e),t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2ab=function(e){const t=[];for(let s=0;s<e.length;s+=2){var i=e.slice(s,s+2);t.push(parseInt(i,16))}return new Uint8Array(t)}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(30),r=i(17),n=i(4);t.siteApiRequest=async(e,t)=>{const i=Object.assign({},t);i.header=Object.assign(Object.assign({},{"Content-Type":"application/json"}),t.headers),delete i.headers;const a=(r.getGlobalData("cloudServiceInfo")||{}).siteInfo||"site.gizwits.com",o=await s.default("http://"+a+e,i);if(o.statusCode>=200&&o.statusCode<300)return{success:!0,data:o.data};let c={success:!1,err:{errorCode:n.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{c={success:!1,err:{errorCode:o.data.error_code,errorMessage:o.data.error_message}}}catch(e){}return c},t.default=async(e,t,i=!0)=>{const a=Object.assign({},t),o={"Content-Type":"application/json","X-Gizwits-Application-Id":r.getGlobalData("appID")};i&&(o["X-Gizwits-User-token"]=r.getGlobalData("token")),a.header=Object.assign(Object.assign({},o),t.headers),delete a.headers;const c=r.getGlobalData("cloudServiceInfo").openAPIInfo,l=await s.default("https://"+c+e,a);if(l.statusCode>=200&&l.statusCode<300)return{success:!0,data:l.data};let d={success:!1,err:{errorCode:n.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{d={success:!1,err:{errorCode:l.data.error_code,errorMessage:l.data.error_message}}}catch(e){}return d}},function(e,t,i){var s,r,n,a,o,c;e.exports=(c=i(0),r=(s=c).lib,n=r.Base,a=r.WordArray,(o=s.x64={}).Word=n.extend({init:function(e,t){this.high=e,this.low=t}}),o.WordArray=n.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:8*e.length},toX32:function(){for(var e=this.words,t=e.length,i=[],s=0;s<t;s++){var r=e[s];i.push(r.high),i.push(r.low)}return a.create(i,this.sigBytes)},clone:function(){for(var e=n.clone.call(this),t=e.words=this.words.slice(0),i=t.length,s=0;s<i;s++)t[s]=t[s].clone();return e}}),c)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=e=>new Promise(t=>setTimeout(()=>t(),e))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(9);const r=new class{constructor(){this.data={},this.key="dataPointConfig",this.init=async()=>{const e=await wx.getStorageSync(this.key)||"{}";let t={};try{t=JSON.parse(e)}catch(e){}this.data=t},this.getConfigFile=async e=>{var t;if(!this.data[e]){const i=`/app/datapoint?product_key=${e}`,r=await s.default(`${i}`,{method:"GET"});if(!r.success||!(null===(t=r.data)||void 0===t?void 0:t.entities))return null;this.data[e]=r.data,wx.setStorageSync(this.key,JSON.stringify(this.data))}return this.data[e]}}};r.init(),t.default=r},function(e,t,i){var s;e.exports=(s=i(0),i(10),i(36),i(37),i(5),i(38),i(6),i(14),i(23),i(39),i(24),i(40),i(41),i(42),i(15),i(43),i(3),i(1),i(44),i(45),i(46),i(47),i(48),i(49),i(50),i(51),i(52),i(53),i(54),i(55),i(56),i(57),i(58),i(59),s)},function(e,t,i){var s,r,n,a,o,c,l,d;e.exports=(d=i(0),r=(s=d).lib,n=r.WordArray,a=r.Hasher,o=s.algo,c=[],l=o.SHA1=a.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],r=i[1],n=i[2],a=i[3],o=i[4],l=0;l<80;l++){if(l<16)c[l]=0|e[t+l];else{var d=c[l-3]^c[l-8]^c[l-14]^c[l-16];c[l]=d<<1|d>>>31}var u=(s<<5|s>>>27)+o+c[l];u+=l<20?1518500249+(r&n|~r&a):l<40?1859775393+(r^n^a):l<60?(r&n|r&a|n&a)-1894007588:(r^n^a)-899497514,o=a,a=n,n=r<<30|r>>>2,r=s,s=u}i[0]=i[0]+s|0,i[1]=i[1]+r|0,i[2]=i[2]+n|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[14+(s+64>>>9<<4)]=Math.floor(i/4294967296),t[15+(s+64>>>9<<4)]=i,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),s.SHA1=a._createHelper(l),s.HmacSHA1=a._createHmacHelper(l),d.SHA1)},function(e,t,i){var s,r,n,a;e.exports=(s=i(0),n=(r=s).lib.Base,a=r.enc.Utf8,void(r.algo.HMAC=n.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var i=e.blockSize,s=4*i;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),n=this._iKey=t.clone(),o=r.words,c=n.words,l=0;l<i;l++)o[l]^=1549556828,c[l]^=909522486;r.sigBytes=n.sigBytes=s,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(i))}})))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),i(25);const s=i(26),r=i(4);t.errorCode=r.default;const n=i(18);t.BleHandle=n.BleHandle,t.default=s.default},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s={};t.setGlobalData=function(e,t){s[e]=t},t.getGlobalData=function(e){return s[e]}},function(e,t,i){"use strict";var s=this&&this.__rest||function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(i[s[r]]=e[s[r]])}return i};Object.defineProperty(t,"__esModule",{value:!0});const r=i(8),n=i(19),a=i(27),o=i(2),c=i(7),l=i(28),d=i(29);t.BleHandle=class{constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"abf0",characteristicUUIDSuffix:"abf7"},globalListenerMap:i,gizSdk:u,offlineThreshold:h}){this.connectedList=[],this.pks=[],this.tmpBleData="",this.tmpDataNum=0,this.listenerMap={},this.globalListenerMap={},this.scanList=[],this.listenDevOffline=e=>{setInterval(()=>{const t=(new Date).getTime(),i=this.scanList.filter(i=>t-i.ctime<e);i.length!==this.scanList.length&&(this.scanList=i,this.gizSdk.bleDevices=i)},500)},this.openBluetoothAdapter=()=>new Promise((e,t)=>{wx.openBluetoothAdapter({success:()=>{console.log("openBluetoothAdapter success"),e({success:!0}),wx.onBLECharacteristicValueChange(this.handleOnBLECharacteristicValueChange)},fail:e=>{console.log("openBluetoothAdapter fail",e),this.notifyError({errMsg:e.errMsg,errCode:-1}),t(e)}})}),this.handleOnBLECharacteristicValueChange=e=>{const t=r.ab2hex(e.value);try{const i=new c.default(o.hexStrint2byte(t));console.log("ProtocolBase",i.len,e.value.byteLength,i),this.tmpBleData=t,this.tmpDataNum=i.len-e.value.byteLength+4+Math.ceil(i.len.toString(2).length/8)}catch(i){this.tmpBleData&&(this.tmpBleData+=t,this.tmpDataNum-=e.value.byteLength)}this.tmpDataNum>0||!this.tmpBleData||(console.log("ProtocolBase141",this.tmpBleData,this.tmpDataNum),this.listenerMap[e.deviceId]&&this.listenerMap[e.deviceId].map(t=>{t(e,this.tmpBleData)}),this.listenerMap.ALL&&(console.log("ProtocolBase1"),this.listenerMap.ALL.map(t=>{console.log("ProtocolBase2"),t(e,this.tmpBleData)})),this.tmpBleData="",this.tmpDataNum=0)},this.notifyError=e=>{var t;null===(t=this.globalListenerMap.onBleHandleError)||void 0===t||t.map(t=>{t(e)})},this.listenConnection=e=>{wx.onBLEConnectionStateChange(t=>{const i=this.connectedList.map(e=>e.deviceId).includes(e)&&t.deviceId===e&&!1===t.connected;console.log("蓝牙状态变化",{connectedList:this.connectedList,res:t,deviceId:e}),i&&this.connectDevice(e)})},this.checkPermission=async()=>{if((await wx.getSetting()).authSetting["scope.bluetooth"]){return await this.openBluetoothAdapter(),await this.getBluetoothAdapterState()}try{return await wx.authorize({scope:"scope.bluetooth"}),await this.openBluetoothAdapter(),await this.getBluetoothAdapterState()}catch(e){console.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1})}},this.getBluetoothAdapterState=async()=>{const e=await wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,n=s(e,["errMsg","available"]);return{data:Object.assign({},n),err:r.wrapErrorInfo(t),success:i}},this.getDeviceStatus=async(e,t,i,s)=>{const n=await d.default.pack(t,i,s);return n?await this.write(e,r.numberArray2Uint8Array(n).buffer):{success:!1}},this.handleBluetoothDeviceFound=(e,t)=>{const i=r.unionBy(e.devices,"deviceId").filter(e=>{const{advertisData:t,deviceId:i,name:s,localName:n}=e,a=r.ab2hex(t),o=this.scanList.find(e=>e.bleDeviceID===i);if(o)return this.gizSdk.setDeviceMeta(o,"ctime",Date.now()),!1;return this.pks.some(e=>a.includes(e))});if(i.length>0){const e=i.map(e=>r.BTDevice2GDevice(e,this.pks));this.scanList.push(...e),t(this.scanList)}},this.startScan=async(e,t=5e3)=>new Promise(async i=>{wx.onBluetoothDeviceFound(t=>{this.handleBluetoothDeviceFound(t,e)}),await wx.startBluetoothDevicesDiscovery({powerLevel:"high",allowDuplicatesKey:!0,interval:500}),setTimeout(()=>{this.stopScan(),i({scanList:this.scanList})},t)}),this.stopScan=async()=>{const{errMsg:e,errCode:t}=await wx.stopBluetoothDevicesDiscovery();return{errMsg:e,errCode:t}},this.connectDevice=async e=>{var t;const i=await wx.createBLEConnection({deviceId:e}).catch(t=>{this.removeDevById(e),this.notifyError(t)});if("createBLEConnection:ok"!==i.errMsg)return{success:!1,message:null==i?void 0:i.errMsg};this.listenConnection(e);const s=await wx.getBLEDeviceServices({deviceId:e}).catch(e=>this.notifyError(e)),n=null===(t=null==s?void 0:s.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)))||void 0===t?void 0:t.uuid;if(!n)return{message:"can not find valid serviceId",success:!1};const o=await wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:n}).catch(e=>this.notifyError(e));console.log({getCharRes:o});const c=null==o?void 0:o.characteristics[0].uuid;this.connectedList.every(t=>t.deviceId!==e)&&this.connectedList.push({deviceId:e,serviceId:n,characteristicId:c});await wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:n,characteristicId:c,state:!0,type:"notification"}).catch(e=>this.notifyError(e));this.write(e,r.numberArray2Uint8Array(a.default.pack()).buffer);const d=await this.handleBindReq(e);if(console.log("handleBindReq",d),d.success){this.write(e,r.numberArray2Uint8Array(l.default.pack({passcode:d.data})).buffer);const t=await this.handleLoginReq(e).catch(e=>this.notifyError(e));if(console.log("loginData",t),null==t?void 0:t.success)return{success:!0,message:"ok"}}return{success:!1,message:"ok"}},this.handleBindReq=e=>new Promise(t=>{console.log("handleBindReq");const i=(s,r)=>{console.log("监听蓝牙特征值发生变化");const n=new a.default(o.hexStrint2byte(r));this.removeDeviceListener(e,i),n.passcode?t({success:!0,data:n.passcode}):t({success:!1,data:""})};this.addDeviceListener(e,i)}),this.handleLoginReq=e=>new Promise(t=>{const i=(s,r)=>{console.log("设备回复LoginReq",r);const n=new l.default(o.hexStrint2byte(r));this.removeDeviceListener(e,i),!0===n.result?t({success:!0,data:n.did}):t({success:!1,data:""})};this.addDeviceListener(e,i)}),this.removeDeviceListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{message:"ok",success:!0}}return{message:"invalid function",success:!1}},this.addDeviceListener=async(e,t)=>{"ALL"===e&&(this.listenerMap.ALL||(this.listenerMap.ALL=[]),this.listenerMap.ALL.push(t));const{serviceId:i,characteristicId:s,errMsg:r}=this.getTargetDevice(e);return r?{success:!1,message:r}:(this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),await wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:s,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),console.log(`监听设备 ${e} 成功!`),{message:"ok",success:!0})},this.write=async(e,t)=>{console.log("app => dev:",r.ab2hex(t));const{serviceId:i,characteristicId:s}=this.getTargetDevice(e);if(i&&s){return await n.unpackWriteBLECharacteristicValue(e,i,s,t)}return{success:!1,message:"serviceId or characteristicId is unvalid!",errbody:{serviceId:i,characteristicId:s}}},this.disConnectDevice=async e=>{this.removeDevById(e);const{errMsg:t}=await wx.closeBLEConnection({deviceId:e});return"closeBLEConnection:ok"===t?{err:t,success:!0}:{err:t,success:!1}},this.removeDevById=e=>{const t=this.connectedList.findIndex(t=>t.deviceId===e);this.connectedList.splice(t,1)},this.getTargetDevice=e=>{const t=this.connectedList.find(t=>e===t.deviceId);return t||{errMsg:"Unable get this device,maybe you forgot to connect it."}};const{serviceUUIDSuffix:f}=t;this.serviceUUIDSuffix=f,this.pks=e,this.globalListenerMap=i,this.gizSdk=u}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(11);function r(e,t,i,s){return new Promise(r=>{console.log("writeBLECharacteristicValue"),wx.writeBLECharacteristicValue({deviceId:e,serviceId:t,characteristicId:i,value:s,complete:r})})}t.openBluetoothAdapter=function(){return new Promise((e,t)=>{wx.openBluetoothAdapter({success:e,fail:t})})},t.closeBluetoothAdapter=function(){return new Promise((e,t)=>{wx.closeBluetoothAdapter({success:e,fail:t})})},t.getBluetoothAdapterState=function(){return new Promise((e,t)=>{wx.getBluetoothAdapterState({success:e,fail:t})})},t.startBluetoothDevicesDiscovery=function(){return new Promise((e,t)=>{wx.startBluetoothDevicesDiscovery({success:e,fail:t,interval:100})})},t.getBluetoothDevices=function(){return new Promise((e,t)=>{wx.getBluetoothDevices({success:({devices:t})=>e(t),fail:t})})},t.createBLEConnection=function(e,t){return new Promise((i,s)=>{wx.createBLEConnection({deviceId:e,timeout:t,success:e=>i(e),fail:e=>{-1===e.errCode?i(e):s(e)}})})},t.getBLEDeviceServices=function(e){return new Promise((t,i)=>{wx.getBLEDeviceServices({deviceId:e,success:({services:e})=>t(e),fail:i})})},t.getBLEDeviceCharacteristics=function(e,t){return new Promise((i,s)=>{wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:t,success:({characteristics:e})=>i(e),fail:s})})},t.notifyBLECharacteristicValueChange=function(e,t,i,s=!0){return new Promise((r,n)=>{wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:t,characteristicId:i,state:s,success:r,fail:n})})},t.writeBLECharacteristicValue=r,t.unpackWriteBLECharacteristicValue=function(e,t,i,n){if(0===n.byteLength)throw new Error("value is not empty");return new Promise(async(a,o)=>{let c,l=0,d=n.byteLength;for(;d>0;){await s.default(30);const a=n.slice(l,l+20);if(l+=20,d-=20,c=await r(e,t,i,a),console.log("unpackWriteBLECharacteristicValue",l/20,c),0!==c.errCode)break}0!==c.errCode?o(c):a(c)})}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(7),r=i(2);class n extends s.default{constructor(e){super(e)}}n.pack=(e,t)=>{const i=[],[s,n]=r.formatCodesFromStr(e),[a,o]=r.formatCodesFromStr(t),c=[0].concat([0,1],n,s,o,a);let l=c.length;for(;l>0;)i.push(l),l-=255;const d=[0,0,0,3].concat(i).concat(c),u=new ArrayBuffer(d.length),h=new Uint8Array(u);for(let e=0;e<u.byteLength;e++)h[e]=d[e];return h},t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(11),r=i(4),n=i(22);t.default=class{constructor(e,t,i,a){this.ssid="",this.password="",this.specialProductKeys=[],this.disableSearchDevice=!1,this.specialProductKeySecrets=[],this.timeoutHandler=null,this.setDeviceOnboardingDeployRej=()=>{},this.cleanTimeout=()=>{this.disableSearchDevice=!0,this.timeoutHandler&&clearTimeout(this.timeoutHandler),this.timeoutHandler=null,console.log("this.timeoutHandler",this.timeoutHandler)},this.stopDeviceOnboardingDeploy=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:r.default.GIZ_SDK_ONBOARDING_STOPPED}),this.cleanTimeout()},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:r.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:r.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,a)=>{console.debug("GIZ_SDK: 开始大循环搜索设备");const o=async()=>{var c;if(this.hasTimeoutHandler())try{const l=await n.checkDeviceRegister({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(c=l.err)||void 0===c?void 0:c.errorCode)===r.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void a({success:!1,err:r.default.GIZ_OPENAPI_TOKEN_INVALID});l.err||0===l.data.length?(console.debug("GIZ_SDK: 大循环没有发现设备"),await s.default(1500),!this.disableSearchDevice&&o()):(console.debug("GIZ_SDK: 大循环搜索到设备",l),i({success:!0,data:l.data}))}catch(e){await s.default(3e3),!this.disableSearchDevice&&o()}};o()}),this.initDeviceOnboardingDeploy=(e,t)=>{this.setDeviceOnboardingDeployRej=t,this.disableSearchDevice=!1},this.startTimeoutTimer=e=>{this.timeoutHandler=setTimeout(this.handleTimeout,1e3*e)},this.bindDevices=e=>(console.log("GIZ_SDK: start bind device"),new Promise(async(t,i)=>{const s=e.map(e=>{const t=this.specialProductKeys.findIndex(t=>e.productKey===t);if(-1===t)return;const i=this.specialProductKeySecrets[t];return n.bindMac({mac:e.mac,productKey:e.productKey,productSecret:i})});try{const n=await Promise.all(s),a=e.filter((e,t)=>{const i=n[t];return i&&i.success});a.length>0?(console.log("GIZ_SDK: bind device success",a),t({success:!0,data:a})):(console.log("GIZ_SDK: bind device error",n),i({success:!1,data:e,err:r.default.GIZ_SDK_BIND_DEVICE_FAILED}))}catch(e){i(e)}})),this.ssid=e,this.password=t,this.specialProductKeys=i,this.specialProductKeySecrets=a}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(9),r=i(33),n=i(60),a=i(13);t.getBindingList=async()=>{const e=await s.default("/app/bindings?show_disabled=0&limit=1000&skip=0",{method:"GET"});if(e.success){return{success:!0,data:e.data.devices.map(e=>({productKey:e.product_key,mac:e.mac,did:e.did,host:e.host,port_s:e.port_s,port:e.port,ws_port:e.ws_port,wss_port:e.wss_port,isBleOnline:!1,isLanOnline:!1,connectType:"NONE",name:e.dev_alias,isBind:!0,isOnline:e.is_online}))}}return{success:!1,err:e.err}},t.bindMac=async function({mac:e,productKey:t,productSecret:i,alias:r,beOwner:a}){const o={mac:e,product_key:t,dev_alias:r,set_owner:a},{Signature:c,timestamp:l}=n.psKeySign(i);return await s.default("/app/bind_mac",{method:"POST",data:o,headers:{"X-Gizwits-Signature":c,"X-Gizwits-Timestamp":l}})},t.unbindDevice=async function({devices:e}){return await s.default("/app/bindings",{method:"DELETE",data:{devices:e.map(e=>({did:e.did}))}})},t.checkDeviceRegister=async function({SSID:e,password:t,productKeys:i}){const n=r.default({SSID:e,password:t,pks:i});let a="";return n.map(e=>{a+=`${e},`}),a=a.substring(0,a.length-1),await s.default(`/app/device_register?random_codes=${a}`,{method:"get"})},t.safeRegister=async function({productKey:e,productSecret:t,mac:i,passcode:r,gwDid:n,isReset:o}){let c=`is_reset=${o?1:0}&mac=${i}&passcode=${r}`;n&&(c+=`&gw_did=${n}`);const l=a.enc.Hex.parse(t),d=a.enc.Hex.parse(""),u=a.enc.Utf8.parse(c),h=a.AES.encrypt(u,l,{iv:d,mode:a.mode.ECB,padding:a.pad.Pkcs7}).ciphertext.toString().toUpperCase(),f=await s.default(`/dev/${e}/device`,{method:"POST",data:{data:h},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);return f.success?{success:!0,data:{successDevices:[],failedDevices:[]}}:{success:!1,err:f.err}}},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,r=i.WordArray,n=i.Hasher,a=t.algo,o=[],c=[];!function(){function t(t){for(var i=e.sqrt(t),s=2;s<=i;s++)if(!(t%s))return!1;return!0}function i(e){return 4294967296*(e-(0|e))|0}for(var s=2,r=0;r<64;)t(s)&&(r<8&&(o[r]=i(e.pow(s,.5))),c[r]=i(e.pow(s,1/3)),r++),s++}();var l=[],d=a.SHA256=n.extend({_doReset:function(){this._hash=new r.init(o.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],r=i[1],n=i[2],a=i[3],o=i[4],d=i[5],u=i[6],h=i[7],f=0;f<64;f++){if(f<16)l[f]=0|e[t+f];else{var p=l[f-15],g=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,v=l[f-2],_=(v<<15|v>>>17)^(v<<13|v>>>19)^v>>>10;l[f]=g+l[f-7]+_+l[f-16]}var y=s&r^s&n^r&n,D=(s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22),m=h+((o<<26|o>>>6)^(o<<21|o>>>11)^(o<<7|o>>>25))+(o&d^~o&u)+c[f]+l[f];h=u,u=d,d=o,o=a+m|0,a=n,n=r,r=s,s=m+(D+y)|0}i[0]=i[0]+s|0,i[1]=i[1]+r|0,i[2]=i[2]+n|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0,i[5]=i[5]+d|0,i[6]=i[6]+u|0,i[7]=i[7]+h|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=e.floor(s/4294967296),i[15+(r+64>>>9<<4)]=s,t.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(d),t.HmacSHA256=n._createHmacHelper(d)}(Math),s.SHA256)},function(e,t,i){var s;e.exports=(s=i(0),i(10),function(){var e=s,t=e.lib.Hasher,i=e.x64,r=i.Word,n=i.WordArray,a=e.algo;function o(){return r.create.apply(r,arguments)}var c=[o(1116352408,3609767458),o(1899447441,602891725),o(3049323471,3964484399),o(3921009573,2173295548),o(961987163,4081628472),o(1508970993,3053834265),o(2453635748,2937671579),o(2870763221,3664609560),o(3624381080,2734883394),o(310598401,1164996542),o(607225278,1323610764),o(1426881987,3590304994),o(1925078388,4068182383),o(2162078206,991336113),o(2614888103,633803317),o(3248222580,3479774868),o(3835390401,2666613458),o(4022224774,944711139),o(264347078,2341262773),o(604807628,2007800933),o(770255983,1495990901),o(1249150122,1856431235),o(1555081692,3175218132),o(1996064986,2198950837),o(2554220882,3999719339),o(2821834349,766784016),o(2952996808,2566594879),o(3210313671,3203337956),o(3336571891,1034457026),o(3584528711,2466948901),o(113926993,3758326383),o(338241895,168717936),o(666307205,1188179964),o(773529912,1546045734),o(1294757372,1522805485),o(1396182291,2643833823),o(1695183700,2343527390),o(1986661051,1014477480),o(2177026350,1206759142),o(2456956037,344077627),o(2730485921,1290863460),o(2820302411,3158454273),o(3259730800,3505952657),o(3345764771,106217008),o(3516065817,3606008344),o(3600352804,1432725776),o(4094571909,1467031594),o(275423344,851169720),o(430227734,3100823752),o(506948616,1363258195),o(659060556,3750685593),o(883997877,3785050280),o(958139571,3318307427),o(1322822218,3812723403),o(1537002063,2003034995),o(1747873779,3602036899),o(1955562222,1575990012),o(2024104815,1125592928),o(2227730452,2716904306),o(2361852424,442776044),o(2428436474,593698344),o(2756734187,3733110249),o(3204031479,2999351573),o(3329325298,3815920427),o(3391569614,3928383900),o(3515267271,566280711),o(3940187606,3454069534),o(4118630271,4000239992),o(116418474,1914138554),o(174292421,2731055270),o(289380356,3203993006),o(460393269,320620315),o(685471733,587496836),o(852142971,1086792851),o(1017036298,365543100),o(1126000580,2618297676),o(1288033470,3409855158),o(1501505948,4234509866),o(1607167915,987167468),o(1816402316,1246189591)],l=[];!function(){for(var e=0;e<80;e++)l[e]=o()}();var d=a.SHA512=t.extend({_doReset:function(){this._hash=new n.init([new r.init(1779033703,4089235720),new r.init(3144134277,2227873595),new r.init(1013904242,4271175723),new r.init(2773480762,1595750129),new r.init(1359893119,2917565137),new r.init(2600822924,725511199),new r.init(528734635,4215389547),new r.init(1541459225,327033209)])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],r=i[1],n=i[2],a=i[3],o=i[4],d=i[5],u=i[6],h=i[7],f=s.high,p=s.low,g=r.high,v=r.low,_=n.high,y=n.low,D=a.high,m=a.low,b=o.high,w=o.low,S=d.high,B=d.low,I=u.high,k=u.low,C=h.high,A=h.low,x=f,E=p,L=g,O=v,P=_,M=y,T=D,H=m,K=b,R=w,N=S,G=B,z=I,U=k,j=C,Z=A,F=0;F<80;F++){var W,V,$=l[F];if(F<16)V=$.high=0|e[t+2*F],W=$.low=0|e[t+2*F+1];else{var X=l[F-15],q=X.high,J=X.low,Y=(q>>>1|J<<31)^(q>>>8|J<<24)^q>>>7,Q=(J>>>1|q<<31)^(J>>>8|q<<24)^(J>>>7|q<<25),ee=l[F-2],te=ee.high,ie=ee.low,se=(te>>>19|ie<<13)^(te<<3|ie>>>29)^te>>>6,re=(ie>>>19|te<<13)^(ie<<3|te>>>29)^(ie>>>6|te<<26),ne=l[F-7],ae=ne.high,oe=ne.low,ce=l[F-16],le=ce.high,de=ce.low;V=(V=(V=Y+ae+((W=Q+oe)>>>0<Q>>>0?1:0))+se+((W+=re)>>>0<re>>>0?1:0))+le+((W+=de)>>>0<de>>>0?1:0),$.high=V,$.low=W}var ue,he=K&N^~K&z,fe=R&G^~R&U,pe=x&L^x&P^L&P,ge=E&O^E&M^O&M,ve=(x>>>28|E<<4)^(x<<30|E>>>2)^(x<<25|E>>>7),_e=(E>>>28|x<<4)^(E<<30|x>>>2)^(E<<25|x>>>7),ye=(K>>>14|R<<18)^(K>>>18|R<<14)^(K<<23|R>>>9),De=(R>>>14|K<<18)^(R>>>18|K<<14)^(R<<23|K>>>9),me=c[F],be=me.high,we=me.low,Se=j+ye+((ue=Z+De)>>>0<Z>>>0?1:0),Be=_e+ge;j=z,Z=U,z=N,U=G,N=K,G=R,K=T+(Se=(Se=(Se=Se+he+((ue+=fe)>>>0<fe>>>0?1:0))+be+((ue+=we)>>>0<we>>>0?1:0))+V+((ue+=W)>>>0<W>>>0?1:0))+((R=H+ue|0)>>>0<H>>>0?1:0)|0,T=P,H=M,P=L,M=O,L=x,O=E,x=Se+(ve+pe+(Be>>>0<_e>>>0?1:0))+((E=ue+Be|0)>>>0<ue>>>0?1:0)|0}p=s.low=p+E,s.high=f+x+(p>>>0<E>>>0?1:0),v=r.low=v+O,r.high=g+L+(v>>>0<O>>>0?1:0),y=n.low=y+M,n.high=_+P+(y>>>0<M>>>0?1:0),m=a.low=m+H,a.high=D+T+(m>>>0<H>>>0?1:0),w=o.low=w+R,o.high=b+K+(w>>>0<R>>>0?1:0),B=d.low=B+G,d.high=S+N+(B>>>0<G>>>0?1:0),k=u.low=k+U,u.high=I+z+(k>>>0<U>>>0?1:0),A=h.low=A+Z,h.high=C+j+(A>>>0<Z>>>0?1:0)},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[30+(s+128>>>10<<5)]=Math.floor(i/4294967296),t[31+(s+128>>>10<<5)]=i,e.sigBytes=4*t.length,this._process(),this._hash.toX32()},clone:function(){var e=t.clone.call(this);return e._hash=this._hash.clone(),e},blockSize:32});e.SHA512=t._createHelper(d),e.HmacSHA512=t._createHmacHelper(d)}(),s.SHA512)},function(e,t){},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(17),r=i(18),n=i(31),a=i(32),o=i(61),c=i(16),l=i(62),d=i(22),u=i(8),h=i(12),f=i(63),p=i(2);t.default=class{constructor({appID:e,appSecret:t,productInfo:i,cloudServiceInfo:r,token:n,uid:g,offlineThreshold:v}){this.version="3.0.7",this.listenerMap={},this._deviceList=[],this._bleDevices=[],this._udpDevices=[],this.productInfo=[],this.autoScanInterval=null,this.handleBleDeviceData=async(e,t)=>{const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){const e=await f.unpack(p.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})})}},this.handleSockerDeviceData=e=>{const t=this.allDevices.find(t=>t.did===e.did);t&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(i=>{i(Object.assign({device:t},"attrs"in e?{data:e.attrs}:{raw:e.raw}))})},this.notiDeviveList=()=>{var e,t;null===(e=this.listenerMap.GizDeviceListNotifications)||void 0===e||e.map(e=>{e(this.allDevices)}),null===(t=this.listenerMap.onScanListChange)||void 0===t||t.map(e=>{e(this.bleScanDevice)})},this.startAutoScan=()=>{this.autoScanInterval&&clearInterval(this.autoScanInterval),this.autoScanInterval=setInterval(async()=>{const e=await this.bleHandle.startScan(e=>{this.bleDevices=e},6e3);console.log("auto scan result",e),this.bleDevices=e.scanList},1e3)},this.stopAutoScan=()=>{this.autoScanInterval&&clearInterval(this.autoScanInterval)},this.setDeviceMeta=(e,t,i)=>{const s=this.allDevices.find(t=>t.mac===e.mac);s&&0!==this.allDevices.length&&(s[t]=i,console.log("setDeviceMeta",this.allDevices),this.notiDeviveList())},this.getVersion=()=>({success:!0,data:this.version}),this.initBle=async()=>{const e=await this.bleHandle.checkPermission();return e.success?(this.bleHandle.addDeviceListener("ALL",this.handleBleDeviceData),console.debug("init BLE succcess",e),{success:!0}):(console.error("init BLE Error",e),{success:!1,err:c.errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON})},this.scanBleDevice=async e=>{console.log("start scanBleDevice"),this.bleHandle.scanList=[];const t=await this.bleHandle.startScan(e=>{this.bleDevices=e},e);return console.debug("scanBleDevice",t),{success:!0,data:t.scanList}},this.write=async(e,t)=>{console.log("待发送指令:",e,t);const i=this.allDevices.find(t=>u.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType)switch(i.connectType){case"BLE":{const e=await f.pack(t,i.productKey);e&&(console.log("write cmd",e,t),this.bleHandle.write(i.bleDeviceID,u.numberArray2Uint8Array(e).buffer));break}case"WAN":this.socketHandle.writeData(i,t)}},this.getProductConfig=async e=>{const t=await h.default.getConfigFile(e);return t?{success:!0,data:t}:{success:!1}},this.stopScanBleDevice=()=>{this.bleHandle.stopScan()},this.login=async e=>{var t,i;const r=await l.AnonymousLogin({uid:e});return r.success&&(s.setGlobalData("token",null===(t=r.data)||void 0===t?void 0:t.token),s.setGlobalData("uid",null===(i=r.data)||void 0===i?void 0:i.uid)),r},this.getDeviceStatus=async(e,t)=>{const i=this.allDevices.find(t=>u.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE":return await this.bleHandle.getDeviceStatus(i.bleDeviceID,i.productKey,i.rootDeviceId,t);case"WAN":return this.socketHandle.readStatus(i,t);default:return{success:!1,message:"Device connectType is unsupported"}}},this.subscribe=async(e,t,i=!0)=>{switch(u.getFirstConnectType(e,t)){case"BLE":{const t=this.bleDevices.find(t=>u.isSameDevice(t,e));if(!t)return{success:!1};const i=await this.bleHandle.connectDevice(t.bleDeviceID);return i.success?(this.setDeviceMeta(t,"connectType","BLE"),setTimeout(()=>{this.getDeviceStatus(t)},500)):this.bleHandle.disConnectDevice(t.bleDeviceID),i}case"WAN":{const t=this.socketHandle.connectDevice(e);return t.success&&this.setDeviceMeta(e,"connectType","WAN"),t}}return{success:!1}},this.unSubscribe=async e=>{switch(e.connectType){case"BLE":{const t=await this.bleHandle.disConnectDevice(e.bleDeviceID);return t.success&&this.setDeviceMeta(e,"connectType","NONE"),t}}return{success:!1}},this.bindRemoteDevice=async({mac:e,productKey:t,alias:i,beOwner:s})=>{const r=u.getProductInfoThroughPK(t,this.productInfo);if(r){const n=await d.bindMac({mac:e,productKey:t,productSecret:r.productSecret,alias:i,beOwner:s});return this.getBindingList(),n}return{success:!1,err:c.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}},this.unbindDevice=async({devices:e})=>{const t=await d.unbindDevice({devices:e});return t.success&&this.getBindingList(),t},this.deviceSafetyRegister=async({mac:e,productKey:t})=>await this.deviceSafetyApi({mac:e,productKey:t,isReset:!1}),this.deviceSafetyUnbind=async({mac:e,productKey:t})=>await this.deviceSafetyApi({mac:e,productKey:t,isReset:!0}),this.setDeviceOnboardingDeploy=async({ssid:e,password:t,mode:i=0,timeout:s,isBind:r=!0,softAPSSIDPrefix:n})=>{if(this.currentWifiConfigHandle)return{success:!1,err:c.errorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const l=(new Date).getTime();console.debug("GIZ_SDK: 配网开始时间:"+l);try{switch(i){case 0:{this.currentWifiConfigHandle=new a.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=await this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:n});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return console.debug("GIZ_SDK: 配网结束时间:"+o),console.debug("GIZ_SDK: 配网用时:"+(o-l)),i}case 3:{this.currentWifiConfigHandle=new o.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=await this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:n});this.currentWifiConfigHandle=null;const a=(new Date).getTime();return console.debug("GIZ_SDK: 配网结束时间:"+a),console.debug("GIZ_SDK: 配网用时:"+(a-l)),i}}}catch(e){return console.error(e),e.err&&e.err.errorCode?e:{success:!1,err:c.errorCode.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}},this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=e&&e.siteInfo||"site.gizwits.com",r=Object.assign(Object.assign({},e||{}),{openAPIInfo:t,siteInfo:i});s.setGlobalData("cloudServiceInfo",r)},this.deviceSafetyApi=async({mac:e,productKey:t,isReset:i})=>{const s=u.getProductInfoThroughPK(t,this.productInfo);return s?await d.safeRegister({productKey:t,productSecret:s.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:c.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}},this.getBindingList=async()=>{const e=await d.getBindingList();this.deviceList=e.data||[]},this.getDevices=async()=>(await this.getBindingList(),{success:!0,data:this.allDevices}),this.stopDeviceOnboardingDeploy=()=>{this.currentWifiConfigHandle&&(this.currentWifiConfigHandle.stopDeviceOnboardingDeploy(),this.currentWifiConfigHandle=null)},this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}},this.addEventListener=async(e,t)=>(this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}),this.productInfo=i,s.setGlobalData("appID",e),s.setGlobalData("appSecret",t),s.setGlobalData("productInfo",i),s.setGlobalData("token",n),s.setGlobalData("uid",g),this.setDomain(r),this.offlineThreshold=v,console.debug(`init sdk success, current version: ${this.version}`)}get deviceList(){return this._deviceList}set deviceList(e){this._deviceList=e,this.notiDeviveList()}get bleDevices(){return this._bleDevices}set bleDevices(e){this._bleDevices=e,this.notiDeviveList()}get udpDevices(){return this._udpDevices}set udpDevices(e){this._udpDevices=e,this.notiDeviveList()}get allDevices(){let e=u.merageBleLocalDevices([...this.deviceList],this.bleDevices);return e=u.merageLanLocalDevices(e,this.udpDevices),this.bleHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.bleDeviceID===t.deviceId);-1!==i&&(e[i].connectType="BLE")}),e}set allDevice(e){this.allDevice=e,this.notiDeviveList()}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}get bleHandle(){return this._bleHandle||(this._bleHandle=new r.BleHandle({pks:this.specialProductKeys,globalListenerMap:this.listenerMap,gizSdk:this,offlineThreshold:this.offlineThreshold})),this._bleHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new n.default({appID:s.getGlobalData("appID"),token:s.getGlobalData("token"),uid:s.getGlobalData("uid")}),this._gizSocket.subscribeDeviceStatus(this.handleSockerDeviceData)),this._gizSocket}get specialProductKeys(){return this.productInfo.map(e=>{var t;return null!==(t=e.productKey)&&void 0!==t?t:""})}get specialProductKeySecrets(){return this.productInfo.map(e=>{var t;return null!==(t=e.productSecret)&&void 0!==t?t:""})}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(7),r=i(2);class n extends s.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt(r.arrayToString(this.content.slice(t,t+2)),16);t+=2;let s="";this.content.slice(t,t+i).map(e=>{s+=String.fromCharCode(e)}),this.passcode=s}}n.pack=()=>[0,0,0,3,3,0,0,6],t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(7),r=i(2);class n extends s.default{constructor(e){super(e),this.result=!1,this.didLength=0,this.did="";let t=0;if(this.result=0===this.content[0],t++,1===this.flag[0]){this.didLength=parseInt(r.arrayToString(this.content.slice(t,t+2)),16),t+=2;let e="";this.content.slice(t,this.content.length).map(t=>{e+=String.fromCharCode(t)}),this.did=e}}}n.pack=({passcode:e})=>{let t=[0];const i=r.hexStrint2byte(r.fillString(e.length.toString(16),4)),s=r.string2Bytes(e),n=[0].concat([0,8]).concat(i).concat(s);return t=r.hexStrint2byte(n.length.toString(16)),[0,0,0,3].concat(t).concat(n)},t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(12),r=i(7),n=i(2);class a extends r.default{}a.pack=async(e,t,i)=>{const r=await s.default.getConfigFile(e);if(r){const e="var_len"===r.protocolType,s=[0,0,0,3],a=[0];let o=[0];const c=[0,147];let l=[0,0,0,0],d=[2];if(t){o=[1];const e=n.fillString(t.length.toString(16),4),i=n.hexStrint2byte(e),s=n.string2Bytes(t);l=l.concat(i).concat(s)}if(e){d=[18];let e="";if(i){const t=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:1}),{});r.entities[0].attrs.map(i=>{e=t[i.name]?`1${e}`:`0${e}`})}else r.entities[0].attrs.map(()=>{e=`1${e}`});e=n.fillString(e,8*Math.ceil(e.length/8)),d=d.concat(n.hexStrint2byte(parseInt(e,2).toString(16)))}const u=o.concat(c).concat(l).concat(d);return a[0]=u.length,s.concat(a).concat(u)}return null},t.default=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise((i,s)=>{wx.request(Object.assign(Object.assign({url:e,timeout:3e3},t),{success:e=>{i(e)},fail:e=>{s(e)}}))})}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),r=i(9),n=i(8);t.default=class{constructor({appID:e,token:t,uid:i,limitSocketNum:o=!0}){this._bindingDevices=null,this._connections={},this._getDevice=e=>{if(null===this._bindingDevices)return s.default.GIZ_SDK_SDK_NOT_INITIALIZED;const t=this._bindingDevices[e];return null==t?s.default.GIZ_OPENAPI_DEVICE_NOT_BOUND:t},this._getConnect=e=>{const t=this._getWebsocketConnInfo(e);return this._connections[t]},this._getDeviceAndConnect=e=>{const t=this._getDevice(e);if(n.isError(t))return t;const i=this._getConnect(t);return null==i?s.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED:[t,i]},this.connectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];if(null==i){const e=Object.keys(this._connections).length;if(0!==this._maxSocketNum&&e>=this._maxSocketNum)return{success:!1,errorCode:s.default.MAX_CONNECT};i=new a({appID:this.appID,token:this.token,uid:this.uid,wsInfo:t,onDeviceStatusChanged:this._handleDeviceStatusChanged}),this._connections[t]=i}return i._addSubDid(e.did),null==i._websocket?i._connectWS():i.ready&&i._subDevices([e.did]),{success:!0}},this.connect=e=>{const t=this._getDevice(e);if(n.isError(t))return t;const i=this.connectDevice(t);return i.success?null:i.errorCode},this.send=(e,t)=>{const i=this._getDeviceAndConnect(e);return n.isError(i)?i:i[1]._send({cmd:"c2s_raw",data:{did:e,raw:t}})},this.writeData=(e,t)=>{const i=this._getConnect(e),s=null!=i;return s&&i._send({cmd:"c2s_write",data:{did:e.did,attrs:t}}),{success:s}},this.write=(e,t)=>{const i=this._getDeviceAndConnect(e);return n.isError(i)?i:i[1]._send({cmd:"c2s_write",data:{did:e,attrs:t}})},this.readStatus=(e,t)=>{const i=this._getConnect(e),s=null!=i;return s&&i._send({cmd:"c2s_read",data:{did:e.did,names:t}}),{success:s}},this.read=(e,t)=>{const i=this._getDeviceAndConnect(e);return n.isError(i)?i:i[1]._send({cmd:"c2s_read",data:{did:e,names:t}})},this.close=()=>{Object.values(this._connections).forEach(e=>e.close())},this.subscribeDeviceStatus=e=>{this._onDeviceStatusChanged=e},this._handleDeviceStatusChanged=e=>{const t=this._getDevice(e.did);n.isError(t)||this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._getBindingList=async(e=20,t=0,i=[])=>{const s=`/app/bindings?show_disabled=0&limit=${e}&skip=${t}`,{err:n,data:a}=await r.default(`${s}`,{method:"GET"});if(n)return{err:n};const o=[...i,...(null==a?void 0:a.devices)||[]];return a&&a.devices.length===e?await this._getBindingList(e,e+t,o):o},this._getWebsocketConnInfo=e=>e.host.includes("stage")?"wss://wxstage.gizwits.com":"wss://wxm2m.gizwits.com",this.appID=e,this.token=t,this.uid=i;const c=wx.getSystemInfoSync().SDKVersion;this._maxSocketNum=o?-1===n.compareWXSDKVersion(c,"1.7.0")?1:5:0}async init(){var e,t;try{const i=await this._getBindingList();return(null===(e=i.err)||void 0===e?void 0:e.errorCode)?{errorCode:null===(t=i.err)||void 0===t?void 0:t.errorCode,errorMessage:"getting binding list failed"}:(this._bindingDevices=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t.did]:t}),{}),null)}catch(e){return s.default.GIZ_SDK_OTHERWISE}}};class a{constructor({appID:e,token:t,uid:i,wsInfo:s,onDeviceStatusChanged:r}){this.ready=!1,this.commType="attrs_v4",this._heartbeatInterval=60,this._keepaliveTime=180,this._loginIntveral=5e3,this.autoSubscribe=!1,this._websocket=null,this._loginFailedTimes=0,this._subDids=new Set,this._socketRespHandleMap={},this._addSubDid=e=>{this._subDids.add(e)},this._connectWS=()=>{this._websocket=wx.connectSocket({url:this._wsUrl}),this._websocket.onClose(this.handleClose),this._websocket.onOpen(this.handleOpen),this._websocket.onError(this.handleError),this._websocket.onMessage(this.handleMessage)},this._subDevices=e=>{const t={cmd:"subscribe_req",data:e.map(e=>({did:e}))};this._send(t)},this._send=(e,t=!1)=>(console.log("Socket send",e,t),new Promise(i=>{this._websocket&&(t||this.ready)&&this._websocket.send({data:JSON.stringify(e),complete:e=>{console.debug("GIZ_SDK: socket send res",e),["sendSocketMessage:fail debug invoke no active session","sendSocketMessage:fail wcwss taskID not exist"].includes(e&&e.errMsg)&&(this._websocket&&this._websocket.close({}),this._connectWS()),i(e)}})})),this.close=()=>{this.ready=!1,this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._websocket&&(this._websocket.close({}),this._websocket=null)},this.handleClose=e=>{console.log("socket close",e),this.close(),this._stopPing()},this.handleOpen=()=>{console.log(" socket open"),this._login()},this.handleMessage=({data:e})=>{console.log("message",e);const t=JSON.parse(e),i=this._socketRespHandleMap[t.cmd];i&&i(t.data)},this.handleError=e=>{console.debug("GIZ_SDK: socket error",e)},this._login=()=>{const e={cmd:"login_req",data:{appid:this.appID,uid:this.uid,token:this.token,p0_type:this.commType,heartbeat_interval:this._keepaliveTime,auto_subscribe:this.autoSubscribe}};this._send(e,!0)},this._tryLoginAgain=()=>{this._loginFailedTimes+=1,setTimeout(()=>{this._login()},this._loginFailedTimes*this._loginIntveral)},this._startPing=()=>{this._heartbeatTimerId=setInterval(()=>{this._send({cmd:"ping"})},1e3*this._heartbeatInterval)},this._stopPing=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId)},this.pongResp=()=>{},this._loginResp=e=>{1==e.success?(this._loginFailedTimes=0,this.ready=!0,this._startPing(),this._subDevices([...this._subDids])):this._loginFailedTimes<3?(console.debug("GIZ_SDK: Login failed, will try again, please wait..."),this._tryLoginAgain()):(console.debug("GIZ_SDK: Login failed"),this.close())},this._subscribeResp=e=>{console.log("GIZ_SDK: subscribe_res",e),e&&e.success&&e.success.forEach(e=>this._send({cmd:"c2s_read",data:{did:e.did}})),console.debug("GIZ_SDK: subscribe_res",e)},this._onlineResp=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged({did:e.did,attrs:Object.assign({is_online:e.online},e)})},this._rawChangedResp=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._statusChangedResp=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._invalidMsgResp=e=>{1003===e.error_code&&this._login(),console.debug("GIZ_SDK: s2c_invalid_msg",e)},this.appID=e,this.token=t,this.uid=i,this._wsUrl=`${s}/ws/app/v1`,this._heartbeatTimerId=void 0,this._loginFailedTimes=0,this._onDeviceStatusChanged=r,this._socketRespHandleMap={pong:this.pongResp,login_res:this._loginResp,subscribe_res:this._subscribeResp,s2c_online_status:this._onlineResp,s2c_raw:this._rawChangedResp,s2c_noti:this._statusChangedResp,s2c_invalid_msg:this._invalidMsgResp}}}t.Connection=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),r=i(20),n=i(21);class a extends n.default{constructor(){super(...arguments),this.disableSendUDP=!1,this.sendMessageInterval=null,this.UDPSocketHandler=null,this.destroy=()=>{this.cleanTimeout(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.sendMessageInterval=null,this.UDPSocketHandler&&(this.UDPSocketHandler.offError(),this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.close())},this.configDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((n,a)=>{console.debug("GIZ_SDK: start config device");let o=!1,c=0;const l=r.default.pack(e,t);this.UDPSocketHandler=wx.createUDPSocket(),this.UDPSocketHandler.bind(),this.disableSendUDP=!1;const d=()=>{try{!this.disableSendUDP&&this.UDPSocketHandler.send({address:"10.10.100.254",port:12414,message:l,offset:0,length:l.byteLength})}catch(e){}};this.sendMessageInterval=setInterval(()=>{d()},2e3),this.UDPSocketHandler.onError(e=>{c+=1,c>2&&(this.destroy(),a({success:!1,err:{errorCode:s.default.WECHAT_ERROR.errorCode,errorMessage:e.errMsg}}))});const u=async()=>{if(!o){this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.offError(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.disableSendUDP=!0,o=!0;try{const i=await this.searchDevice({ssid:e,password:t});n(i)}catch(e){a(e)}}};this.UDPSocketHandler.onMessage(e=>{u()}),wx.onNetworkStatusChange(async()=>{!o&&wx.getConnectedWifi({success:async e=>{-1===e.wifi.SSID.indexOf(i)&&u()}})})}),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>{const s=this.ssid,r=this.password;return new Promise(async(n,a)=>{this.destroy(),this.initDeviceOnboardingDeploy(n,a),this.startTimeoutTimer(e);try{const e=((await this.configDevice({ssid:s,password:r,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));if(t)try{n(await this.bindDevices(e))}catch(e){a(e)}else n({success:!0,data:e})}catch(e){a(e)}finally{this.destroy()}})}}}t.default=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(13),r=({SSID:e,password:t,pk:i})=>{let r=s.MD5(e+t).toString();r=s.enc.Hex.parse(r);let n=s.enc.Utf8.parse(i),a=s.AES.encrypt(n,r,{iv:r,mode:s.mode.ECB,padding:s.pad.ZeroPadding});return s.MD5(a.ciphertext).toString()};t.default=({SSID:e,password:t,pks:i})=>{const s=[];return i.map(i=>{const n=r({SSID:e,password:t,pk:i});s.push(n)}),s}},function(e,t){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t){},function(e,t,i){var s;e.exports=(s=i(0),function(){if("function"==typeof ArrayBuffer){var e=s.lib.WordArray,t=e.init;(e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var i=e.byteLength,s=[],r=0;r<i;r++)s[r>>>2]|=e[r]<<24-r%4*8;t.call(this,s,i)}else t.apply(this,arguments)}).prototype=e}}(),s.lib.WordArray)},function(e,t,i){var s;e.exports=(s=i(0),function(){var e=s,t=e.lib.WordArray,i=e.enc;function r(e){return e<<8&4278255360|e>>>8&16711935}i.Utf16=i.Utf16BE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],r=0;r<i;r+=2){var n=t[r>>>2]>>>16-r%4*8&65535;s.push(String.fromCharCode(n))}return s.join("")},parse:function(e){for(var i=e.length,s=[],r=0;r<i;r++)s[r>>>1]|=e.charCodeAt(r)<<16-r%2*16;return t.create(s,2*i)}},i.Utf16LE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n+=2){var a=r(t[n>>>2]>>>16-n%4*8&65535);s.push(String.fromCharCode(a))}return s.join("")},parse:function(e){for(var i=e.length,s=[],n=0;n<i;n++)s[n>>>1]|=r(e.charCodeAt(n)<<16-n%2*16);return t.create(s,2*i)}}}(),s.enc.Utf16)},function(e,t,i){var s,r,n;e.exports=(n=i(0),r=(s=n).lib.WordArray,s.enc.Base64url={stringify:function(e,t=!0){var i=e.words,s=e.sigBytes,r=t?this._safe_map:this._map;e.clamp();for(var n=[],a=0;a<s;a+=3)for(var o=(i[a>>>2]>>>24-a%4*8&255)<<16|(i[a+1>>>2]>>>24-(a+1)%4*8&255)<<8|i[a+2>>>2]>>>24-(a+2)%4*8&255,c=0;c<4&&a+.75*c<s;c++)n.push(r.charAt(o>>>6*(3-c)&63));var l=r.charAt(64);if(l)for(;n.length%4;)n.push(l);return n.join("")},parse:function(e,t=!0){var i=e.length,s=t?this._safe_map:this._map,n=this._reverseMap;if(!n){n=this._reverseMap=[];for(var a=0;a<s.length;a++)n[s.charCodeAt(a)]=a}var o=s.charAt(64);if(o){var c=e.indexOf(o);-1!==c&&(i=c)}return function(e,t,i){for(var s=[],n=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,l=o|c;s[n>>>2]|=l<<24-n%4*8,n++}return r.create(s,n)}(e,i,n)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},n.enc.Base64url)},function(e,t,i){var s,r,n,a,o,c;e.exports=(c=i(0),i(23),r=(s=c).lib.WordArray,n=s.algo,a=n.SHA256,o=n.SHA224=a.extend({_doReset:function(){this._hash=new r.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var e=a._doFinalize.call(this);return e.sigBytes-=4,e}}),s.SHA224=a._createHelper(o),s.HmacSHA224=a._createHmacHelper(o),c.SHA224)},function(e,t,i){var s,r,n,a,o,c,l,d;e.exports=(d=i(0),i(10),i(24),r=(s=d).x64,n=r.Word,a=r.WordArray,o=s.algo,c=o.SHA512,l=o.SHA384=c.extend({_doReset:function(){this._hash=new a.init([new n.init(3418070365,3238371032),new n.init(1654270250,914150663),new n.init(2438529370,812702999),new n.init(355462360,4144912697),new n.init(1731405415,4290775857),new n.init(2394180231,1750603025),new n.init(3675008525,1694076839),new n.init(1203062813,3204075428)])},_doFinalize:function(){var e=c._doFinalize.call(this);return e.sigBytes-=16,e}}),s.SHA384=c._createHelper(l),s.HmacSHA384=c._createHmacHelper(l),d.SHA384)},function(e,t,i){var s;e.exports=(s=i(0),i(10),function(e){var t=s,i=t.lib,r=i.WordArray,n=i.Hasher,a=t.x64.Word,o=t.algo,c=[],l=[],d=[];!function(){for(var e=1,t=0,i=0;i<24;i++){c[e+5*t]=(i+1)*(i+2)/2%64;var s=(2*e+3*t)%5;e=t%5,t=s}for(e=0;e<5;e++)for(t=0;t<5;t++)l[e+5*t]=t+(2*e+3*t)%5*5;for(var r=1,n=0;n<24;n++){for(var o=0,u=0,h=0;h<7;h++){if(1&r){var f=(1<<h)-1;f<32?u^=1<<f:o^=1<<f-32}128&r?r=r<<1^113:r<<=1}d[n]=a.create(o,u)}}();var u=[];!function(){for(var e=0;e<25;e++)u[e]=a.create()}();var h=o.SHA3=n.extend({cfg:n.cfg.extend({outputLength:512}),_doReset:function(){for(var e=this._state=[],t=0;t<25;t++)e[t]=new a.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(e,t){for(var i=this._state,s=this.blockSize/2,r=0;r<s;r++){var n=e[t+2*r],a=e[t+2*r+1];n=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),a=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),(A=i[r]).high^=a,A.low^=n}for(var o=0;o<24;o++){for(var h=0;h<5;h++){for(var f=0,p=0,g=0;g<5;g++)f^=(A=i[h+5*g]).high,p^=A.low;var v=u[h];v.high=f,v.low=p}for(h=0;h<5;h++){var _=u[(h+4)%5],y=u[(h+1)%5],D=y.high,m=y.low;for(f=_.high^(D<<1|m>>>31),p=_.low^(m<<1|D>>>31),g=0;g<5;g++)(A=i[h+5*g]).high^=f,A.low^=p}for(var b=1;b<25;b++){var w=(A=i[b]).high,S=A.low,B=c[b];B<32?(f=w<<B|S>>>32-B,p=S<<B|w>>>32-B):(f=S<<B-32|w>>>64-B,p=w<<B-32|S>>>64-B);var I=u[l[b]];I.high=f,I.low=p}var k=u[0],C=i[0];for(k.high=C.high,k.low=C.low,h=0;h<5;h++)for(g=0;g<5;g++){var A=i[b=h+5*g],x=u[b],E=u[(h+1)%5+5*g],L=u[(h+2)%5+5*g];A.high=x.high^~E.high&L.high,A.low=x.low^~E.low&L.low}A=i[0];var O=d[o];A.high^=O.high,A.low^=O.low}},_doFinalize:function(){var t=this._data,i=t.words,s=(this._nDataBytes,8*t.sigBytes),n=32*this.blockSize;i[s>>>5]|=1<<24-s%32,i[(e.ceil((s+1)/n)*n>>>5)-1]|=128,t.sigBytes=4*i.length,this._process();for(var a=this._state,o=this.cfg.outputLength/8,c=o/8,l=[],d=0;d<c;d++){var u=a[d],h=u.high,f=u.low;h=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8),f=16711935&(f<<8|f>>>24)|4278255360&(f<<24|f>>>8),l.push(f),l.push(h)}return new r.init(l,o)},clone:function(){for(var e=n.clone.call(this),t=e._state=this._state.slice(0),i=0;i<25;i++)t[i]=t[i].clone();return e}});t.SHA3=n._createHelper(h),t.HmacSHA3=n._createHmacHelper(h)}(Math),s.SHA3)},function(e,t,i){var s;e.exports=(s=i(0),
|
|
2
2
|
/** @preserve
|
|
3
3
|
(c) 2012 by Cédric Mesnil. All rights reserved.
|
|
4
4
|
|
package/dist/src/sdk.d.ts
CHANGED
|
@@ -82,8 +82,8 @@ declare class SDK {
|
|
|
82
82
|
private version;
|
|
83
83
|
private listenerMap;
|
|
84
84
|
private _deviceList;
|
|
85
|
-
private get
|
|
86
|
-
private set
|
|
85
|
+
private get deviceList();
|
|
86
|
+
private set deviceList(value);
|
|
87
87
|
private _bleDevices;
|
|
88
88
|
get bleDevices(): IDevice[];
|
|
89
89
|
set bleDevices(data: IDevice[]);
|