qcloud-iotexplorer-bluetooth-adapter-llsync
Advanced tools
Comparing version 1.0.1 to 1.1.0
import { DeviceFilterFunction } from 'qcloud-iotexplorer-bluetooth-adapter'; | ||
import { ProductUIDevConfig } from '@tencent/iotexplorer-ui-dev-config'; | ||
import { ProductUIDevConfig } from 'iotexplorer-ui-dev-config'; | ||
import { AppDevSdk, Reporter } from 'qcloud-iotexplorer-appdev-sdk'; | ||
@@ -4,0 +4,0 @@ import { Models } from './Models'; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StandardDeviceAdapter=exports.LLSyncDeviceAdapter=void 0;var tslib_1=require("tslib"),constants=tslib_1.__importStar(require("../../constants")),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),constants_1=require("../../constants"),libs_1=require("../../libs"),utils=tslib_1.__importStar(require("../../libs")),Models_1=require("./Models"),LLSyncDeviceAdapterBase_1=require("../LLSyncDeviceAdapterBase"),LLSyncOtaProcessor_1=require("./LLSyncOtaProcessor"),LLSyncProtocol_1=require("./LLSyncProtocol"),arrayBufferToHexStringArray=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.arrayBufferToHexStringArray,LLSyncDeviceAdapter=function(e){function t(r){var o=e.call(this,r)||this,s=function(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return tslib_1.__awaiter(o,void 0,void 0,(function(){return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,this.init()];case 1:return r.sent(),[2,e.apply(void 0,tslib_1.__spread(t))]}}))}))}};o.models=new Models_1.Models(t.options.appDevSdk),o.userIdentify=t.getUserIdentify(),o.on("disconnect",(function(){o.authorized=!1})),o.appDevSdk=t.options.appDevSdk,o.protocol=new LLSyncProtocol_1.LLSyncProtocol(o),o.otaProcessor=new LLSyncOtaProcessor_1.LLSyncOtaProcessor(o),Object.assign(o,{bindDevice:s(o.bindDevice.bind(o)),unbindDevice:s(o.unbindDevice.bind(o)),controlDevice:s(o.controlDevice.bind(o)),controlAction:s(o.controlAction.bind(o)),authenticateConnection:s(o.authenticateConnection.bind(o)),startOta:s(o.startOta.bind(o)),cancelOta:s(o.cancelOta.bind(o)),userCancelBindDevice:s(o.protocol.cancelUserCheck.bind(o.protocol,"cancel"))}),o.init(),o.reporter={info:function(e,r){void 0===e&&(e=""),void 0===r&&(r={});var s=r.message,n=void 0===s?"":s,i=r.serviceId,c=tslib_1.__rest(r,["message","serviceId"]),a=o,d=a.explorerDeviceId,l=a.deviceId,u=a.isConnected;t.options.appDevSdk.reporter.info(constants_1.REPORT_EVENT_TYPE,{serviceId:i||t.serviceId,message:n||(e&&constants.ACTION_DESC[e]?e+"("+constants.ACTION_DESC[e]+")":e),timeCost:c.timeCost||0,action:e,data:tslib_1.__assign({deviceId:d,bleDeviceId:l,isConnected:u},c)})},error:function(e,r){void 0===e&&(e=""),void 0===r&&(r={});var s=r.error,n=tslib_1.__rest(r,["error"]),i=o,c=i.explorerDeviceId,a=i.deviceId,d=i.isConnected;s.code&&constants.ERROR_MESSAGES[s.code]&&(s.msg=constants.ERROR_MESSAGES[s.code]),t.options.appDevSdk.reporter.error(constants_1.REPORT_EVENT_TYPE,{message:constants.ERROR_MESSAGES[e]?e+"("+constants.ERROR_MESSAGES[e]+":"+(s&&(s.message||s.errMsg||s.msg||s.code))+")":"",timeCost:n.timeCost||0,action:e,error:s,data:tslib_1.__assign(tslib_1.__assign({deviceId:c,bleDeviceId:a,isConnected:d},n),s)})}};var n=function(e){var t=e.deviceId,r=e.deviceData;if(console.log("llsync receive onControl",t,r),o.ready&&t===o.explorerDeviceId){var s={};Object.keys(r).forEach((function(e){s[e]=r[e].Value})),o.controlDevice({deviceData:s})}},i=function(e){var t=e.deviceId,r=e.Payload;o.ready&&t!==o.explorerDeviceId||o.controlAction({actionData:r})};return o.on("authorized",(function(){o.init(!0),o.appDevSdk.on(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsControl,n),o.appDevSdk.on(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsActionPush,i)})).on("disconnect",(function(){o.appDevSdk.off(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsControl,n),o.appDevSdk.off(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsActionPush,i)})),o}return tslib_1.__extends(t,e),t.getUserIdentify=function(){var e,r,o,s;return libs_1.getUserIdentify(null===(s=null===(o=null===(r=null===(e=t.options)||void 0===e?void 0:e.appDevSdk)||void 0===r?void 0:r.loginManager)||void 0===o?void 0:o.userInfo)||void 0===s?void 0:s.UserID)},t.injectOptions=function(e){t.options=e},Object.defineProperty(t.prototype,"ready",{get:function(){return this.isConnected&&this.authorized},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"needUserCheck",{get:function(){var e,t,r;try{return!!parseInt((null===(r=null===(t=null===(e=null==this?void 0:this.productConfig)||void 0===e?void 0:e.BleConfig)||void 0===t?void 0:t.bindingBootConfig)||void 0===r?void 0:r.confirmRequired)||"0")}catch(e){return console.warn("LLSync check confirmRequired fail",e),!1}},enumerable:!1,configurable:!0}),t.prototype.normalizeError=function(t){return!(t=e.prototype._normalizeError.call(this,t)).msg&&t.code&&constants.ERROR_MESSAGES[t.code]&&(t.msg=constants.ERROR_MESSAGES[t.code]),t},t.prototype.init=function(r){return tslib_1.__awaiter(this,void 0,void 0,(function(){var o=this;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:if(!t.options)throw"标准蓝牙适配器未初始化Options";return[4,e.prototype.init.call(this)];case 1:return s.sent(),r&&(this.productInfo=this.productConfig=this._initPromise=null),[2,this._initPromise||(this._initPromise=new Promise((function(e,t){return tslib_1.__awaiter(o,void 0,void 0,(function(){var r,o,s,n,i,c,a;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:return d.trys.push([0,2,,3]),o=(r=this).productConfig,s=r.productInfo,[4,Promise.all([o?Promise.resolve(o):this.models.getProduct({ProductId:this.productId}),s?Promise.resolve(s):this.models.getProductConfig({ProductId:this.productId})])];case 1:return n=tslib_1.__read.apply(void 0,[d.sent(),2]),i=n[0],c=n[1],this.dataTemplate=libs_1.getProductDateTemplate(i),this.productInfo=i,this.productConfig=c,console.log("init llsync done",{productInfo:this.productInfo,productConfig:this.productConfig,dataTemplate:this.dataTemplate}),e(),[3,3];case 2:return a=d.sent(),console.error("init standard device adapter fail",a),t(a),this._initPromise=null,[3,3];case 3:return[2]}}))}))})))]}}))}))},t.prototype.getDevicePsk=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,this.models.getDeviceConfig({DeviceId:this.productId+"/"+(e||this.deviceName),DeviceKey:LLSyncProtocol_1.LLSyncConfig.BLE_PSK_DEVICE_KEY})];case 1:if(!(t=r.sent()))throw{code:constants.PSK_GET_ERROR};return[2,t]}}))}))},t.prototype.startOta=function(e){var t=e.onProgress;return this.otaProcessor.startOta({onProgress:t})},t.prototype.cancelOta=function(){return this.otaProcessor.cancelOta()},t.prototype.startListenLLEvents=function(){this.on(constants.PROPERTY_REPORT,utils.wrapEventHandler(this.onPropertyReport.bind(this),constants.PROPERTY_REPORT)),this.on(constants.GET_STATUS,this.onGetStatus.bind(this)),this.on(constants.EVENT_REPORT,utils.wrapEventHandler(this.onEventReport.bind(this),constants.EVENT_REPORT))},t.prototype.stopListenLLEvents=function(){this.off(constants.PROPERTY_REPORT),this.off(constants.GET_STATUS),this.off(constants.EVENT_REPORT)},t.prototype.onPropertyReport=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,o,s;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),console.log("onPropertyReport check this",this),t=utils.convertPropertiesTlvToJsObject(e.slice(2),this.dataTemplate),this.reporter.info(constants.REPORT_RESULT,{data:utils.formatArrayToReportString(e),jsObj:t}),[4,this.models.reportBlueToothDeviceData({ProductId:this.productId,DeviceName:this.deviceName,Data:t,DataTimeStamp:Date.now()})];case 1:return(r=n.sent().Data)&&(o=JSON.parse(r),this.protocol.reportPropertyReportResult(o.code)),[3,3];case 2:return s=n.sent(),this.reporter.error(constants.REPORT_RESULT_ERROR,{error:s}),this.protocol.reportPropertyReportResult(-1),[3,3];case 3:return[2]}}))}))},t.prototype.onGetStatus=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r,o,s,n;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.models.getDeviceData({ProductId:this.productId,DeviceName:this.deviceName})];case 1:return e=i.sent(),t={},Object.keys(e).forEach((function(r){t[r]=e[r].Value})),r=utils.convertPropertiesChangeToTlv(t,this.dataTemplate),o=r.tlvData,s=r.tmpData,this.reporter.info(constants.GET_STATUS,{properties:t,tlvData:utils.formatArrayToReportString(o),tmpData:s}),this.protocol.reportGetStatusResult(0,o,s),[3,3];case 2:return n=i.sent(),this.reporter.error(constants.GET_STATUS_ERROR,{error:n}),this.protocol.reportGetStatusResult(-1),[2,Promise.reject(this.normalizeError(n))];case 3:return[2]}}))}))},t.prototype.onEventReport=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,o,s,n,i,c,a;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:d.trys.push([0,8,,9]),console.log("onEventReport check this",this),t=utils.getStrLength(e),r=utils.convertEventTlvToJsObject(e.slice(2,2+t),this.dataTemplate),o=r.eventId,s=r.params,n=r.eventIndex,i={DeviceId:this.explorerDeviceId,EventId:o,Params:JSON.stringify(s)},this.reporter.info(constants.EVENT_REPLY,tslib_1.__assign(tslib_1.__assign({},i),{eventIndex:n})),d.label=1;case 1:return d.trys.push([1,6,,7]),[4,this.models.reportDeviceEvent(i)];case 2:return d.sent(),e.length-2>t?[4,this.onEventReport({data:e.slice(t+2+1)})]:[3,4];case 3:return d.sent(),[3,5];case 4:this.protocol.reportEventReportResult(0,n),d.label=5;case 5:return[3,7];case 6:throw c=d.sent(),this.protocol.reportEventReportResult(-1,n),c;case 7:return[3,9];case 8:return a=d.sent(),this.reporter.error(constants.EVENT_REPLY_ERROR,{error:a}),[2,Promise.reject(this.normalizeError(a))];case 9:return[2]}}))}))},t.prototype.bindDevice=function(e){var t=e.familyId,r=e.roomId;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,o,s,n,i,c,a,d,l,u;return tslib_1.__generator(this,(function(p){switch(p.label){case 0:return p.trys.push([0,7,,8]),this.reporter.info(constants.BIND_AUTH),e=Date.now(),[4,this.protocol.requestBindDevice(this.needUserCheck)];case 1:o=p.sent(),s=o.sign,n=o.timestamp,i=o.nonce,c=o.deviceName,this.deviceName=c,p.label=2;case 2:return p.trys.push([2,4,,5]),a={Signature:s,DeviceTimestamp:n,DeviceId:this.explorerDeviceId,ConnId:""+i,FamilyId:t,RoomId:r,BindType:"bluetooth_sign"},this.reporter.info(constants.BIND_AUTH_DETAIL,a),[4,this.models.addDeviceBySigInFamily(a)];case 3:return p.sent(),[3,5];case 4:return d=p.sent(),this.protocol.reportBindError(d.code),[2,Promise.reject(this.normalizeError(d))];case 5:return l=this,[4,this.protocol.reportBindSuccess(e)];case 6:return l.localPsk=p.sent(),this.authorized=!0,[2,this.explorerDeviceId];case 7:return u=p.sent(),console.log(u),console.log("error in bindDevice",u),this.reporter.error(constants.BIND_AUTH_FAIL,{error:u}),[2,Promise.reject(this.normalizeError(u))];case 8:return[2]}}))}))},t.prototype.unbindDevice=function(e){var t=e.familyId,r=e.deviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,o,s,n,i;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:if(c.trys.push([0,5,,6]),!r)throw{code:constants.DEVICE_NAME_IS_EMPTY};return e=Date.now(),[4,this.getDevicePsk(r)];case 1:return o=c.sent(),this.reporter.info(constants.UNBIND_AUTH,{localPsk:o}),[4,this.protocol.getUnbindAuthSign()];case 2:if(s=c.sent().sign,n=utils.encrypt(constants.UNBIND_RESPONSE,o),s!==n)throw{code:constants.UNBIND_REPLY_ERROR};return this.localPsk=o,this.deviceName=r,[4,this.models.deleteDeviceFromFamily({FamilyId:t,DeviceId:this.explorerDeviceId})];case 3:return c.sent(),this.reporter.info(constants.UNBIND_RESULT_AUTH_SUCCESS,{timeCost:Date.now()-e}),[4,this.protocol.reportUnbindResult("success")];case 4:return c.sent(),this.stopListenLLEvents(),this.authorized=!1,this.disconnectDevice(),[3,6];case 5:return i=c.sent(),this.protocol.reportUnbindResult("fail"),this.reporter.error(constants.UNBIND_RESULT_AUTH_FAIL,{error:i}),[2,Promise.reject(this.normalizeError(i))];case 6:return[2]}}))}))},t.prototype.controlDevice=function(e){var t=e.deviceData;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),console.log("controlDevice check this",this),this.reporter.info(constants.CONTROL_DEVICE,{deviceData:t}),[4,this.protocol.controlDeviceProperty(t)];case 1:return r.sent(),[4,this.models.reportBlueToothDeviceData({ProductId:this.productId,DeviceName:this.deviceName,Data:t,DataTimeStamp:Date.now()})];case 2:return r.sent(),[3,4];case 3:return e=r.sent(),this.reporter.error(constants.CONTROL_DEVICE_REPLY_ERROR,{error:e}),[2,Promise.reject(this.normalizeError(e))];case 4:return[2]}}))}))},t.prototype.controlAction=function(e){var t=e.actionData;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,o,s,n,i;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return c.trys.push([0,4,,5]),console.log("controlAction check this",this),[4,this.protocol.controlDeviceAction(t)];case 1:return e=c.sent().output,[4,utils.convertActionOutputTlvToJsObject(e,this.dataTemplate)];case 2:return r=c.sent(),o=r.outputParams,s=r.actionIndex,n=r.actionId,[4,this.models.publishDeviceActionMessage({deviceName:this.deviceName,productId:this.productId,actionId:n,clientToken:t.clientToken,output:o})];case 3:return c.sent(),this.reporter.info(constants.CONTROL_ACTION_SUCCESS,{outputParams:o,actionIndex:s,actionId:n}),[3,5];case 4:return i=c.sent(),this.reporter.error(constants.CONTROL_ACTION_ERROR,{error:i}),[2,Promise.reject(this.normalizeError(i))];case 5:return[2]}}))}))},t.prototype.authenticateConnection=function(e){var t=(void 0===e?{}:e).deviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,o,s,n,i,c,a,d,l,u,p;return tslib_1.__generator(this,(function(v){switch(v.label){case 0:if(v.trys.push([0,8,,9]),console.log("start authenticate connection",t),!t)throw{code:constants.DEVICE_NAME_IS_EMPTY};return e=Date.now(),[4,this.getDevicePsk(t)];case 1:return r=v.sent(),this.localPsk=r,this.reporter.info(constants.CONNECT_AUTH,{localPsk:r}),[4,this.protocol.getDeviceAuthInfo()];case 2:if(o=v.sent(),s=o.sign,n=o.timestamp,i=utils.encrypt(""+(n+60)+this.productId+t,r),s!==i)throw{code:constants.CONNECT_SIGN_AUTH_ERROR};return[4,this.protocol.getDeviceInfo()];case 3:if(c=v.sent(),a=c.version,d=c.mtu,l=c.needSetMtu,u=c.otaVersion,this.deviceName=t,this.bleVersion=a,this.mtu=d,!l)return[3,7];v.label=4;case 4:return v.trys.push([4,6,,7]),[4,this.setMtu(this.mtu)];case 5:return v.sent(),this.writeMtuResult("success"),[3,7];case 6:return v.sent(),this.writeMtuResult("fail"),[3,7];case 7:return this.otaVersion=u,u&&this.models.reportOTAVersion({Version:u,DeviceId:this.explorerDeviceId}),this.reporter.info(constants.CONNECT_RESULT_WRITE_SUCCESS,{timeCost:Date.now()-e,version:a,mtu:d,otaVersion:u}),this.authorized=!0,this.emit("authorized",{version:a,mtu:d,otaVersion:u}),this.stopListenLLEvents(),this.startListenLLEvents(),[3,9];case 8:return p=v.sent(),this.protocol.reportConnectError(),this.reporter.error(constants.CONNECT_RESULT_WRITE_FAIL,{error:p}),[2,Promise.reject(this.normalizeError(p))];case 9:return[2]}}))}))},t.serviceId16="0000FFE0-0000-1000-8000-00805F9B34FB",t.serviceId="0000FFE0-65D0-4E20-B56A-E493541BA4E2",t.deviceFilter=function(e,r){if(!e.advertisServiceUUIDs||!e.advertisServiceUUIDs.find((function(e){return e===t.serviceId16}))||!e.advertisData)return null;var o=t.options.appDevSdk.reporter;try{var s=Math.floor(10*Math.random())%10==1||!0,n=arrayBufferToHexStringArray(e.advertisData);s&&o.info(constants_1.REPORT_EVENT_TYPE,{message:"收到广播",serviceId:t.serviceId,hexArr:n.join(",")});var i=parseInt(n[2],16)-(parseInt(n[2],16)>>2<<2),c=parseInt(n[2],16)>>4,a=r.productId&&r.deviceName?r.productId+"/"+r.deviceName:"",d=a?utils.get8ByteFromStr(""+a.replace("/","")):"",l=!!a,u="",p="",v="",_=constants.DEVICE_STATE_MAP[i],h=[constants.DEVICE_HAS_BINDED,constants.DEVICE_HAS_CONNECTED].indexOf(_)>-1;if(h)v=n.slice(3,11).join("").toLocaleLowerCase(),p=n.slice(11).join("").toLocaleLowerCase(),u=r.productId;else{var E=n.slice(3,9);e.name&&-1===e.name.indexOf("_")&&(e.name=e.name+"_"+E.slice(0,2).join("")),u=libs_1.hex2str(n.slice(9))}s&&o.info(constants_1.REPORT_EVENT_TYPE,{message:"解析广播",serviceId:t.serviceId,data:{bindState:_||"x",targetDeviceId:a,targetDeviceIdentify:d,deviceUserIdentify:p||"x",deviceProductId:u||"x",deviceIdentify:v||"x"}});var f=function(){var o=tslib_1.__assign(tslib_1.__assign({},e),{standard:!0,bindState:constants.DEVICE_STATE_MAP[_],serviceId:t.serviceId,deviceName:r.deviceName||"",productId:u,extendInfo:{moduleVersion:c}});return console.log("---设备匹配成功---",o),o};return h?l&&v===d?f():null:f()}catch(e){console.error("llsync device filter error",e),o.error(constants_1.REPORT_EVENT_TYPE,{message:"协议广播出错",error:e})}},t}(LLSyncDeviceAdapterBase_1.LLSyncDeviceAdapterBase);exports.LLSyncDeviceAdapter=LLSyncDeviceAdapter,exports.StandardDeviceAdapter=LLSyncDeviceAdapter; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StandardDeviceAdapter=exports.LLSyncDeviceAdapter=void 0;var tslib_1=require("tslib"),constants=tslib_1.__importStar(require("../../constants")),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),constants_1=require("../../constants"),libs_1=require("../../libs"),utils=tslib_1.__importStar(require("../../libs")),Models_1=require("./Models"),LLSyncDeviceAdapterBase_1=require("../LLSyncDeviceAdapterBase"),LLSyncOtaProcessor_1=require("./LLSyncOtaProcessor"),LLSyncProtocol_1=require("./LLSyncProtocol"),arrayBufferToHexStringArray=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.arrayBufferToHexStringArray,LLSyncDeviceAdapter=function(e){function t(r){var o=e.call(this,r)||this,s=function(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return tslib_1.__awaiter(o,void 0,void 0,(function(){return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,this.init()];case 1:return r.sent(),[2,e.apply(void 0,tslib_1.__spread(t))]}}))}))}};o.models=new Models_1.Models(t.options.appDevSdk),o.userIdentify=t.getUserIdentify(),o.on("disconnect",(function(){o.authorized=!1})),o.appDevSdk=t.options.appDevSdk,o.protocol=new LLSyncProtocol_1.LLSyncProtocol(o),o.otaProcessor=new LLSyncOtaProcessor_1.LLSyncOtaProcessor(o),Object.assign(o,{bindDevice:s(o.bindDevice.bind(o)),unbindDevice:s(o.unbindDevice.bind(o)),controlDevice:s(o.controlDevice.bind(o)),controlAction:s(o.controlAction.bind(o)),authenticateConnection:s(o.authenticateConnection.bind(o)),startOta:s(o.startOta.bind(o)),cancelOta:s(o.cancelOta.bind(o)),userCancelBindDevice:s(o.protocol.cancelUserCheck.bind(o.protocol,"cancel"))}),o.init(),o.reporter={info:function(e,r){void 0===e&&(e=""),void 0===r&&(r={});var s=r.message,i=void 0===s?"":s,n=r.serviceId,c=tslib_1.__rest(r,["message","serviceId"]),a=o,d=a.explorerDeviceId,l=a.deviceId,u=a.isConnected;t.options.appDevSdk.reporter.info(constants_1.REPORT_EVENT_TYPE,{serviceId:n||t.serviceId,message:i||(e&&constants.ACTION_DESC[e]?e+"("+constants.ACTION_DESC[e]+")":e),timeCost:c.timeCost||0,action:e,data:tslib_1.__assign({deviceId:d,bleDeviceId:l,isConnected:u},c)})},error:function(e,r){void 0===e&&(e=""),void 0===r&&(r={});var s=r.error,i=tslib_1.__rest(r,["error"]),n=o,c=n.explorerDeviceId,a=n.deviceId,d=n.isConnected;s.code&&constants.ERROR_MESSAGES[s.code]&&(s.msg=constants.ERROR_MESSAGES[s.code]),t.options.appDevSdk.reporter.error(constants_1.REPORT_EVENT_TYPE,{message:constants.ERROR_MESSAGES[e]?e+"("+constants.ERROR_MESSAGES[e]+":"+(s&&(s.message||s.errMsg||s.msg||s.code))+")":"",timeCost:i.timeCost||0,action:e,error:s,data:tslib_1.__assign(tslib_1.__assign({deviceId:c,bleDeviceId:a,isConnected:d},i),s)})}};var i=function(e){var t=e.deviceId,r=e.deviceData;if(console.log("llsync receive onControl",t,r),o.ready&&t===o.explorerDeviceId){var s={};Object.keys(r).forEach((function(e){s[e]=r[e].Value})),o.controlDevice({deviceData:s})}},n=function(e){var t=e.deviceId,r=e.Payload;o.ready&&t!==o.explorerDeviceId||o.controlAction({actionData:r})};return o.on("authorized",(function(){o.init(!0),o.appDevSdk.on(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsControl,i),o.appDevSdk.on(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsActionPush,n)})).on("disconnect",(function(){o.appDevSdk.off(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsControl,i),o.appDevSdk.off(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsActionPush,n)})),o}return tslib_1.__extends(t,e),t.getUserIdentify=function(){var e,r,o,s;return libs_1.getUserIdentify(null===(s=null===(o=null===(r=null===(e=t.options)||void 0===e?void 0:e.appDevSdk)||void 0===r?void 0:r.loginManager)||void 0===o?void 0:o.userInfo)||void 0===s?void 0:s.UserID)},t.injectOptions=function(e){t.options=e},Object.defineProperty(t.prototype,"ready",{get:function(){return this.isConnected&&this.authorized},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"needUserCheck",{get:function(){var e,t,r;try{return!!parseInt((null===(r=null===(t=null===(e=null==this?void 0:this.productConfig)||void 0===e?void 0:e.BleConfig)||void 0===t?void 0:t.bindingBootConfig)||void 0===r?void 0:r.confirmRequired)||"0")}catch(e){return console.warn("LLSync check confirmRequired fail",e),!1}},enumerable:!1,configurable:!0}),t.prototype.normalizeError=function(t){return!(t=e.prototype._normalizeError.call(this,t)).msg&&t.code&&constants.ERROR_MESSAGES[t.code]&&(t.msg=constants.ERROR_MESSAGES[t.code]),t},t.prototype.init=function(r){return tslib_1.__awaiter(this,void 0,void 0,(function(){var o=this;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:if(!t.options)throw"标准蓝牙适配器未初始化Options";return[4,e.prototype.init.call(this)];case 1:return s.sent(),r&&(this.productInfo=this.productConfig=this._initPromise=null),[2,this._initPromise||(this._initPromise=new Promise((function(e,t){return tslib_1.__awaiter(o,void 0,void 0,(function(){var r,o,s,i,n,c,a;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:return d.trys.push([0,2,,3]),o=(r=this).productConfig,s=r.productInfo,[4,Promise.all([o?Promise.resolve(o):this.models.getProduct({ProductId:this.productId}),s?Promise.resolve(s):this.models.getProductConfig({ProductId:this.productId})])];case 1:return i=tslib_1.__read.apply(void 0,[d.sent(),2]),n=i[0],c=i[1],this.dataTemplate=libs_1.getProductDateTemplate(n),this.productInfo=n,this.productConfig=c,console.log("init llsync done",{productInfo:this.productInfo,productConfig:this.productConfig,dataTemplate:this.dataTemplate}),e(),[3,3];case 2:return a=d.sent(),console.error("init standard device adapter fail",a),t(a),this._initPromise=null,[3,3];case 3:return[2]}}))}))})))]}}))}))},t.prototype.getDevicePsk=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,o,s,i,n;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return t={DeviceId:this.productId+"/"+(e||this.deviceName),DeviceKey:LLSyncProtocol_1.LLSyncConfig.BLE_PSK_DEVICE_KEY},[4,Promise.all([this.models.getDeviceConfig(tslib_1.__assign(tslib_1.__assign({},t),{isUserConfig:!0})),this.models.getDeviceConfig(t)])];case 1:if(r=tslib_1.__read.apply(void 0,[c.sent(),2]),o=r[0],s=r[1],!o||s)return[3,5];c.label=2;case 2:return c.trys.push([2,4,,5]),[4,this.models.setDeviceConfig({DeviceId:t.DeviceId,DeviceKey:t.DeviceKey,DeviceValue:o})];case 3:return c.sent(),[3,5];case 4:return i=c.sent(),console.error("update psk to DeviceConfig fail",i),[3,5];case 5:if(!(n=s||o))throw{code:constants.PSK_GET_ERROR};return[2,n]}}))}))},t.prototype.startOta=function(e){var t=e.onProgress;return this.otaProcessor.startOta({onProgress:t})},t.prototype.cancelOta=function(){return this.otaProcessor.cancelOta()},t.prototype.startListenLLEvents=function(){this.on(constants.PROPERTY_REPORT,utils.wrapEventHandler(this.onPropertyReport.bind(this),constants.PROPERTY_REPORT)),this.on(constants.GET_STATUS,this.onGetStatus.bind(this)),this.on(constants.EVENT_REPORT,utils.wrapEventHandler(this.onEventReport.bind(this),constants.EVENT_REPORT))},t.prototype.stopListenLLEvents=function(){this.off(constants.PROPERTY_REPORT),this.off(constants.GET_STATUS),this.off(constants.EVENT_REPORT)},t.prototype.onPropertyReport=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,o,s;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),console.log("onPropertyReport check this",this),t=utils.convertPropertiesTlvToJsObject(e.slice(2),this.dataTemplate),this.reporter.info(constants.REPORT_RESULT,{data:utils.formatArrayToReportString(e),jsObj:t}),[4,this.models.reportBlueToothDeviceData({ProductId:this.productId,DeviceName:this.deviceName,Data:t,DataTimeStamp:Date.now()})];case 1:return(r=i.sent().Data)&&(o=JSON.parse(r),this.protocol.reportPropertyReportResult(o.code)),[3,3];case 2:return s=i.sent(),this.reporter.error(constants.REPORT_RESULT_ERROR,{error:s}),this.protocol.reportPropertyReportResult(-1),[3,3];case 3:return[2]}}))}))},t.prototype.onGetStatus=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r,o,s,i;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.models.getDeviceData({ProductId:this.productId,DeviceName:this.deviceName})];case 1:return e=n.sent(),t={},Object.keys(e).forEach((function(r){t[r]=e[r].Value})),r=utils.convertPropertiesChangeToTlv(t,this.dataTemplate),o=r.tlvData,s=r.tmpData,this.reporter.info(constants.GET_STATUS,{properties:t,tlvData:utils.formatArrayToReportString(o),tmpData:s}),this.protocol.reportGetStatusResult(0,o,s),[3,3];case 2:return i=n.sent(),this.reporter.error(constants.GET_STATUS_ERROR,{error:i}),this.protocol.reportGetStatusResult(-1),[2,Promise.reject(this.normalizeError(i))];case 3:return[2]}}))}))},t.prototype.onEventReport=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,o,s,i,n,c,a;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:d.trys.push([0,8,,9]),console.log("onEventReport check this",this),t=utils.getStrLength(e),r=utils.convertEventTlvToJsObject(e.slice(2,2+t),this.dataTemplate),o=r.eventId,s=r.params,i=r.eventIndex,n={DeviceId:this.explorerDeviceId,EventId:o,Params:JSON.stringify(s)},this.reporter.info(constants.EVENT_REPLY,tslib_1.__assign(tslib_1.__assign({},n),{eventIndex:i})),d.label=1;case 1:return d.trys.push([1,6,,7]),[4,this.models.reportDeviceEvent(n)];case 2:return d.sent(),e.length-2>t?[4,this.onEventReport({data:e.slice(t+2+1)})]:[3,4];case 3:return d.sent(),[3,5];case 4:this.protocol.reportEventReportResult(0,i),d.label=5;case 5:return[3,7];case 6:throw c=d.sent(),this.protocol.reportEventReportResult(-1,i),c;case 7:return[3,9];case 8:return a=d.sent(),this.reporter.error(constants.EVENT_REPLY_ERROR,{error:a}),[2,Promise.reject(this.normalizeError(a))];case 9:return[2]}}))}))},t.prototype.bindDevice=function(e){var t=e.familyId,r=e.roomId;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,o,s,i,n,c,a,d,l,u;return tslib_1.__generator(this,(function(p){switch(p.label){case 0:return p.trys.push([0,7,,8]),this.reporter.info(constants.BIND_AUTH),e=Date.now(),[4,this.protocol.requestBindDevice(this.needUserCheck)];case 1:o=p.sent(),s=o.sign,i=o.timestamp,n=o.nonce,c=o.deviceName,this.deviceName=c,p.label=2;case 2:return p.trys.push([2,4,,5]),a={Signature:s,DeviceTimestamp:i,DeviceId:this.explorerDeviceId,ConnId:""+n,FamilyId:t,RoomId:r,BindType:"bluetooth_sign"},this.reporter.info(constants.BIND_AUTH_DETAIL,a),[4,this.models.addDeviceBySigInFamily(a)];case 3:return p.sent(),[3,5];case 4:return d=p.sent(),this.protocol.reportBindError(d.code),[2,Promise.reject(this.normalizeError(d))];case 5:return l=this,[4,this.protocol.reportBindSuccess(e)];case 6:return l.localPsk=p.sent(),[2,this.explorerDeviceId];case 7:return u=p.sent(),console.log(u),console.log("error in bindDevice",u),this.reporter.error(constants.BIND_AUTH_FAIL,{error:u}),[2,Promise.reject(this.normalizeError(u))];case 8:return[2]}}))}))},t.prototype.unbindDevice=function(e){var t=e.familyId,r=e.deviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,o,s,i,n;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:if(c.trys.push([0,5,,6]),!r)throw{code:constants.DEVICE_NAME_IS_EMPTY};return e=Date.now(),[4,this.getDevicePsk(r)];case 1:return o=c.sent(),this.reporter.info(constants.UNBIND_AUTH,{localPsk:o}),[4,this.protocol.getUnbindAuthSign()];case 2:if(s=c.sent().sign,i=utils.encrypt(constants.UNBIND_RESPONSE,o),s!==i)throw{code:constants.UNBIND_REPLY_ERROR};return this.localPsk=o,this.deviceName=r,[4,this.models.deleteDeviceFromFamily({FamilyId:t,DeviceId:this.explorerDeviceId})];case 3:return c.sent(),this.reporter.info(constants.UNBIND_RESULT_AUTH_SUCCESS,{timeCost:Date.now()-e}),[4,this.protocol.reportUnbindResult("success")];case 4:return c.sent(),this.stopListenLLEvents(),this.authorized=!1,this.disconnectDevice(),[3,6];case 5:return n=c.sent(),this.protocol.reportUnbindResult("fail"),this.reporter.error(constants.UNBIND_RESULT_AUTH_FAIL,{error:n}),[2,Promise.reject(this.normalizeError(n))];case 6:return[2]}}))}))},t.prototype.controlDevice=function(e){var t=e.deviceData;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),console.log("controlDevice check this",this),this.reporter.info(constants.CONTROL_DEVICE,{deviceData:t}),[4,this.protocol.controlDeviceProperty(t)];case 1:return r.sent(),[4,this.models.reportBlueToothDeviceData({ProductId:this.productId,DeviceName:this.deviceName,Data:t,DataTimeStamp:Date.now()})];case 2:return r.sent(),[3,4];case 3:return e=r.sent(),this.reporter.error(constants.CONTROL_DEVICE_REPLY_ERROR,{error:e}),[2,Promise.reject(this.normalizeError(e))];case 4:return[2]}}))}))},t.prototype.controlAction=function(e){var t=e.actionData;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,o,s,i,n;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return c.trys.push([0,4,,5]),console.log("controlAction check this",this),[4,this.protocol.controlDeviceAction(t)];case 1:return e=c.sent().output,[4,utils.convertActionOutputTlvToJsObject(e,this.dataTemplate)];case 2:return r=c.sent(),o=r.outputParams,s=r.actionIndex,i=r.actionId,[4,this.models.publishDeviceActionMessage({deviceName:this.deviceName,productId:this.productId,actionId:i,clientToken:t.clientToken,output:o})];case 3:return c.sent(),this.reporter.info(constants.CONTROL_ACTION_SUCCESS,{outputParams:o,actionIndex:s,actionId:i}),[3,5];case 4:return n=c.sent(),this.reporter.error(constants.CONTROL_ACTION_ERROR,{error:n}),[2,Promise.reject(this.normalizeError(n))];case 5:return[2]}}))}))},t.prototype.authenticateConnection=function(e){var t=(void 0===e?{}:e).deviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,o,s,i,n,c,a,d,l,u,p;return tslib_1.__generator(this,(function(v){switch(v.label){case 0:if(v.trys.push([0,8,,9]),console.log("start authenticate connection",t),!t)throw{code:constants.DEVICE_NAME_IS_EMPTY};return e=Date.now(),[4,this.getDevicePsk(t)];case 1:return r=v.sent(),this.localPsk=r,this.reporter.info(constants.CONNECT_AUTH,{localPsk:r}),[4,this.protocol.getDeviceAuthInfo()];case 2:if(o=v.sent(),s=o.sign,i=o.timestamp,n=utils.encrypt(""+(i+60)+this.productId+t,r),s!==n)throw{code:constants.CONNECT_SIGN_AUTH_ERROR};return[4,this.protocol.getDeviceInfo()];case 3:if(c=v.sent(),a=c.version,d=c.mtu,l=c.needSetMtu,u=c.otaVersion,this.deviceName=t,this.bleVersion=a,this.mtu=d,!l)return[3,7];v.label=4;case 4:return v.trys.push([4,6,,7]),[4,this.setMtu(this.mtu)];case 5:return v.sent(),this.writeMtuResult("success"),[3,7];case 6:return v.sent(),this.writeMtuResult("fail"),[3,7];case 7:return this.otaVersion=u,u&&this.models.reportOTAVersion({Version:u,DeviceId:this.explorerDeviceId}),this.reporter.info(constants.CONNECT_RESULT_WRITE_SUCCESS,{timeCost:Date.now()-e,version:a,mtu:d,otaVersion:u}),this.authorized=!0,this.emit("authorized",{version:a,mtu:d,otaVersion:u}),this.stopListenLLEvents(),this.startListenLLEvents(),[3,9];case 8:return p=v.sent(),this.protocol.reportConnectError(),this.reporter.error(constants.CONNECT_RESULT_WRITE_FAIL,{error:p}),[2,Promise.reject(this.normalizeError(p))];case 9:return[2]}}))}))},t.serviceId16="0000FFE0-0000-1000-8000-00805F9B34FB",t.serviceId="0000FFE0-65D0-4E20-B56A-E493541BA4E2",t.deviceFilter=function(e,r){if(!e.advertisServiceUUIDs||!e.advertisServiceUUIDs.find((function(e){return e===t.serviceId16}))||!e.advertisData)return null;var o=t.options.appDevSdk.reporter;try{var s=Math.floor(10*Math.random())%10==1||!0,i=arrayBufferToHexStringArray(e.advertisData);s&&o.info(constants_1.REPORT_EVENT_TYPE,{message:"收到广播",serviceId:t.serviceId,hexArr:i.join(",")});var n=parseInt(i[2],16)-(parseInt(i[2],16)>>2<<2),c=parseInt(i[2],16)>>4,a=r.productId&&r.deviceName?r.productId+"/"+r.deviceName:"",d=a?utils.get8ByteFromStr(""+a.replace("/","")):"",l=!!a,u="",p="",v="",_=constants.DEVICE_STATE_MAP[n],h=[constants.DEVICE_HAS_BINDED,constants.DEVICE_HAS_CONNECTED].indexOf(_)>-1;if(h)v=i.slice(3,11).join("").toLocaleLowerCase(),p=i.slice(11).join("").toLocaleLowerCase(),u=r.productId;else{var E=i.slice(3,9);e.name&&-1===e.name.indexOf("_")&&(e.name=e.name+"_"+E.slice(0,2).join("")),u=libs_1.hex2str(i.slice(9))}s&&o.info(constants_1.REPORT_EVENT_TYPE,{message:"解析广播",serviceId:t.serviceId,data:{bindState:_||"x",targetDeviceId:a,targetDeviceIdentify:d,deviceUserIdentify:p||"x",deviceProductId:u||"x",deviceIdentify:v||"x"}});var f=function(){var o=tslib_1.__assign(tslib_1.__assign({},e),{standard:!0,bindState:constants.DEVICE_STATE_MAP[_],serviceId:t.serviceId,deviceName:r.deviceName||"",productId:u,extendInfo:{moduleVersion:c}});return console.log("---设备匹配成功---",o),o};return l&&h&&v===d?f():l||h?null:f()}catch(e){console.error("llsync device filter error",e),o.error(constants_1.REPORT_EVENT_TYPE,{message:"协议广播出错",error:e})}},t}(LLSyncDeviceAdapterBase_1.LLSyncDeviceAdapterBase);exports.LLSyncDeviceAdapter=LLSyncDeviceAdapter,exports.StandardDeviceAdapter=LLSyncDeviceAdapter; | ||
//# sourceMappingURL=LLSyncDeviceAdapter.js.map |
@@ -5,10 +5,12 @@ import { AppDevSdk } from 'qcloud-iotexplorer-appdev-sdk'; | ||
constructor(appDevSdk: any); | ||
getDeviceConfig({ DeviceId, DeviceKey, }: { | ||
getDeviceConfig({ DeviceId, DeviceKey, isUserConfig, }: { | ||
DeviceId: string; | ||
DeviceKey: string; | ||
isUserConfig?: boolean; | ||
}): Promise<any>; | ||
setDeviceConfig({ DeviceId, DeviceKey, DeviceValue, }: { | ||
setDeviceConfig({ DeviceId, DeviceKey, DeviceValue, isUserConfig, }: { | ||
DeviceId?: string; | ||
DeviceKey: string; | ||
DeviceValue: any; | ||
isUserConfig?: boolean; | ||
}): any; | ||
@@ -15,0 +17,0 @@ reportBlueToothDeviceData({ ProductId, DeviceName, Data, DataTimeStamp, }: { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Models=void 0;var tslib_1=require("tslib"),iotexplorer_ui_dev_config_1=require("@tencent/iotexplorer-ui-dev-config"),Models=function(){function e(e){this.appDevSdk=e}return e.prototype.getDeviceConfig=function(e){var t=e.DeviceId,i=e.DeviceKey,r=void 0===i?"*":i;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,i,n,o;return tslib_1.__generator(this,(function(a){switch(a.label){case 0:e={},a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.appDevSdk.requestApi("AppGetDeviceConfig",{DeviceId:t,DeviceKey:r})];case 2:return i=a.sent().Configs,e=i,[3,4];case 3:return n=a.sent(),console.warn("AppGetDeviceConfig fail",n),[3,4];case 4:if("*"===r)return[2,e];if("string"==typeof(o=e[r])&&~o.indexOf("{"))try{o=JSON.parse(o)}catch(e){console.warn("parse device value fail",e)}return[2,o]}}))}))},e.prototype.setDeviceConfig=function(e){var t=e.DeviceId,i=e.DeviceKey,r=e.DeviceValue;return"string"!=typeof r&&(r=JSON.stringify(r)),this.appDevSdk.requestApi("AppSetDeviceConfig",{DeviceId:t,DeviceKey:i,DeviceValue:r})},e.prototype.reportBlueToothDeviceData=function(e){var t=e.ProductId,i=e.DeviceName,r=e.Data,n=e.DataTimeStamp;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return r||(r={}),"string"!=typeof r&&(r=JSON.stringify(r)),[2,this.appDevSdk.requestApi("AppReportDataAsDevice",{ProductId:t,DeviceName:i,Data:r,DataTimeStamp:n})]}))}))},e.prototype.getDeviceData=function(e){var t=e.ProductId,i=e.DeviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,this.appDevSdk.requestApi("AppGetDeviceData",{ProductId:t,DeviceName:i})];case 1:e=r.sent().Data;try{return"string"==typeof e&&(e=JSON.parse(e)),[2,e]}catch(e){return console.error("parse json fail",{ProductId:t,DeviceName:i},e),[2,{}]}return[2]}}))}))},e.prototype.reportDeviceEvent=function(e){var t=e.DeviceId,i=e.EventId,r=e.Params;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2,this.appDevSdk.requestApi("AppReportDeviceEvent",{DeviceId:t,EventId:i,Params:r,Method:"ReportEventAsDevice"})]}))}))},e.prototype.addDeviceBySigInFamily=function(e){var t=e.Signature,i=e.DeviceTimestamp,r=e.ProductId,n=e.DeviceName,o=e.DeviceId,a=e.ConnId,c=e.FamilyId,s=e.RoomId,u=e.SignMethod,p=void 0===u?"hmacsha1":u,d=e.BindType,v=void 0===d?"other_sign":d;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return[4,this.appDevSdk.requestApi("AppSigBindDeviceInFamily",{Signature:t,DeviceTimestamp:i,ProductId:r,DeviceName:n,DeviceId:o,ConnId:a,FamilyId:c,RoomId:s,BindType:v,SignMethod:p})];case 1:return[2,e.sent().Data.AppDeviceInfo]}}))}))},e.prototype.deleteDeviceFromFamily=function(e){var t=e.FamilyId,i=e.DeviceId;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2,this.appDevSdk.requestApi("AppDeleteDeviceInFamily",{FamilyId:t,DeviceId:i})]}))}))},e.prototype.publishDeviceActionMessage=function(e){var t=e.productId,i=e.deviceName,r=e.clientToken,n=e.actionId,o=e.output;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,a;return tslib_1.__generator(this,(function(c){return e={method:"action_reply",clientToken:r,ActionId:n,timestamp:Math.floor(Date.now()/1e3),response:o,code:0,status:"action execute success!"},a={ProductId:t,DeviceName:i,Topic:"$thing/up/action/"+t+"/"+i,Payload:JSON.stringify(e)},console.log("---reply action---",a),[2,this.appDevSdk.requestApi("AppPublishMsgAsDevice",a)]}))}))},e.prototype.reportOTAVersion=function(e){var t=e.Version,i=e.DeviceId;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2,this.appDevSdk.requestApi("AppReportFirmwareVersion",{Version:t,DeviceId:i})]}))}))},e.prototype.getDeviceOTAInfo=function(e){var t=e.DeviceId;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2,this.appDevSdk.requestApi("AppGetDeviceOTAInfo",{DeviceId:t})]}))}))},e.prototype.getProduct=function(e){var t=e.ProductId;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return[4,this.appDevSdk.requestApi("AppGetProducts",{ProductIds:[t]})];case 1:return[2,e.sent().Products[0]]}}))}))},e.prototype.getProductConfig=function(e){var t=e.ProductId;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,i;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,this.appDevSdk.requestApi("AppGetProductsConfig",{ProductIds:[t]})];case 1:return e=r.sent().Data,i={},e.forEach((function(e){try{e.Config=JSON.parse(e.Config)}catch(t){e.Config={}}i[e.ProductId]=iotexplorer_ui_dev_config_1.initializeUIDevConfig(e.Config)})),[2,i[t]]}}))}))},e}();exports.Models=Models; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Models=void 0;var tslib_1=require("tslib"),iotexplorer_ui_dev_config_1=require("iotexplorer-ui-dev-config"),Models=function(){function e(e){this.appDevSdk=e}return e.prototype.getDeviceConfig=function(e){var t=e.DeviceId,i=e.DeviceKey,r=void 0===i?"*":i,o=e.isUserConfig,n=void 0!==o&&o;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,i,o,a;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:e={},s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.appDevSdk.requestApi(n?"AppGetUserDeviceConfig":"AppGetDeviceConfig",{DeviceId:t,DeviceKey:r})];case 2:return i=s.sent().Configs,e=i,[3,4];case 3:return o=s.sent(),console.warn("AppGetDeviceConfig fail",o),[3,4];case 4:if("*"===r)return[2,e];if("string"==typeof(a=e[r])&&~a.indexOf("{"))try{a=JSON.parse(a)}catch(e){console.warn("parse device value fail",e)}return[2,a]}}))}))},e.prototype.setDeviceConfig=function(e){var t=e.DeviceId,i=e.DeviceKey,r=e.DeviceValue,o=e.isUserConfig,n=void 0!==o&&o;return"string"!=typeof r&&(r=JSON.stringify(r)),this.appDevSdk.requestApi(n?"AppSetUserDeviceConfig":"AppSetDeviceConfig",{DeviceId:t,DeviceKey:i,DeviceValue:r})},e.prototype.reportBlueToothDeviceData=function(e){var t=e.ProductId,i=e.DeviceName,r=e.Data,o=e.DataTimeStamp;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return r||(r={}),"string"!=typeof r&&(r=JSON.stringify(r)),[2,this.appDevSdk.requestApi("AppReportDataAsDevice",{ProductId:t,DeviceName:i,Data:r,DataTimeStamp:o})]}))}))},e.prototype.getDeviceData=function(e){var t=e.ProductId,i=e.DeviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,this.appDevSdk.requestApi("AppGetDeviceData",{ProductId:t,DeviceName:i})];case 1:e=r.sent().Data;try{return"string"==typeof e&&(e=JSON.parse(e)),[2,e]}catch(e){return console.error("parse json fail",{ProductId:t,DeviceName:i},e),[2,{}]}return[2]}}))}))},e.prototype.reportDeviceEvent=function(e){var t=e.DeviceId,i=e.EventId,r=e.Params;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2,this.appDevSdk.requestApi("AppReportDeviceEvent",{DeviceId:t,EventId:i,Params:r,Method:"ReportEventAsDevice"})]}))}))},e.prototype.addDeviceBySigInFamily=function(e){var t=e.Signature,i=e.DeviceTimestamp,r=e.ProductId,o=e.DeviceName,n=e.DeviceId,a=e.ConnId,s=e.FamilyId,c=e.RoomId,u=e.SignMethod,p=void 0===u?"hmacsha1":u,d=e.BindType,v=void 0===d?"other_sign":d;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return[4,this.appDevSdk.requestApi("AppSigBindDeviceInFamily",{Signature:t,DeviceTimestamp:i,ProductId:r,DeviceName:o,DeviceId:n,ConnId:a,FamilyId:s,RoomId:c,BindType:v,SignMethod:p})];case 1:return[2,e.sent().Data.AppDeviceInfo]}}))}))},e.prototype.deleteDeviceFromFamily=function(e){var t=e.FamilyId,i=e.DeviceId;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2,this.appDevSdk.requestApi("AppDeleteDeviceInFamily",{FamilyId:t,DeviceId:i})]}))}))},e.prototype.publishDeviceActionMessage=function(e){var t=e.productId,i=e.deviceName,r=e.clientToken,o=e.actionId,n=e.output;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,a;return tslib_1.__generator(this,(function(s){return e={method:"action_reply",clientToken:r,ActionId:o,timestamp:Math.floor(Date.now()/1e3),response:n,code:0,status:"action execute success!"},a={ProductId:t,DeviceName:i,Topic:"$thing/up/action/"+t+"/"+i,Payload:JSON.stringify(e)},console.log("---reply action---",a),[2,this.appDevSdk.requestApi("AppPublishMsgAsDevice",a)]}))}))},e.prototype.reportOTAVersion=function(e){var t=e.Version,i=e.DeviceId;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2,this.appDevSdk.requestApi("AppReportFirmwareVersion",{Version:t,DeviceId:i})]}))}))},e.prototype.getDeviceOTAInfo=function(e){var t=e.DeviceId;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2,this.appDevSdk.requestApi("AppGetDeviceOTAInfo",{DeviceId:t})]}))}))},e.prototype.getProduct=function(e){var t=e.ProductId;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return[4,this.appDevSdk.requestApi("AppGetProducts",{ProductIds:[t]})];case 1:return[2,e.sent().Products[0]]}}))}))},e.prototype.getProductConfig=function(e){var t=e.ProductId;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,i;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,this.appDevSdk.requestApi("AppGetProductsConfig",{ProductIds:[t]})];case 1:return e=r.sent().Data,i={},e.forEach((function(e){try{e.Config=JSON.parse(e.Config)}catch(t){e.Config={}}i[e.ProductId]=iotexplorer_ui_dev_config_1.initializeUIDevConfig(e.Config)})),[2,i[t]]}}))}))},e}();exports.Models=Models; | ||
//# sourceMappingURL=Models.js.map |
@@ -0,1 +1,5 @@ | ||
import { StandardDeviceAdapter } from '../base'; | ||
declare class Adapter4H5 extends StandardDeviceAdapter { | ||
constructor(props: any); | ||
} | ||
export declare const StandardDeviceAdapter4H5: (new (...props: any[]) => { | ||
@@ -14,3 +18,3 @@ write(data: any, writeId: any): Promise<void>; | ||
characteristicsMap: {}; | ||
_actions: Pick<import("qcloud-iotexplorer-bluetooth-adapter").BlueToothActions, "registerDevice" | "bindDevice" | "reportDeviceData">; | ||
_actions: Pick<import("qcloud-iotexplorer-bluetooth-adapter/lib/base/types").BlueToothActions, "registerDevice" | "bindDevice" | "reportDeviceData">; | ||
_bluetoothApi: any; | ||
@@ -89,2 +93,3 @@ _getNotifyId({ serviceId }?: { | ||
emit: (type: any, ...argus: any[]) => Promise<any>; | ||
}) & typeof import("../base").LLSyncDeviceAdapter; | ||
}) & typeof Adapter4H5; | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StandardDeviceAdapter4H5=void 0;var qcloud_iotexplorer_bluetooth_adapter_1=require("qcloud-iotexplorer-bluetooth-adapter"),base_1=require("../base");exports.StandardDeviceAdapter4H5=qcloud_iotexplorer_bluetooth_adapter_1.AdapterDeviceAdapter4H5(base_1.StandardDeviceAdapter); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StandardDeviceAdapter4H5=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_bluetooth_adapter_1=require("qcloud-iotexplorer-bluetooth-adapter"),base_1=require("../base"),Adapter4H5=function(e){function r(r){var t=e.call(this,r)||this;return t.on("authorized",(function(){var e;null===(e=t._h5Websocket)||void 0===e||e.send("Control",{action:"llsync_device_authorized",payload:{explorerDeviceId:t.explorerDeviceId,deviceId:t.deviceId}})})),t}return tslib_1.__extends(r,e),r}(base_1.StandardDeviceAdapter);exports.StandardDeviceAdapter4H5=qcloud_iotexplorer_bluetooth_adapter_1.AdapterDeviceAdapter4H5(Adapter4H5); | ||
//# sourceMappingURL=StandardDeviceAdapter.js.map |
@@ -13,3 +13,3 @@ export declare const StandardDeviceAdapter4Mp: (new (...args: any[]) => { | ||
characteristicsMap: {}; | ||
_actions: Pick<import("qcloud-iotexplorer-bluetooth-adapter").BlueToothActions, "registerDevice" | "bindDevice" | "reportDeviceData">; | ||
_actions: Pick<import("qcloud-iotexplorer-bluetooth-adapter/lib/base/types").BlueToothActions, "registerDevice" | "bindDevice" | "reportDeviceData">; | ||
_bluetoothApi: any; | ||
@@ -16,0 +16,0 @@ _getNotifyId({ serviceId }?: { |
{ | ||
"name": "qcloud-iotexplorer-bluetooth-adapter-llsync", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -17,6 +17,6 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@tencent/iotexplorer-ui-dev-config": "^1.0.19", | ||
"event-emitter-for-miniprogram": "^0.0.12", | ||
"qcloud-iotexplorer-appdev-sdk": "^1.1.9", | ||
"qcloud-iotexplorer-bluetooth-adapter": "^0.2.8", | ||
"iotexplorer-ui-dev-config": "^1.0.22", | ||
"qcloud-iotexplorer-appdev-sdk": "^1.1.10", | ||
"qcloud-iotexplorer-bluetooth-adapter": "^0.3.0", | ||
"shortid-for-miniprogram": "^2.2.15", | ||
@@ -26,3 +26,3 @@ "spark-md5": "^3.0.1", | ||
}, | ||
"gitHead": "06ced37b4436e6afe3d1145abd976e25dc0e6b54" | ||
"gitHead": "c8eb9f744772b74877b2d14400331f9889ca986f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
207188
1350
+ Addedevent-emitter-for-miniprogram@0.0.24(transitive)
+ Addediotexplorer-ui-dev-config@1.8.12(transitive)
+ Addedlodash.uniqwith@4.5.0(transitive)
+ Addedqcloud-iotexplorer-bluetooth-adapter@0.3.33(transitive)
+ Addedqcloud-iotexplorer-common-libs@0.0.19(transitive)
- Removedqcloud-iotexplorer-bluetooth-adapter@0.2.8(transitive)