qcloud-iotexplorer-appdev-plugin-wificonf-core
Advanced tools
Comparing version 1.0.12 to 1.0.13
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UdpServer=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),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,d=void 0===n?5:n,i=r.retryGap,a=void 0===i?2e3:i,p=r.messageNoParse,c=void 0!==p&&p;Object.assign(this,{address:s,port:t,sdk:o,retryTime:d,retryGap:a,messageNoParse:c});var u=this.socket=wx.createUDPSocket();u.bind();var l=function(r){return e._onErrorHandler(r)},h=function(r){return e._onMessageHandler(r)};u.onError(l),u.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,d,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,s(r)}catch(r){t(r)}})),(n=function(){o++,i.sdk&&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,qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.delay(this.retryGap)]:[3,3];case 2:return a.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 d=a.sent(),t(tslib_1.__assign({code:"UDP_SEND_MSG_FAIL"},d)),[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"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),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,d=void 0===n?5:n,i=r.retryGap,a=void 0===i?2e3:i,p=r.messageNoParse,c=void 0!==p&&p;Object.assign(this,{address:s,port:t,sdk:o,retryTime:d,retryGap:a,messageNoParse:c});var u=this.socket=wx.createUDPSocket();u.bind();var l=function(r){return e._onErrorHandler(r)},h=function(r){return e._onMessageHandler(r)};u.onError(l),u.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):5==+s.cmdType&&("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,d,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,s(r)}catch(r){t(r)}})),(n=function(){o++,i.sdk&&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,qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.delay(this.retryGap)]:[3,3];case 2:return a.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 d=a.sent(),t(tslib_1.__assign({code:"UDP_SEND_MSG_FAIL"},d)),[3,5];case 5:return[2]}}))}))}))},r.prototype.abort=function(){this.aborted=!0},r}();exports.UdpServer=UdpServer; | ||
//# sourceMappingURL=UdpServer.js.map |
@@ -8,3 +8,3 @@ import { AppDevSdk } from 'qcloud-iotexplorer-appdev-sdk'; | ||
export interface WifiConfOption { | ||
wifiConfType: 'SmartConfig' | 'AirKiss' | 'SimpleConfig' | 'SmartConfig' | 'SoftAp' | string; | ||
wifiConfType: 'SmartConfig' | 'AirKiss' | 'SimpleConfig' | 'SoftAp' | string; | ||
targetWifiInfo: WifiInfo; | ||
@@ -19,2 +19,5 @@ onComplete: (deviceInfo: DeviceInfo) => any; | ||
roomId?: string; | ||
getDeviceExtendInfo?: ({ udpServer }: { | ||
udpServer: any; | ||
}) => Promise<{}>; | ||
onProgress?: (event: Response) => any; | ||
@@ -21,0 +24,0 @@ onError?: (error: Response) => any; |
@@ -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]:[4,issueHandler_1.issueHandler({error:_,targetWifiInfo:this.options.targetWifiInfo,wifiConfType:this.options.wifiConfType,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,d=this;return tslib_1.__generator(this,(function(a){switch(a.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(),t=new utils_1.UdpServer({address:e,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(),t.onError((function(o){return s.reject({code:"UDP_ERROR",errMsg:o})})),t.onProgressError((function(o){return r.reject({code:"BUSINESS_DEVICE_ERROR",message:o})})),n=function(){return tslib_1.__awaiter(d,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 i=a.sent(),this.onProgress({code:constants_1.WifiConfStepCode.BUSINESS_SUCCESS,detail:{response:i}}),[2,i]}}))}))},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(e){function o(o,t){var s=e.call(this)||this;return s.connectAborted=!1,s.options={udpPort:8266,stepInterval:1e3,familyId:"default",autoRetry:!1},s.sdk=o,Object.assign(s.options,t),s}return tslib_1.__extends(o,e),o.prototype.onProgress=function(e){"function"==typeof this.options.onProgress&&this.options.onProgress(e)},o.prototype.onComplete=function(e){"function"==typeof this.options.onComplete&&this.options.onComplete(e)},o.prototype.onError=function(e){"function"==typeof this.options.onError&&this.options.onError(e)},o.prototype.start=function(e){var o=(void 0===e?{}:e).doNotRetry,t=void 0!==o&&o;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,o,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}),e=this.options.targetWifiInfo,o=e.SSID,s=e.BSSID,r=e.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:o,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]:[4,issueHandler_1.issueHandler({error:_,targetWifiInfo:this.options.targetWifiInfo,wifiConfType:this.options.wifiConfType,onProgress:function(e){p.onProgress.call(p,e)}})];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]}}))}))},o.prototype.doProtocol=function(e){throw new Error("子类必须自行实现自己协议传输逻辑")},o.prototype.doBusiness=function(e){var o=e.address;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,s,r,n,i,d=this;return tslib_1.__generator(this,(function(a){switch(a.label){case 0:return this.onProgress({code:constants_1.WifiConfStepCode.BUSINESS_START}),this.onProgress({code:constants_1.WifiConfStepCode.CREATE_UDP_CONNECTION_START}),e=Date.now(),t=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(),t.onError((function(e){return s.reject({code:"UDP_ERROR",errMsg:e})})),t.onProgressError((function(e){return r.reject({code:"BUSINESS_DEVICE_ERROR",message:e})})),n=function(){return tslib_1.__awaiter(d,void 0,void 0,(function(){var o,s,r,n,i,d,a,c=this;return tslib_1.__generator(this,(function(_){switch(_.label){case 0:return[4,(o=function(e){return tslib_1.__awaiter(c,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(e||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 _.sent(),s="2.0",r={},console.log("getDeviceExtendInfo",this.options.getDeviceExtendInfo),"function"!=typeof this.options.getDeviceExtendInfo?[3,3]:[4,this.options.getDeviceExtendInfo({udpServer:t})];case 2:r=_.sent(),_.label=3;case 3:return[4,t.send(tslib_1.__assign({cmdType:0,token:this.options.wifiConfToken},r))];case 4:return n=_.sent(),this.onProgress({code:constants_1.WifiConfStepCode.CREATE_UDP_CONNECTION_SUCCESS,detail:{data:n,timeCost:Date.now()-e,protoVersion:s}}),[4,o()];case 5:return _.sent(),i=n.productId,d=n.deviceName,a=this,[4,queryTokenStateAndBind_1.queryTokenStateAndBind({token:this.options.wifiConfToken,productId:i,deviceName:d,familyId:this.options.familyId,roomId:this.options.roomId,onProgress:function(e){a.onProgress.call(a,e)},sdk:this.sdk})];case 6:return _.sent(),t.destroy(),[2,{productId:i,deviceName:d}]}}))}))},[4,Promise.race([n(),s.promise,r.promise])];case 1:return i=a.sent(),this.onProgress({code:constants_1.WifiConfStepCode.BUSINESS_SUCCESS,detail:{response:i}}),[2,i]}}))}))},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.12", | ||
"version": "1.0.13", | ||
"description": "", | ||
@@ -16,3 +16,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"qcloud-iotexplorer-appdev-sdk": "^1.0.17" | ||
"qcloud-iotexplorer-appdev-sdk": "^1.0.20" | ||
}, | ||
@@ -19,0 +19,0 @@ "devDependencies": { |
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
83316
857