qcloud-iotexplorer-appdev-plugin-wificonf-smartconfig
Advanced tools
Comparing version 1.0.17 to 1.1.0-alpha.0
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SmartConfig=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),qcloud_iotexplorer_appdev_plugin_wificonf_core_1=require("qcloud-iotexplorer-appdev-plugin-wificonf-core"),esptouchTaskParameter_1=require("../base/esptouchTaskParameter"),EsptouchGenerator_1=require("../protocol/EsptouchGenerator"),UDPSocketClient=qcloud_iotexplorer_appdev_plugin_wificonf_core_1.utils.UDPSocketClient,UDPSocketServer=qcloud_iotexplorer_appdev_plugin_wificonf_core_1.utils.UDPSocketServer,parseInetAddr=qcloud_iotexplorer_appdev_plugin_wificonf_core_1.utils.parseInetAddr,byteUtil=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.byteUtil,SmartConfig=function(e){function t(t,r,s,i,o,a){var n=e.call(this)||this;return n.TAG="SmartConfig",n.ONE_DATA_LEN=3,n.mIsSuc=!1,n.mIsInterrupt=!1,n.mIsExecuted=!1,n.mEncryptor=a,n.mApSsid=t.getData(),n.mApPassword=s.getData(),n.mApBssid=r.getData(),n.mIsCancelled=!1,n.mParameter=esptouchTaskParameter_1.esptouchTaskParameter,n.mSocketClient=new UDPSocketClient(n.mParameter.getPortListening()),n.mSocketServer=new UDPSocketServer(n.mSocketClient.mSocket,n.mParameter.getWaitUdpTotalMillisecond(),n.mParameter.getEsptouchResultTotalLen()),n.mSocketClient.on("udpSocketError",(function(e){var t=e.errMsg;n.emit("onError",{code:"UDP_ERROR",errMsg:t}),n.interrupt()})),n.mEsptouchResultList=[],n.mBssidTaskSucCountMap={},n.mLocalIp=i,n.logger=o,n.logger.info("Welcome Esptouch smartconfig in weapp"),n}return tslib_1.__extends(t,e),t.prototype.__checkTaskValid=function(){return this.mIsExecuted?(this.logger.error({msg:"the Esptouch task could be executed only once"}),!1):(this.mIsExecuted=!0,!0)},t.prototype.start=function(e){return void 0===e&&(e=1),tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:if(!this.__checkTaskValid())return[2];this.mParameter.setExpectTaskResultCount(e),this.logger.info("start smartconfig in promise settimeout"),t=new EsptouchGenerator_1.EsptouchGenerator(this.mApSsid,this.mApBssid,this.mApPassword,this.mLocalIp,this.mEncryptor),this.mSocketServer.startServer(),this.__listenAsyn(this.mParameter.getEsptouchResultTotalLen()),!1,r=0,s.label=1;case 1:return r<this.mParameter.getTotalRepeatTime()?[4,this.__execute(t)]:[3,4];case 2:if(s.sent())return[2,this.__getEsptouchResultList()];s.label=3;case 3:return r++,[3,1];case 4:return this.mIsInterrupt?[3,6]:[4,qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.delay(this.mParameter.getWaitUdpReceivingMillisecond())];case 5:s.sent(),this.mIsSuc||this.emit("onError",{code:"PROTOCOL_TIMEOUT"}),this.interrupt(),s.label=6;case 6:return[2,this.__getEsptouchResultList()]}}))}))},t.prototype.startInNoPromise=function(e){var t=this;if(void 0===e&&(e=1),this.__checkTaskValid()){this.mParameter.setExpectTaskResultCount(e),this.logger.info("start smartconfig in no promise settimeout");var r=new EsptouchGenerator_1.EsptouchGenerator(this.mApSsid,this.mApBssid,this.mApPassword,this.mLocalIp,this.mEncryptor);this.mSocketServer.startServer(),this.__listenAsyn(this.mParameter.getEsptouchResultTotalLen()),this.__executeInNoPromise(r),setTimeout((function(){t.mIsSuc||t.emit("onError",{code:"PROTOCOL_TIMEOUT"}),t.emit("result",t.__getEsptouchResultList()),t.interrupt()}),this.mParameter.getWaitUdpTotalMillisecond())}},t.prototype.__executeInNoPromise=function(e){var t=Date.now(),r=t-this.mParameter.getTimeoutTotalCodeMillisecond(),s=0,i=this,o=e.getGCBytes2(),a=e.getDCBytes2();function n(){if(!i.mIsInterrupt&&Date.now()-t<i.mParameter.getTimeoutGuideCodeMillisecond())return i.mSocketClient.sendDataSideBySide(o,0,o.length,i.mParameter.getTargetHostname(),i.mParameter.getTargetPort(),i.mParameter.getIntervalGuideCodeMillisecond(),n);u()}function u(){i.mIsInterrupt?i.emit("result",i.__getEsptouchResultList()):(t-r>=i.mParameter.getTimeoutDataCodeMillisecond()?(i.logger.info("send gc code "),n(),r=t):(i.mSocketClient.sendDataSideBySide(a,s,i.ONE_DATA_LEN,i.mParameter.getTargetHostname(),i.mParameter.getTargetPort(),i.mParameter.getIntervalDataCodeMillisecond(),u),s=(s+i.ONE_DATA_LEN)%a.length),t=Date.now())}u(),setTimeout((function(){i.interrupt()}),this.mParameter.getWaitUdpSendingMillisecond())},t.prototype.__execute=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,s,i,o,a;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:t=Date.now(),s=(r=t)-this.mParameter.getTimeoutTotalCodeMillisecond(),i=e.getGCBytes2(),o=e.getDCBytes2(),a=0,n.label=1;case 1:if(this.mIsInterrupt)return[3,8];if(!(r-s>=this.mParameter.getTimeoutDataCodeMillisecond()))return[3,5];this.logger.info("send gc code "),n.label=2;case 2:return!this.mIsInterrupt&&Date.now()-r<this.mParameter.getTimeoutGuideCodeMillisecond()?[4,this.mSocketClient.sendData(i,0,i.length,this.mParameter.getTargetHostname(),this.mParameter.getTargetPort(),this.mParameter.getIntervalGuideCodeMillisecond())]:[3,4];case 3:return n.sent(),Date.now()-t>this.mParameter.getWaitUdpSendingMillisecond()?[3,4]:[3,2];case 4:return s=r,[3,7];case 5:return[4,this.mSocketClient.sendData(o,a,this.ONE_DATA_LEN,this.mParameter.getTargetHostname(),this.mParameter.getTargetPort(),this.mParameter.getIntervalDataCodeMillisecond())];case 6:n.sent(),a=(a+this.ONE_DATA_LEN)%o.length,n.label=7;case 7:return(r=Date.now())-t>this.mParameter.getWaitUdpSendingMillisecond()?[3,8]:[3,1];case 8:return[2,this.mIsSuc]}}))}))},t.prototype.__listenAsyn=function(){var e=this;this.logger.info("__listenAsyn() start");var t=this.mApSsid,r=this.mApPassword,s=Date.now(),i=byteUtil.convertUint8toByte(t.length+r.length+9);this.logger.info("expectOneByte: "+i);this.mSocketServer.on("recieveCorrectMsg",(function(t){e.mIsInterrupt||(e.logger.info("RECIEVE_MSG",t),function(t){var r=t.message,o=t.remoteInfo,a=-1,n=new Int8Array(r);if(e.logger.info("Int8Array",{data:n}),a=null!=n?n[0]:-1,e.logger.info("receiveOneByte: "+a),a===i){e.logger.info("receive correct broadcast");var u=Date.now()-s,c=Number(e.mParameter.getWaitUdpTotalMillisecond()-u);if(c<0)e.logger.error({msg:"esptouch receive timeout"});else if(e.logger.info("mSocketServer's new timeout is "+c+" milliseconds"),e.logger.info("receive correct broadcast"),null!=n){var l=byteUtil.parseBssid(n,e.mParameter.getEsptouchResultOneLen(),e.mParameter.getEsptouchResultMacLen()),m=parseInetAddr(n,e.mParameter.getEsptouchResultOneLen()+e.mParameter.getEsptouchResultMacLen(),e.mParameter.getEsptouchResultIpLen());e.__putEsptouchResult(!0,l,m,o)}}else e.logger.info("receive rubbish message, just ignore")}(t),e.mIsSuc=e.mEsptouchResultList.length>=e.mParameter.getExpectTaskResultCount(),e.mIsSuc&&(e.logger.info("__listenAsyn() finish"),e.interrupt()))}))},t.prototype.__putEsptouchResult=function(e,t,r,s){var i=this.mBssidTaskSucCountMap[t];if(null==i&&(i=0),++i,this.logger.info("PUT_ESPTOUCH_RESULT:__putEsptouchResult(): count = "+i),this.mBssidTaskSucCountMap[t]=i,i>=this.mParameter.getThresholdSucBroadcastCount()){for(var o=!1,a=0;a<this.mEsptouchResultList.length;a++)if(this.mEsptouchResultList[a].bssid===t){o=!0;break}if(!o){this.logger.info("PUT_ESPTOUCH_RESULT:put one more result bssid = "+t+",\n address = "+r+",\n the remoteInfo from weapp"+JSON.stringify(s)+"\n ");var n={isSuc:e,bssid:t,inetAddress:r,remoteInfo:s};this.mEsptouchResultList.push(n)}}else this.logger.info("PUT_ESPTOUCH_RESULT:__putEsptouchResult(): count = "+i+", isn't enough")},t.prototype.__getEsptouchResultList=function(){return this.logger.info("GET_RESULT",{data:this.mEsptouchResultList}),this.mEsptouchResultList},t.prototype.interrupt=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return this.mIsInterrupt||(this.mIsCancelled=!0,this.mIsInterrupt=!0,this.mSocketClient.interrupt(),delete this.mSocketClient),[2]}))}))},t.prototype.isCancelled=function(){return this.mIsCancelled},t.prototype.setPackageBroadcast=function(e){this.mParameter.setBroadcast(e)},t}(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.EventEmitter);exports.SmartConfig=SmartConfig; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SmartConfig=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),qcloud_iotexplorer_appdev_plugin_wificonf_core_1=require("qcloud-iotexplorer-appdev-plugin-wificonf-core"),esptouchTaskParameter_1=require("../base/esptouchTaskParameter"),EsptouchGenerator_1=require("../protocol/EsptouchGenerator"),UDPSocketClient=qcloud_iotexplorer_appdev_plugin_wificonf_core_1.utils.UDPSocketClient,UDPSocketServer=qcloud_iotexplorer_appdev_plugin_wificonf_core_1.utils.UDPSocketServer,parseInetAddr=qcloud_iotexplorer_appdev_plugin_wificonf_core_1.utils.parseInetAddr,byteUtil=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.byteUtil,SmartConfig=function(e){function t(t,r,s,i,o,a){var n=e.call(this)||this;return n.TAG="SmartConfig",n.ONE_DATA_LEN=3,n.mIsSuc=!1,n.mIsInterrupt=!1,n.mIsExecuted=!1,n.mEncryptor=a,n.mApSsid=t.getData(),n.mApPassword=s.getData(),n.mApBssid=r.getData(),n.mIsCancelled=!1,n.mParameter=esptouchTaskParameter_1.esptouchTaskParameter,n.mSocketClient=new UDPSocketClient(n.mParameter.getPortListening()),n.mSocketServer=new UDPSocketServer(n.mSocketClient.mSocket,n.mParameter.getWaitUdpTotalMillisecond(),n.mParameter.getEsptouchResultTotalLen()),n.mSocketClient.on("udpSocketError",(function(e){var t=e.errMsg;n.emit("onError",{code:"UDP_ERROR",errMsg:t}),n.interrupt()})),n.mEsptouchResultList=[],n.mBssidTaskSucCountMap={},n.mLocalIp=i,n.logger=o,n.logger.info("Welcome Esptouch smartconfig in weapp"),n}return tslib_1.__extends(t,e),t.prototype.__checkTaskValid=function(){return this.mIsExecuted?(this.logger.error({msg:"the Esptouch task could be executed only once"}),!1):(this.mIsExecuted=!0,!0)},t.prototype.start=function(e){return void 0===e&&(e=1),tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:if(!this.__checkTaskValid())return[2];this.mParameter.setExpectTaskResultCount(e),this.logger.info("start smartconfig in promise settimeout"),t=new EsptouchGenerator_1.EsptouchGenerator(this.mApSsid,this.mApBssid,this.mApPassword,this.mLocalIp,this.mEncryptor),this.mSocketServer.startServer(),this.__listenAsyn(this.mParameter.getEsptouchResultTotalLen()),!1,r=0,s.label=1;case 1:return r<this.mParameter.getTotalRepeatTime()?[4,this.__execute(t)]:[3,4];case 2:if(s.sent())return[2,this.__getEsptouchResultList()];s.label=3;case 3:return r++,[3,1];case 4:return this.mIsInterrupt?[3,6]:[4,qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.delay(this.mParameter.getWaitUdpReceivingMillisecond())];case 5:s.sent(),this.mIsSuc||this.emit("onError",{code:"PROTOCOL_TIMEOUT"}),this.interrupt(),s.label=6;case 6:return[2,this.__getEsptouchResultList()]}}))}))},t.prototype.startInNoPromise=function(e){var t=this;if(void 0===e&&(e=1),this.__checkTaskValid()){this.mParameter.setExpectTaskResultCount(e),this.logger.info("start smartconfig in no promise settimeout");var r=new EsptouchGenerator_1.EsptouchGenerator(this.mApSsid,this.mApBssid,this.mApPassword,this.mLocalIp,this.mEncryptor);this.mSocketServer.startServer(),this.__listenAsyn(this.mParameter.getEsptouchResultTotalLen()),this.__executeInNoPromise(r),setTimeout((function(){t.mIsSuc||t.emit("onError",{code:"PROTOCOL_TIMEOUT"}),t.emit("result",t.__getEsptouchResultList()),t.interrupt()}),this.mParameter.getWaitUdpTotalMillisecond())}},t.prototype.__executeInNoPromise=function(e){var t=this,r=Date.now(),s=r-this.mParameter.getTimeoutTotalCodeMillisecond(),i=0,o=e.getGCBytes2(),a=e.getDCBytes2(),n=function(){if(!t.mIsInterrupt&&Date.now()-r<t.mParameter.getTimeoutGuideCodeMillisecond())return t.mSocketClient.sendDataSideBySide(o,0,o.length,t.mParameter.getTargetHostname(),t.mParameter.getTargetPort(),t.mParameter.getIntervalGuideCodeMillisecond(),n);u()},u=function(){t.mIsInterrupt?t.emit("result",t.__getEsptouchResultList()):(r-s>=t.mParameter.getTimeoutDataCodeMillisecond()?(t.logger.info("send gc code "),n(),s=r):(t.mSocketClient.sendDataSideBySide(a,i,t.ONE_DATA_LEN,t.mParameter.getTargetHostname(),t.mParameter.getTargetPort(),t.mParameter.getIntervalDataCodeMillisecond(),u),i=(i+t.ONE_DATA_LEN)%a.length),r=Date.now())};u(),setTimeout((function(){t.interrupt()}),this.mParameter.getWaitUdpSendingMillisecond())},t.prototype.__execute=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,s,i,o,a;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:t=Date.now(),s=(r=t)-this.mParameter.getTimeoutTotalCodeMillisecond(),i=e.getGCBytes2(),o=e.getDCBytes2(),a=0,n.label=1;case 1:if(this.mIsInterrupt)return[3,8];if(!(r-s>=this.mParameter.getTimeoutDataCodeMillisecond()))return[3,5];this.logger.info("send gc code "),n.label=2;case 2:return!this.mIsInterrupt&&Date.now()-r<this.mParameter.getTimeoutGuideCodeMillisecond()?[4,this.mSocketClient.sendData(i,0,i.length,this.mParameter.getTargetHostname(),this.mParameter.getTargetPort(),this.mParameter.getIntervalGuideCodeMillisecond())]:[3,4];case 3:return n.sent(),Date.now()-t>this.mParameter.getWaitUdpSendingMillisecond()?[3,4]:[3,2];case 4:return s=r,[3,7];case 5:return[4,this.mSocketClient.sendData(o,a,this.ONE_DATA_LEN,this.mParameter.getTargetHostname(),this.mParameter.getTargetPort(),this.mParameter.getIntervalDataCodeMillisecond())];case 6:n.sent(),a=(a+this.ONE_DATA_LEN)%o.length,n.label=7;case 7:return(r=Date.now())-t>this.mParameter.getWaitUdpSendingMillisecond()?[3,8]:[3,1];case 8:return[2,this.mIsSuc]}}))}))},t.prototype.__listenAsyn=function(){var e=this;this.logger.info("__listenAsyn() start");var t=this.mApSsid,r=this.mApPassword,s=Date.now(),i=byteUtil.convertUint8toByte(t.length+r.length+9);this.logger.info("expectOneByte: "+i);this.mSocketServer.on("recieveCorrectMsg",(function(t){e.mIsInterrupt||(e.logger.info("RECIEVE_MSG",t),function(t){var r=t.message,o=t.remoteInfo,a=-1,n=new Int8Array(r);if(e.logger.info("Int8Array",{data:n}),a=null!=n?n[0]:-1,e.logger.info("receiveOneByte: "+a),a===i){e.logger.info("receive correct broadcast");var u=Date.now()-s,c=Number(e.mParameter.getWaitUdpTotalMillisecond()-u);if(c<0)e.logger.error({msg:"esptouch receive timeout"});else if(e.logger.info("mSocketServer's new timeout is "+c+" milliseconds"),e.logger.info("receive correct broadcast"),null!=n){var l=byteUtil.parseBssid(n,e.mParameter.getEsptouchResultOneLen(),e.mParameter.getEsptouchResultMacLen()),m=parseInetAddr(n,e.mParameter.getEsptouchResultOneLen()+e.mParameter.getEsptouchResultMacLen(),e.mParameter.getEsptouchResultIpLen());e.__putEsptouchResult(!0,l,m,o)}}else e.logger.info("receive rubbish message, just ignore")}(t),e.mIsSuc=e.mEsptouchResultList.length>=e.mParameter.getExpectTaskResultCount(),e.mIsSuc&&(e.logger.info("__listenAsyn() finish"),e.interrupt()))}))},t.prototype.__putEsptouchResult=function(e,t,r,s){var i=this.mBssidTaskSucCountMap[t];if(null==i&&(i=0),++i,this.logger.info("PUT_ESPTOUCH_RESULT:__putEsptouchResult(): count = "+i),this.mBssidTaskSucCountMap[t]=i,i>=this.mParameter.getThresholdSucBroadcastCount()){for(var o=!1,a=0;a<this.mEsptouchResultList.length;a++)if(this.mEsptouchResultList[a].bssid===t){o=!0;break}if(!o){this.logger.info("PUT_ESPTOUCH_RESULT:put one more result bssid = "+t+",\n address = "+r+",\n the remoteInfo from weapp"+JSON.stringify(s)+"\n ");var n={isSuc:e,bssid:t,inetAddress:r,remoteInfo:s};this.mEsptouchResultList.push(n)}}else this.logger.info("PUT_ESPTOUCH_RESULT:__putEsptouchResult(): count = "+i+", isn't enough")},t.prototype.__getEsptouchResultList=function(){return this.logger.info("GET_RESULT",{data:this.mEsptouchResultList}),this.mEsptouchResultList},t.prototype.interrupt=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return this.mIsInterrupt||(this.mIsCancelled=!0,this.mIsInterrupt=!0,this.mSocketClient.interrupt(),delete this.mSocketClient),[2]}))}))},t.prototype.isCancelled=function(){return this.mIsCancelled},t.prototype.setPackageBroadcast=function(e){this.mParameter.setBroadcast(e)},t}(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.EventEmitter);exports.SmartConfig=SmartConfig; | ||
//# sourceMappingURL=SmartConfig.js.map |
{ | ||
"name": "qcloud-iotexplorer-appdev-plugin-wificonf-smartconfig", | ||
"version": "1.0.17", | ||
"description": "", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"build": "rm -rf lib && npx tsc -p tsconfig.json -t es5 --outDir lib && node bin/minify.js -t lib", | ||
"typing": "cd @types && tsc" | ||
}, | ||
"miniprogram": "dist/release", | ||
"author": "1138920007@qq.com", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/tencentyun/qcloud-iotexplorer-appdev-sdk/issues" | ||
}, | ||
"dependencies": { | ||
"qcloud-iotexplorer-appdev-plugin-wificonf-core": "^1.0.29", | ||
"qcloud-iotexplorer-appdev-sdk": "^1.0.38" | ||
}, | ||
"devDependencies": { | ||
"commander": "^6.0.0", | ||
"miniprogram-api-typings": "^3.1.2", | ||
"query-string": "^6.9.0", | ||
"terser": "^5.0.0", | ||
"tslib": "^2.0.1", | ||
"typescript": "^3.9.7" | ||
} | ||
"name": "qcloud-iotexplorer-appdev-plugin-wificonf-smartconfig", | ||
"version": "1.1.0-alpha.0", | ||
"description": "", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"build": "rm -rf lib && npx tsc -p tsconfig.json -t es5 --outDir lib && node ../../bin/minify.js -p appdev-plugin-wificonf-smartconfig -t lib", | ||
"typing": "cd @types && tsc" | ||
}, | ||
"miniprogram": "dist/release", | ||
"author": "1138920007@qq.com", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/tencentyun/qcloud-iotexplorer-appdev-sdk/issues" | ||
}, | ||
"dependencies": { | ||
"qcloud-iotexplorer-appdev-plugin-wificonf-core": "^1.1.0-alpha.0", | ||
"qcloud-iotexplorer-appdev-sdk": "^1.1.0-alpha.0", | ||
"tslib": "^2.0.1" | ||
}, | ||
"gitHead": "dcb52a29c53f506732f2b835adc941bd6a4fa220" | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
30362
3
10