qcloud-iotexplorer-appdev-plugin-wificonf-core
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,3 +0,4 @@ | ||
export function collectModuleLog({ reporter, }: { | ||
export function collectModuleLog({ reporter, sdk, }: { | ||
reporter: any; | ||
sdk: any; | ||
}): Promise<boolean>; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.collectModuleLog=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),constants_1=require("../constants"),UdpServer_1=require("./UdpServer"),wxApis_1=tslib_1.__importDefault(require("./wxApis")),MODULE_REPORT_AP_SSID="ESP-LOG-QUERY",MODULE_REPORT_AP_PASSWORD="86013388",MODULE_REPORT_AP_UDP_ADDRESS="192.168.4.1",MODULE_REPORT_AP_UDP_PORT="9876",MODULE_REPORT_AP_TIMEOUT=6e4,MODULE_REPORT_RETRY_TIMES=12,collectModuleLogInternal=function(e){var t=e.reporter;return tslib_1.__awaiter(void 0,void 0,void 0,(function(){var e,r,o,_,s,i,n;return tslib_1.__generator(this,(function(E){switch(E.label){case 0:return E.trys.push([0,,5,7]),[4,wxApis_1.default.getSystemInfo()];case 1:return e=E.sent().platform,r="android"===e,o=Date.now(),t.info(constants_1.WifiConfStepCode.MODULE_REPORT_START),r||wxlib.tips.showLoading("收集日志中"),t.info(constants_1.WifiConfStepCode.MODULE_REPORT_CONNECT_WIFI_START,{urgent:!0}),[4,wxApis_1.default.connectWifi({SSID:MODULE_REPORT_AP_SSID,password:MODULE_REPORT_AP_PASSWORD})];case 2:return E.sent(),[4,wxApis_1.default.getConnectedWifi()];case 3:if(E.sent().wifi.SSID!==MODULE_REPORT_AP_SSID)throw{code:"WIFI_RECONNECT_FAIL"};return r&&qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.tips.showLoading("收集日志中"),t.info(constants_1.WifiConfStepCode.MODULE_REPORT_CONNECT_WIFI_SUCCESS,{timeCost:Date.now()-o,shouldStopTemp:!0}),_=new UdpServer_1.UdpServer({address:MODULE_REPORT_AP_UDP_ADDRESS,port:MODULE_REPORT_AP_UDP_PORT,reporter:t,retryTime:MODULE_REPORT_RETRY_TIMES,retryGap:MODULE_REPORT_AP_TIMEOUT/MODULE_REPORT_RETRY_TIMES,messageNoParse:!0}),s=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.genPromise(),i=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.genPromise(),_.onError((function(e){return s.reject({code:"MODULE_REPORT_COMMUNICATE_AP_ERROR",detail:{errMsg:e}})})),_.onProgressError((function(e){return i.reject({code:"MODULE_REPORT_COMMUNICATE_AP_ERROR",detail:e})})),t.info(constants_1.WifiConfStepCode.MODULE_REPORT_COMMUNICATE_AP_START),[4,_.send({cmdType:3})];case 4:return n=E.sent(),t.info(constants_1.WifiConfStepCode.MODULE_REPORT_COMMUNICATE_AP_SUCCESS,{moudleDetail:n,timeCost:Date.now()-o}),[3,7];case 5:return wxlib.tips.hideLoading(),[4,delay(1e3)];case 6:return E.sent(),t.info(constants_1.WifiConfStepCode.MODULE_REPORT_COMMUNICATE_END,{shouldStopTemp:!1}),[7];case 7:return[2]}}))}))};exports.collectModuleLog=function(e){var t=e.reporter;return tslib_1.__awaiter(void 0,void 0,void 0,(function(){var e,r,o;return tslib_1.__generator(this,(function(_){switch(_.label){case 0:return _.trys.push([0,2,,3]),e=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.genPromise(),setTimeout((function(){e.reject({code:"MODULE_REPORT_TIMEOUT"})}),MODULE_REPORT_AP_TIMEOUT),[4,Promise.race([e.promise,collectModuleLogInternal({reporter:t})])];case 1:return _.sent(),qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.tips.showModal({title:"上报设备端日志成功",content:"收集成功,已上报给工程师处理",confirmText:"我知道了",showCancel:!1}),[2,!0];case 2:return r=_.sent(),(o=r&&(r.errCode||r.code))&&(o in constants_1.WifiConfErrorMsg||o in constants_1.WifiConfErrorMsg)&&(r.uiMsg=constants_1.WifiConfErrorMsg[o]),t.error("MODULE_REPORT_FAIL",{error:r}),qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.tips.showModal({title:"上报设备端日志失败",content:r.uiMsg||constants_1.WifiConfErrorMsg.MODULE_REPORT_ERROR,confirmText:"我知道了",showCancel:!1}),[2,!1];case 3:return[2]}}))}))}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.collectModuleLog=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),constants_1=require("../constants"),UdpServer_1=require("./UdpServer"),wxApis_1=tslib_1.__importDefault(require("./wxApis")),MODULE_REPORT_AP_SSID="ESP-LOG-QUERY",MODULE_REPORT_AP_PASSWORD="86013388",MODULE_REPORT_AP_UDP_ADDRESS="192.168.4.1",MODULE_REPORT_AP_UDP_PORT="9876",MODULE_REPORT_AP_TIMEOUT=6e4,MODULE_REPORT_RETRY_TIMES=12,collectModuleLogInternal=function(e){var r=e.reporter,t=e.sdk;return tslib_1.__awaiter(void 0,void 0,void 0,(function(){var e,o,_,s,i,n,d,p;return tslib_1.__generator(this,(function(E){switch(E.label){case 0:return E.trys.push([0,,9,11]),[4,wxApis_1.default.getSystemInfo()];case 1:return e=E.sent().platform,o="android"===e,_=Date.now(),r.info(constants_1.WifiConfStepCode.MODULE_REPORT_START),o||qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.tips.showLoading("收集日志中"),r.info(constants_1.WifiConfStepCode.MODULE_REPORT_CONNECT_WIFI_START,{urgent:!0}),[4,wxApis_1.default.startWifi()];case 2:return E.sent(),[4,wxApis_1.default.connectWifi({SSID:MODULE_REPORT_AP_SSID,password:MODULE_REPORT_AP_PASSWORD})];case 3:return E.sent(),[4,wxApis_1.default.getConnectedWifi()];case 4:if(E.sent().wifi.SSID!==MODULE_REPORT_AP_SSID)throw{code:"WIFI_RECONNECT_FAIL"};o&&qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.tips.showLoading("收集日志中"),r.info(constants_1.WifiConfStepCode.MODULE_REPORT_CONNECT_WIFI_SUCCESS,{timeCost:Date.now()-_,shouldStopTemp:!0}),E.label=5;case 5:return E.trys.push([5,7,,8]),s=new UdpServer_1.UdpServer({address:MODULE_REPORT_AP_UDP_ADDRESS,port:MODULE_REPORT_AP_UDP_PORT,reporter:r,retryTime:MODULE_REPORT_RETRY_TIMES,retryGap:MODULE_REPORT_AP_TIMEOUT/MODULE_REPORT_RETRY_TIMES,messageNoParse:!0,sdk:t}),i=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.genPromise(),n=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.genPromise(),s.onError((function(e){return i.reject({code:"MODULE_REPORT_COMMUNICATE_AP_ERROR",detail:{errMsg:e}})})),s.onProgressError((function(e){return n.reject({code:"MODULE_REPORT_COMMUNICATE_AP_ERROR",detail:e})})),r.info(constants_1.WifiConfStepCode.MODULE_REPORT_COMMUNICATE_AP_START),[4,s.send({cmdType:3})];case 6:return d=E.sent(),r.info(constants_1.WifiConfStepCode.MODULE_REPORT_COMMUNICATE_AP_SUCCESS,{moudleDetail:d,timeCost:Date.now()-_}),[3,8];case 7:return p=E.sent(),r.error("MODULE_REPORT_COMMUNICATE_AP_ERROR",{error:p}),[3,8];case 8:return[3,11];case 9:return qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.tips.hideLoading(),[4,qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.delay(2e3)];case 10:return E.sent(),r.info(constants_1.WifiConfStepCode.MODULE_REPORT_COMMUNICATE_END,{shouldStopTemp:!1}),[7];case 11:return[2]}}))}))};exports.collectModuleLog=function(e){var r=e.reporter,t=e.sdk;return tslib_1.__awaiter(void 0,void 0,void 0,(function(){var e,o,_;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),e=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.genPromise(),setTimeout((function(){e.reject({code:"MODULE_REPORT_TIMEOUT"})}),MODULE_REPORT_AP_TIMEOUT),[4,Promise.race([e.promise,collectModuleLogInternal({reporter:r,sdk:t})])];case 1:return s.sent(),qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.tips.showModal({title:"上报设备端日志成功",content:"收集成功,已上报给工程师处理",confirmText:"我知道了",showCancel:!1}),[2,!0];case 2:return o=s.sent(),(_=o&&(o.errCode||o.code))&&(_ in constants_1.WifiConfErrorMsg||_ in constants_1.WifiConfErrorMsg)&&(o.uiMsg=constants_1.WifiConfErrorMsg[_]),r.error("MODULE_REPORT_FAIL",{error:o}),qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.tips.showModal({title:"上报设备端日志失败",content:o.uiMsg||constants_1.WifiConfErrorMsg.MODULE_REPORT_ERROR,confirmText:"我知道了",showCancel:!1}),[2,!1];case 3:return[2]}}))}))}; | ||
//# sourceMappingURL=moduleLog.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UdpServer=void 0;var tslib_1=require("tslib"),_utillib_1=require("@utillib"),decodeUdpMsg=function(r){var e=new Uint8Array(r),t=String.fromCharCode.apply(null,e);return decodeURIComponent(escape(t))},UdpServer=function(){function r(r){var e=this,t=r.address,s=r.port,o=r.sdk,n=r.retryTime,i=void 0===n?5:n,a=r.retryGap,d=void 0===a?2e3:a,p=r.messageNoParse,u=void 0!==p&&p;Object.assign(this,{address:t,port:s,sdk:o,retryTime:i,retryGap:d,messageNoParse:u});var c=this.socket=wx.createUDPSocket();c.bind();var l=function(r){return e._onErrorHandler(r)},h=function(r){return e._onMessageHandler(r)};c.onError(l),c.onMessage(h),this.destroy=function(){e.socket.offError(l),e.socket.offMessage(h),e.socket.close()}}return r.prototype._onErrorHandler=function(r){"function"==typeof this._errorHandler?this._errorHandler(r):console.warn("UdpServer unhandled error",r)},r.prototype._onMessageHandler=function(r){try{if(this.messageNoParse){var e=decodeUdpMsg(r.message);return this.sdk.reporter.info("udp-on-message",{data:{message:e}}),void("function"==typeof this._msgHandler?this._msgHandler(e):console.warn("UdpServer unhandled msg",e))}var t=JSON.parse(decodeUdpMsg(r.message));this.sdk.reporter.info("udp-on-message",{data:{message:t}}),2==+t.cmdType&&("Current_Error"===t.deviceReply?this._onProgressErrorHandler({code:"BUSINESS_DEVICE_ERROR",detail:t}):"Previous_Error"===t.deviceReply?this.sdk.reporter.info("softap-receive-prev-error",{data:{message:t}}):"function"==typeof this._msgHandler?this._msgHandler(t):console.warn("UdpServer unhandled msg",t))}catch(r){this.sdk.reporter.info("udp-parse-message-error",{error:r})}},r.prototype._onProgressErrorHandler=function(r){"function"==typeof this._progressErrorHandler?this._progressErrorHandler(r):console.warn("UdpServer unhandled progress error",r)},r.prototype.onError=function(r){return this._errorHandler=r,this},r.prototype.onProgressError=function(r){return this._progressErrorHandler=r,this},r.prototype.onMessage=function(r){return this._msgHandler=r,this},r.prototype._send=function(r){"string"!=typeof r&&(r=JSON.stringify(r)),this.socket.send({address:this.address,port:this.port,message:r})},r.prototype.send=function(r){var e=this;return this.aborted=!1,new Promise((function(t,s){return tslib_1.__awaiter(e,void 0,void 0,(function(){var e,o,n,i=this;return tslib_1.__generator(this,(function(a){switch(a.label){case 0:a.trys.push([0,4,,5]),e=!0,o=0,this.onMessage((function(r){try{e=!1,t(r)}catch(r){s(r)}})),(n=function(){o++,i.sdk.reporter.info("udp-send-msg",{data:{msg:r,retryCount:o}}),i._send(r)})(),a.label=1;case 1:return!this.aborted&&e&&o<=this.retryTime?[4,_utillib_1.delay(this.retryGap)]:[3,3];case 2:return a.sent(),this.aborted?[2,s(null)]:e?(n(),[3,1]):[2];case 3:return this.aborted?[2,s(null)]:(s({code:"UDP_NOT_RESPONSE"}),[3,5]);case 4:return a.sent(),s({code:"UDP_SEND_MSG_FAIL"}),[3,5];case 5:return[2]}}))}))}))},r.prototype.abort=function(){this.aborted=!0},r}();exports.UdpServer=UdpServer; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UdpServer=void 0;var tslib_1=require("tslib"),_utillib_1=require("@utillib"),decodeUdpMsg=function(r){var e=new Uint8Array(r),s=String.fromCharCode.apply(null,e);return decodeURIComponent(escape(s))},UdpServer=function(){function r(r){var e=this,s=r.address,t=r.port,o=r.sdk,n=r.retryTime,i=void 0===n?5:n,a=r.retryGap,d=void 0===a?2e3:a,p=r.messageNoParse,u=void 0!==p&&p;Object.assign(this,{address:s,port:t,sdk:o,retryTime:i,retryGap:d,messageNoParse:u});var c=this.socket=wx.createUDPSocket();c.bind();var l=function(r){return e._onErrorHandler(r)},h=function(r){return e._onMessageHandler(r)};c.onError(l),c.onMessage(h),this.destroy=function(){e.socket.offError(l),e.socket.offMessage(h),e.socket.close()}}return r.prototype._onErrorHandler=function(r){"function"==typeof this._errorHandler?this._errorHandler(r):console.warn("UdpServer unhandled error",r)},r.prototype._onMessageHandler=function(r){try{if(this.messageNoParse){var e=decodeUdpMsg(r.message);return this.sdk&&this.sdk.reporter.info("udp-on-message",{data:{message:e}}),void("function"==typeof this._msgHandler?this._msgHandler(e):console.warn("UdpServer unhandled msg",e))}var s=JSON.parse(decodeUdpMsg(r.message));this.sdk&&this.sdk.reporter.info("udp-on-message",{data:{message:s}}),2==+s.cmdType&&("Current_Error"===s.deviceReply?this._onProgressErrorHandler({code:"BUSINESS_DEVICE_ERROR",detail:s}):"Previous_Error"===s.deviceReply?this.sdk&&this.sdk.reporter.info("softap-receive-prev-error",{data:{message:s}}):"function"==typeof this._msgHandler?this._msgHandler(s):console.warn("UdpServer unhandled msg",s))}catch(r){this.sdk&&this.sdk.reporter.info("udp-parse-message-error",{error:r})}},r.prototype._onProgressErrorHandler=function(r){"function"==typeof this._progressErrorHandler?this._progressErrorHandler(r):console.warn("UdpServer unhandled progress error",r)},r.prototype.onError=function(r){return this._errorHandler=r,this},r.prototype.onProgressError=function(r){return this._progressErrorHandler=r,this},r.prototype.onMessage=function(r){return this._msgHandler=r,this},r.prototype._send=function(r){"string"!=typeof r&&(r=JSON.stringify(r)),this.socket.send({address:this.address,port:this.port,message:r})},r.prototype.send=function(r){var e=this;return this.aborted=!1,new Promise((function(s,t){return tslib_1.__awaiter(e,void 0,void 0,(function(){var e,o,n,i,a=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:d.trys.push([0,4,,5]),e=!0,o=0,this.onMessage((function(r){try{e=!1,s(r)}catch(r){t(r)}})),(n=function(){o++,a.sdk&&a.sdk.reporter.info("udp-send-msg",{data:{msg:r,retryCount:o}}),a._send(r)})(),d.label=1;case 1:return!this.aborted&&e&&o<=this.retryTime?[4,_utillib_1.delay(this.retryGap)]:[3,3];case 2:return d.sent(),this.aborted?[2,t(null)]:e?(n(),[3,1]):[2];case 3:return this.aborted?[2,t(null)]:(t({code:"UDP_NOT_RESPONSE"}),[3,5]);case 4:return i=d.sent(),t(tslib_1.__assign({code:"UDP_SEND_MSG_FAIL"},i)),[3,5];case 5:return[2]}}))}))}))},r.prototype.abort=function(){this.aborted=!0},r}();exports.UdpServer=UdpServer; | ||
//# sourceMappingURL=UdpServer.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.issueHandler=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),constants_1=require("../constants"),wxApis_1=tslib_1.__importDefault(require("../utils/wxApis")),utils_1=require("qcloud-iotexplorer-appdev-sdk/lib/utils"),UDP_ERROR_WAIT_RETRY_TIME=1500,WIFI_CONNECT_WAIT_RETRY_TIME=4e3,handleWifiIssue=function(e){var t=e.code,r=e.targetWifiInfo,s=e.onProgress;return tslib_1.__awaiter(void 0,void 0,void 0,(function(){var e,i,o;return tslib_1.__generator(this,(function(_){switch(_.label){case 0:s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_START,detail:{targetWifiInfo:r}}),_.label=1;case 1:return _.trys.push([1,6,,7]),[4,wxApis_1.default.getConnectedWifi()];case 2:return(e=_.sent().wifi)&&e.SSID===r.SSID?"UDP_ERROR"!==t&&"UDP_SEND_MSG_FAIL"!==t?[3,4]:[4,utils_1.delay(UDP_ERROR_WAIT_RETRY_TIME)]:[3,5];case 3:return _.sent(),s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_SUCCESS,detail:{msg:"UDP错误,或许是连接wifi的延迟,直接重试下"}}),[2,!0];case 4:return s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_CANCEL,detail:{msg:"当前连接的wifi正确,不需要处理"}}),[2,!1];case 5:return[3,7];case 6:return i=_.sent(),console.error(i),qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.logger.debug("getConnectedWifi failed",i),12010!==i.errCode?(s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_CANCEL,detail:{msg:"获取当前连接的wifi出错"}}),[2,!1]):[3,7];case 7:return _.trys.push([7,11,,13]),[4,wxApis_1.default.startWifi()];case 8:return _.sent(),[4,wxApis_1.default.connectWifi({SSID:r.SSID,password:r.password})];case 9:return _.sent(),[4,utils_1.delay(WIFI_CONNECT_WAIT_RETRY_TIME)];case 10:return _.sent(),s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_SUCCESS,detail:{handled:!0}}),[2,!0];case 11:return o=_.sent(),console.error(o),qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.logger.debug("connectWifi fail",o),[4,qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.tips.showModal({title:"手机连接"+r.SSID+"失败,请在设置页面手动切换到"+r.SSID+"再继续",confirmText:"继续",confirmColor:qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.themeColorMap.primary,cancelText:"取消",cancelColor:qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.themeColorMap.danger})];case 12:return _.sent()?(s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_SUCCESS,detail:{msg:"自动连接的wifi错误,用户设置自动连接"}}),[2,!0]):(s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_CANCEL,detail:{msg:"自动连接的wifi错误,用户取消自动连接"}}),[2,!1]);case 13:return[2]}}))}))};exports.issueHandler=function(e){var t=e.error,r=e.targetWifiInfo,s=e.onProgress;return tslib_1.__awaiter(void 0,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:switch(e=!1,t.code){case"PROTOCOL_TIMEOUT":case"CONNECT_SMARTCONFIG_FAIL":case"UDP_ERROR":case"UDP_SEND_MSG_FAIL":return[3,1]}return[3,3];case 1:return[4,handleWifiIssue({code:t.code,targetWifiInfo:r,onProgress:s})];case 2:return e=i.sent(),[3,4];case 3:return[3,4];case 4:return[2,e]}}))}))}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.issueHandler=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),constants_1=require("../constants"),wxApis_1=tslib_1.__importDefault(require("../utils/wxApis")),utils_1=require("qcloud-iotexplorer-appdev-sdk/lib/utils"),UDP_ERROR_WAIT_RETRY_TIME=1500,WIFI_CONNECT_WAIT_RETRY_TIME=4e3,handleWifiIssue=function(e){var t=e.code,r=e.targetWifiInfo,s=e.onProgress;return tslib_1.__awaiter(void 0,void 0,void 0,(function(){var e,i,o;return tslib_1.__generator(this,(function(_){switch(_.label){case 0:s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_START,detail:{targetWifiInfo:r}}),_.label=1;case 1:return _.trys.push([1,6,,7]),[4,wxApis_1.default.getConnectedWifi()];case 2:return(e=_.sent().wifi)&&e.SSID===r.SSID?"UDP_ERROR"!==t&&"UDP_SEND_MSG_FAIL"!==t?[3,4]:[4,utils_1.delay(UDP_ERROR_WAIT_RETRY_TIME)]:[3,5];case 3:return _.sent(),s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_SUCCESS,detail:{msg:"UDP错误,或许是连接wifi的延迟,直接重试下"}}),[2,!0];case 4:return s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_CANCEL,detail:{msg:"当前连接的wifi正确,不需要处理"}}),[2,!1];case 5:return[3,7];case 6:return i=_.sent(),console.error("getConnectedWifi failed",i),i.errCode&&12010!==i.errCode?(s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_CANCEL,detail:tslib_1.__assign({msg:"获取当前连接的wifi出错"},i)}),[2,!1]):[3,7];case 7:return _.trys.push([7,11,,13]),[4,wxApis_1.default.startWifi()];case 8:return _.sent(),[4,wxApis_1.default.connectWifi({SSID:r.SSID,password:r.password})];case 9:return _.sent(),[4,utils_1.delay(WIFI_CONNECT_WAIT_RETRY_TIME)];case 10:return _.sent(),s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_SUCCESS,detail:{handled:!0}}),[2,!0];case 11:return o=_.sent(),console.error(o),qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.logger.debug("connectWifi fail",o),[4,qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.tips.showModal({title:"手机连接"+r.SSID+"失败,请在设置页面手动切换到"+r.SSID+"再继续",confirmText:"继续",confirmColor:qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.themeColorMap.primary,cancelText:"取消",cancelColor:qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.themeColorMap.danger})];case 12:return _.sent()?(s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_SUCCESS,detail:{msg:"自动连接的wifi错误,用户设置自动连接"}}),[2,!0]):(s({code:constants_1.WifiConfStepCode.AUTO_HANDLE_WIFI_PROBLEM_CANCEL,detail:{msg:"自动连接的wifi错误,用户取消自动连接"}}),[2,!1]);case 13:return[2]}}))}))};exports.issueHandler=function(e){var t=e.error,r=e.targetWifiInfo,s=e.onProgress;return tslib_1.__awaiter(void 0,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:switch(e=!1,t.code){case"PROTOCOL_TIMEOUT":case"CONNECT_SMARTCONFIG_FAIL":case"UDP_ERROR":case"UDP_SEND_MSG_FAIL":return[3,1]}return[3,3];case 1:return[4,handleWifiIssue({code:t.code,targetWifiInfo:r,onProgress:s})];case 2:return e=i.sent(),[3,4];case 3:return[3,4];case 4:return[2,e]}}))}))}; | ||
//# sourceMappingURL=issueHandler.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WifiConfProtocolBase=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),queryTokenStateAndBind_1=require("./queryTokenStateAndBind"),constants_1=require("../constants"),utils_1=require("../utils"),issueHandler_1=require("./issueHandler"),WifiConfProtocolBase=function(o){function e(e,t){var s=o.call(this)||this;return s.connectAborted=!1,s.options={udpPort:8266,stepInterval:1e3,familyId:"default",autoRetry:!1},s.sdk=e,Object.assign(s.options,t),s}return tslib_1.__extends(e,o),e.prototype.onProgress=function(o){"function"==typeof this.options.onProgress&&this.options.onProgress(o)},e.prototype.onComplete=function(o){"function"==typeof this.options.onComplete&&this.options.onComplete(o)},e.prototype.onError=function(o){"function"==typeof this.options.onError&&this.options.onError(o)},e.prototype.start=function(o){var e=(void 0===o?{}:o).doNotRetry,t=void 0!==e&&e;return tslib_1.__awaiter(this,void 0,void 0,(function(){var o,e,s,r,n,i,d,a,c,_,p=this;return tslib_1.__generator(this,(function(u){switch(u.label){case 0:this.onProgress({code:constants_1.WifiConfStepCode.WIFI_CONF_START}),this.onProgress({code:constants_1.WifiConfStepCode.PROTOCOL_START}),o=this.options.targetWifiInfo,e=o.SSID,s=o.BSSID,r=o.password,u.label=1;case 1:u.trys.push([1,7,,10]),n=Date.now(),i=void 0,u.label=2;case 2:return u.trys.push([2,4,,5]),[4,this.doProtocol({SSID:e,BSSID:s,password:r})];case 3:return d=u.sent(),i=d?d.address:null,[3,5];case 4:throw a=u.sent(),console.error(a),tslib_1.__assign({code:"PROTOCOL_FAIL"},a);case 5:if(!i)throw{code:"PROTOCOL_INVALID_RESPONSE"};return this.onProgress({code:constants_1.WifiConfStepCode.PROTOCOL_SUCCESS,detail:{data:{address:i},timeCost:Date.now()-n}}),[4,this.doBusiness({address:i})];case 6:return c=u.sent(),this.onProgress({code:constants_1.WifiConfStepCode.WIFI_CONF_SUCCESS,detail:tslib_1.__assign({timeCost:Date.now()-n},c)}),this.onComplete(c),[3,10];case 7:return _=u.sent(),console.error(_),_&&_.code in constants_1.WifiConfErrorMsg&&(_.uiMsg=constants_1.WifiConfErrorMsg[_.code]),t||!this.options.autoRetry?[3,9]:(this.options.targetWifiInfo={SSID:"L-0558",password:"video123."},[4,issueHandler_1.issueHandler({error:_,targetWifiInfo:this.options.targetWifiInfo,onProgress:function(o){p.onProgress.call(p,o)}})]);case 8:if(u.sent())return this.onProgress({code:constants_1.WifiConfStepCode.WIFI_CONF_AUTO_RETRY}),[2,this.start({doNotRetry:!0})];u.label=9;case 9:return this.connectAborted=!0,this.onProgress({code:constants_1.WifiConfStepCode.WIFI_CONF_FAIL,detail:{error:_}}),this.onError({code:"WIFI_CONF_FAIL",detail:{error:_}}),[3,10];case 10:return[2]}}))}))},e.prototype.doProtocol=function(o){throw new Error("子类必须自行实现自己协议传输逻辑")},e.prototype.doBusiness=function(o){var e=o.address;return tslib_1.__awaiter(this,void 0,void 0,(function(){var o,t,s,r,n,i=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:return this.onProgress({code:constants_1.WifiConfStepCode.BUSINESS_START}),this.onProgress({code:constants_1.WifiConfStepCode.CREATE_UDP_CONNECTION_START}),o=Date.now(),console.log("----new UdpServer---",this.options.udpPort),t=new utils_1.UdpServer({address:e,port:this.options.udpPort,sdk:this.sdk}),console.log("----new UdpServer success---"),s=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.genPromise(),r=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.genPromise(),t.onError((function(o){return s.reject({code:"UDP_ERROR",detail:{errMsg:o}})})),t.onProgressError((function(o){return r.reject({code:"BUSINESS_DEVICE_ERROR",detail:o})})),n=function(){return tslib_1.__awaiter(i,void 0,void 0,(function(){var e,s,r,n,i,d,a=this;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return[4,(e=function(o){return tslib_1.__awaiter(a,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return[4,qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.delay(o||this.options.stepInterval)];case 1:return e.sent(),this.connectAborted&&qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.logger.debug("connection aborted"),[2]}}))}))})()];case 1:return c.sent(),s="2.0",[4,t.send({cmdType:0,token:this.options.wifiConfToken})];case 2:return r=c.sent(),this.onProgress({code:constants_1.WifiConfStepCode.CREATE_UDP_CONNECTION_SUCCESS,detail:{data:r,timeCost:Date.now()-o,protoVersion:s}}),[4,e()];case 3:return c.sent(),n=r.productId,i=r.deviceName,d=this,[4,queryTokenStateAndBind_1.queryTokenStateAndBind({token:this.options.wifiConfToken,productId:n,deviceName:i,familyId:this.options.familyId,roomId:this.options.roomId,onProgress:function(o){d.onProgress.call(d,o)},sdk:this.sdk})];case 4:return c.sent(),t.destroy(),[2,{productId:n,deviceName:i}]}}))}))},[4,Promise.race([n(),s.promise,r.promise])];case 1:return[2,d.sent()]}}))}))},e}(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.EventEmitter);exports.WifiConfProtocolBase=WifiConfProtocolBase; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WifiConfProtocolBase=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),queryTokenStateAndBind_1=require("./queryTokenStateAndBind"),constants_1=require("../constants"),utils_1=require("../utils"),issueHandler_1=require("./issueHandler"),WifiConfProtocolBase=function(t){function o(o,e){var s=t.call(this)||this;return s.connectAborted=!1,s.options={udpPort:8266,stepInterval:1e3,familyId:"default",autoRetry:!1},s.sdk=o,Object.assign(s.options,e),s}return tslib_1.__extends(o,t),o.prototype.onProgress=function(t){"function"==typeof this.options.onProgress&&this.options.onProgress(t)},o.prototype.onComplete=function(t){"function"==typeof this.options.onComplete&&this.options.onComplete(t)},o.prototype.onError=function(t){"function"==typeof this.options.onError&&this.options.onError(t)},o.prototype.start=function(t){var o=(void 0===t?{}:t).doNotRetry,e=void 0!==o&&o;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,o,s,r,n,i,d,a,c,_,u=this;return tslib_1.__generator(this,(function(p){switch(p.label){case 0:this.onProgress({code:constants_1.WifiConfStepCode.WIFI_CONF_START}),this.onProgress({code:constants_1.WifiConfStepCode.PROTOCOL_START}),t=this.options.targetWifiInfo,o=t.SSID,s=t.BSSID,r=t.password,p.label=1;case 1:p.trys.push([1,7,,10]),n=Date.now(),i=void 0,p.label=2;case 2:return p.trys.push([2,4,,5]),[4,this.doProtocol({SSID:o,BSSID:s,password:r})];case 3:return d=p.sent(),i=d?d.address:null,[3,5];case 4:throw a=p.sent(),console.error(a),tslib_1.__assign({code:"PROTOCOL_FAIL"},a);case 5:if(!i)throw{code:"PROTOCOL_INVALID_RESPONSE"};return this.onProgress({code:constants_1.WifiConfStepCode.PROTOCOL_SUCCESS,detail:{data:{address:i},timeCost:Date.now()-n}}),[4,this.doBusiness({address:i})];case 6:return c=p.sent(),this.onProgress({code:constants_1.WifiConfStepCode.WIFI_CONF_SUCCESS,detail:tslib_1.__assign({timeCost:Date.now()-n},c)}),this.onComplete(c),[3,10];case 7:return(_=p.sent())&&_.code in constants_1.WifiConfErrorMsg&&(_.uiMsg=constants_1.WifiConfErrorMsg[_.code]),e||!this.options.autoRetry?[3,9]:[4,issueHandler_1.issueHandler({error:_,targetWifiInfo:this.options.targetWifiInfo,onProgress:function(t){u.onProgress.call(u,t)}})];case 8:if(p.sent())return this.onProgress({code:constants_1.WifiConfStepCode.WIFI_CONF_AUTO_RETRY}),[2,this.start({doNotRetry:!0})];p.label=9;case 9:return this.connectAborted=!0,this.onProgress({code:constants_1.WifiConfStepCode.WIFI_CONF_FAIL,detail:{error:_}}),this.onError({code:"WIFI_CONF_FAIL",detail:{error:_}}),[3,10];case 10:return[2]}}))}))},o.prototype.doProtocol=function(t){throw new Error("子类必须自行实现自己协议传输逻辑")},o.prototype.doBusiness=function(t){var o=t.address;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,e,s,r,n,i=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:return this.onProgress({code:constants_1.WifiConfStepCode.BUSINESS_START}),this.onProgress({code:constants_1.WifiConfStepCode.CREATE_UDP_CONNECTION_START}),t=Date.now(),e=new utils_1.UdpServer({address:o,port:this.options.udpPort,sdk:this.sdk}),s=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.genPromise(),r=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.genPromise(),e.onError((function(t){return s.reject({code:"UDP_ERROR",detail:{errMsg:t}})})),e.onProgressError((function(t){return r.reject({code:"BUSINESS_DEVICE_ERROR",detail:t})})),n=function(){return tslib_1.__awaiter(i,void 0,void 0,(function(){var o,s,r,n,i,d,a=this;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return[4,(o=function(t){return tslib_1.__awaiter(a,void 0,void 0,(function(){return tslib_1.__generator(this,(function(o){switch(o.label){case 0:return[4,qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.delay(t||this.options.stepInterval)];case 1:return o.sent(),this.connectAborted&&qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.logger.debug("connection aborted"),[2]}}))}))})()];case 1:return c.sent(),s="2.0",[4,e.send({cmdType:0,token:this.options.wifiConfToken})];case 2:return r=c.sent(),this.onProgress({code:constants_1.WifiConfStepCode.CREATE_UDP_CONNECTION_SUCCESS,detail:{data:r,timeCost:Date.now()-t,protoVersion:s}}),[4,o()];case 3:return c.sent(),n=r.productId,i=r.deviceName,d=this,[4,queryTokenStateAndBind_1.queryTokenStateAndBind({token:this.options.wifiConfToken,productId:n,deviceName:i,familyId:this.options.familyId,roomId:this.options.roomId,onProgress:function(t){d.onProgress.call(d,t)},sdk:this.sdk})];case 4:return c.sent(),e.destroy(),[2,{productId:n,deviceName:i}]}}))}))},[4,Promise.race([n(),s.promise,r.promise])];case 1:return[2,d.sent()]}}))}))},o}(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.EventEmitter);exports.WifiConfProtocolBase=WifiConfProtocolBase; | ||
//# sourceMappingURL=WifiConfProtocolBase.js.map |
{ | ||
"name": "qcloud-iotexplorer-appdev-plugin-wificonf-core", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76884
806