Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

qcloud-iotexplorer-appdev-plugin-wificonf-core

Package Overview
Dependencies
Maintainers
2
Versions
206
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qcloud-iotexplorer-appdev-plugin-wificonf-core - npm Package Compare versions

Comparing version 1.0.13 to 1.0.14

5

lib/utils/UdpServer.d.ts

@@ -14,2 +14,3 @@ export class UdpServer {

_onMessageHandler(resp: any): void;
_cmdTypeHandler(message: any): void;
_onProgressErrorHandler(error: any): void;

@@ -23,5 +24,7 @@ onError(fn: any): UdpServer;

_send(message: any): void;
send(msg: any): Promise<any>;
send(msg: any, { validateResponse }?: {
validateResponse: any;
}): Promise<any>;
aborted: boolean;
abort(): void;
}

2

lib/utils/UdpServer.js

@@ -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):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;
"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(e){var r=new Uint8Array(e),s=String.fromCharCode.apply(null,r);return decodeURIComponent(escape(s))},UdpServer=function(){function e(e){var r=this,s=e.address,t=e.port,o=e.sdk,n=e.retryTime,d=void 0===n?5:n,i=e.retryGap,a=void 0===i?2e3:i,p=e.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(e){return r._onErrorHandler(e)},h=function(e){return r._onMessageHandler(e)};u.onError(l),u.onMessage(h),this.destroy=function(){r.socket.offError(l),r.socket.offMessage(h),r.socket.close()}}return e.prototype._onErrorHandler=function(e){"function"==typeof this._errorHandler?this._errorHandler(e):console.warn("UdpServer unhandled error",e)},e.prototype._onMessageHandler=function(e){try{if(this.messageNoParse){var r=decodeUdpMsg(e.message);return this.sdk&&this.sdk.reporter.info("udp-on-message",{data:{message:r}}),void("function"==typeof this._msgHandler?this._msgHandler(r):console.warn("UdpServer unhandled msg",r))}var s=JSON.parse(decodeUdpMsg(e.message));this.sdk&&this.sdk.reporter.info("udp-on-message",{data:{message:s}}),this._cmdTypeHandler(s)}catch(e){this.sdk&&this.sdk.reporter.info("udp-parse-message-error",{error:e})}},e.prototype._cmdTypeHandler=function(e){var r=this,s=function(e){"function"==typeof r._msgHandler?r._msgHandler(e):console.warn("UdpServer unhandled msg",e)};switch(console.log("------",e),+e.cmdType){case 2:"Current_Error"===e.deviceReply?this._onProgressErrorHandler({code:"BUSINESS_DEVICE_ERROR",detail:e}):"Previous_Error"===e.deviceReply?this.sdk&&this.sdk.reporter.info("softap-receive-prev-error",{data:{message:e}}):s(e);break;case 5:s(e)}},e.prototype._onProgressErrorHandler=function(e){"function"==typeof this._progressErrorHandler?this._progressErrorHandler(e):console.warn("UdpServer unhandled progress error",e)},e.prototype.onError=function(e){return this._errorHandler=e,this},e.prototype.onProgressError=function(e){return this._progressErrorHandler=e,this},e.prototype.onMessage=function(e){return this._msgHandler=e,this},e.prototype._send=function(e){"string"!=typeof e&&(e=JSON.stringify(e)),this.socket.send({address:this.address,port:this.port,message:e})},e.prototype.send=function(e,r){var s=this,t=(void 0===r?{}:r).validateResponse;return this.aborted=!1,new Promise((function(r,o){return tslib_1.__awaiter(s,void 0,void 0,(function(){var s,n,d,i,a=this;return tslib_1.__generator(this,(function(p){switch(p.label){case 0:p.trys.push([0,4,,5]),s=!0,n=0,this.onMessage((function(e){try{s=!1,(!t||"function"==typeof t&&!0===t(e))&&r(e)}catch(e){o(e)}})),(d=function(){n++,a.sdk&&a.sdk.reporter.info("udp-send-msg",{data:{msg:e,retryCount:n}}),a._send(e)})(),p.label=1;case 1:return!this.aborted&&s&&n<=this.retryTime?[4,qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.delay(this.retryGap)]:[3,3];case 2:return p.sent(),this.aborted?[2,o(null)]:s?(d(),[3,1]):[2];case 3:return this.aborted?[2,o(null)]:(o({code:"UDP_NOT_RESPONSE"}),[3,5]);case 4:return i=p.sent(),o(tslib_1.__assign({code:"UDP_SEND_MSG_FAIL"},i)),[3,5];case 5:return[2]}}))}))}))},e.prototype.abort=function(){this.aborted=!0},e}();exports.UdpServer=UdpServer;
//# sourceMappingURL=UdpServer.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(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;
"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,n,r,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,n=e.password,u.label=1;case 1:u.trys.push([1,7,,10]),r=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:n})];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()-r}}),[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()-r},c)}),this.onComplete(c),[3,10];case 7:return p=u.sent(),console.error(p),p&&p.code in constants_1.WifiConfErrorMsg&&(p.uiMsg=constants_1.WifiConfErrorMsg[p.code]),t||!this.options.autoRetry?[3,9]:[4,issueHandler_1.issueHandler({error:p,targetWifiInfo:this.options.targetWifiInfo,wifiConfType:this.options.wifiConfType,onProgress:function(e){_.onProgress.call(_,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:p}}),this.onError({code:"WIFI_CONF_FAIL",detail:{error:p}}),[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,n,r,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(),n=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 n.reject({code:"BUSINESS_DEVICE_ERROR",message:e})})),r=function(){return tslib_1.__awaiter(d,void 0,void 0,(function(){var o,s,n,r,i,d,a,c=this;return tslib_1.__generator(this,(function(p){switch(p.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 p.sent(),s="2.0",n={},console.log("getDeviceExtendInfo",this.options.getDeviceExtendInfo),"function"!=typeof this.options.getDeviceExtendInfo?[3,3]:[4,this.options.getDeviceExtendInfo({udpServer:t})];case 2:n=p.sent(),p.label=3;case 3:return[4,t.send(tslib_1.__assign({cmdType:0,token:this.options.wifiConfToken},n),{validateResponse:function(e){return console.log("cmdType",e.cmdType),2==+e.cmdType}})];case 4:return r=p.sent(),this.onProgress({code:constants_1.WifiConfStepCode.CREATE_UDP_CONNECTION_SUCCESS,detail:{data:r,timeCost:Date.now()-e,protoVersion:s}}),[4,o()];case 5:return p.sent(),i=r.productId,d=r.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 p.sent(),t.destroy(),[2,{productId:i,deviceName:d}]}}))}))},[4,Promise.race([r(),s.promise,n.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.13",
"version": "1.0.14",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc