Socket
Socket
Sign inDemoInstall

qcloud-iotexplorer-bluetooth-adapter

Package Overview
Dependencies
5
Maintainers
5
Versions
164
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.11.1-alpha.0 to 0.11.2-alpha.0

2

lib/base/DeviceAdapter.d.ts

@@ -52,2 +52,3 @@ /// <reference types="miniprogram-api-typings" />

_deviceRegistered: boolean;
_characteristicsAutoNotified: boolean;
_services: any[];

@@ -119,2 +120,3 @@ characteristicsMap: {};

}): Promise<void>;
autoNotifyCharacteristics(force?: boolean): Promise<void>;
write(data: any, { writeId, serviceId, }?: {

@@ -121,0 +123,0 @@ writeId?: string;

2

lib/base/DeviceAdapter.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DeviceAdapter=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),BlueToothBase_1=require("./BlueToothBase"),types_1=require("./types"),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,arrayBufferToHexStringArray=_a.arrayBufferToHexStringArray,hexToArrayBuffer=_a.hexToArrayBuffer,DeviceAdapter=function(e){function t(t){var i=t.deviceId,r=t.productId,c=t.deviceName,o=t.name,n=t.actions,s=t.bluetoothApi,a=t.h5Websocket,d=t.extendInfo,u=void 0===d?{}:d,h=t.bluetoothAdapter,v=e.call(this)||this;if(v.extendInfo={},v._name="",v._deviceId="",v._deviceName="",v._deviceConnected=!1,v._productId="",v._deviceRegistered=!1,v._services=[],v.characteristicsMap={},v._actions={},v._bluetoothApi={},!i)throw"无deviceId";if(!r)throw"productId为空";return v._h5Websocket=a,v._bluetoothApi=s,v._actions=n,v._name=o,v._deviceName=c,v._deviceId=i,v._productId=r,v.extendInfo=u||{},v.bluetoothAdapter=h,v.communicationMode=types_1.CommunicationMode.GATT,v}return tslib_1.__extends(t,e),t.prototype._getNotifyId=function(e){var t=(void 0===e?{}:e).serviceId,i=void 0===t?"":t;i=i||this.serviceId;var r=this.characteristicsMap[i]||{writeIds:[],notifyIds:[],readIds:[],indicateIds:[]};return r.notifyIds[0]||r.indicateIds[0]},Object.defineProperty(t.prototype,"_writeId",{get:function(){return((this.characteristicsMap[this.serviceId]||{}).writeIds||[])[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_notifyId",{get:function(){return((this.characteristicsMap[this.serviceId]||{}).notifyIds||[])[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_readId",{get:function(){return((this.characteristicsMap[this.serviceId]||{}).readIds||[])[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_indicateId",{get:function(){return((this.characteristicsMap[this.serviceId]||{}).indicateIds||[])[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"deviceId",{get:function(){return this._deviceId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"productId",{get:function(){return this._productId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"deviceName",{get:function(){return this._deviceName},set:function(e){this._deviceName=e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isConnected",{get:function(){return this._deviceConnected},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"originName",{get:function(){return this._name},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"explorerDeviceId",{get:function(){return[this._productId||"",this._deviceName||""].join("/")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"serviceId",{get:function(){return this.constructor.serviceId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"deviceInfo",{get:function(){return{productId:this.productId,deviceName:this.deviceName,deviceId:this.deviceId,explorerDeviceId:this.explorerDeviceId,name:this.originName}},enumerable:!1,configurable:!0}),t.prototype.init=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return this.bluetoothAdapter?[4,this.bluetoothAdapter.init()]:[3,2];case 1:return e.sent(),[3,3];case 2:console.warn("DeviceAdapter未注入bluetoothAdapter实例,可能使用的不是最新版本的qcloud-iotexplorer-bluetooth-adapter模块"),e.label=3;case 3:return[2]}}))}))},t.prototype.handleBLEMessage=function(e,t){t.serviceId,t.characteristicId;return{}},t.prototype.registerDevice=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return this._deviceRegistered?[3,2]:[4,this._actions.registerDevice({deviceId:this.explorerDeviceId,deviceName:this._deviceName,productId:this._productId})];case 1:e.sent(),this._deviceRegistered=!0,e.label=2;case 2:return[2]}}))}))},t.prototype.bindDevice=function(e){var t=void 0===e?{}:e,i=t.familyId,r=void 0===i?"":i,c=t.roomId,o=void 0===c?"":c;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),[4,this.registerDevice()];case 1:return i.sent(),e={deviceId:this.explorerDeviceId,deviceName:this._deviceName,productId:this._productId,familyId:r,roomId:o},[4,this._actions.bindDevice(e)];case 2:return i.sent(),this.emit("bind",e),[2,this.explorerDeviceId];case 3:return t=i.sent(),[2,Promise.reject(this._normalizeError(t))];case 4:return[2]}}))}))},t.prototype.onBleConnectionStateChange=function(e){var t=e.connected;console.log("onBleConnectionStateChange => ",t);var i=this._deviceConnected!==t;this._deviceConnected=t,i&&(t?this.emit("connect",tslib_1.__assign({},this.deviceInfo)):this.emit("disconnect",tslib_1.__assign({},this.deviceInfo)),this.emit("bLEConnectionStateChange",{connected:t}))},t.prototype.onBLECharacteristicValueChange=function(e){var t=e.serviceId,i=e.characteristicId,r=e.value;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,c,o,n,s,a,d,u;return tslib_1.__generator(this,(function(h){switch(h.label){case 0:return h.trys.push([0,4,,5]),e=r,r instanceof ArrayBuffer&&(e=arrayBufferToHexStringArray(r)),c=this.handleBLEMessage(e,{serviceId:t,characteristicId:i})||{},o=c.shouldIgnore,n=c.reportData,s=tslib_1.__rest(c,["shouldIgnore","reportData"]),o?[2]:(console.log("[DeviceAdapter] receive data:",e,s),a=Date.now(),d=!1,this._deviceName&&n?(d=!0,"function"!=typeof this._actions.reportDeviceData?[3,2]:[4,this._actions.reportDeviceData({deviceId:this.explorerDeviceId,deviceName:this._deviceName,productId:this._productId,data:n,timestamp:a})]):[3,3]);case 1:return h.sent(),[3,3];case 2:console.warn("handleBLEMessage return should report but actions.reportDeviceData is not implement."),h.label=3;case 3:return this.emit("message",tslib_1.__assign(tslib_1.__assign({},s),{timestamp:a,dataReported:d})),[3,5];case 4:return u=h.sent(),console.error("onBLECharacteristicValueChange onError,",u),[3,5];case 5:return[2]}}))}))},t.prototype.disconnectDevice=function(){this._bluetoothApi.closeBLEConnection({deviceId:this._deviceId}),this._deviceConnected=!1,this.emit("disconnect",tslib_1.__assign({},this.deviceInfo))},t.prototype.connectDevice=function(e){var t=(void 0===e?{}:e).autoNotify,i=void 0===t||t;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r,c,o,n;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:e=Date.now(),s.label=1;case 1:return s.trys.push([1,10,,11]),[4,this.init()];case 2:return s.sent(),console.log("start connect device",this.deviceInfo),this.isConnected?(console.log("device is already connected",this.deviceInfo),[2]):(t=Date.now(),[4,this._bluetoothApi.createBLEConnection({deviceId:this._deviceId})]);case 3:if(s.sent(),this._deviceConnected=!0,console.log("createBLEConnection succ",Date.now()-t),!i)return[3,9];s.label=4;case 4:return s.trys.push([4,8,,9]),t=Date.now(),[4,this.getBLEDeviceServices()];case 5:return r=s.sent(),console.log("getBLEDeviceServices succ",r,Date.now()-t),this.emit("onGetBLEDeviceServices",r),t=Date.now(),[4,this.getBLEDeviceCharacteristics()];case 6:return c=s.sent(),console.log("getBLEDeviceCharacteristics succ",c,Date.now()-t),this.emit("onGetBLEDeviceCharacteristics",c),t=Date.now(),[4,this.notifyBLECharacteristicValueChange()];case 7:return s.sent(),console.log("notifyBLECharacteristicValueChange succ",Date.now()-t),[3,9];case 8:throw o=s.sent(),this.isConnected&&this.disconnectDevice(),o;case 9:return console.log("connectDevice succeed, time cost: ",Date.now()-e),[3,11];case 10:return n=s.sent(),(n=this._normalizeError(n)).errMsg&&n.errMsg.indexOf("already connect")>-1?(console.log("device is already connected, resolve directly, time cost: ",Date.now()-e),[2,Promise.resolve()]):(console.error("connectDevice error",n),[2,Promise.reject(n)]);case 11:return[2]}}))}))},t.prototype.write=function(e,t){var i=void 0===t?{}:t,r=i.writeId,c=void 0===r?"":r,o=i.serviceId,n=void 0===o?"":o;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(t){if("string"==typeof e)console.log("writeBLECharacteristicValue",e),e=hexToArrayBuffer(e);else if(e instanceof ArrayBuffer)try{console.log("writeBLECharacteristicValue",arrayBufferToHexStringArray(e).join(""))}catch(e){}return[2,this._write(e,{writeId:c,serviceId:n})]}))}))},t.prototype._write=function(e,t){var i=void 0===t?{}:t,r=i.writeId,c=void 0===r?"":r,o=i.serviceId,n=void 0===o?"":o;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._bluetoothApi.writeBLECharacteristicValue({deviceId:this._deviceId,characteristicId:c||this._writeId,serviceId:n||this.serviceId,value:e})];case 1:return i.sent(),[3,3];case 2:return t=i.sent(),[2,Promise.reject(this._normalizeError(t))];case 3:return[2]}}))}))},t.prototype.getBLEDeviceServices=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(t){switch(t.label){case 0:return[4,this._bluetoothApi.getBLEDeviceServices({deviceId:this._deviceId})];case 1:return e=t.sent().services,this._services=e,[2,e]}}))}))},t.prototype.setCharacteristicsIds=function(e,t){var i={notifyIds:[],writeIds:[],indicateIds:[],readIds:[]},r=function(e,t){-1===e.indexOf(t)&&e.push(t)};t.forEach((function(e){var t=e.uuid,c=e.properties,o=c.notify,n=c.write,s=c.indicate,a=c.read;o?r(i.notifyIds,t):n?r(i.writeIds,t):s?r(i.indicateIds,t):a&&r(i.readIds,t)})),this.characteristicsMap[e]=i},t.prototype.getBLEDeviceCharacteristics=function(e){var t=(void 0===e?{}:e).serviceId,i=void 0===t?"":t;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(t){switch(t.label){case 0:return i=i||this.serviceId,[4,this._bluetoothApi.getBLEDeviceCharacteristics({deviceId:this._deviceId,serviceId:i})];case 1:return e=t.sent().characteristics,this.setCharacteristicsIds(i,e),[2,e]}}))}))},t.prototype.notifyBLECharacteristicValueChange=function(e){var t=void 0===e?{}:e,i=t.characteristicId,r=void 0===i?"":i,c=t.serviceId,o=void 0===c?"":c,n=t.state,s=void 0===n||n;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return r=r||this._getNotifyId(),o=o||this.serviceId,r?[3,1]:(console.warn("未找到指定service下的notifyId,该设备可能不支持notify"),[3,3]);case 1:return[4,this._bluetoothApi.notifyBLECharacteristicValueChange({deviceId:this._deviceId,characteristicId:r,serviceId:o,state:s})];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},t.prototype.readBLECharacteristicValue=function(e){var t=void 0===e?{}:e,i=t.serviceId,r=void 0===i?"":i,c=t.characteristicId,o=void 0===c?"":c;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return r=r||this.serviceId,o||(o=((this.characteristicsMap[this.serviceId]||{}).readIds||[])[0]),o?[3,1]:(console.warn("未找到指定service下的readId,该设备可能不支持read"),[3,3]);case 1:return[4,this._bluetoothApi.readBLECharacteristicValue({deviceId:this._deviceId,characteristicId:o,serviceId:r})];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},t.prototype.setBLEMTU=function(e){return this._bluetoothApi.setBLEMTU(tslib_1.__assign({deviceId:this._deviceId},e))},t.prototype.getBLEDeviceRSSI=function(){return this._bluetoothApi.getBLEDeviceRSSI({deviceId:this._deviceId})},t.prototype.destroy=function(){this.emit("destroy")},t.prototype.advertFilter=function(e){return null},t.prototype.onScanAdvert=function(e){},t.serviceId="",t.deviceFilter=function(e,t){},t}(BlueToothBase_1.BlueToothBase);exports.DeviceAdapter=DeviceAdapter;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DeviceAdapter=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),BlueToothBase_1=require("./BlueToothBase"),types_1=require("./types"),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,arrayBufferToHexStringArray=_a.arrayBufferToHexStringArray,hexToArrayBuffer=_a.hexToArrayBuffer,DeviceAdapter=function(e){function t(t){var i=t.deviceId,r=t.productId,o=t.deviceName,c=t.name,s=t.actions,n=t.bluetoothApi,a=t.h5Websocket,d=t.extendInfo,u=void 0===d?{}:d,h=t.bluetoothAdapter,v=e.call(this)||this;if(v.extendInfo={},v._name="",v._deviceId="",v._deviceName="",v._deviceConnected=!1,v._productId="",v._deviceRegistered=!1,v._characteristicsAutoNotified=!1,v._services=[],v.characteristicsMap={},v._actions={},v._bluetoothApi={},!i)throw"无deviceId";if(!r)throw"productId为空";return v._h5Websocket=a,v._bluetoothApi=n,v._actions=s,v._name=c,v._deviceName=o,v._deviceId=i,v._productId=r,v.extendInfo=u||{},v.bluetoothAdapter=h,v.communicationMode=types_1.CommunicationMode.GATT,v.on("disconnect",(function(){v._characteristicsAutoNotified=!1})),v}return tslib_1.__extends(t,e),t.prototype._getNotifyId=function(e){var t=(void 0===e?{}:e).serviceId,i=void 0===t?"":t;i=i||this.serviceId;var r=this.characteristicsMap[i]||{writeIds:[],notifyIds:[],readIds:[],indicateIds:[]};return r.notifyIds[0]||r.indicateIds[0]},Object.defineProperty(t.prototype,"_writeId",{get:function(){return((this.characteristicsMap[this.serviceId]||{}).writeIds||[])[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_notifyId",{get:function(){return((this.characteristicsMap[this.serviceId]||{}).notifyIds||[])[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_readId",{get:function(){return((this.characteristicsMap[this.serviceId]||{}).readIds||[])[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_indicateId",{get:function(){return((this.characteristicsMap[this.serviceId]||{}).indicateIds||[])[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"deviceId",{get:function(){return this._deviceId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"productId",{get:function(){return this._productId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"deviceName",{get:function(){return this._deviceName},set:function(e){this._deviceName=e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isConnected",{get:function(){return this._deviceConnected},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"originName",{get:function(){return this._name},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"explorerDeviceId",{get:function(){return[this._productId||"",this._deviceName||""].join("/")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"serviceId",{get:function(){return this.constructor.serviceId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"deviceInfo",{get:function(){return{productId:this.productId,deviceName:this.deviceName,deviceId:this.deviceId,explorerDeviceId:this.explorerDeviceId,name:this.originName}},enumerable:!1,configurable:!0}),t.prototype.init=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return this.bluetoothAdapter?[4,this.bluetoothAdapter.init()]:[3,2];case 1:return e.sent(),[3,3];case 2:console.warn("DeviceAdapter未注入bluetoothAdapter实例,可能使用的不是最新版本的qcloud-iotexplorer-bluetooth-adapter模块"),e.label=3;case 3:return[2]}}))}))},t.prototype.handleBLEMessage=function(e,t){t.serviceId,t.characteristicId;return{}},t.prototype.registerDevice=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return this._deviceRegistered?[3,2]:[4,this._actions.registerDevice({deviceId:this.explorerDeviceId,deviceName:this._deviceName,productId:this._productId})];case 1:e.sent(),this._deviceRegistered=!0,e.label=2;case 2:return[2]}}))}))},t.prototype.bindDevice=function(e){var t=void 0===e?{}:e,i=t.familyId,r=void 0===i?"":i,o=t.roomId,c=void 0===o?"":o;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),[4,this.registerDevice()];case 1:return i.sent(),e={deviceId:this.explorerDeviceId,deviceName:this._deviceName,productId:this._productId,familyId:r,roomId:c},[4,this._actions.bindDevice(e)];case 2:return i.sent(),this.emit("bind",e),[2,this.explorerDeviceId];case 3:return t=i.sent(),[2,Promise.reject(this._normalizeError(t))];case 4:return[2]}}))}))},t.prototype.onBleConnectionStateChange=function(e){var t=e.connected;console.log("onBleConnectionStateChange => ",t);var i=this._deviceConnected!==t;this._deviceConnected=t,i&&(t?this.emit("connect",tslib_1.__assign({},this.deviceInfo)):this.emit("disconnect",tslib_1.__assign({},this.deviceInfo)),this.emit("bLEConnectionStateChange",{connected:t}))},t.prototype.onBLECharacteristicValueChange=function(e){var t=e.serviceId,i=e.characteristicId,r=e.value;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,o,c,s,n,a,d,u;return tslib_1.__generator(this,(function(h){switch(h.label){case 0:return h.trys.push([0,4,,5]),e=r,r instanceof ArrayBuffer&&(e=arrayBufferToHexStringArray(r)),o=this.handleBLEMessage(e,{serviceId:t,characteristicId:i})||{},c=o.shouldIgnore,s=o.reportData,n=tslib_1.__rest(o,["shouldIgnore","reportData"]),c?[2]:(console.log("[DeviceAdapter] receive data:",e,n),a=Date.now(),d=!1,this._deviceName&&s?(d=!0,"function"!=typeof this._actions.reportDeviceData?[3,2]:[4,this._actions.reportDeviceData({deviceId:this.explorerDeviceId,deviceName:this._deviceName,productId:this._productId,data:s,timestamp:a})]):[3,3]);case 1:return h.sent(),[3,3];case 2:console.warn("handleBLEMessage return should report but actions.reportDeviceData is not implement."),h.label=3;case 3:return this.emit("message",tslib_1.__assign(tslib_1.__assign({},n),{timestamp:a,dataReported:d})),[3,5];case 4:return u=h.sent(),console.error("onBLECharacteristicValueChange onError,",u),[3,5];case 5:return[2]}}))}))},t.prototype.disconnectDevice=function(){this._bluetoothApi.closeBLEConnection({deviceId:this._deviceId}),this._deviceConnected=!1,this.emit("disconnect",tslib_1.__assign({},this.deviceInfo))},t.prototype.connectDevice=function(e){var t=(void 0===e?{}:e).autoNotify,i=void 0===t||t;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r;return tslib_1.__generator(this,(function(o){switch(o.label){case 0:e=Date.now(),o.label=1;case 1:return o.trys.push([1,4,,5]),[4,this.init()];case 2:return o.sent(),console.log("start connect device",this.deviceInfo),this.isConnected?(console.log("device is already connected",this.deviceInfo),[2]):(t=Date.now(),[4,this._bluetoothApi.createBLEConnection({deviceId:this._deviceId})]);case 3:if(o.sent(),this._deviceConnected=!0,console.log("createBLEConnection succ",Date.now()-t),i)try{this.autoNotifyCharacteristics(!0)}catch(e){throw this.isConnected&&this.disconnectDevice(),e}return console.log("connectDevice succeed, time cost: ",Date.now()-e),[3,5];case 4:return r=o.sent(),(r=this._normalizeError(r)).errMsg&&r.errMsg.indexOf("already connect")>-1?(console.log("device is already connected, resolve directly, time cost: ",Date.now()-e),[2,Promise.resolve()]):(console.error("connectDevice error",r),[2,Promise.reject(r)]);case 5:return[2]}}))}))},t.prototype.autoNotifyCharacteristics=function(e){return void 0===e&&(e=!1),tslib_1.__awaiter(this,void 0,void 0,(function(){var t,i,r;return tslib_1.__generator(this,(function(o){switch(o.label){case 0:return this._characteristicsAutoNotified&&!e?(console.log("[DeviceAdapter.autoNotifyCharacteristics] characteristics already notified, no operation performed"),[2]):(t=Date.now(),[4,this.getBLEDeviceServices()]);case 1:return i=o.sent(),console.log("getBLEDeviceServices succ",i,Date.now()-t),this.emit("onGetBLEDeviceServices",i),t=Date.now(),[4,this.getBLEDeviceCharacteristics()];case 2:return r=o.sent(),console.log("getBLEDeviceCharacteristics succ",r,Date.now()-t),this.emit("onGetBLEDeviceCharacteristics",r),t=Date.now(),[4,this.notifyBLECharacteristicValueChange()];case 3:return o.sent(),console.log("notifyBLECharacteristicValueChange succ",Date.now()-t),this._characteristicsAutoNotified=!0,[2]}}))}))},t.prototype.write=function(e,t){var i=void 0===t?{}:t,r=i.writeId,o=void 0===r?"":r,c=i.serviceId,s=void 0===c?"":c;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(t){if("string"==typeof e)console.log("writeBLECharacteristicValue",e),e=hexToArrayBuffer(e);else if(e instanceof ArrayBuffer)try{console.log("writeBLECharacteristicValue",arrayBufferToHexStringArray(e).join(""))}catch(e){}return[2,this._write(e,{writeId:o,serviceId:s})]}))}))},t.prototype._write=function(e,t){var i=void 0===t?{}:t,r=i.writeId,o=void 0===r?"":r,c=i.serviceId,s=void 0===c?"":c;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._bluetoothApi.writeBLECharacteristicValue({deviceId:this._deviceId,characteristicId:o||this._writeId,serviceId:s||this.serviceId,value:e})];case 1:return i.sent(),[3,3];case 2:return t=i.sent(),[2,Promise.reject(this._normalizeError(t))];case 3:return[2]}}))}))},t.prototype.getBLEDeviceServices=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(t){switch(t.label){case 0:return[4,this._bluetoothApi.getBLEDeviceServices({deviceId:this._deviceId})];case 1:return e=t.sent().services,this._services=e,[2,e]}}))}))},t.prototype.setCharacteristicsIds=function(e,t){var i={notifyIds:[],writeIds:[],indicateIds:[],readIds:[]},r=function(e,t){-1===e.indexOf(t)&&e.push(t)};t.forEach((function(e){var t=e.uuid,o=e.properties,c=o.notify,s=o.write,n=o.indicate,a=o.read;c?r(i.notifyIds,t):s?r(i.writeIds,t):n?r(i.indicateIds,t):a&&r(i.readIds,t)})),this.characteristicsMap[e]=i},t.prototype.getBLEDeviceCharacteristics=function(e){var t=(void 0===e?{}:e).serviceId,i=void 0===t?"":t;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(t){switch(t.label){case 0:return i=i||this.serviceId,[4,this._bluetoothApi.getBLEDeviceCharacteristics({deviceId:this._deviceId,serviceId:i})];case 1:return e=t.sent().characteristics,this.setCharacteristicsIds(i,e),[2,e]}}))}))},t.prototype.notifyBLECharacteristicValueChange=function(e){var t=void 0===e?{}:e,i=t.characteristicId,r=void 0===i?"":i,o=t.serviceId,c=void 0===o?"":o,s=t.state,n=void 0===s||s;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return r=r||this._getNotifyId(),c=c||this.serviceId,r?[3,1]:(console.warn("未找到指定service下的notifyId,该设备可能不支持notify"),[3,3]);case 1:return[4,this._bluetoothApi.notifyBLECharacteristicValueChange({deviceId:this._deviceId,characteristicId:r,serviceId:c,state:n})];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},t.prototype.readBLECharacteristicValue=function(e){var t=void 0===e?{}:e,i=t.serviceId,r=void 0===i?"":i,o=t.characteristicId,c=void 0===o?"":o;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return r=r||this.serviceId,c||(c=((this.characteristicsMap[this.serviceId]||{}).readIds||[])[0]),c?[3,1]:(console.warn("未找到指定service下的readId,该设备可能不支持read"),[3,3]);case 1:return[4,this._bluetoothApi.readBLECharacteristicValue({deviceId:this._deviceId,characteristicId:c,serviceId:r})];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},t.prototype.setBLEMTU=function(e){return this._bluetoothApi.setBLEMTU(tslib_1.__assign({deviceId:this._deviceId},e))},t.prototype.getBLEDeviceRSSI=function(){return this._bluetoothApi.getBLEDeviceRSSI({deviceId:this._deviceId})},t.prototype.destroy=function(){this.emit("destroy")},t.prototype.advertFilter=function(e){return null},t.prototype.onScanAdvert=function(e){},t.serviceId="",t.deviceFilter=function(e,t){},t}(BlueToothBase_1.BlueToothBase);exports.DeviceAdapter=DeviceAdapter;
//# sourceMappingURL=DeviceAdapter.js.map

