Socket
Socket
Sign inDemoInstall

qcloud-iotexplorer-appdev-sdk

Package Overview
Dependencies
Maintainers
5
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qcloud-iotexplorer-appdev-sdk - npm Package Compare versions

Comparing version 2.3.11 to 2.3.12

2

lib/modules/IotWebsocket.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IotWebsocket=void 0;var tslib_1=require("tslib"),event_emitter_for_miniprogram_1=tslib_1.__importDefault(require("event-emitter-for-miniprogram")),shortid_for_miniprogram_1=tslib_1.__importDefault(require("shortid-for-miniprogram")),utils_1=require("../utils"),logger_1=require("./logger"),defaultOptions={url:"wss://iot.cloud.tencent.com/ws/explorer",heartbeatInterval:5e4},IotWebsocket=function(e){function t(t,r){var s=e.call(this)||this;return s.sdk=t,s.requestHandlerMap=new Map,s.options=Object.assign({},defaultOptions,r),s._connected=!1,s._subscribeDeviceIdList=[],s._heartBeatTimer=null,s}return tslib_1.__extends(t,e),t.prototype.isConnected=function(){return!!this._connected},t.prototype.doConnectWs=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e=this;return tslib_1.__generator(this,(function(t){return[2,this._doConnectWsPromise||(this._doConnectWsPromise=new Promise((function(t,r){return tslib_1.__awaiter(e,void 0,void 0,(function(){var e,s,i,n=this;return tslib_1.__generator(this,(function(o){e=shortid_for_miniprogram_1.default(),logger_1.wsLogger.updateGetReportData((function(){return{event:logger_1.WS_EVENT_PREFIX,context:{flowId:e}}})),s=function(e){r(e),logger_1.wsLogger.error("connection","error",{error:e}),n.disconnect(),n.emit("error",e)};try{logger_1.wsLogger.info("connection","start"),i=this.options.url,this.ws=new utils_1.WebSocket(utils_1.appendParams(i,{uin:this.sdk._debug?this.sdk._defaultUin:this.sdk.loginManager.userId,cId:e})),this.ws.onOpen((function(){n._connected=!0,n.emit("connect"),t(),logger_1.wsLogger.info("connection","connected")})),this.ws.onError(s),this.ws.onMessage((function(e){var t=e.data;n.emit("message",t);try{t=JSON.parse(t)}catch(e){return void logger_1.wsLogger.error("message","parseFail",{data:t})}t.push?(n.emit("push",t),logger_1.wsLogger.info("message","pushData",{data:t})):void 0!==t.reqId&&n.requestHandlerMap.has(t.reqId)?n.requestHandlerMap.get(t.reqId)(null,t):logger_1.wsLogger.info("message","otherData",{data:t})})),this.ws.onClose((function(e){return tslib_1.__awaiter(n,void 0,void 0,(function(){return tslib_1.__generator(this,(function(t){return logger_1.wsLogger.info("connection","close",{data:e}),this.disconnect(),this.emit("close",e),[2]}))}))}))}catch(e){s(e)}return[2]}))}))})))]}))}))},t.prototype.connect=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(t){switch(t.label){case 0:return e&&(this._subscribeDeviceIdList=e),[4,this.sdk.loginManager.checkLogin()];case 1:return t.sent(),this.isConnected()||!this._subscribeDeviceIdList.length?[3,3]:[4,this.doConnectWs()];case 2:t.sent(),t.label=3;case 3:return[2,this.activePush()]}}))}))},t.prototype.disconnect=function(){this.ws&&(logger_1.wsLogger.info("connection","disconnect"),this.ws.close(),this._connected=!1,this._doConnectWsPromise=null,this.ws=null,clearInterval(this._heartBeatTimer),this._heartBeatTimer=null)},t.prototype.send=function(e,t,r){void 0===t&&(t={});var s=(void 0===r?{}:r).reqId;return tslib_1.__awaiter(this,void 0,void 0,(function(){var r,i,n,o,a,c=this;return tslib_1.__generator(this,(function(u){switch(u.label){case 0:if(s||(s=shortid_for_miniprogram_1.default()),r="send."+e,logger_1.wsLogger.info(r,{message:"send start",data:{reqBody:utils_1.cutoffLong(JSON.stringify(t))},metric:{type:"start",spanId:s}}),!this.ws)return[3,6];i=Date.now(),this.ws.send({data:JSON.stringify({action:e,reqId:s,params:t})}),n={reqBody:utils_1.cutoffLong(JSON.stringify(t)),action:e,reqId:s,timeCost:null},o="success",u.label=1;case 1:return u.trys.push([1,3,4,5]),[4,Promise.race([new Promise((function(e,t){c.requestHandlerMap.set(s,(function(a,c){if(n.timeCost=Date.now()-i,!a)return c.data||!c.error&&!c.error_message?(logger_1.wsLogger.info(r,{message:"send "+o,metric:{type:o,spanId:s,timeCost:Date.now()-i},data:{resBody:utils_1.cutoffLong(JSON.stringify(c.data))}}),e(c.data)):(t({code:c.error,msg:c.error_message}),void(o="fail"));t(a),o="fail"}))})),new Promise((function(e,t){setTimeout((function(){t({code:"TIMEOUT"}),o="timeout"}),2e4)}))])];case 2:return[2,u.sent()];case 3:return a=u.sent(),logger_1.wsLogger.error(r,{message:"send "+o,metric:{type:o,spanId:s,timeCost:Date.now()-i},error:a}),[3,5];case 4:return this.requestHandlerMap.delete(s),[7];case 5:return[3,7];case 6:logger_1.wsLogger.error(r,{message:"no ws instance",metric:{type:"end",spanId:s}}),u.label=7;case 7:return[2]}}))}))},t.prototype.sendWsHeatBeat=function(){var e;if(null===(e=this._subscribeDeviceIdList)||void 0===e?void 0:e.length){var t=shortid_for_miniprogram_1.default(),r={Action:"AppDeviceTraceHeartBeat",ActionParams:Object.assign({},{Platform:this.sdk._apiPlatform,RequestId:t,AccessToken:this.sdk.loginManager.accessToken,DeviceIds:this._subscribeDeviceIdList})};return this.send("YunApi",r,{reqId:t})}},t.prototype.activePush=function(){var e=this,t=this.sdk.loginManager,r=t.isLogin,s=t.accessToken,i=t.appKey;r&&s&&this._subscribeDeviceIdList&&(this.send("ActivePush",{DeviceIds:this._subscribeDeviceIdList,Platform:"weapp",AccessToken:s,AppKey:i,RegionId:this.sdk._apiRegionId}),this.sendWsHeatBeat(),clearInterval(this._heartBeatTimer),this._heartBeatTimer=setInterval((function(){return e.sendWsHeatBeat()}),this.options.heartbeatInterval))},t}(event_emitter_for_miniprogram_1.default);exports.IotWebsocket=IotWebsocket;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IotWebsocket=void 0;var tslib_1=require("tslib"),event_emitter_for_miniprogram_1=tslib_1.__importDefault(require("event-emitter-for-miniprogram")),shortid_for_miniprogram_1=tslib_1.__importDefault(require("shortid-for-miniprogram")),utils_1=require("../utils"),logger_1=require("./logger"),defaultOptions={url:"wss://iot.cloud.tencent.com/ws/explorer",heartbeatInterval:5e4},IotWebsocket=function(e){function t(t,r){var s=e.call(this)||this;return s.sdk=t,s.requestHandlerMap=new Map,s.options=Object.assign({},defaultOptions,r),s._connected=!1,s._subscribeDeviceIdList=[],s._heartBeatTimer=null,s}return tslib_1.__extends(t,e),t.prototype.isConnected=function(){return!!this._connected},t.prototype.doConnectWs=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e=this;return tslib_1.__generator(this,(function(t){return[2,this._doConnectWsPromise||(this._doConnectWsPromise=new Promise((function(t,r){return tslib_1.__awaiter(e,void 0,void 0,(function(){var e,s,i,n=this;return tslib_1.__generator(this,(function(o){e=shortid_for_miniprogram_1.default(),logger_1.wsLogger.updateGetReportData((function(){return{event:logger_1.WS_EVENT_PREFIX,context:{flowId:e}}})),s=function(e){r(e),logger_1.wsLogger.error("connection","error",{error:e}),n.disconnect(),n.emit("error",e)};try{logger_1.wsLogger.info("connection","start"),i=this.options.url,this.ws=new utils_1.WebSocket(utils_1.appendParams(i,{uin:this.sdk._debug?this.sdk._defaultUin:this.sdk.loginManager.userId,cId:e})),this.ws.onOpen((function(){n._connected=!0,n.emit("connect"),t(),logger_1.wsLogger.info("connection","connected")})),this.ws.onError(s),this.ws.onMessage((function(e){var t=e.data;n.emit("message",t);try{t=JSON.parse(t)}catch(e){return void logger_1.wsLogger.error("message","parseFail",{data:t})}t.push?(n.emit("push",t),logger_1.wsLogger.info("message","pushData",{data:t})):void 0!==t.reqId&&n.requestHandlerMap.has(t.reqId)?n.requestHandlerMap.get(t.reqId)(null,t):logger_1.wsLogger.info("message","otherData",{data:t})})),this.ws.onClose((function(e){return tslib_1.__awaiter(n,void 0,void 0,(function(){return tslib_1.__generator(this,(function(t){return logger_1.wsLogger.info("connection","close",{data:e}),this.disconnect(),this.emit("close",e),[2]}))}))}))}catch(e){s(e)}return[2]}))}))})))]}))}))},t.prototype.connect=function(e){var t;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return e&&(this._subscribeDeviceIdList=e),[4,this.sdk.loginManager.checkLogin()];case 1:return r.sent(),this.isConnected()||!(null===(t=this._subscribeDeviceIdList)||void 0===t?void 0:t.length)?[3,3]:[4,this.doConnectWs()];case 2:r.sent(),r.label=3;case 3:return[2,this.activePush()]}}))}))},t.prototype.disconnect=function(){this.ws&&(logger_1.wsLogger.info("connection","disconnect"),this.ws.close(),this._connected=!1,this._doConnectWsPromise=null,this.ws=null,clearInterval(this._heartBeatTimer),this._heartBeatTimer=null)},t.prototype.send=function(e,t,r){void 0===t&&(t={});var s=(void 0===r?{}:r).reqId;return tslib_1.__awaiter(this,void 0,void 0,(function(){var r,i,n,o,a,c=this;return tslib_1.__generator(this,(function(u){switch(u.label){case 0:if(s||(s=shortid_for_miniprogram_1.default()),r="send."+e,logger_1.wsLogger.info(r,{message:"send start",data:{reqBody:utils_1.cutoffLong(JSON.stringify(t))},metric:{type:"start",spanId:s}}),!this.ws)return[3,6];i=Date.now(),this.ws.send({data:JSON.stringify({action:e,reqId:s,params:t})}),n={reqBody:utils_1.cutoffLong(JSON.stringify(t)),action:e,reqId:s,timeCost:null},o="success",u.label=1;case 1:return u.trys.push([1,3,4,5]),[4,Promise.race([new Promise((function(e,t){c.requestHandlerMap.set(s,(function(a,c){if(n.timeCost=Date.now()-i,!a)return c.data||!c.error&&!c.error_message?(logger_1.wsLogger.info(r,{message:"send "+o,metric:{type:o,spanId:s,timeCost:Date.now()-i},data:{resBody:utils_1.cutoffLong(JSON.stringify(c.data))}}),e(c.data)):(t({code:c.error,msg:c.error_message}),void(o="fail"));t(a),o="fail"}))})),new Promise((function(e,t){setTimeout((function(){t({code:"TIMEOUT"}),o="timeout"}),2e4)}))])];case 2:return[2,u.sent()];case 3:return a=u.sent(),logger_1.wsLogger.error(r,{message:"send "+o,metric:{type:o,spanId:s,timeCost:Date.now()-i},error:a}),[3,5];case 4:return this.requestHandlerMap.delete(s),[7];case 5:return[3,7];case 6:logger_1.wsLogger.error(r,{message:"no ws instance",metric:{type:"end",spanId:s}}),u.label=7;case 7:return[2]}}))}))},t.prototype.sendWsHeatBeat=function(){var e;if(null===(e=this._subscribeDeviceIdList)||void 0===e?void 0:e.length){var t=shortid_for_miniprogram_1.default(),r={Action:"AppDeviceTraceHeartBeat",ActionParams:Object.assign({},{Platform:this.sdk._apiPlatform,RequestId:t,AccessToken:this.sdk.loginManager.accessToken,DeviceIds:this._subscribeDeviceIdList})};return this.send("YunApi",r,{reqId:t})}},t.prototype.activePush=function(){var e=this,t=this.sdk.loginManager,r=t.isLogin,s=t.accessToken,i=t.appKey;r&&s&&this._subscribeDeviceIdList&&this.ws&&(this.send("ActivePush",{DeviceIds:this._subscribeDeviceIdList,Platform:"weapp",AccessToken:s,AppKey:i,RegionId:this.sdk._apiRegionId}),this.sendWsHeatBeat(),clearInterval(this._heartBeatTimer),this._heartBeatTimer=setInterval((function(){return e.sendWsHeatBeat()}),this.options.heartbeatInterval))},t}(event_emitter_for_miniprogram_1.default);exports.IotWebsocket=IotWebsocket;
//# sourceMappingURL=IotWebsocket.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.requestTokenApi=void 0;var tslib_1=require("tslib"),shortid_for_miniprogram_1=tslib_1.__importDefault(require("shortid-for-miniprogram")),utils_1=require("../utils"),logger_1=require("./logger"),env_detect_1=require("../utils/env-detect"),defaultUrl="https://iot.cloud.tencent.com/api/exploreropen/";exports.requestTokenApi=function(e,r,t){return void 0===r&&(r={}),void 0===t&&(t={}),tslib_1.__awaiter(void 0,void 0,void 0,(function(){var o,i,s,n,a,c,d,u,l,_,g,p,m,f=r.uin,v=r.AccessToken,h=tslib_1.__rest(r,["uin","AccessToken"]),b=t.method,w=void 0===b?"POST":b,q=t.doNotReport,y=void 0!==q&&q,A=t.isSecureApi,I=void 0!==A&&A,k=t.isTokenApi,x=void 0===k||k,T=t.url,C=tslib_1.__rest(t,["method","doNotReport","isSecureApi","isTokenApi","url"]);return tslib_1.__generator(this,(function(r){switch(r.label){case 0:shortid_for_miniprogram_1.default.characters("0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ-_$@#%"),o=shortid_for_miniprogram_1.default(),i=Date.now(),!y&&logger_1.cgiLogger.info(e,{context:{flowId:o},message:"CGI start",metric:{type:"start",spanId:o},data:{reqBody:utils_1.cutoffLong(JSON.stringify(h))}}),r.label=1;case 1:if(r.trys.push([1,6,,7]),n={uin:f,cmd:e},h=Object.assign({},h,{Action:e,RequestId:o,AccessToken:v}),T=T||defaultUrl,!I)return[3,3];if(!env_detect_1.isMiniProgram)throw new Error("secure api 仅支持在小程序中调用");return T+="appsecureapi",n.cmd=e,[4,utils_1.pify(wx.login)()];case 2:return a=r.sent().code,h.JsCode=a,[3,4];case 3:x?(T+="tokenapi",n.cmd=e):T+=e,r.label=4;case 4:return T=utils_1.appendParams(T,n),s=tslib_1.__assign({url:T,data:h,method:w},C),[4,utils_1.request(s)];case 5:if(c=r.sent().data,d=c.code,u=c.msg,l=c.data,_=void 0===l?{}:l,m=Date.now()-i,d){if(null==_?void 0:_.Error)throw{code:_.Error.Code,msg:_.Error.Message};throw{code:d,msg:u}}return!y&&logger_1.cgiLogger.info(e,{context:{flowId:o},message:"CGI success",metric:{type:"success",spanId:o,timeCost:m},data:{resBody:utils_1.cutoffLong(JSON.stringify(_))}}),[2,_];case 6:return g=r.sent(),p=utils_1.normalizeError(g),m=Date.now()-i,!y&&logger_1.cgiLogger.error(e,{context:{flowId:o},message:"CGI fail #"+p.msg,metric:{type:"fail",spanId:o,timeCost:m},error:p}),[2,Promise.reject(g)];case 7:return[2]}}))}))};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.requestTokenApi=void 0;var tslib_1=require("tslib"),shortid_for_miniprogram_1=tslib_1.__importDefault(require("shortid-for-miniprogram")),utils_1=require("../utils"),logger_1=require("./logger"),env_detect_1=require("../utils/env-detect"),defaultUrl="https://iot.cloud.tencent.com/api/exploreropen/";exports.requestTokenApi=function(e,r,t){return void 0===r&&(r={}),void 0===t&&(t={}),tslib_1.__awaiter(void 0,void 0,void 0,(function(){var i,o,s,n,a,d,c,u,l,_,g,p,f,m,v,h=r.uin,b=r.AccessToken,w=tslib_1.__rest(r,["uin","AccessToken"]),y=t.method,A=void 0===y?"POST":y,I=t.doNotReport,q=void 0!==I&&I,T=t.isSecureApi,k=void 0!==T&&T,x=t.isTokenApi,C=void 0===x||x,S=t.url,D=tslib_1.__rest(t,["method","doNotReport","isSecureApi","isTokenApi","url"]);return tslib_1.__generator(this,(function(r){switch(r.label){case 0:shortid_for_miniprogram_1.default.characters("0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ-_$@#%"),i=shortid_for_miniprogram_1.default(),o=Date.now(),n=!1,!q&&logger_1.cgiLogger.info(e,{context:{flowId:i},message:"CGI start",metric:{type:"start",spanId:i},data:{reqBody:utils_1.cutoffLong(JSON.stringify(w))}}),r.label=1;case 1:if(r.trys.push([1,6,,7]),a={uin:h,cmd:e},w=Object.assign({},w,{Action:e,RequestId:i,AccessToken:b}),S=S||defaultUrl,!k)return[3,3];if(!env_detect_1.isMiniProgram)throw new Error("secure api 仅支持在小程序中调用");return S+="appsecureapi",a.cmd=e,[4,utils_1.pify(wx.login)()];case 2:return d=r.sent().code,w.JsCode=d,[3,4];case 3:C?(S+="tokenapi",a.cmd=e):S+=e,r.label=4;case 4:return S=utils_1.appendParams(S,a),s=tslib_1.__assign({url:S,data:w,method:A},D),[4,utils_1.request(s)];case 5:if(c=r.sent(),u=c.data,l=u.code,_=u.msg,g=u.data,p=void 0===g?{}:g,v=Date.now()-o,"header"in c&&"object"==typeof c.header&&c.header["In-Test-Ip"]&&(n=!0),l){if(null==p?void 0:p.Error)throw{code:p.Error.Code,msg:p.Error.Message};throw{code:l,msg:_}}return!q&&logger_1.cgiLogger.info(e,{context:{flowId:i},message:"CGI success",metric:{type:"success",spanId:i,timeCost:v},data:{resBody:utils_1.cutoffLong(JSON.stringify(p))}}),[2,p];case 6:return f=r.sent(),m=utils_1.normalizeError(f),v=Date.now()-o,!q&&logger_1.cgiLogger.error(e,{context:{flowId:i},message:"CGI fail #"+m.msg,metric:{type:"fail",spanId:i,timeCost:v,forgive:n?"AppDevSdk.cgi.inTest":void 0},error:m}),[2,Promise.reject(f)];case 7:return[2]}}))}))};
//# sourceMappingURL=requestTokenApi.js.map
{
"name": "qcloud-iotexplorer-appdev-sdk",
"version": "2.3.11",
"version": "2.3.12",
"description": "",

@@ -27,3 +27,3 @@ "main": "lib/index.js",

},
"gitHead": "51eee68d2e99e79ae0ba2b649cb40813e744dc0e"
"gitHead": "bb1bad2ea0f91ce15b1dadc287a0bb25d17feb07"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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