!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,(function(){return function(e){var t=window.webpackHotUpdate;window.webpackHotUpdate=function(e,n){!function(e,t){if(!_[e]||!w[e])return;for(var n in w[e]=!1,t)Object.prototype.hasOwnProperty.call(t,n)&&(h[n]=t[n]);0==--g&&0===y&&T()}(e,n),t&&t(e,n)};var n,r=!0,o="630b600bf580aa26280f",i={},a=[],c=[];function u(e){var t=I[e];if(!t)return D;var r=function(r){return t.hot.active?(I[r]?-1===I[r].parents.indexOf(e)&&I[r].parents.push(e):(a=[e],n=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),a=[]),D(r)},o=function(e){return{configurable:!0,enumerable:!0,get:function(){return D[e]},set:function(t){D[e]=t}}};for(var i in D)Object.prototype.hasOwnProperty.call(D,i)&&"e"!==i&&"t"!==i&&Object.defineProperty(r,i,o(i));return r.e=function(e){return"ready"===f&&d("prepare"),y++,D.e(e).then(t,(function(e){throw t(),e}));function t(){y--,"prepare"===f&&(b[e]||C(e),0===y&&0===g&&T())}},r.t=function(e,t){return 1&t&&(e=r(e)),D.t(e,-2&t)},r}function s(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:n!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var n=0;n=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,f){case"idle":(h={})[t]=e[t],d("ready");break;case"ready":O(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:k,apply:S,status:function(e){if(!e)return f;l.push(e)},addStatusHandler:function(e){l.push(e)},removeStatusHandler:function(e){var t=l.indexOf(e);t>=0&&l.splice(t,1)},data:i[t]};return n=void 0,r}var l=[],f="idle";function d(e){f=e;for(var t=0;t0;){var o=r.pop(),i=o.id,a=o.chain;if((l=I[i])&&(!l.hot._selfAccepted||l.hot._selfInvalidated)){if(l.hot._selfDeclined)return{type:"self-declined",chain:a,moduleId:i};if(l.hot._main)return{type:"unaccepted",chain:a,moduleId:i};for(var c=0;c ")),T.type){case"self-declined":r.onDeclined&&r.onDeclined(T),r.ignoreDeclined||(S=new Error("Aborted because of self decline: "+T.moduleId+N));break;case"declined":r.onDeclined&&r.onDeclined(T),r.ignoreDeclined||(S=new Error("Aborted because of declined dependency: "+T.moduleId+" in "+T.parentId+N));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(T),r.ignoreUnaccepted||(S=new Error("Aborted because "+f+" is not accepted"+N));break;case"accepted":r.onAccepted&&r.onAccepted(T),O=!0;break;case"disposed":r.onDisposed&&r.onDisposed(T),P=!0;break;default:throw new Error("Unexception type "+T.type)}if(S)return d("abort"),Promise.reject(S);if(O)for(f in w[f]=h[f],g(b,T.outdatedModules),T.outdatedDependencies)Object.prototype.hasOwnProperty.call(T.outdatedDependencies,f)&&(y[f]||(y[f]=[]),g(y[f],T.outdatedDependencies[f]));P&&(g(b,[T.moduleId]),w[f]=k)}var A,R=[];for(u=0;u0;)if(f=j.pop(),l=I[f]){var U={},F=l.hot._disposeHandlers;for(s=0;s=0&&B.parents.splice(A,1))}}for(f in y)if(Object.prototype.hasOwnProperty.call(y,f)&&(l=I[f]))for(L=y[f],s=0;s=0&&l.children.splice(A,1);d("apply"),void 0!==v&&(o=v,v=void 0);for(f in h=void 0,w)Object.prototype.hasOwnProperty.call(w,f)&&(e[f]=w[f]);var V=null;for(f in y)if(Object.prototype.hasOwnProperty.call(y,f)&&(l=I[f])){L=y[f];var W=[];for(u=0;u=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function u(e,t){return function(n,r){t(n,r,e)}}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function l(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function c(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){e.done?o(e.value):new n((function(t){t(e.value)})).then(a,c)}u((r=r.apply(e,t||[])).next())}))}function f(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}function h(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}function v(){for(var e=[],t=0;t1||c(e,t)}))})}function c(e,t){try{(n=o[e](t)).value instanceof g?Promise.resolve(n.value.v).then(u,s):l(i[0][2],n)}catch(e){l(i[0][3],e)}var n}function u(e){c("next",e)}function s(e){c("throw",e)}function l(e,t){e(t),i.shift(),i.length&&c(i[0][0],i[0][1])}}function b(e){var t,n;return t={},r("next"),r("throw",(function(e){throw e})),r("return"),t[Symbol.iterator]=function(){return this},t;function r(r,o){t[r]=e[r]?function(t){return(n=!n)?{value:g(e[r](t)),done:"return"===r}:o?o(t):t}:o}}function w(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=p(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise((function(r,o){!function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)}(r,o,(t=e[n](t)).done,t.value)}))}}}function _(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function E(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function k(e){return e&&e.__esModule?e:{default:e}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(4),o=n(7),i=r.__importDefault(n(9));t.appendParams=function(e,n){void 0===n&&(n={});var r=[];return Object.keys(n).forEach((function(e){var o=n[e];if(void 0!==o){if(t.isPlainObject(o))try{o=JSON.stringify(o)}catch(e){}r.push(e+"="+encodeURIComponent(o))}})),r.length?(e.indexOf("?")>-1?e+"&":e+"?")+r.join("&"):e},t.delay=function(e){return new Promise((function(t){return setTimeout(t,e)}))},t.genPromise=function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),resolve:e,reject:t}},t.noop=function(){},t.getErrorMsg=function(e){if(e){var t="";return"string"==typeof e?e:(t=e.msg||e.Message||e.message||e.errMsg||"连接服务器失败,请稍后再试",e.reqId&&(t+="("+e.reqId+")"),t||(t="连接服务器失败,请稍后再试"),t)}},t.isPlainObject=function(e){if("object"!=(void 0===e?"undefined":typeof e)||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t},t.hasModalShow=!1,t.showModal=function(e,n,i){void 0===n&&(n=""),i.confirmText;var a=(void 0===(void 0===i.confirmColor&&o.themeColorMap.primary,i.cancelText,i.cancelColor)&&o.themeColorMap.weak,r.__rest(i,["confirmText","confirmColor","cancelText","cancelColor"]));return wx.hideToast(),t.hasModalShow=!0,new Promise((function(o,i){wx.showModal(r.__assign(r.__assign({title:e,content:n},a),{success:function(e){var t=e.confirm;o(!!t)},fail:function(){o(!1)},complete:function(){t.hasModalShow=!1}}))}))},t.cutoffLong=function(e,t,n,r){void 0===t&&(t=4096),void 0===n&&(n=10),void 0===r&&(r=20);try{return function e(t,n,o){return t?"string"==typeof t&&t.length>n?t.substr(0,n)+"... ("+(t.length-n)+" characters truncated)":Array.isArray(t)?t.length>o?t.slice(0,o).map((function(t){return e(t,n,o)})).concat("... ("+(t.length-o)+" items truncated)"):t:"object"==typeof t?Object.keys(t).reduce((function(i,a,c,u){return c-1&&r.splice(o,1)}else n[e].length=0;return this},e.prototype.emit=function(e){for(var t=this,n=[],r=1;r-1})))if(0===e.errMsg.indexOf("getUserInfo"))Object.assign(e,{code:i.ErrorCode.GET_USERINFO_NEED_AUTH,msg:"尚未开启微信基本信息授权,请授权后使用"});else{var n=r.__read(e.errMsg.split(":"),1)[0];Object.assign(e,{code:i.ErrorCode.WX_API_NEED_AUTH,msg:"小程序接口("+n+")需要用户授权,请授权后使用"})}else Object.assign(e,{code:i.ErrorCode.WX_API_FAIL,msg:"小程序接口调用失败,请稍后再试"});else t.isVerifyLoginError(e)&&(e=t.genVerifyLoginFailError(e));else e instanceof Error&&(e={code:i.ErrorCode.INTERNAL_ERROR,msg:e.message,stack:e.stack,error:e});return e},t.genVerifyLoginFailError=function(e){e||(e={}),e.code,e.msg;var t=r.__rest(e,["code","msg"]);return r.__assign({code:i.ErrorCode.VERIFY_LOGIN_FAIL,msg:"登录态验证失败,请重新登录"},t)},t.isVerifyLoginError=function(e){return e&&String(e.code||"").indexOf("InvalidAccessToken")>-1},t.handleVerifyLoginError=function(e){if(t.isVerifyLoginError(e))throw t.genVerifyLoginFailError(e)}},function(e,t,n){var r=n(50),o=n(1);e.exports=function(e,t){return!t||"object"!==r(t)&&"function"!=typeof t?o(e):t}},function(e,t){function n(t){return e.exports=n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},n(t)}e.exports=n},function(e,t,n){var r=n(51);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}},function(e,t,n){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0}),t.isMiniProgram=function(){try{return!!(wx&&wx.request&&wx.connectSocket)}catch(e){return!1}}(),t.isBrowser=function(){try{return"undefined"!=typeof window&&void 0!==window.document}catch(e){return!1}}(),t.isNode=function(){try{return!!e.versions.node}catch(e){return!1}}(),t.isRN=function(){try{return"ReactNative"===navigator.product}catch(e){return!1}}()}).call(this,n(28))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(4);t.pify=function(e,t){return void 0===t&&(t=wx),function(n){for(var o=[],i=1;i0;)o=a.nextValue(),e=Math.floor(o*t.length),n.push(t.splice(e,1)[0]);return n.join("")}())}e.exports={get:function(){return r||c},characters:function(e){return s(e),r},seed:function(e){a.seed(e),o!==e&&(u(),o=e)},lookup:function(e){return l()[e]},shuffled:l}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(4);r.__exportStar(n(20),t),r.__exportStar(n(30),t)},function(e,t,n){"use strict";var r=n(17),o=n(32),i=n(36),a=n(37)||0;function c(){return o(a)}e.exports=c,e.exports.generate=c,e.exports.seed=function(t){return r.seed(t),e.exports},e.exports.worker=function(t){return a=t,e.exports},e.exports.characters=function(e){return void 0!==e&&r.characters(e),r.shuffled()},e.exports.isValid=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(4),o=r.__importDefault(n(24)),i=n(15),a=r.__importDefault(n(29)),c=n(16),u=0;function s(e,t,n){return void 0===t&&(t={}),void 0===n&&(n={}),new Promise((function(r,i){try{var a=n.method,c=n.headers,u=void 0===c?{}:c,s=n.responseType,l=void 0===s?"json":s;a=(a||"get").toUpperCase(),Object.assign(u,{"Content-type":"application/json"});var f=new window.XMLHttpRequest;f.responseType=l,f.timeout=1e4,f.onreadystatechange=function(){4===f.readyState&&(200===f.status?r({data:f.response}):i({code:f.status,msg:f.statusText}))},"GET"===a?e="url"+(-1===e.indexOf("?")?"?":"&")+o.default.stringify(t):"POST"===a&&(t=JSON.stringify(t)),f.open(a,e,!0),Object.keys(u).forEach((function(e){f.setRequestHeader(e,u[e])})),f.send("POST"===a?t:null)}catch(e){console.error(e),i(e)}}))}t.request=function(e){return r.__awaiter(void 0,void 0,void 0,(function(){var t,n=e.url,o=e.data,l=e.header,f=void 0===l?{}:l,d=e.method,p=void 0===d?"get":d,h=e.dataType,v=e.responseType,m=r.__rest(e,["url","data","header","method","dataType","responseType"]);return r.__generator(this,(function(e){switch(e.label){case 0:if(i.isBrowser)return[2,s(n,o,{headers:f,method:p,responseType:v})];e.label=1;case 1:e.trys.push([1,6,7,8]),e.label=2;case 2:return u>=10?[4,a.default.startBlocking()]:[3,4];case 3:return e.sent(),[3,2];case 4:return u++,[4,c.pify(wx.request)(r.__assign({url:n,data:o,header:f,method:p,dataType:h,responseType:v},m))];case 5:return[2,e.sent()];case 6:return t=e.sent(),[2,Promise.reject(t)];case 7:return u--,a.default.resolveFirstBlock(),[7];case 8:return[2]}}))}))}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(4);n(38);var o=n(39),i=r.__importDefault(n(8)),a=n(41),c=r.__importDefault(n(9)),u=n(43),s=n(7),l=n(5),f=n(18),d=n(11),p=n(44),h=n(15),v=function(e){function t(t){var n=t.getAccessToken,i=t.appKey,u=void 0===i?"":i,f=t.apiPlatform,d=void 0===f?"":f,p=t.debug,v=void 0!==p&&p,m=t.wsConfig,g=void 0===m?{}:m,y=g.autoReconnect,b=void 0===y||y,w=g.disconnectWhenAppHide,_=void 0===w||w,E=g.connectWhenAppShow,k=void 0===E||E,C=r.__rest(g,["autoReconnect","disconnectWhenAppHide","connectWhenAppShow"]),T=t.reportor,S=e.call(this)||this;S.isManuallyClose=!1,S._defaultFamilyIdPromise=null,S.reportor=null,c.default.config({debug:v});var x=T||l.noop;return S.reportor={info:function(e,t){void 0===t&&(t={});try{x(e,r.__assign({level:0},t))}catch(e){c.default.warn(e)}},warn:function(e,t){void 0===t&&(t={});try{x(e,r.__assign({level:1},t))}catch(e){c.default.warn(e)}},error:function(e,t){void 0===t&&(t={});try{x(e,r.__assign({level:2},t))}catch(e){c.default.warn(e)}}},S.ws=new a.IotWebsocket(S,r.__assign(r.__assign({},C),{apiPlatform:d})),S.loginManager=new o.LoginManager(S,{getAccessToken:n,appKey:u}),S._apiPlatform=d,S.ws.on("error",(function(e){c.default.debug("websocket error",e),S.emit(s.EventTypes.WsError,e),b&&S._reconnectWs()})),S.ws.on("close",(function(e){var t=void 0===e?{}:e,n=t.code,r=t.reason;c.default.debug("websocket close",{code:n,reason:r}),S.emit(s.EventTypes.WsClose,{code:n,reason:r}),b&&S._onWebsocketClose()})),S.ws.on("push",(function(e){return S._handlePushEvent(e)})),h.isMiniProgram&&(wx.onAppHide((function(){_&&(S.isManuallyClose=!0,S.ws.disconnect({reason:"appHide"}))})),wx.onAppShow((function(){k&&S.isLogin&&S.ws.connect()}))),S}return r.__extends(t,e),Object.defineProperty(t.prototype,"userInfo",{get:function(){return this.loginManager.userInfo},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isLogin",{get:function(){return this.loginManager.isLogin},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"userId",{get:function(){return this.loginManager.userId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nickName",{get:function(){return this.loginManager.nickName},enumerable:!0,configurable:!0}),t.prototype.init=function(e){return r.__awaiter(this,void 0,void 0,(function(){var t=this;return r.__generator(this,(function(n){return e||(e={}),e.reload&&(this._initPromise=null),[2,this._initPromise||(this._initPromise=new Promise((function(e,n){return r.__awaiter(t,void 0,void 0,(function(){var t;return r.__generator(this,(function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),[4,this.loginManager.login()];case 1:return r.sent(),[4,this.ws.connect()];case 2:return r.sent(),e(),[3,4];case 3:return t=r.sent(),n(d.normalizeError(t)),this._initPromise=null,[3,4];case 4:return[2]}}))}))})))]}))}))},t.prototype.getDefaultFamilyId=function(){var e=this;return this._defaultFamilyIdPromise||(this._defaultFamilyIdPromise=new Promise((function(t,n){return r.__awaiter(e,void 0,void 0,(function(){var e,o,i,a;return r.__generator(this,(function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),[4,this.requestApi("AppGetFamilyList",{Offset:0,Limit:100})];case 1:return e=r.sent(),o=e.FamilyList,e.Total?[3,3]:[4,this.requestApi("AppCreateFamily",{Name:this.loginManager.nickName})];case 2:return i=r.sent().Data.FamilyId,[2,t(i)];case 3:return t(o[0].FamilyId),[3,5];case 4:return a=r.sent(),n(a),this._defaultFamilyIdPromise=null,[3,5];case 5:return[2]}}))}))})))},t.prototype.sendWebsocketMessage=function(e,t){return void 0===t&&(t={}),r.__awaiter(this,void 0,void 0,(function(){return r.__generator(this,(function(n){switch(n.label){case 0:return[4,this.init()];case 1:return n.sent(),[2,this.ws.send(e,t)]}}))}))},t.prototype.connectWebsocket=function(){return r.__awaiter(this,void 0,void 0,(function(){return r.__generator(this,(function(e){switch(e.label){case 0:return[4,this.init()];case 1:return e.sent(),[4,this.ws.connect()];case 2:return e.sent(),[2]}}))}))},t.prototype.disconnectWebsocket=function(e){this.ws.disconnect(e)},t.prototype.subscribeDevices=function(e){return r.__awaiter(this,void 0,void 0,(function(){return r.__generator(this,(function(t){return this.ws.subscribe((e||[]).map((function(e){return"string"==typeof e?e:e&&e.DeviceId?e.DeviceId:void 0})).filter(Boolean)),[2]}))}))},t.prototype.requestApi=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n={});var o=n.doNotRetry,i=void 0!==o&&o,a=n.needLogin,u=void 0===a||a,s=n.doNotReport,l=void 0!==s&&s,p=r.__rest(n,["doNotRetry","needLogin","doNotReport"]);return r.__awaiter(this,void 0,void 0,(function(){var n,o,a,s,h,v,m;return r.__generator(this,(function(g){switch(g.label){case 0:return g.trys.push([0,6,,13]),u?[4,this.loginManager.checkLogin()]:[3,2];case 1:g.sent(),g.label=2;case 2:return n=this.loginManager,o=n.accessToken,a=n.userId,t&&"default"===t.FamilyId?(s=t,[4,this.getDefaultFamilyId()]):[3,4];case 3:s.FamilyId=g.sent(),g.label=4;case 4:return h=r.__assign({uin:a},t),o&&(h.AccessToken=o),this._apiPlatform&&(h.Platform=this._apiPlatform),[4,f.requestTokenApi(e,h,r.__assign({reportor:this.reportor,doNotReport:l},p))];case 5:return[2,g.sent()];case 6:if(v=g.sent(),c.default.debug("requestApi fail",v),!d.isVerifyLoginError(v))return[3,12];if(i)return[3,11];g.label=7;case 7:return g.trys.push([7,9,,10]),[4,this.loginManager.reLogin()];case 8:return g.sent(),[3,10];case 9:return m=g.sent(),c.default.error("reLogin fail",m),[2,Promise.reject(d.genVerifyLoginFailError(v))];case 10:return[2,this.requestApi(e,t,r.__assign({doNotRetry:!0},p))];case 11:return[2,Promise.reject(d.genVerifyLoginFailError(v))];case 12:return[2,Promise.reject(d.normalizeError(v))];case 13:return[2]}}))}))},t.prototype.connectDevice=function(e){if(!h.isMiniProgram)throw"只有小程序内支持该接口调用";return p.connectDevice(this,e)},t.prototype._handlePushEvent=function(e){e||(e={}),this.emit(s.EventTypes.WsPush,e);var t=e.action,n=e.params;n||(n={});var r=n.DeviceId,o=n.Type,i=n.SubType,a=n.Payload,l=n.Time,f=new Date(l).getTime();switch(a&&(a=JSON.parse(u.decodeBase64(a))),c.default.debug("websocket push payload",a),t){case"DeviceChange":switch(o){case"Property":case"Shadow":case"Template":switch(i){case"Report":var d={};try{if(a){var p=a.type,h=a.state,v=a.method,m=a.params;if(p&&"update"===p&&h&&h.reported&&(v="report",m=h.reported),m||(m={}),"report"===v)for(var g in m)d[g]={Value:m[g],lastUpdate:f}}}catch(e){c.default.error("handle report event error",e)}this.emit(s.EventTypes.WsReport,{deviceId:r,deviceData:d});break;case"Push":d={};try{if(a){p=a.type;var y=a.payload;if(v=a.method,m=a.params,p&&"delta"===p&&y&&y.state&&(v="control",m=y.state),"control"===v&&m){for(var g in m)d[g]={Value:m[g],LastUpdate:f};this.emit(s.EventTypes.WsControl,{deviceId:r,deviceData:d})}}}catch(e){c.default.error(e)}}break;case"StatusChange":var b="Online"===i?1:0;this.emit(s.EventTypes.WsStatusChange,{deviceId:r,deviceStatus:b})}}},t.prototype._onWebsocketClose=function(){if(!this.isManuallyClose)return this._reconnectWs();this.isManuallyClose=!1},t.prototype._reconnectWs=function(){return r.__awaiter(this,void 0,void 0,(function(){var e;return r.__generator(this,(function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),c.default.debug("websocket reconnecting in 2 seconds"),[4,l.delay(2e3)];case 1:return t.sent(),[4,this.ws.connect()];case 2:return t.sent(),[3,4];case 3:return e=t.sent(),c.default.error("error when reconnect ws",e),[2,Promise.reject(e)];case 4:return[2]}}))}))},t}(i.default);t.QcloudIotExplorerAppDevSdk=v},function(e,t,n){var r=n(47),o=n(48),i=n(49);e.exports=function(e){return r(e)||o(e)||i()}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(4),o=n(18);t.request=o.request,r.__exportStar(n(5),t),r.__exportStar(n(7),t),r.__exportStar(n(21),t);var i=n(21);t.default=i.QcloudIotExplorerAppDevSdk},function(e,t,n){"use strict";const r=n(25),o=n(26),i=n(27);function a(e,t){return t.encode?t.strict?r(e):encodeURIComponent(e):e}function c(e,t){return t.decode?o(e):e}function u(e){const t=e.indexOf("#");return-1!==t&&(e=e.slice(0,t)),e}function s(e){const t=(e=u(e)).indexOf("?");return-1===t?"":e.slice(t+1)}function l(e,t){return t.parseNumbers&&!Number.isNaN(Number(e))&&"string"==typeof e&&""!==e.trim()?e=Number(e):!t.parseBooleans||null===e||"true"!==e.toLowerCase()&&"false"!==e.toLowerCase()||(e="true"===e.toLowerCase()),e}function f(e,t){const n=function(e){let t;switch(e.arrayFormat){case"index":return(e,n,r)=>{t=/\[(\d*)\]$/.exec(e),e=e.replace(/\[\d*\]$/,""),t?(void 0===r[e]&&(r[e]={}),r[e][t[1]]=n):r[e]=n};case"bracket":return(e,n,r)=>{t=/(\[\])$/.exec(e),e=e.replace(/\[\]$/,""),t?void 0!==r[e]?r[e]=[].concat(r[e],n):r[e]=[n]:r[e]=n};case"comma":return(e,t,n)=>{const r="string"==typeof t&&t.split("").indexOf(",")>-1?t.split(","):t;n[e]=r};default:return(e,t,n)=>{void 0!==n[e]?n[e]=[].concat(n[e],t):n[e]=t}}}(t=Object.assign({decode:!0,sort:!0,arrayFormat:"none",parseNumbers:!1,parseBooleans:!1},t)),r=Object.create(null);if("string"!=typeof e)return r;if(!(e=e.trim().replace(/^[?#&]/,"")))return r;for(const o of e.split("&")){let[e,a]=i(t.decode?o.replace(/\+/g," "):o,"=");a=void 0===a?null:c(a,t),n(c(e,t),a,r)}for(const e of Object.keys(r)){const n=r[e];if("object"==typeof n&&null!==n)for(const e of Object.keys(n))n[e]=l(n[e],t);else r[e]=l(n,t)}return!1===t.sort?r:(!0===t.sort?Object.keys(r).sort():Object.keys(r).sort(t.sort)).reduce((e,t)=>{const n=r[t];return Boolean(n)&&"object"==typeof n&&!Array.isArray(n)?e[t]=function e(t){return Array.isArray(t)?t.sort():"object"==typeof t?e(Object.keys(t)).sort((e,t)=>Number(e)-Number(t)).map(e=>t[e]):t}(n):e[t]=n,e},Object.create(null))}t.extract=s,t.parse=f,t.stringify=(e,t)=>{if(!e)return"";const n=function(e){switch(e.arrayFormat){case"index":return t=>(n,r)=>{const o=n.length;return void 0===r||e.skipNull&&null===r?n:null===r?[...n,[a(t,e),"[",o,"]"].join("")]:[...n,[a(t,e),"[",a(o,e),"]=",a(r,e)].join("")]};case"bracket":return t=>(n,r)=>void 0===r||e.skipNull&&null===r?n:null===r?[...n,[a(t,e),"[]"].join("")]:[...n,[a(t,e),"[]=",a(r,e)].join("")];case"comma":return t=>(n,r)=>null==r||0===r.length?n:0===n.length?[[a(t,e),"=",a(r,e)].join("")]:[[n,a(r,e)].join(",")];default:return t=>(n,r)=>void 0===r||e.skipNull&&null===r?n:null===r?[...n,a(t,e)]:[...n,[a(t,e),"=",a(r,e)].join("")]}}(t=Object.assign({encode:!0,strict:!0,arrayFormat:"none"},t)),r=Object.assign({},e);if(t.skipNull)for(const e of Object.keys(r))void 0!==r[e]&&null!==r[e]||delete r[e];const o=Object.keys(r);return!1!==t.sort&&o.sort(t.sort),o.map(r=>{const o=e[r];return void 0===o?"":null===o?a(r,t):Array.isArray(o)?o.reduce(n(r),[]).join("&"):a(r,t)+"="+a(o,t)}).filter(e=>e.length>0).join("&")},t.parseUrl=(e,t)=>({url:u(e).split("?")[0]||"",query:f(s(e),t)})},function(e,t,n){"use strict";e.exports=e=>encodeURIComponent(e).replace(/[!'()*]/g,e=>"%"+e.charCodeAt(0).toString(16).toUpperCase())},function(e,t,n){"use strict";var r=new RegExp("%[a-f0-9]{2}","gi"),o=new RegExp("(%[a-f0-9]{2})+","gi");function i(e,t){try{return decodeURIComponent(e.join(""))}catch(e){}if(1===e.length)return e;t=t||1;var n=e.slice(0,t),r=e.slice(t);return Array.prototype.concat.call([],i(n),i(r))}function a(e){try{return decodeURIComponent(e)}catch(o){for(var t=e.match(r),n=1;n{if("string"!=typeof e||"string"!=typeof t)throw new TypeError("Expected the arguments to be of type `string`");if(""===t)return[e];const n=e.indexOf(t);return-1===n?[e]:[e.slice(0,n),e.slice(n+t.length)]}},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function c(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var u,s=[],l=!1,f=-1;function d(){l&&u&&(l=!1,u.length?s=u.concat(s):f=-1,s.length&&p())}function p(){if(!l){var e=c(d);l=!0;for(var t=s.length;t;){for(u=s,s=[];++f1)for(var n=1;n0&&(t+=i(r)),t+i(n)}},function(e,t,n){"use strict";var r=n(17),o=n(34),i=n(35);e.exports=function(e){for(var t,n=0,a="";!t;)a+=i(o,r.get(),1),t=e ",d),r.label=1;case 1:return r.trys.push([1,3,,11]),[4,this.send("YunApi",d,{reqId:n})];case 2:if(!(p=r.sent()))throw u.default.error("empty response",d),{msg:"连接服务器失败,请稍后重试"};if(!(h=p.Response))throw u.default.error("empty response",d,h),{msg:"连接服务器失败,请稍后重试"};if(v=h.Error,m=h.error,g=h.error_message,v)throw{code:v.Code,msg:v.Message};if(m)throw{code:m,msg:g};return u.default.debug("yunapi success("+n+") => ",d,h),[2,h];case 3:if(y=r.sent(),u.default.error("yunapi fail("+n+") => ",y),!s.isVerifyLoginError(y))return[3,10];if(o)return[3,8];r.label=4;case 4:return r.trys.push([4,6,,7]),[4,this.sdk.loginManager.reLogin()];case 5:return r.sent(),[3,7];case 6:return b=r.sent(),u.default.error("reLogin fail",b),[2,Promise.reject(s.genVerifyLoginFailError(y))];case 7:return[2,this.callYunApi(e,t,{doNotRetry:!0})];case 8:return[4,this.sdk.loginManager.logout()];case 9:return r.sent(),[2,s.genVerifyLoginFailError(y)];case 10:return a.isPlainObject(y)&&(y.reqId=n),[2,Promise.reject(y)];case 11:return[2]}}))}))},t.prototype.sendWsHeatBeat=function(){if(this._subscribeDeviceIdList&&this._subscribeDeviceIdList.length)return this.callYunApi("AppDeviceTraceHeartBeat",{DeviceIds:this._subscribeDeviceIdList})},t.prototype.activePush=function(e){var t=this;e&&(this._subscribeDeviceIdList=e);var n=this.sdk.loginManager,r=n.isLogin,o=n.accessToken,i=n.appKey;r&&o&&this._subscribeDeviceIdList&&(this.send("ActivePush",{DeviceIds:this._subscribeDeviceIdList,AccessToken:o,AppKey:i}),this.sendWsHeatBeat(),clearInterval(this._heartBeatTimer),this._heartBeatTimer=setInterval((function(){return t.sendWsHeatBeat()}),this.options.heartbeatInterval))},t}(o.default);t.IotWebsocket=f},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(4).__importStar(n(15)),o=function(){function e(e){this.url=e,this.ws=null,this.initWs()}return e.prototype.initWs=function(){r.isMiniProgram?this.ws=wx.connectSocket({url:this.url}):this.ws=new window.WebSocket(this.url)},e.prototype.send=function(e){var t=e.data;r.isMiniProgram?this.ws.send({data:t}):this.ws.send(t)},e.prototype.close=function(e){var t=void 0===e?{}:e,n=t.code,o=t.reason;r.isMiniProgram?this.ws.close({code:n,reason:o}):this.ws.close(n,o)},e.prototype.onOpen=function(e){r.isMiniProgram?this.ws.onOpen(e):this.ws.addEventListener("open",e)},e.prototype.onClose=function(e){r.isMiniProgram?this.ws.onClose(e):this.ws.addEventListener("close",e)},e.prototype.onMessage=function(e){r.isMiniProgram?this.ws.onMessage(e):this.ws.addEventListener("message",e)},e.prototype.onError=function(e){r.isMiniProgram?this.ws.onError(e):this.ws.addEventListener("error",e)},e}();t.WebSocket=o},function(e,t){const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.encodeBase64=e=>{if(!e)return!1;let t,r,o,i,a,c,u,s="",l=0;do{t=e.charCodeAt(l++),r=e.charCodeAt(l++),o=e.charCodeAt(l++),i=t>>2,a=(3&t)<<4|r>>4,c=(15&r)<<2|o>>6,u=63&o,isNaN(r)?c=u=64:isNaN(o)&&(u=64),s+=n.charAt(i)+n.charAt(a)+n.charAt(c)+n.charAt(u)}while(l{if(!e)return!1;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");let t,r,o,i,a="",c=0;do{t=n.indexOf(e.charAt(c++)),r=n.indexOf(e.charAt(c++)),o=n.indexOf(e.charAt(c++)),i=n.indexOf(e.charAt(c++)),a+=String.fromCharCode(t<<2|r>>4),64!=o&&(a+=String.fromCharCode((15&r)<<4|o>>2)),64!=i&&(a+=String.fromCharCode((3&o)<<6|i))}while(c "+e+", detail => "+JSON.stringify(t))}catch(e){}x(r.__assign({code:e,msg:c.SmartConfigStepMsg[e]},t))})(c.ConnectDeviceStepCode.CONNECT_DEVICE_START),[4,i.pify(wx.startWifi)()];case 1:return S.sent(),[4,w()];case 2:return S.sent(),h(c.ConnectDeviceStepCode.CONNECT_DEVICE_SUCCESS),P(),[3,4];case 3:return(E=S.sent())&&E.code in c.ConnectDeviceErrorCode&&(E.msg=c.SmartConfigErrorMsg[E.code]),I(E),[3,4];case 4:return[2]}}))}))}},function(e,t,n){var r=function(e){"use strict";var t,n=Object.prototype,r=n.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(e,t,n,r){var o=t&&t.prototype instanceof v?t:v,i=Object.create(o.prototype),a=new x(r||[]);return i._invoke=function(e,t,n){var r=l;return function(o,i){if(r===d)throw new Error("Generator is already running");if(r===p){if("throw"===o)throw i;return I()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var c=C(a,n);if(c){if(c===h)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===l)throw r=p,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=d;var u=s(e,t,n);if("normal"===u.type){if(r=n.done?p:f,u.arg===h)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=p,n.method="throw",n.arg=u.arg)}}}(e,n,a),i}function s(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var l="suspendedStart",f="suspendedYield",d="executing",p="completed",h={};function v(){}function m(){}function g(){}var y={};y[i]=function(){return this};var b=Object.getPrototypeOf,w=b&&b(b(O([])));w&&w!==n&&r.call(w,i)&&(y=w);var _=g.prototype=v.prototype=Object.create(y);function E(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function k(e){var t;this._invoke=function(n,o){function i(){return new Promise((function(t,i){!function t(n,o,i,a){var c=s(e[n],e,o);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==typeof l&&r.call(l,"__await")?Promise.resolve(l.__await).then((function(e){t("next",e,i,a)}),(function(e){t("throw",e,i,a)})):Promise.resolve(l).then((function(e){u.value=e,i(u)}),(function(e){return t("throw",e,i,a)}))}a(c.arg)}(n,o,t,i)}))}return t=t?t.then(i,i):i()}}function C(e,n){var r=e.iterator[n.method];if(r===t){if(n.delegate=null,"throw"===n.method){if(e.iterator.return&&(n.method="return",n.arg=t,C(e,n),"throw"===n.method))return h;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var o=s(r,e.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,h;var i=o.arg;return i?i.done?(n[e.resultName]=i.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,h):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,h)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function S(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function O(e){if(e){var n=e[i];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function n(){for(;++o=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),s=r.call(a,"finallyLoc");if(u&&s){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),S(n),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;S(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:O(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),h}},e}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}},function(e,t){e.exports=function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t "+e+", detail => "+JSON.stringify(t))}catch(e){}T(r.__assign({code:e,msg:u.SoftApStepMsg[e]},t))})(u.ConnectDeviceStepCode.CONNECT_DEVICE_START),[4,i.pify(wx.startWifi)()];case 2:if(N.sent(),!f)return[3,6];N.label=3;case 3:return N.trys.push([3,5,,6]),h(u.ConnectDeviceStepCode.CONNECT_SOFTAP_START),[4,w(f)];case 4:return N.sent(),h(u.ConnectDeviceStepCode.CONNECT_SOFTAP_SUCCESS),[3,6];case 5:throw C=N.sent(),S={code:u.ConnectDeviceErrorCode.CONNECT_SOFTAP_FAIL},C&&C.errMsg&&(S.errMsg=C.errMsg),S;case 6:return[4,E()];case 7:return N.sent(),h(u.ConnectDeviceStepCode.CONNECT_DEVICE_SUCCESS),I(),[3,9];case 8:return(O=N.sent())&&O.code in u.ConnectDeviceErrorCode&&(O.msg=u.SoftApErrorMsg[O.code]),x(O),[3,9];case 9:return[2]}}))}))}},function(e,t,n){"use strict";n.r(t);var r=n(6),o=n.n(r),i=n(10),a=n.n(i),c=n(2),u=n.n(c),s=n(3),l=n.n(s),f=n(0),d=n.n(f),p=n(22),h=n.n(p),v=new(function(){function e(){u()(this,e),d()(this,"ESPTOUCH_ENCODING_CHARSET","UTF-8")}return l()(e,[{key:"stringToByteArray",value:function(e){for(var t=[],n=0,r=0;r255&&(t[n++]=255&o,o>>=8),t[n++]=o}return t}},{key:"putString2bytes",value:function(e,t,n,r,o){for(var i=this.stringToByteArray(t),a=0;a1?t:"0".concat(t)}},{key:"byteArrayToHex",value:function(e,t){var n=this;return e.map((function(e){return n.byteToHex(e)})).join(t||"")}},{key:"convertByte2HexString",value:function(e){var t=this.convertByte2Uint8(e);return this.byteToHex(t)}},{key:"convertU8ToHexString",value:function(e){return this.byteToHex(e)}},{key:"splitUint8To2bytes",value:function(e){if(e<0||e>255)throw"Out of Boundary";var t,n,r=this.convertByte2HexString(e);return r.length>1?(n=parseInt(r.substring(0,1),16),t=parseInt(r.substring(1,2),16)):(n=0,t=parseInt(r.substring(0,1),16)),new Array(n,t)}},{key:"combine2bytesToOne",value:function(e,t){if(e<0||e>15||t<0||t>15)throw"Out of Boundary";return e<<4|t}},{key:"combine2bytesToU16",value:function(e,t){return this.convertByte2Uint8(e)<<8|this.convertByte2Uint8(t)}},{key:"getSpecBytesFromChar",value:function(e){for(var t=new Int8Array(e),n=0;n>6|192,t[n++]=63&o|128):55296==(64512&o)&&r+1>18|240,t[n++]=o>>12&63|128,t[n++]=o>>6&63|128,t[n++]=63&o|128):(t[n++]=o>>12|224,t[n++]=o>>6&63|128,t[n++]=63&o|128)}return t}},{key:"getBytesByString",value:function(e){try{switch(this.ESPTOUCH_ENCODING_CHARSET){case"UTF-8":return this.stringToUtf8ByteArray(e)}}catch(e){throw"the charset is invalid"}}},{key:"testSplitUint8To2bytes",value:function(){var e=this.splitUint8To2bytes(20);1===e[0]&&4===e[1]?console.log("test_splitUint8To2bytes(): pass"):console.log("test_splitUint8To2bytes(): fail")}},{key:"testCombine2bytesToOne",value:function(){20===this.combine2bytesToOne(1,4)?console.log("test_combine2bytesToOne(): pass"):console.log("test_combine2bytesToOne(): fail")}},{key:"testConvertChar2Uint8",value:function(){97===this.convertByte2Uint8("a")&&128===this.convertByte2Uint8(-128)&&255===this.convertByte2Uint8(-1)?console.log("test_convertChar2Uint8(): pass"):console.log("test_convertChar2Uint8(): fail")}},{key:"testConvertUint8toByte",value:function(){97===this.convertUint8toByte("a")&&-128===this.convertUint8toByte(128)&&-1===this.convertUint8toByte(255)?console.log("test_convertUint8toByte(): pass"):console.log("test_convertUint8toByte(): fail")}},{key:"testParseBssid",value:function(){var e=[15,-2,52,-102,-93,-60];console.log(this.parseBssid(e)),"0ffe349aa3c4"===this.parseBssid(e)?console.log("test_parseBssid(): pass"):console.log("test_parseBssid(): fail")}},{key:"testMain",value:function(){this.testConvertUint8toByte(),this.testConvertChar2Uint8(),this.testSplitUint8To2bytes(),this.testCombine2bytesToOne(),this.testParseBssid()}}]),e}()),m=function(){function e(t){if(u()(this,e),d()(this,"mData",""),"string"==typeof t)this.mData=v.stringToByteArray(t);else{if(!(t instanceof Int8Array))throw"data cannot be null";this.mData=t}}return l()(e,[{key:"getData",value:function(){return this.mData}}]),e}(),g=n(12),y=n.n(g),b=n(13),w=n.n(b),_=n(1),E=n.n(_),k=n(14),C=n.n(k),T=new(function(){function e(){u()(this,e),this.mBroadcast=!0,this.mIntervalGuideCodeMillisecond=20,this.mIntervalDataCodeMillisecond=20,this.mTimeoutGuideCodeMillisecond=1500,this.mTimeoutDataCodeMillisecond=5e3,this.mTotalRepeatTime=1,this.mEsptouchResultOneLen=1,this.mEsptouchResultMacLen=6,this.mEsptouchResultIpLen=4,this.mEsptouchResultTotalLen=11,this.mPortListening=18266,this.mTargetPort=7001,this.mWaitUdpReceivingMilliseond=25e3,this.mWaitUdpSendingMillisecond=45e3,this.mThresholdSucBroadcastCount=1,this.mExpectTaskResultCount=1,this._datagramCount=0}return l()(e,[{key:"getIntervalGuideCodeMillisecond",value:function(){return this.mIntervalGuideCodeMillisecond}},{key:"getIntervalDataCodeMillisecond",value:function(){return this.mIntervalDataCodeMillisecond}},{key:"getTimeoutGuideCodeMillisecond",value:function(){return this.mTimeoutGuideCodeMillisecond}},{key:"getTimeoutDataCodeMillisecond",value:function(){return this.mTimeoutDataCodeMillisecond}},{key:"getTimeoutTotalCodeMillisecond",value:function(){return this.mTimeoutGuideCodeMillisecond+this.mTimeoutDataCodeMillisecond}},{key:"getTotalRepeatTime",value:function(){return this.mTotalRepeatTime}},{key:"getEsptouchResultOneLen",value:function(){return this.mEsptouchResultOneLen}},{key:"getEsptouchResultMacLen",value:function(){return this.mEsptouchResultMacLen}},{key:"getEsptouchResultIpLen",value:function(){return this.mEsptouchResultIpLen}},{key:"getEsptouchResultTotalLen",value:function(){return this.mEsptouchResultTotalLen}},{key:"getPortListening",value:function(){return this.mPortListening}},{key:"getTargetHostname",value:function(){if(this.mBroadcast)return"255.255.255.255";var e=this.__getNextDatagramCount();return"234.".concat(e,".").concat(e,".").concat(e)}},{key:"getTargetPort",value:function(){return this.mTargetPort}},{key:"getWaitUdpReceivingMillisecond",value:function(){return this.mWaitUdpReceivingMilliseond}},{key:"getWaitUdpSendingMillisecond",value:function(){return this.mWaitUdpSendingMillisecond}},{key:"getWaitUdpTotalMillisecond",value:function(){return this.mWaitUdpReceivingMilliseond+this.mWaitUdpSendingMillisecond}},{key:"setWaitUdpTotalMillisecond",value:function(e){if(ei)return 1;if(o1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0,a=arguments.length>5?arguments[5]:void 0,c=arguments.length>6?arguments[6]:void 0;if(1===r)return this.mSocket.send({address:o,port:i,message:e[n]}),c();setTimeout((function(){var u=Math.min(e.length-1,n+1),s=u>=e.length-1?1:r-1;t.mSocket.send({address:o,port:i,message:e[n]}),t.sendDataSideBySide(e,u,s,o,i,a,c)}),a)}},{key:"sendData",value:(n=a()(o.a.mark((function e(t){var n,r,i,a,c,u,s=arguments;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=s.length>1&&void 0!==s[1]?s[1]:0,r=s.length>2?s[2]:void 0,i=s.length>3?s[3]:void 0,a=s.length>4?s[4]:void 0,c=s.length>5?s[5]:void 0,!(null==t||t.length<=0)){e.next=8;break}return console.log(this.TAG,"sendData(): data == null or length <= 0"),e.abrupt("return");case 8:if(!this.isClose){e.next=11;break}return console.log(this.TAG,"udpsocket is close"),e.abrupt("return");case 11:u=n;case 12:if(!(u>>1^this.CRC_POLYNOM:n>>>=1;this.crcTable[t]=n}this.value=this.init=this.CRC_INITIAL}return l()(e,[{key:"updateValue",value:function(e,t,n){for(var r=0;rthis.INDEX_MAX)throw"index > INDEX_MAX";var r=v.splitUint8To2bytes(t);this.mDataHigh=r[0],this.mDataLow=r[1];var o=new N;o.update(v.convertUint8toByte(t)),o.update(n);var i=v.splitUint8To2bytes(v.convertNumberToChar(o.getValue()));this.mCrcHigh=i[0],this.mCrcLow=i[1],this.mSeqHeader=v.convertNumberToByte(n)}return l()(e,[{key:"getBytes",value:function(){var e=new Int8Array(this.DATA_CODE_LEN);return e[0]=0,e[1]=v.combine2bytesToOne(this.mCrcHigh,this.mDataHigh),e[2]=1,e[3]=this.mSeqHeader,e[4]=0,e[5]=v.combine2bytesToOne(this.mCrcLow,this.mDataLow),e}},{key:"toString",value:function(){for(var e="",t=this.getBytes(),n=0;n0&&void 0!==arguments[0]?arguments[0]:"").split("."),t=new Int8Array(e.length),n=0;n127?r-256:r}return t}(o),m=h.length,g=v.convertNumberToChar(this.EXTRA_HEAD_LEN+m+c+p);this.mDataCodes=[],this.mDataCodes.push(new A(g,0)),a^=g,this.mDataCodes.push(new A(c,1)),a^=c,this.mDataCodes.push(new A(l,2)),a^=l,this.mDataCodes.push(new A(f,3)),a^=f;for(var y=0;y=this.mDataCodes.length?this.mDataCodes.push(O):this.mDataCodes.splice(C,0,O),C+=4}}return l()(e,[{key:"getBytes",value:function(){var e=new Int8Array(this.mDataCodes.length*this.DATA_CODE_LEN),t=0;return this.mDataCodes.forEach((function(n){n.getBytes().forEach((function(n){e[t++]=n}))})),e}},{key:"toString",value:function(){for(var e="",t=this.getBytes(),n=0;n2&&void 0!==arguments[2]?arguments[2]:{};i[e]("".concat(c.TAG,"log detail"),{errorCode:t,data:n})},c.logger("info","Welcome Esptouch smartconfig in weapp"),c}var n,r;return C()(t,e),l()(t,[{key:"__checkTaskValid",value:function(){return this.mIsExecuted?(this.logger("error","the Esptouch task could be executed only once"),!1):(this.mIsExecuted=!0,!0)}},{key:"start",value:(r=a()(o.a.mark((function e(){var t,n,r,i=arguments;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=i.length>0&&void 0!==i[0]?i[0]:1,this.__checkTaskValid()){e.next=3;break}return e.abrupt("return");case 3:this.mParameter.setExpectTaskResultCount(t),this.logger("info","start smartconfig in promise settimeout"),n=new L(this.mApSsid,this.mApBssid,this.mApPassword,this.mLocalIp,this.mEncryptor),this.mSocketServer.startServer(),this.__listenAsyn(this.mParameter.getEsptouchResultTotalLen()),r=0;case 10:if(!(r0&&void 0!==arguments[0]?arguments[0]:1;if(this.__checkTaskValid()){this.mParameter.setExpectTaskResultCount(t),this.logger("info","start smartconfig in no promise settimeout");var n=new L(this.mApSsid,this.mApBssid,this.mApPassword,this.mLocalIp,this.mEncryptor);this.mSocketServer.startServer(),this.__listenAsyn(this.mParameter.getEsptouchResultTotalLen()),this.__executeInNoPromise(n),setTimeout((function(){e.mIsSuc||e.emit("onError",{code:j.ConnectDeviceErrorCode.SMART_CONFIG_TIMEOUT}),e.emit("result",e.__getEsptouchResultList()),e.interrupt()}),this.mParameter.getWaitUdpReceivingMillisecond())}}},{key:"__executeInNoPromise",value:function(e){var t=Date.now(),n=t-this.mParameter.getTimeoutTotalCodeMillisecond(),r=0,o=this,i=e.getGCBytes2(),a=e.getDCBytes2();function c(){if(!o.mIsInterrupt&&Date.now()-t=o.mParameter.getTimeoutDataCodeMillisecond()?(o.logger("info","send gc code "),c(),n=t):(o.mSocketClient.sendDataSideBySide(a,r,o.ONE_DATA_LEN,o.mParameter.getTargetHostname(),o.mParameter.getTargetPort(),o.mParameter.getIntervalDataCodeMillisecond(),u),r=(r+o.ONE_DATA_LEN)%a.length),t=Date.now())}u(),setTimeout((function(){o.interrupt(),o.emit("result",o.__getEsptouchResultList())}),this.mParameter.getWaitUdpSendingMillisecond())}},{key:"__execute",value:(n=a()(o.a.mark((function e(t){var n,r,i,a,c,u;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=Date.now(),i=(r=n)-this.mParameter.getTimeoutTotalCodeMillisecond(),a=t.getGCBytes2(),c=t.getDCBytes2(),u=0;case 6:if(this.mIsInterrupt){e.next=27;break}if(!(r-i>=this.mParameter.getTimeoutDataCodeMillisecond())){e.next=19;break}this.logger("info","send gc code ");case 9:if(this.mIsInterrupt||!(Date.now()-rthis.mParameter.getWaitUdpSendingMillisecond())){e.next=14;break}return e.abrupt("break",16);case 14:e.next=9;break;case 16:i=r,e.next=22;break;case 19:return e.next=21,this.mSocketClient.sendData(c,u,this.ONE_DATA_LEN,this.mParameter.getTargetHostname(),this.mParameter.getTargetPort(),this.mParameter.getIntervalDataCodeMillisecond());case 21:u=(u+this.ONE_DATA_LEN)%c.length;case 22:if(!((r=Date.now())-n>this.mParameter.getWaitUdpSendingMillisecond())){e.next=25;break}return e.abrupt("break",27);case 25:e.next=6;break;case 27:return e.abrupt("return",this.mIsSuc);case 28:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"__listenAsyn",value:function(){var e=this;this.logger("info","__listenAsyn() start");var t=this.mApSsid,n=this.mApPassword,r=Date.now(),o=v.convertUint8toByte(t.length+n.length+9);this.logger("info","expectOneByte: ".concat(o)),this.mSocketServer.on("recieveCorrectMsg",(function(t){e.logger("info","RECIEVE_MSG",t),function(t){var n,i=t.message,a=t.remoteInfo,c=new Int8Array(i);if(e.logger("info","Int8Array",c),n=null!=c?c[0]:-1,e.logger("info","receiveOneByte: ".concat(n)),n===o){e.logger("info","receive correct broadcast");var u=Date.now()-r,s=Number(e.mParameter.getWaitUdpTotalMillisecond()-u);if(s<0)e.logger("error","esptouch timeout");else if(e.logger("error","mSocketServer's new timeout is ".concat(s," milliseconds")),e.logger("info","receive correct broadcast"),null!=c){var l=v.parseBssid(c,e.mParameter.getEsptouchResultOneLen(),e.mParameter.getEsptouchResultMacLen()),f=function(e,t,n){for(var r="",o=0;o=e.mParameter.getExpectTaskResultCount(),e.mIsSuc&&(e.logger("info","__listenAsyn() finish"),e.interrupt())}))}},{key:"__putEsptouchResult",value:function(e,t,n,r){var o=this.mBssidTaskSucCountMap[t];if(null==o&&(o=0),++o,this.logger("info","PUT_ESPTOUCH_RESULT","__putEsptouchResult(): count = ".concat(o)),this.mBssidTaskSucCountMap[t]=o,o>=this.mParameter.getThresholdSucBroadcastCount()){for(var i=!1,a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}},function(e,t,n){var r=n(16),o=n(17),i=n(18);e.exports=function(e){return r(e)||o(e)||i()}},function(e,t,n){"use strict";var r,o,i,a=n(25),c="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";function u(){i=!1}function s(e){if(e){if(e!==r){if(e.length!==c.length)throw new Error("Custom alphabet for shortid must be "+c.length+" unique characters. You submitted "+e.length+" characters: "+e);var t=e.split("").filter((function(e,t,n){return t!==n.lastIndexOf(e)}));if(t.length)throw new Error("Custom alphabet for shortid must be "+c.length+" unique characters. These characters were not unique: "+t.join(", "));r=e,u()}}else r!==c&&(r=c,u())}function l(){return i||(i=function(){r||s(c);for(var e,t=r.split(""),n=[],o=a.nextValue();t.length>0;)o=a.nextValue(),e=Math.floor(o*t.length),n.push(t.splice(e,1)[0]);return n.join("")}())}e.exports={get:function(){return r||c},characters:function(e){return s(e),r},seed:function(e){a.seed(e),o!==e&&(u(),o=e)},lookup:function(e){return l()[e]},shuffled:l}},function(e,t,n){var r=n(21),o=n(22),i=n(23);e.exports=function(e,t){return r(e)||o(e,t)||i()}},function(e,t,n){"use strict";var r=n(13),o=n(26),i=n(30),a=n(31)||0;function c(){return o(a)}e.exports=c,e.exports.generate=c,e.exports.seed=function(t){return r.seed(t),e.exports},e.exports.worker=function(t){return a=t,e.exports},e.exports.characters=function(e){return void 0!==e&&r.characters(e),r.shuffled()},e.exports.isValid=i},function(e,t){e.exports=function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),_(n),s}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;_(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),s}},e}(e.exports);try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}},function(e,t){function n(t,r){return e.exports=n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(t,r)}e.exports=n},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,o=!1,i=void 0;try{for(var a,c=e[Symbol.iterator]();!(r=(a=c.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==c.return||c.return()}finally{if(o)throw i}}return n}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(e,t){e.exports=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r=0||(o[n]=e[n]);return o}},function(e,t,n){"use strict";var r=1;e.exports={nextValue:function(){return(r=(9301*r+49297)%233280)/233280},seed:function(e){r=e}}},function(e,t,n){"use strict";var r,o,i=n(27);n(13),e.exports=function(e){var t="",n=Math.floor(.001*(Date.now()-1459707606518));return n===o?r++:(r=0,o=n),t+=i(6),t+=i(e),r>0&&(t+=i(r)),t+i(n)}},function(e,t,n){"use strict";var r=n(13),o=n(28),i=n(29);e.exports=function(e){for(var t,n=0,a="";!t;)a+=i(o,r.get(),1),t=e-1&&r.splice(o,1)}else n[e].length=0;return this}},{key:"emit",value:function(e){for(var t=this,n=arguments.length,r=new Array(n>1?n-1:0),o=1;o2?n-2:0),o=2;o1&&void 0!==r[1]&&r[1],e.prev=1,e.next=4,this.callWxApi("createBLEConnection",t);case 4:e.next=24;break;case 6:if(e.prev=6,e.t0=e.catch(1),n||!e.t0||!e.t0.errMsg||!e.t0.errMsg.indexOf(!1)){e.next=23;break}return console.log("already connect, try disconnect"),e.prev=10,e.next=13,this.closeBLEConnection(t);case 13:console.log("disconnect success",t),e.next=19;break;case 16:e.prev=16,e.t1=e.catch(10),console.warn("disconnect fail",e.t1);case 19:return console.log("try connect again",t),e.abrupt("return",this.createBLEConnection(t,!0));case 23:return e.abrupt("return",Promise.reject(e.t0));case 24:case"end":return e.stop()}}),e,this,[[1,6],[10,16]])}))),function(e){return n.apply(this,arguments)})},{key:"closeBLEConnection",value:function(e){return this.callWxApi("closeBLEConnection",e)}},{key:"onBluetoothAdapterStateChange",value:function(e){this._onBluetoothAdapterStateChangeHandler=e}},{key:"offBluetoothAdapterStateChange",value:function(){this._onBluetoothAdapterStateChangeHandler=null}},{key:"onBLEConnectionStateChange",value:function(e){this._onBLEConnectionStateChangeHandler=e}},{key:"offBLEConnectionStateChange",value:function(){this._onBLEConnectionStateChangeHandler=null}},{key:"onBLECharacteristicValueChange",value:function(e){this._onBLECharacteristicValueChangeHandler=e}},{key:"offBLECharacteristicValueChange",value:function(){this._onBLECharacteristicValueChangeHandler=null}},{key:"onBluetoothDeviceFound",value:function(e){this._onBluetoothDeviceFoundHandler=e}},{key:"offBluetoothDeviceFound",value:function(){this._onBluetoothDeviceFoundHandler=null}}]),t}(N),j=n(10),U=n.n(j),F=n(11),B=n.n(F);function V(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function W(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:{},t=e.serviceId;t=t||this.serviceId;var n=this.characteristicsMap[t]||{writeIds:[],notifyIds:[],readIds:[],indicateIds:[]};return n.notifyIds[0]||n.indicateIds[0]}},{key:"isDevMode",value:function(){return location.href.indexOf("/developing/")>-1}},{key:"handleBLEMessage",value:function(e,t){return t.serviceId,t.characteristicId,e}},{key:"registerDevice",value:(p=C()(u.a.mark((function e(){return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._deviceRegistered){e.next=4;break}return e.next=3,this.sdk.blueToothBridge.control("registryDevice",{deviceName:this._deviceName,productId:this.isDevMode()?this._productId:""});case 3:this._deviceRegistered=!0;case 4:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"_onBleConnectionStateChange",value:function(e){var t=e.connected;this._deviceConnected=t,this.emit("bLEConnectionStateChange",{connected:t}),t?this.emit("connect"):this.disconnectDevice()}},{key:"_onBLECharacteristicValueChange",value:(f=C()(u.a.mark((function e(t){var n,r,o,i,a,c,s,l,f;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.serviceId,r=t.characteristicId,o=t.value,e.prev=1,i=this.handleBLEMessage(o,{serviceId:n,characteristicId:r}),a=i.shouldIgnore,c=i.reportData,s=B()(i,["shouldIgnore","reportData"]),console.log("shouldIgnore?",a),!a){e.next=6;break}return e.abrupt("return");case 6:if(console.log("receive data",o,s),console.log("should report?",!!c,c),l=Date.now(),f=!1,!this._deviceName||!c){e.next=14;break}return f=!0,e.next=14,this.sdk.requestTokenApi("AppReportDataAsDevice",{ProductId:this._productId,DeviceName:this._deviceName,Data:JSON.stringify(c),DataTimeStamp:l});case 14:this.emit("message",W({},s,{timestamp:l,dataReported:f})),e.next=20;break;case 17:e.prev=17,e.t0=e.catch(1),console.error("onBLECharacteristicValueChange onError,",e.t0);case 20:case"end":return e.stop()}}),e,this,[[1,17]])}))),function(e){return f.apply(this,arguments)})},{key:"disconnectDevice",value:function(){this.sdk.blueToothBridge.closeBLEConnection({deviceId:this._deviceId}),this.emit("disconnect")}},{key:"connectDevice",value:(s=C()(u.a.mark((function e(){var t,n,r,o,i,a,c=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=c.length>0&&void 0!==c[0]?c[0]:{},n=t.autoNotify,r=void 0===n||n,o=this.sdk.blueToothBridge,e.prev=2,!this._deviceConnected){e.next=6;break}return console.log("Device已经连接",this._deviceId),e.abrupt("return");case 6:return e.next=8,this.registerDevice();case 8:return e.next=10,o.createBLEConnection({deviceId:this._deviceId});case 10:if(console.log("createBLEConnection succ"),!r){e.next=25;break}return e.next=14,this.getBLEDeviceServices();case 14:return i=e.sent,console.log("getBLEDeviceServices succ",i),this.emit("onGetBLEDeviceServices",i),e.next=19,this.getBLEDeviceCharacteristics();case 19:return a=e.sent,console.log("getBLEDeviceCharacteristics succ",a),this.emit("onGetBLEDeviceCharacteristics",a),e.next=24,this.notifyBLECharacteristicValueChange();case 24:console.log("notifyBLECharacteristicValueChange succ");case 25:e.next=31;break;case 27:throw e.prev=27,e.t0=e.catch(2),console.error("connectDevice error",e.t0),e.t0;case 31:case"end":return e.stop()}}),e,this,[[2,27]])}))),function(){return s.apply(this,arguments)})},{key:"bindDevice",value:(c=C()(u.a.mark((function e(){return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.registerDevice();case 2:return e.next=4,this.sdk.blueToothBridge.control("bindDevice",{deviceName:this._deviceName,productId:this.isDevMode()?this._productId:""});case 4:return e.abrupt("return",this.explorerDeviceId);case 5:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"write",value:(i=C()(u.a.mark((function e(t){var n,r,o,i,a,c=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=c.length>1&&void 0!==c[1]?c[1]:{},r=n.writeId,o=void 0===r?"":r,i=n.serviceId,a=void 0===i?"":i,e.prev=1,e.next=4,this.sdk.blueToothBridge.writeBLECharacteristicValue({deviceId:this._deviceId,characteristicId:o||this._writeId,serviceId:a||this.serviceId,value:t});case 4:e.next=9;break;case 6:return e.prev=6,e.t0=e.catch(1),e.abrupt("return",Promise.reject(e.t0));case 9:case"end":return e.stop()}}),e,this,[[1,6]])}))),function(e){return i.apply(this,arguments)})},{key:"getBLEDeviceServices",value:(o=C()(u.a.mark((function e(){var t,n;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sdk.blueToothBridge.getBLEDeviceServices({deviceId:this._deviceId});case 2:return t=e.sent,n=t.services,this._services=n,e.abrupt("return",n);case 6:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"setCharacteristicsIds",value:function(e,t){var n=this,r=function(e,t){-1===e.indexOf(t)&&e.push(t)};t.forEach((function(e){var t=e.uuid,o=e.properties,i=o.notify,a=o.write,c=o.indicate,u=o.read;i?r(n.map.notifyIds,t):a?r(n.map.writeIds,t):c?r(n.map.indicateIds,t):u&&r(n.map.readIds,t)})),this.characteristicsMap[e]={notifyIds:[],writeIds:[],indicateIds:[],readIds:[]}}},{key:"getBLEDeviceCharacteristics",value:(r=C()(u.a.mark((function e(){var t,n,r,o,i=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=i.length>0&&void 0!==i[0]?i[0]:{},n=(n=t.serviceId)||this.serviceId,e.next=4,this.sdk.blueToothBridge.getBLEDeviceCharacteristics({deviceId:this._deviceId,serviceId:n});case 4:return r=e.sent,o=r.characteristics,this.setCharacteristicsIds(n,o),e.abrupt("return",o);case 8:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"notifyBLECharacteristicValueChange",value:(n=C()(u.a.mark((function e(){var t,n,r,o,i,a=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=a.length>0&&void 0!==a[0]?a[0]:{},n=t.characteristicId,r=t.serviceId,o=t.state,i=void 0===o||o,n=n||this._getNotifyId(),r=r||this.serviceId,n){e.next=7;break}console.warn("未找到指定service下的notifyId,该设备可能不支持notify"),e.next=9;break;case 7:return e.next=9,this.sdk.blueToothBridge.notifyBLECharacteristicValueChange({deviceId:this._deviceId,characteristicId:n,serviceId:r,state:i});case 9:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"deviceId",get:function(){return this._deviceId}},{key:"isConnected",get:function(){return this._deviceConnected}},{key:"originName",get:function(){return this._name}},{key:"explorerDeviceId",get:function(){return"".concat(this._productId,"/").concat(this._deviceName)}},{key:"serviceId",get:function(){return this.constructor.serviceId}},{key:"_writeId",get:function(){return((this.characteristicsMap[this.serviceId]||{}).writeIds||[])[0]}},{key:"_notifyId",get:function(){return((this.characteristicsMap[this.serviceId]||{}).notifyIds||[])[0]}},{key:"_readId",get:function(){return((this.characteristicsMap[this.serviceId]||{}).readIds||[])[0]}},{key:"_indicateId",get:function(){return((this.characteristicsMap[this.serviceId]||{}).indicateIds||[])[0]}}],[{key:"deviceFilter",value:function(e){throw new Error("具体产品需要自行实现该方法")}}]),t}(N);a()(H,"helper",{hexToArrayBuffer:function(e){return new Uint8Array(e.match(/[\da-f]{2}/gi).map((function(e){return parseInt(e,16)}))).buffer},arrayBufferToHexStringArray:function(e){try{if("[object ArrayBuffer]"!==Object.prototype.toString.call(e))throw"invalid array buffer";for(var t=new DataView(e),n=[],r=0,o=t.byteLength;r0&&void 0!==o[0]?o[0]:{},n=t.devices,r=void 0===n?[]:n,"function"==typeof this._onBluetoothDeviceFoundHandler&&this._onBluetoothDeviceFoundHandler(r);case 2:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"startSearch",value:(r=C()(u.a.mark((function e(t){var n,r,o,i,a,c,s,l,f,d,p,h,v,m=this;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.serviceId,r=t.serviceIds,o=t.ignoreDeviceIds,i=void 0===o?[]:o,a=t.onSearch,c=void 0===a?R:a,s=t.onError,l=void 0===s?R:s,f=t.timeout,d=void 0===f?2e4:f,n&&!r&&(r=[n]),p=0,h=function(e){m.stopSearch(),l(e)},e.prev=4,e.next=7,this.sdk.blueToothBridge.startBluetoothDevicesDiscovery();case 7:this._onBluetoothDeviceFoundHandler=function(e){try{var t=m._filterDevices({devices:e,serviceIds:r,ignoreDeviceIds:i});p=t.length,c(t)}catch(e){console.log("onSearch error",e),h(e)}},v=function(e){e.available||h({code:10001,msg:"发现设备需开启手机蓝牙"})},this.on("adapterStateChange",v),this.addCleanupTask("startSearch",(function(){m._onBluetoothDeviceFoundHandler=null,m.off("adapterStateChange",v)})),setTimeout((function(){p||h("未发现设备,请确认设备已开启")}),d),e.next=18;break;case 14:throw e.prev=14,e.t0=e.catch(4),this.cleanup("startSearch"),e.t0;case 18:case"end":return e.stop()}}),e,this,[[4,14]])}))),function(e){return r.apply(this,arguments)})},{key:"stopSearch",value:function(){this.cleanup("startSearch"),this.sdk.blueToothBridge.stopBluetoothDevicesDiscovery()}},{key:"searchDevice",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.serviceId,r=t.serviceIds,o=t.deviceName,i=t.ignoreDeviceIds,a=void 0===i?[]:i,c=this.sdk.blueToothBridge;return n&&!r&&(r=[n]),o||console.log("searching for deviceName => ",o),this._searchDevicePromise||(this._searchDevicePromise=new Promise(function(){var t=C()(u.a.mark((function t(n,i){var s,l;return u.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return s=function(t){c.stopBluetoothDevicesDiscovery(),i(t),e._searchDevicePromise=null},l=function(t){c.stopBluetoothDevicesDiscovery(),n(t),e._searchDevicePromise=null},e._onBluetoothDeviceFoundHandler=function(t){try{var n=e._filterDevices({devices:t,serviceIds:r,deviceName:o,ignoreDeviceIds:a});console.log("matchedDevices: ",n),n.length>0&&(console.log("doFindDevice",n[0]),l(n[0]))}catch(e){s(e)}},t.prev=3,t.next=6,c.startBluetoothDevicesDiscovery();case 6:console.log("startBluetoothDevicesDiscovery succ"),setTimeout((function(){l()}),5e3),t.next=13;break;case 10:t.prev=10,t.t0=t.catch(3),s(t.t0);case 13:case"end":return t.stop()}}),t,null,[[3,10]])})));return function(e,n){return t.apply(this,arguments)}}()))}},{key:"getDeviceAdapter",value:function(e){return this._deviceMap[e]}},{key:"connectDevice",value:(n=C()(u.a.mark((function e(t){var n,r,o,i,a,c,s,l,f,d,p=this,h=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.deviceId,r=t.serviceId,o=t.deviceName,i=t.productId,a=t.name,c=h.length>1&&void 0!==h[1]?h[1]:{},s=c.autoNotify,l=void 0===s||s,e.prev=2,f=this._deviceAdapterMap[r]){e.next=6;break}throw"无匹配的 deviceAdapter!";case 6:if(!this._deviceMap[n]||!this._deviceMap[n].isConnected){e.next=9;break}return console.log("find device adapter",this._deviceMap[n]),e.abrupt("return",this._deviceMap[n]);case 9:return d=this._deviceMap[n]=new f(this.sdk,{deviceId:n,deviceName:o,productId:i,name:a,autoNotify:l}),e.next=12,d.connectDevice();case 12:return console.log("deviceConnected"),d.on("disconnect",(function(){console.log("ondisconnect, cleanup adapter",d),delete p._deviceMap[n]})),console.log("return adapter"),e.abrupt("return",d);case 18:return e.prev=18,e.t0=e.catch(2),delete this._deviceMap[n],e.abrupt("return",Promise.reject(e.t0));case 22:case"end":return e.stop()}}),e,this,[[2,18]])}))),function(e){return n.apply(this,arguments)})}]),t}(N),G=n(15),q=n.n(G);function $(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Q(e){for(var t=1;t ".concat(t._manuallyClose)),t.disconnect(),t.emit("close",n),t.sdk.insightReportor.info("websocket-close",{data:n}),t._manuallyClose&&(t._manuallyClose=!1);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}())}catch(e){o(e)}case 2:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}())));case 1:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"connect",value:(r=C()(u.a.mark((function e(){return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isConnected()){e.next=3;break}return e.next=3,this.doConnectWs();case 3:return e.next=5,this.activeConnect();case 5:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"disconnect",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.ws&&(this._manuallyClose=e,this.ws.close(),this._connected=!1,this._doConnectWsPromise=null,this.ws=null,clearInterval(this._heartBeatTimer),this._heartBeatTimer=null)}},{key:"send",value:(n=C()(u.a.mark((function e(t){var n,r,o,i,a,c,s,l,f=this,d=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=d.length>1&&void 0!==d[1]?d[1]:{},r=d.length>2&&void 0!==d[2]?d[2]:{},o=r.reqId,i=r.doNotWaitForClientResponse,o||(o=q()()),a=Date.now(),e.next=6,this.sdk.appDevSdk.init();case 6:if(c={AccessToken:this.sdk.appDevSdk.loginManager.accessToken,Type:"h5",Data:n},!this.ws){e.next=23;break}return this.ws.send(JSON.stringify({action:t,params:c,reqId:o})),s={reqBody:Object(T.cutoffLong)(JSON.stringify(c)),action:t,reqId:o},l=function(){return f.requestHandlerMap.delete(o)},e.prev=11,e.next=14,Promise.race([new Promise((function(e,t){f.requestHandlerMap.set(o,(function(n,r){if(s.timeCost=Date.now()-a,n)t(n),l();else if(r.error||r.error_message)t({code:r.error,msg:r.error_message}),l();else if(r.data&&"response"===r.data.action){var o=r.data.payload,c=void 0===o?{}:o,u=c.code,d=c.msg,p=B()(c,["code","msg"]);u?t(Q({code:u,msg:d},p)):(e(c),f.sdk.insightReportor.info("h5-websocket-response",Q({},s,{data:c}))),l()}else i&&(e(r.data),f.sdk.insightReportor.info("h5-websocket-response",Q({},s,{data:r.data})))}))})),new Promise((function(e,t){setTimeout((function(){t({code:"TIMEOUT"})}),2e4)}))]);case 14:return e.abrupt("return",e.sent);case 17:return e.prev=17,e.t0=e.catch(11),this.sdk.insightReportor.error("h5-websocket-error",{error:e.t0}),e.abrupt("return",Promise.reject(e.t0));case 21:e.next=24;break;case 23:console.warn("Try send ws message but no ws instance",t,c);case 24:case"end":return e.stop()}}),e,this,[[11,17]])}))),function(e){return n.apply(this,arguments)})},{key:"activeConnect",value:function(){return this.send("ActiveConnect",{},{doNotWaitForClientResponse:!0})}}]),t}(N),X=function(){function e(t){l()(this,e),this.$offlineTips=document.querySelector("#J_offline_modal"),this.$offlineTipsMask=document.querySelector("#J_offline_mask"),this.$offlineTipsCloseBtn=document.querySelector("#J_offline_close"),this.$offlineTipsFeedBack=document.querySelector("#J_offline_feedback"),this.$offlineTipsBackHome=document.querySelector("#J_offline_backHome"),this.sdk=t,this._bindClickEvents()}return d()(e,[{key:"hide",value:function(){this.$offlineTips.classList.add("hide")}},{key:"show",value:function(){this.$offlineTips.classList.remove("hide")}},{key:"_bindClickEvents",value:function(){var e=this;this.$offlineTipsMask.addEventListener("click",(function(){e.hide()})),this.$offlineTipsCloseBtn.addEventListener("click",(function(){e.hide()})),this.$offlineTipsFeedBack.addEventListener("click",(function(){e.sdk.goFeedBackPage()})),this.$offlineTipsBackHome.addEventListener("click",(function(){e.sdk.navBack()}))}}]),e}(),J=["vendor/regenerator-runtime.js","lib/WAService.js"];function Z(e){var t=e.split(/\r?\n/g);return(t=t.filter((function(e){return!J.some((function(t){return e.indexOf(t)>-1}))}))).join("\n")}function ee(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function te(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:{},r=n.consumeCountPerTime,o=void 0===r?20:r,i=n.minConsumeCount,c=void 0===i?10:i,u=n.consumeInterval,s=void 0===u?5e3:u,f=n.eventFilter,d=void 0===f?R:f;l()(this,e),a()(this,"config",{consumeCountPerTime:20,consumeInterval:5e3,minConsumeCount:10,maxIdleTime:1e4}),a()(this,"eventQueue",[]),a()(this,"eventFilters",R),a()(this,"lastConsumeTime",Date.now()),a()(this,"tid",void 0),this.sdk=t,this.config={consumeCountPerTime:o,minConsumeCount:c,consumeInterval:s,maxIdleTime:2*s},"function"==typeof d&&(this.eventFilter=d)}var t,n,r;return d()(e,[{key:"startReportPolling",value:function(){var e=this;console.log("startReportPolling"),this.tid=setInterval((function(){if(e.eventQueue.length){var t=(new Date).getTime();(e.eventQueue.length>=e.config.minConsumeCount||t-e.lastConsumeTime>e.config.maxIdleTime)&&e.consume()}}),this.config.consumeInterval)}},{key:"stopReportPolling",value:function(){console.log("stopReportPolling"),this.clearQueue(),clearInterval(this.tid)}},{key:"doReport",value:(r=C()(u.a.mark((function e(t){return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Object(T.request)({url:"https://iot.cloud.tencent.com/insight/event",data:t,method:"POST"}));case 1:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})},{key:"report",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.pushEventQueue(e,t)}},{key:"info",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.report(e,te({level:0},t))}},{key:"warn",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.report(e,te({level:1},t))}},{key:"error",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.report(e,te({level:2},t))}},{key:"pushEventQueue",value:function(e,t){try{var n=t||{},r=n.app,o=void 0===r?"iot-weapp":r,i=n.type,a=void 0===i?"iot-weapp-h5":i,c=n.at,u=n.path,s=n.level,l=void 0===s?0:s,f=n.message,d=n.stack,p=n.error,h=B()(n,["app","type","at","path","level","message","stack","error"]);c||(c=Date.now()),u=u||location.pathname;var v=this.sdk,m=v.lid,g=v.born,y=v.quid,b=te({event:e,type:a,app:o,lid:m,born:g,at:c,path:u,level:l,uin:v.uin,quid:y,message:f,stack:d,deviceId:v.deviceId},h);if(p&&("string"==typeof p?b.message=p:(b.message||(b.message=p.message||p.msg||p.errMsg),p instanceof Error&&(b.stack=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Error("captureStack");try{return e&&e.stack?Z(e.stack):""}catch(t){return e?e.stack:""}}(p),b.message=p.message),"code"in p&&(b.code=p.code),p.detail&&(b.data=p.detail))),void 0!==b.code&&(b.code=String(b.code)),this.eventFilters(b))return;this.enqueue(b)}catch(e){console.error("push insight queue fail",e)}}},{key:"consume",value:(n=C()(u.a.mark((function e(){var t;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.lastConsumeTime=Date.now(),e.prev=1,this.eventQueue.length>1e3&&this.eventQueue.splice(0,100),t=this.eventQueue.slice(0,this.config.consumeCountPerTime),this.sdk.debug){e.next=9;break}return e.next=7,this.doReport(t);case 7:e.next=10;break;case 9:console.log("report insight",t);case 10:this.eventQueue.splice(0,this.config.consumeCountPerTime),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(1),console.warn("report insight fail",e.t0);case 16:case"end":return e.stop()}}),e,this,[[1,13]])}))),function(){return n.apply(this,arguments)})},{key:"enqueue",value:function(e,t){if(t)return this.eventQueue.unshift(e),void this.consume();this.eventQueue.push(e)}},{key:"clearQueue",value:(t=C()(u.a.mark((function e(){return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.eventQueue.length){e.next=10;break}return e.prev=1,e.next=4,this.consume();case 4:e.next=8;break;case 6:e.prev=6,e.t0=e.catch(1);case 8:e.next=0;break;case 10:case"end":return e.stop()}}),e,this,[[1,6]])}))),function(){return t.apply(this,arguments)})}]),e}(),re=["border-radius: 50%","width: 10px","height: 10px","background: #f00","position: absolute","right: 17px","top: 50%","margin-top: -5px","visibility: hidden"].join("; "),oe=function(e){return'
'.concat(e,"
")},ie=function(){function e(t){l()(this,e),this.sdk=t}var t,n,r,o;return d()(e,[{key:"renderRedDot",value:function(e){var t=e.deviceId;return this.deviceId=t,'
')}},{key:"getUpgradeInfo",value:(o=C()(u.a.mark((function e(t){var n,r,o,i,a,c,s,l,f;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.deviceId,r=n.split("/"),o=E()(r,2),i=o[0],a=o[1],e.next=4,this.sdk.requestTokenApi("AppCheckFirmwareUpdate",{ProductId:i,DeviceName:a});case 4:return c=e.sent,s=c.CurrentVersion,l=c.DstVersion,f=Boolean(l)&&l!==s,n===this.deviceId&&this.setRedDotVisible(f),e.abrupt("return",{CurrentVersion:s,DstVersion:l,IsUpgradable:f});case 10:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"showCheckUpgradeModal",value:(r=C()(u.a.mark((function e(t){var n,r,o,i,a=this;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.deviceId,o=new Promise((function(e,t){r=t})),this.sdk.tips.showModal({title:"正在检查…",content:"",confirmText:"取消",showCancel:!1}).then((function(e){e&&r()})),e.prev=3,e.next=6,Promise.race([this.getUpgradeInfo({deviceId:n}),o]);case 6:(i=e.sent).IsUpgradable?this.sdk.tips.showModal({title:"可升级固件",content:oe("当前固件版本为".concat(i.CurrentVersion,"
最新固件版本为").concat(i.DstVersion,"
是否升级?")),confirmText:"立即升级",cancelText:"取消"}).then((function(e){e&&a.goFirmwareUpgradePage({deviceId:n})})):this.sdk.tips.showModal({title:"已是最新版本",content:oe(i.CurrentVersion?"当前固件版本为".concat(i.CurrentVersion):""),confirmText:"确定",showCancel:!1}),e.next=15;break;case 10:if(e.prev=10,e.t0=e.catch(3),e.t0){e.next=14;break}return e.abrupt("return");case 14:this.sdk.tips.showModal({title:"检查固件更新失败",content:"",confirmText:"确定",showCancel:!1});case 15:case"end":return e.stop()}}),e,this,[[3,10]])}))),function(e){return r.apply(this,arguments)})},{key:"showUpgradableModal",value:(n=C()(u.a.mark((function e(t){var n,r;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.deviceId,r=t.dstVersion,e.next=3,this.sdk.tips.showModal({title:"发现新固件",content:oe("发现设备有新版本(".concat(r,"),是否升级?")),confirmText:"立即升级",cancelText:"取消"});case 3:e.sent&&this.goFirmwareUpgradePage({deviceId:n});case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"goFirmwareUpgradePage",value:function(e){var t=this,n=e.deviceId;if(n===this.deviceId){var r={WaitForHide:0,WaitForShow:1},o=r.WaitForHide;document.addEventListener("visibilitychange",(function e(){switch(o){case r.WaitForHide:"hidden"===document.visibilityState&&(o=r.WaitForShow);break;case r.WaitForShow:"visible"===document.visibilityState&&(document.removeEventListener("visibilitychange",e),t.refreshRedDot())}}))}return this.sdk.callMpApi("navigateTo",{url:"/pages/Device/DeviceUpgradeFirmware/DeviceUpgradeFirmware?deviceId=".concat(n)})}},{key:"refreshRedDot",value:(t=C()(u.a.mark((function e(){return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.getUpgradeInfo({deviceId:this.deviceId});case 3:e.next=8;break;case 5:e.prev=5,e.t0=e.catch(0),console.error("refreshRedDot fail",e.t0);case 8:case"end":return e.stop()}}),e,this,[[0,5]])}))),function(){return t.apply(this,arguments)})},{key:"setRedDotVisible",value:function(e){var t=document.querySelector(".".concat("explorer-device-detail-firmware-upgrade-dot"));t&&(t.style.visibility=e?"visible":"hidden")}}]),e}();function ae(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function ce(e){for(var t=1;t-1)return console.log("match heatbeat, ignore"),!0}}),e.appDevSdk=new S.a({debug:e.debug,appKey:"",getAccessToken:(n=C()(u.a.mark((function e(){return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",{Token:ue});case 1:case"end":return e.stop()}}),e)}))),function(){return n.apply(this,arguments)}),wsConfig:{},reportor:function(t,n){return e.insightReportor.report(t,n)}}),e.appDevSdk.init().then((function(){e.insightReportor.info("app-dev-sdk-init"),e.appDevSdk.subscribeDevices([ye]),e.h5Websocket.connect(),e.insightReportor.startReportPolling()})).catch((function(t){return e.insightReportor.error("app-dev-sdk-fail",{error:t}),Promise.reject(t)}));var r=(ke.find((function(e){return e.RoomId===ge.RoomId}))||{}).RoomName,o=void 0===r?"":r;return e.roomName=o,e.dataTemplate={},e.productInfo=ve,e.wx=window.wx,e.tips=window.iotexplorerH5PanelTips,e.iotexplorerH5PanelDeviceDetail=window.iotexplorerH5PanelDeviceDetail,e.themeColorMap={primary:"#0052d9",success:"#29cc85",grey:"#bbb",danger:"#ff584c",weak:"#888",muted:"#bbb"},e.offlineTip=new X(y()(e)),e.firmwareUpgrade=new ie(y()(e)),e.h5Websocket=new Y(y()(e)),e.blueToothBridge=new L(y()(e)),e.blueToothAdapter=new z(y()(e)),e.injectEventsHandler(),e.on("appShow",(function(){return e.insightReportor.startReportPolling()})).on("appHide",(function(){return e.insightReportor.stopReportPolling()})),e}var n,r,i,a,c,s,f,p,v,g;return w()(t,e),d()(t,[{key:"callMpApi",value:(g=C()(u.a.mark((function e(t){var n,r,o=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=o.length>1&&void 0!==o[1]?o[1]:{},e.prev=1,e.next=4,this.wxSdkReady();case 4:return e.next=6,new Promise((function(e,r){try{wx.miniProgram[t](ce({},n,{success:function(t){e(t)},fail:function(e){r(e)}}))}catch(e){r(e)}}));case 6:return r=e.sent,this.insightReportor.info("call-mp-api-success",{action:t,reqBody:n,data:r}),e.abrupt("return",r);case 11:e.prev=11,e.t0=e.catch(1),this.insightReportor.info("call-mp-api-fail",{action:t,reqBody:n,error:e.t0});case 14:case"end":return e.stop()}}),e,this,[[1,11]])}))),function(e){return g.apply(this,arguments)})},{key:"showOfflineTip",value:function(){this.offlineTip.show(),this.insightReportor.info("show-offline-tip")}},{key:"hideOfflineTip",value:function(){this.offlineTip.hide(),this.insightReportor.info("hide-offline-tip")}},{key:"enableBlueToothBridge",value:function(){return this.insightReportor.info("enable-bluetooth-bridge"),this.blueToothBridge.init()}},{key:"injectEventsHandler",value:function(){var e=this;Object.keys(T.EventTypes).forEach((function(t){if(t.startsWith("Ws")){var n=T.EventTypes[t],r="_".concat(n,"Handler");e["on".concat(t[0].toUpperCase()).concat(t.slice(1))]=function(t){return e[r]=t,e},e.appDevSdk.on(n,(function(t){try{switch(n){case T.EventTypes.WsReport:var o=t.deviceId,i=t.deviceData,a={};o===e.deviceId&&(Object.keys(i||{}).forEach((function(e){a[e]=i[e].Value})),Object.assign(e.deviceData,a));break;case T.EventTypes.WsStatusChange:var c=t.deviceId,u=t.deviceStatus;c===e.deviceId&&(e.deviceStatus=u)}}catch(e){console.error("handler event err",e)}e.emit(n,t),"function"==typeof e[r]&&e[r](t)}))}})),this.h5Websocket.on("message",(function(t){var n=t.action,r=t.payload;switch(n){case"appShow":e.emit("appShow",r);break;case"appHide":e.emit("appHide",r);break;case"pageShow":e.emit("pageShow",r);break;case"pageHide":e.emit("pageHide",r)}}))}},{key:"ready",value:function(){return this.appDevSdk.init()}},{key:"wxSdkReady",value:function(){var e=this;return this._wxSdkReadyPromise||(this._wxSdkReadyPromise=new Promise((function(t,n){window.wechatJsSdk?wechatJsSdk.init((function(r){if(r)return n(r),void(e._wxSdkReadyPromise=null);e.insightReportor.info("wxjssdk-init"),t(window.wechatJsSdk)})):(n("微信jssdk未注册"),e._wxSdkReadyPromise=null)})).catch((function(t){return e.insightReportor.error("wxjssdk-fail",{error:t}),Promise.reject(t)})))}},{key:"requestTokenApi",value:function(e,t,n){var r=this;return this.appDevSdk.init().then((function(){return r.appDevSdk.requestApi(e,t,n)}))}},{key:"getDeviceDataHistory",value:function(e){var t=e.FieldName,n=e.MaxTime,r=e.MinTime,o=e.Context,i=e.Limit;return this.requestTokenApi("AppGetDeviceDataHistory",{FieldName:t,MaxTime:n,MinTime:r,DeviceId:ye,Context:o,Limit:i})}},{key:"getShareParams",value:(v=C()(u.a.mark((function e(){var t,n,r,o,i,a,c,s=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:{},n=(n=t.deviceId)||this.deviceId,r="SHARE_CONTEXT_KEY",o={},e.prev=4,e.next=7,this.requestTokenApi("AppGetUserDeviceConfig",{DeviceId:n,DeviceKey:r});case 7:i=e.sent,a=i.Configs,o=a,e.next=14;break;case 12:e.prev=12,e.t0=e.catch(4);case 14:if("string"==typeof(c=o[r]))try{c=JSON.parse(c)}catch(e){console.warn("parse device value fail",e)}return e.abrupt("return",c);case 17:case"end":return e.stop()}}),e,this,[[4,12]])}))),function(){return v.apply(this,arguments)})},{key:"setShareConfig",value:function(e){var t=e.title,n=e.imgUrl;return this.insightReportor.info("set-share-config",{title:t,imgUrl:n}),this.wxSdkReady().then((function(e){return e.share({default:{title:t,imgUrl:n}})}))}},{key:"controlDeviceData",value:function(e,t){if(t=t||this.deviceId,"string"!=typeof e)try{e=JSON.stringify(e)}catch(e){}return this.requestTokenApi("AppControlDeviceData",{Data:e,DeviceId:t})}},{key:"goDeviceDetailPage",value:(p=C()(u.a.mark((function e(){var t,n,r,o,i,a,c=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=c.length>0&&void 0!==c[0]?c[0]:{},n=t.reload,r=void 0!==n&&n,o=t.deviceId,i=t.isShareDevice,a=t.shareParams,o=o||this.deviceId,i=i||this.isShareDevice,a&&"string"!=typeof a&&(a=JSON.stringify(a)),e.abrupt("return",this.callMpApi("navigateTo",{url:"/pages/Device/DeviceDetail/DeviceDetail?deviceId=".concat(o,"&isShareDevice=").concat(i,"&reload=").concat(r,"&shareParams=").concat(encodeURIComponent(a))}));case 5:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"navBack",value:function(){return this.callMpApi("navigateBack")}},{key:"goFeedBackPage",value:function(){return this.callMpApi("navigateTo",{url:"/pages/User/Feedback/Feedback"})}},{key:"getUserInfo",value:(f=C()(u.a.mark((function e(){var t,n;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.requestTokenApi("AppGetUser");case 2:return t=e.sent,(n=t.Data)&&n.PhoneNumber&&(n.originPhoneNumber=n.PhoneNumber,n.PhoneNumber=Ne(n.PhoneNumber)),this.userInfo=n,e.abrupt("return",n);case 7:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"getProductInfo",value:(s=C()(u.a.mark((function e(){var t,n,r,o,i=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=i.length>0&&void 0!==i[0]?i[0]:{},n=(n=t.productId)||this.productId,e.next=4,this.requestTokenApi("AppGetProducts",{ProductIds:[n]});case 4:return r=e.sent,o=r.Products,this.productInfo=o[0],e.abrupt("return",this.productInfo);case 8:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"getDeviceInfo",value:(c=C()(u.a.mark((function e(){var t,n,r,o,i,a,c=this,s=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:{},n=(n=t.deviceId)||this.deviceId,r=function(){return Se((function(e){var t=e.offset,n=e.limit;return c.requestTokenApi("AppGetFamilyDeviceList",{FamilyId:c.familyId,RoomId:c.roomId,Offset:t,Limit:n}).then((function(e){return{list:e.DeviceList,total:e.Total}}))}))},o=function(){return Se((function(e){var t=e.offset,n=e.limit;return c.requestTokenApi("AppListUserShareDevices",{Offset:t,Limit:n}).then((function(e){return{list:e.ShareDevices,total:e.Total}}))}))},e.next=6,this.isShareDevice?o():r();case 6:return(i=e.sent).length&&(a=i.find((function(e){return e.DeviceId===n}))),e.abrupt("return",a);case 9:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"getDeviceData",value:(a=C()(u.a.mark((function e(){var t,n,r,o,i=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=i.length>0&&void 0!==i[0]?i[0]:{},n=(n=t.deviceId)||this.deviceId,e.next=4,this.requestTokenApi("AppGetDeviceData",{DeviceId:n});case 4:r=e.sent,o=r.Data;try{o=JSON.parse(o)}catch(e){o={}}return e.abrupt("return",o);case 8:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"getDeviceStatus",value:(i=C()(u.a.mark((function e(){var t,n,r,o,i=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=i.length>0&&void 0!==i[0]?i[0]:{},n=(n=t.deviceId)||this.deviceId,e.next=4,this.requestTokenApi("AppGetDeviceStatuses",{ProductId:De,DeviceIds:[n]});case 4:return r=e.sent,o=r.DeviceStatuses,e.abrupt("return",o[0]?o[0].Online:0);case 7:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"reloadAfterUnmount",value:function(){return this.callMpApi("postMessage",{data:{type:"action",params:{action:"reloadAfterUnmount",payload:{href:location.href}}}})}},{key:"goDeviceInfoPage",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.deviceId;return t=t||this.deviceId,this.callMpApi("navigateTo",{url:"/pages/Device/DeviceDetail/DeviceInfo/DeviceInfo?deviceId=".concat(t)})}},{key:"goEditDeviceNamePage",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.deviceId,n=e.name;return t=t||this.deviceId,n=n||this.deviceInfo.AliasName,this.callMpApi("navigateTo",{url:"/pages/Device/EditDeviceName/EditDeviceName?deviceId=".concat(t,"&name=").concat(encodeURIComponent(n))})}},{key:"goRoomSettingPage",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.deviceId;return t=t||this.deviceId,this.callMpApi("navigateTo",{url:"/pages/Device/DeviceDetail/DeviceChooseRoom/DeviceChooseRoom?deviceId=".concat(t)})}},{key:"goShareDevicePage",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.deviceId,n=e.shareParams;return t=t||this.deviceId,n&&"string"!=typeof n&&(n=JSON.stringify(n)),this.callMpApi("navigateTo",{url:"/pages/Device/DeviceDetail/ShareList/ShareList?deviceId=".concat(t,"¶ms=").concat(encodeURIComponent(n))})}},{key:"deleteDevice",value:(r=C()(u.a.mark((function e(){var t,n,r,o,i,a,c,s,l=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=l.length>0&&void 0!==l[0]?l[0]:{},n=(n=t.deviceId)||this.deviceId,this.isShareDevice?(r="确认移除该分享设备吗?",o="",s="移除",i="AppRemoveUserShareDevice",a={DeviceId:n},c="移除成功"):(r="确认删除设备吗?",o="删除设备后与其相关的任务将会失效。",s="删除",i="AppDeleteDeviceInFamily",a={FamilyId:le,DeviceId:n},c="删除成功"),e.next=5,this.tips.confirm(r,o,{confirmText:s,confirmColor:this.themeColorMap.danger});case 5:if(!e.sent){e.next=21;break}return e.prev=7,e.next=10,this.requestTokenApi(i,a);case 10:return e.next=12,this.reloadAfterUnmount();case 12:return e.next=14,this.tips.showSuccess(c);case 14:return e.next=16,this.navBack();case 16:e.next=21;break;case 18:e.prev=18,e.t0=e.catch(7),this.tips.showError(e.t0);case 21:case"end":return e.stop()}}),e,this,[[7,18]])}))),function(){return r.apply(this,arguments)})},{key:"showDeviceDetail",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.deviceInfo,r=t.labelWidth,i=t.marginTop,a=t.extendItems,c=void 0===a?[]:a,u=t.extendButtons,s=void 0===u?[]:u,l=t.containerClassName,f=t.shareParams;n=n||this.deviceInfo;var d=!this.isShareDevice&&this.isFamilyOwner;this.insightReportor.info("show-device-detail",{data:{extendItems:c,extendButtons:s,shareParams:f}});var p=this.iotexplorerH5PanelDeviceDetail.render({labelWidth:r,marginTop:i,items:[{label:"设备名称",content:n.AliasName,onClick:function(){return e.goEditDeviceNamePage({deviceId:n.DeviceId,name:n.AliasName})}},{label:"设备信息",onClick:function(){return e.goDeviceInfoPage({deviceId:n.DeviceId})}}].concat(o()(d?[{label:"房间设置",content:this.roomName,onClick:function(){return e.goRoomSettingPage({deviceId:n.DeviceId})}},{label:"设备分享",onClick:function(){return e.goShareDevicePage({deviceId:n.DeviceId,shareParams:f})}},{label:"固件升级",content:this.firmwareUpgrade.renderRedDot({deviceId:n.DeviceId}),onClick:function(){return e.firmwareUpgrade.showCheckUpgradeModal({deviceId:n.DeviceId})}}]:[]),o()(c)),buttons:[].concat(o()(this.isShareDevice||d?[{text:_e?"移除分享设备":"删除设备",type:"danger",onClick:function(){return e.deleteDevice({deviceId:n.DeviceId})}}]:[]),o()(s))});this.iotexplorerH5PanelDeviceDetail.$container.innerHTML='\n
\n ').concat(p,"\n
\n "),d&&this.firmwareUpgrade.refreshRedDot({deviceId:n.DeviceId})}},{key:"hideDeviceDetail",value:function(){this.insightReportor.info("hide-device-detail"),this.iotexplorerH5PanelDeviceDetail.$container.innerHTML=""}},{key:"checkFirmwareUpgrade",value:(n=C()(u.a.mark((function e(){var t,n,r,o,i=arguments;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=i.length>0&&void 0!==i[0]?i[0]:{},n=t.deviceId,r=t.silent,n=n||this.deviceId,e.next=4,this.firmwareUpgrade.getUpgradeInfo({deviceId:n});case 4:if(!(o=e.sent).IsUpgradable||r){e.next=10;break}return e.next=8,this.getDeviceStatus({deviceId:this.deviceId});case 8:e.sent&&this.firmwareUpgrade.showUpgradableModal({deviceId:n,dstVersion:o.DstVersion});case 10:return e.abrupt("return",{CurrentVersion:o.CurrentVersion,DstVersion:o.DstVersion});case 11:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"goFirmwareUpgradePage",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.deviceId;return t=t||this.deviceId,this.firmwareUpgrade.goFirmwareUpgradePage({deviceId:t})}},{key:"productInfo",set:function(e){if(e&&e.DataTemplate){var t;try{t=JSON.parse(e.DataTemplate)}catch(e){t={}}this.dataTemplate=t}this._productInfo=e},get:function(){return this._productInfo}}]),t}(N);t.default=new Ae}])},function(e,t,n){var r; /*! Copyright (c) 2017 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames */!function(){"use strict";var n={}.hasOwnProperty;function o(){for(var e=[],t=0;t-1){e.visited=!0;var n=e.cloneNode();n.isLoaded=!1,n.addEventListener("load",(function(){n.isLoaded=!0,e.parentNode.removeChild(e)})),n.addEventListener("error",(function(){n.isLoaded=!0,e.parentNode.removeChild(e)})),n.href="".concat(t,"?").concat(Date.now()),e.nextSibling?e.parentNode.insertBefore(n,e.nextSibling):e.parentNode.appendChild(n)}}function s(e){if(!e)return!1;var t=document.querySelectorAll("link"),n=!1;return a.call(t,(function(t){if(t.href){var o=function(e,t){var n;return e=r(e,{stripWWW:!1}),t.some((function(r){e.indexOf(t)>-1&&(n=r)})),n}(t.href,e);f(o)&&!0!==t.visited&&o&&(u(t,o),n=!0)}})),n}function l(){var e=document.querySelectorAll("link");a.call(e,(function(e){!0!==e.visited&&u(e)}))}function f(e){return!!/^https?:/i.test(e)}e.exports=function(e,t){if(i)return console.log("no window.document found, will not HMR CSS"),c;var n,a,u,f=function(e){var t=o[e];if(!t){if(document.currentScript)t=document.currentScript.src;else{var n=document.getElementsByTagName("script"),i=n[n.length-1];i&&(t=i.src)}o[e]=t}return function(e){if(!t)return null;var n=t.split(/([^\\/]+)\.js$/),o=n&&n[1];return o&&e?e.split(",").map((function(e){var n=new RegExp("".concat(o,"\\.js$"),"g");return r(t.replace(n,"".concat(e.replace(/{fileName}/g,o),".css")))})):[t.replace(".js",".css")]}}(e);return n=function(){var e=f(t.filename),n=s(e);if(t.locals)return console.log("[HMR] Detected local css modules. Reload all css"),void l();n?console.log("[HMR] css reload %s",e.join(" ")):(console.log("[HMR] Reload all css"),l())},a=50,u=0,function(){var e=this,t=arguments,r=function(){return n.apply(e,t)};clearTimeout(u),u=setTimeout(r,a)}}},function(e,t,n){"use strict";function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}n.d(t,"a",(function(){return r}))},function(e,t){function n(e,t,n,r,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void n(e)}c.done?t(u):Promise.resolve(u).then(r,o)}e.exports=function(e){return function(){var t=this,r=arguments;return new Promise((function(o,i){var a=e.apply(t,r);function c(e){n(a,o,i,c,u,"next",e)}function u(e){n(a,o,i,c,u,"throw",e)}c(void 0)}))}}},function(e,t,n){e.exports=n(48)()},function(e,t,n){var r=n(39);e.exports=function(e,t){if(null==e)return{};var n,o,i=r(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(o=0;o=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}},,function(e,t){function n(t){return e.exports=n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},n(t)}e.exports=n},function(e,t,n){"use strict";(function(e){var r=n(0),o=n.n(r),i=n(7),a=n(9),c=n.n(a),u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==e?e:{};function s(e){var t=[];return{on:function(e){t.push(e)},off:function(e){t=t.filter((function(t){return t!==e}))},get:function(){return e},set:function(n,r){e=n,t.forEach((function(t){return t(e,r)}))}}}var l=o.a.createContext||function(e,t){var n,o,a,l="__create-react-context-"+((u[a="__global_unique_id__"]=(u[a]||0)+1)+"__"),f=function(e){function n(){var t;return(t=e.apply(this,arguments)||this).emitter=s(t.props.value),t}Object(i.a)(n,e);var r=n.prototype;return r.getChildContext=function(){var e;return(e={})[l]=this.emitter,e},r.componentWillReceiveProps=function(e){if(this.props.value!==e.value){var n,r=this.props.value,o=e.value;((i=r)===(a=o)?0!==i||1/i==1/a:i!=i&&a!=a)?n=0:(n="function"==typeof t?t(r,o):1073741823,0!==(n|=0)&&this.emitter.set(e.value,n))}var i,a},r.render=function(){return this.props.children},n}(r.Component);f.childContextTypes=((n={})[l]=c.a.object.isRequired,n);var d=function(t){function n(){var e;return(e=t.apply(this,arguments)||this).state={value:e.getValue()},e.onUpdate=function(t,n){0!=((0|e.observedBits)&n)&&e.setState({value:e.getValue()})},e}Object(i.a)(n,t);var r=n.prototype;return r.componentWillReceiveProps=function(e){var t=e.observedBits;this.observedBits=null==t?1073741823:t},r.componentDidMount=function(){this.context[l]&&this.context[l].on(this.onUpdate);var e=this.props.observedBits;this.observedBits=null==e?1073741823:e},r.componentWillUnmount=function(){this.context[l]&&this.context[l].off(this.onUpdate)},r.getValue=function(){return this.context[l]?this.context[l].get():e},r.render=function(){return(e=this.props.children,Array.isArray(e)?e[0]:e)(this.state.value);var e},n}(r.Component);return d.contextTypes=((o={})[l]=c.a.object,o),{Provider:f,Consumer:d}};t.a=l}).call(this,n(16))},function(e,t,n){var r=n(62);e.exports=p,e.exports.parse=i,e.exports.compile=function(e,t){return c(i(e,t),t)},e.exports.tokensToFunction=c,e.exports.tokensToRegExp=d;var o=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function i(e,t){for(var n,r=[],i=0,a=0,c="",l=t&&t.delimiter||"/";null!=(n=o.exec(e));){var f=n[0],d=n[1],p=n.index;if(c+=e.slice(a,p),a=p+f.length,d)c+=d[1];else{var h=e[a],v=n[2],m=n[3],g=n[4],y=n[5],b=n[6],w=n[7];c&&(r.push(c),c="");var _=null!=v&&null!=h&&h!==v,E="+"===b||"*"===b,k="?"===b||"*"===b,C=n[2]||l,T=g||y;r.push({name:m||i++,prefix:v||"",delimiter:C,optional:k,repeat:E,partial:_,asterisk:!!w,pattern:T?s(T):w?".*":"[^"+u(C)+"]+?"})}}return aD.length&&D.push(e)}function A(e,t,n){return null==e?0:function e(t,n,r,o){var c=typeof t;"undefined"!==c&&"boolean"!==c||(t=null);var u=!1;if(null===t)u=!0;else switch(c){case"string":case"number":u=!0;break;case"object":switch(t.$$typeof){case i:case a:u=!0}}if(u)return r(o,t,""===n?"."+R(t,0):n),1;if(u=0,n=""===n?".":n+":",Array.isArray(t))for(var s=0;s