@@ -15,2 +15,3 @@ import { DeviceAdapter } from '../base';

_deviceRegistered: boolean;
_characteristicsAutoNotified: boolean;
_services: any[];

@@ -64,2 +65,3 @@ characteristicsMap: {};

}): Promise<void>;
autoNotifyCharacteristics(force?: boolean): Promise<void>;
_write(value: any, { writeId, serviceId, }?: {

@@ -114,2 +116,3 @@ writeId?: string;

_deviceRegistered: boolean;
_characteristicsAutoNotified: boolean;
_services: any[];

@@ -163,2 +166,3 @@ characteristicsMap: {};

}): Promise<void>;
autoNotifyCharacteristics(force?: boolean): Promise<void>;
_write(value: any, { writeId, serviceId, }?: {

@@ -165,0 +169,0 @@ writeId?: string;

@@ -14,2 +14,3 @@ import { DeviceAdapter } from '../base';

_deviceRegistered: boolean;
_characteristicsAutoNotified: boolean;
_services: any[];

@@ -63,2 +64,3 @@ characteristicsMap: {};

}): Promise<void>;
autoNotifyCharacteristics(force?: boolean): Promise<void>;
write(data: any, { writeId, serviceId, }?: {

@@ -116,2 +118,3 @@ writeId?: string;

_deviceRegistered: boolean;
_characteristicsAutoNotified: boolean;
_services: any[];

@@ -165,2 +168,3 @@ characteristicsMap: {};

}): Promise<void>;
autoNotifyCharacteristics(force?: boolean): Promise<void>;
write(data: any, { writeId, serviceId, }?: {

@@ -167,0 +171,0 @@ writeId?: string;

{
"name": "qcloud-iotexplorer-bluetooth-adapter",
"version": "0.11.1-alpha.0",
"version": "0.11.2-alpha.0",
"description": "",

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

},
"gitHead": "4b94a1153454fdc36d7b53e5beee31362b68e7bc"
"gitHead": "632c146c29217f586da47f75b48bbbba41dabe35"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc