Socket
Socket
Sign inDemoInstall

qcloud-iotexplorer-bluetooth-adapter

Package Overview
Dependencies
Maintainers
1
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qcloud-iotexplorer-bluetooth-adapter - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

2

lib/core/BlueToothAdapter.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlueToothAdapter=void 0;var tslib_1=require("tslib"),utillib_1=require("../libs/utillib"),BlueToothBase_1=require("./BlueToothBase"),DeviceAdapter_1=require("./DeviceAdapter"),nativeBluetoothApi_1=tslib_1.__importDefault(require("./nativeBluetoothApi")),throttle_1=require("../libs/throttle"),BlueToothAdapter=function(e){function t(t){var o=t.deviceAdapters,i=void 0===o?[]:o,r=t.actions,n=t.bluetoothApi,c=t.h5Websocket,s=t.devMode,a=e.call(this)||this;return a._devMode=!1,a._bluetoothApi={},a._actions={},a._deviceAdapterMap={},a._productIdMap={},a._deviceMap={},a._inited=!1,a._available=!1,a._discovering=!1,a._onBluetoothDeviceFoundHandler=null,a._initPromise=null,a._searchDevicePromise=null,a._devMode=s,a.addAdapter(i),utillib_1.isEmpty(a._deviceAdapterMap)&&console.warn("无合法的deviceAdapter"),a._h5Websocket=c,a._bluetoothApi=n||nativeBluetoothApi_1.default,a._actions=r,a}return tslib_1.__extends(t,e),Object.defineProperty(t.prototype,"devMode",{get:function(){return"function"==typeof this._devMode?this._devMode():this._devMode},enumerable:!1,configurable:!0}),t.prototype.addAdapter=function(e){var t=this,o=function(e){Object.prototype.isPrototypeOf.call(DeviceAdapter_1.DeviceAdapter,e)?e.serviceId?t._deviceAdapterMap[e.serviceId]=e:console.error("非法的设备适配器,未配置serviceId",e):console.error("非法的设备适配器",e)};e&&e.splice?e.forEach(o):o(e)},t.prototype._filterDevices=function(e){var t=this,o=e.devices,i=void 0===o?[]:o,r=e.serviceIds,n=e.deviceName,c=e.ignoreDeviceIds,s=void 0===c?[]:c,a=e.ignoreServiceIds,u=void 0===a?[]:a,l=e.extendInfo,d=void 0===l?{}:l;r&&r.length||(r=this._getSupportServiceIds());var h={};u&&u.length&&(u.forEach((function(e){return h[e]=!0})),r=r.filter((function(e){return!h[e]}))),console.log("support serviceIds",r);for(var v=[],p=r.map((function(e){return t._deviceAdapterMap[e].deviceFilter})),_=function(e,t){if(s.find((function(t){return i[e].deviceId===t})))return{value:void 0};for(var o=void 0,r=0,c=p.length;r<c;r++)if(o=p[r](i[r],d),n){if(o&&o.deviceName===n)return{value:[o]}}else if(o){v.push(o);break}},f=0,b=i.length;f<b;f++){var g=_(f);if("object"==typeof g)return g.value}return v},t.prototype._getSupportServiceIds=function(){return Object.keys(this._deviceAdapterMap)},t.prototype.startBluetoothDevicesDiscovery=function(){return this._bluetoothApi.startBluetoothDevicesDiscovery()},t.prototype.stopBluetoothDevicesDiscovery=function(e){return void 0===e&&(e=!1),this._bluetoothApi.stopBluetoothDevicesDiscovery()},t.prototype.cleanup=function(t){var o=this;e.prototype.cleanup.call(this,t),t||(console.log("cleanup bluetooth adapter"),this._discovering&&this.stopBluetoothDevicesDiscovery(),this._bluetoothApi.closeBluetoothAdapter(),console.log("manually disconnect all device",this._deviceMap),Object.keys(this._deviceMap).forEach((function(e){o._deviceMap[e]&&o._deviceMap[e].disconnectDevice()})))},t.prototype.init=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e=this;return tslib_1.__generator(this,(function(t){return[2,this._initPromise||(this._initPromise=new Promise((function(t,o){return tslib_1.__awaiter(e,void 0,void 0,(function(){var e,i,r,n,c,s,a=this;return tslib_1.__generator(this,(function(u){switch(u.label){case 0:if(u.trys.push([0,4,,5]),this._inited){if(this._available)return this._initPromise=null,[2,t()];throw{errCode:10001}}return[4,this.initProductIds()];case 1:return u.sent(),e=function(e){var o=e.available,i=e.discovering;console.log("onBluetoothAdapterStateChange",{available:o,discovering:i}),a._available=o,a._discovering=i,a.emit("adapterStateChange",{available:o,discovering:i}),o?(a._inited=!0,t(),a._initPromise=null):a.cleanup()},i=function(e){return a.onBleConnectionStateChange(e)},r=function(e){return a.onBLECharacteristicValueChange(e)},n=throttle_1.throttle(1e3,(function(e){return a.onBluetoothDeviceFound(e)})),this._bluetoothApi.onBluetoothAdapterStateChange(e),this._bluetoothApi.onBLEConnectionStateChange(i),this._bluetoothApi.onBLECharacteristicValueChange(r),this._bluetoothApi.onBluetoothDeviceFound(n),this.addCleanupTask("init",(function(){a._available=a._discovering=a._inited=!1,a._initPromise=null,a._bluetoothApi.offBluetoothAdapterStateChange(e),a._bluetoothApi.offBLEConnectionStateChange(i),a._bluetoothApi.offBLECharacteristicValueChange(r),a._bluetoothApi.offBluetoothDeviceFound(n),a._bluetoothApi.closeBluetoothAdapter()})),[4,this._bluetoothApi.openBluetoothAdapter()];case 2:return u.sent(),c=e,[4,this._bluetoothApi.getBluetoothAdapterState()];case 3:return c.apply(void 0,[u.sent()]),[3,5];case 4:return s=u.sent(),this._available=!1,this._inited=!1,this._initPromise=null,o(this._normalizeError(s)),[3,5];case 5:return[2]}}))}))})))]}))}))},t.prototype.initProductIds=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"function"!=typeof this._actions.initProductIds?[3,2]:(e=this,[4,this._actions.initProductIds()]);case 1:e._productIdMap=t.sent(),t.label=2;case 2:return[2]}}))}))},t.prototype.onBleConnectionStateChange=function(e){var t=e.deviceId,o=e.connected;console.log("onBLEConnectionStateChange",t,o);var i=this.getDeviceAdapter(t);i?i.onBleConnectionStateChange({connected:o}):console.warn("on bLEConnectionStateChange, but no adapter")},t.prototype.onBLECharacteristicValueChange=function(e){var t=e.deviceId,o=e.serviceId,i=e.characteristicId,r=e.value;console.log("onBLECharacteristicValueChange",t,o,i,r);var n=this._deviceMap[t];if(n)return n.onBLECharacteristicValueChange({serviceId:o,characteristicId:i,value:r});console.warn("on onBLECharacteristicValueChange, but no adapter")},t.prototype.getBluetoothDevices=function(){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._bluetoothApi.getBluetoothDevices()];case 1:return[2,e.sent().devices.filter((function(e){return"未知设备"!==e.name}))]}}))}))},t.prototype.onBluetoothDeviceFound=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.getBluetoothDevices()];case 1:e=t.sent();try{"function"==typeof this._onBluetoothDeviceFoundHandler&&this._onBluetoothDeviceFoundHandler(e)}catch(e){console.error("_onBluetoothDeviceFoundHandler error",e)}return[2,e]}}))}))},t.prototype.startSearch=function(e){var t=e.serviceId,o=e.serviceIds,i=e.ignoreDeviceIds,r=void 0===i?[]:i,n=e.ignoreServiceIds,c=void 0===n?[]:n,s=e.onSearch,a=void 0===s?utillib_1.noop:s,u=e.onError,l=void 0===u?utillib_1.noop:u,d=e.timeout,h=void 0===d?2e4:d,v=e.extendInfo,p=void 0===v?{}:v;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,i,n,s,u=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:t&&!o&&(o=[t]),e=0,i=function(e){u.stopSearch(),l(e)},d.label=1;case 1:return d.trys.push([1,3,,4]),[4,this.startBluetoothDevicesDiscovery()];case 2:return d.sent(),this._onBluetoothDeviceFoundHandler=function(t){try{var n=u._filterDevices({devices:t,serviceIds:o,ignoreDeviceIds:r,ignoreServiceIds:c,extendInfo:p});e=n.length,a(n)}catch(e){console.log("onSearch error",e),i(u._normalizeError(e))}},this.onBluetoothDeviceFound(),n=function(e){e.available||i(u._normalizeError({errCode:10001}))},this.on("adapterStateChange",n),this.addCleanupTask("startSearch",(function(){u._onBluetoothDeviceFoundHandler=null,u.off("adapterStateChange",n)})),setTimeout((function(){e||i("未发现设备,请确认设备已开启")}),h),[3,4];case 3:throw s=d.sent(),this.cleanup("startSearch"),this._normalizeError(s);case 4:return[2]}}))}))},t.prototype.stopSearch=function(){this.cleanup("startSearch"),this.stopBluetoothDevicesDiscovery()},t.prototype.searchDevice=function(e){var t=this,o=e.serviceId,i=e.serviceIds,r=e.deviceName,n=e.explorerDeviceId,c=e.ignoreDeviceIds,s=void 0===c?[]:c,a=e.timeout,u=void 0===a?5e3:a,l=e.extendInfo,d=void 0===l?{}:l;if(o&&!i&&(i=[o]),!r&&n){var h=tslib_1.__read(n.split("/"),2)[1];r=h}return console.log("searching for explorerDeviceId => ",r),this._searchDevicePromise||(this._searchDevicePromise=new Promise((function(e,o){return tslib_1.__awaiter(t,void 0,void 0,(function(){var t,n,c,a=this;return tslib_1.__generator(this,(function(l){switch(l.label){case 0:t=function(e){a.stopBluetoothDevicesDiscovery(),o(a._normalizeError(e)),a._searchDevicePromise=null},n=function(t){a.stopBluetoothDevicesDiscovery(),e(t),a._searchDevicePromise=null},this._onBluetoothDeviceFoundHandler=function(e){try{var o=a._filterDevices({devices:e,serviceIds:i,deviceName:r,ignoreDeviceIds:s,extendInfo:d});console.log("matchedDevices: ",o),o.length>0&&(console.log("doFindDevice",o[0]),n(o[0]))}catch(e){t(e)}},l.label=1;case 1:return l.trys.push([1,3,,4]),[4,this.startBluetoothDevicesDiscovery()];case 2:return l.sent(),console.log("startBluetoothDevicesDiscovery succ"),this.onBluetoothDeviceFound(),setTimeout((function(){n(null)}),u),[3,4];case 3:return c=l.sent(),t(c),[3,4];case 4:return[2]}}))}))})))},t.prototype.getDeviceAdapter=function(e){return this._deviceMap[e]},t.prototype.connectDevice=function(e){var t=e.deviceId,o=e.serviceId,i=e.mac,r=e.deviceName,n=e.name,c=e.productId,s=e.autoNotify;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,a,u,l=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:i&&console.warn("[DEPRECATED] mac is deprecated, please use deviceName instead."),r=r||i,d.label=1;case 1:if(d.trys.push([1,3,,4]),!(e=this._deviceAdapterMap[o]))throw"无匹配serviceId为"+o+"的 deviceAdapter";return this._deviceMap[t]&&this._deviceMap[t].isConnected?(console.log("find device adapter",this._deviceMap[t]),[2,this._deviceMap[t]]):[4,(a=this._deviceMap[t]=new e({deviceId:t,deviceName:r,productId:c||this._productIdMap[o],name:n,actions:this._actions,bluetoothApi:this._bluetoothApi})).connectDevice({autoNotify:s})];case 2:return d.sent(),console.log("deviceConnected"),a.on("disconnect",(function(){console.log("ondisconnect, cleanup adapter",a),delete l._deviceMap[t]})),console.log("return adapter"),[2,a];case 3:return u=d.sent(),delete this._deviceMap[t],[2,Promise.reject(u)];case 4:return[2]}}))}))},t}(BlueToothBase_1.BlueToothBase);exports.BlueToothAdapter=BlueToothAdapter;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlueToothAdapter=void 0;var tslib_1=require("tslib"),utillib_1=require("../libs/utillib"),BlueToothBase_1=require("./BlueToothBase"),DeviceAdapter_1=require("./DeviceAdapter"),nativeBluetoothApi_1=tslib_1.__importDefault(require("./nativeBluetoothApi")),throttle_1=require("../libs/throttle"),BlueToothAdapter=function(e){function t(t){var i=t.deviceAdapters,o=void 0===i?[]:i,r=t.actions,n=t.bluetoothApi,c=t.h5Websocket,s=t.devMode,a=e.call(this)||this;return a._devMode=!1,a._bluetoothApi={},a._actions={},a._deviceAdapterMap={},a._productIdMap={},a._deviceMap={},a._inited=!1,a._available=!1,a._discovering=!1,a._onBluetoothDeviceFoundHandler=null,a._initPromise=null,a._searchDevicePromise=null,a._devMode=s,a.addAdapter(o),utillib_1.isEmpty(a._deviceAdapterMap)&&console.warn("无合法的deviceAdapter"),a._h5Websocket=c,a._bluetoothApi=n||nativeBluetoothApi_1.default,a._actions=r,a}return tslib_1.__extends(t,e),Object.defineProperty(t.prototype,"devMode",{get:function(){return"function"==typeof this._devMode?this._devMode():this._devMode},enumerable:!1,configurable:!0}),t.prototype.addAdapter=function(e){var t=this,i=function(e){Object.prototype.isPrototypeOf.call(DeviceAdapter_1.DeviceAdapter,e)?e.serviceId?t._deviceAdapterMap[e.serviceId]=e:console.error("非法的设备适配器,未配置serviceId",e):console.error("非法的设备适配器",e)};e&&e.splice?e.forEach(i):i(e)},t.prototype._filterDevices=function(e){var t=this,i=e.devices,o=void 0===i?[]:i,r=e.serviceIds,n=e.deviceName,c=e.ignoreDeviceIds,s=void 0===c?[]:c,a=e.ignoreServiceIds,u=void 0===a?[]:a,l=e.extendInfo,d=void 0===l?{}:l;r&&r.length||(r=this._getSupportServiceIds());var h={};u&&u.length&&(u.forEach((function(e){return h[e]=!0})),r=r.filter((function(e){return!h[e]}))),console.log("support serviceIds",r);for(var v=[],p=r.map((function(e){return t._deviceAdapterMap[e].deviceFilter})),_=function(e,t){if(s.find((function(t){return o[e].deviceId===t})))return{value:void 0};for(var i=void 0,c=0,a=p.length;c<a;c++)if(i=p[c](o[c],{serviceIds:r,deviceName:n,ignoreDeviceIds:s,ignoreServiceIds:u,extendInfo:d}),n){if(i&&i.deviceName===n)return{value:[i]}}else if(i){v.push(i);break}},f=0,b=o.length;f<b;f++){var g=_(f);if("object"==typeof g)return g.value}return v},t.prototype._getSupportServiceIds=function(){return Object.keys(this._deviceAdapterMap)},t.prototype.startBluetoothDevicesDiscovery=function(){return this._bluetoothApi.startBluetoothDevicesDiscovery()},t.prototype.stopBluetoothDevicesDiscovery=function(e){return void 0===e&&(e=!1),this._bluetoothApi.stopBluetoothDevicesDiscovery()},t.prototype.cleanup=function(t){var i=this;e.prototype.cleanup.call(this,t),t||(console.log("cleanup bluetooth adapter"),this._discovering&&this.stopBluetoothDevicesDiscovery(),this._bluetoothApi.closeBluetoothAdapter(),console.log("manually disconnect all device",this._deviceMap),Object.keys(this._deviceMap).forEach((function(e){i._deviceMap[e]&&i._deviceMap[e].disconnectDevice()})))},t.prototype.init=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e=this;return tslib_1.__generator(this,(function(t){return[2,this._initPromise||(this._initPromise=new Promise((function(t,i){return tslib_1.__awaiter(e,void 0,void 0,(function(){var e,o,r,n,c,s,a=this;return tslib_1.__generator(this,(function(u){switch(u.label){case 0:if(u.trys.push([0,4,,5]),this._inited){if(this._available)return this._initPromise=null,[2,t()];throw{errCode:10001}}return[4,this.initProductIds()];case 1:return u.sent(),e=function(e){var i=e.available,o=e.discovering;console.log("onBluetoothAdapterStateChange",{available:i,discovering:o}),a._available=i,a._discovering=o,a.emit("adapterStateChange",{available:i,discovering:o}),i?(a._inited=!0,t(),a._initPromise=null):a.cleanup()},o=function(e){return a.onBleConnectionStateChange(e)},r=function(e){return a.onBLECharacteristicValueChange(e)},n=throttle_1.throttle(1e3,(function(e){return a.onBluetoothDeviceFound(e)})),this._bluetoothApi.onBluetoothAdapterStateChange(e),this._bluetoothApi.onBLEConnectionStateChange(o),this._bluetoothApi.onBLECharacteristicValueChange(r),this._bluetoothApi.onBluetoothDeviceFound(n),this.addCleanupTask("init",(function(){a._available=a._discovering=a._inited=!1,a._initPromise=null,a._bluetoothApi.offBluetoothAdapterStateChange(e),a._bluetoothApi.offBLEConnectionStateChange(o),a._bluetoothApi.offBLECharacteristicValueChange(r),a._bluetoothApi.offBluetoothDeviceFound(n),a._bluetoothApi.closeBluetoothAdapter()})),[4,this._bluetoothApi.openBluetoothAdapter()];case 2:return u.sent(),c=e,[4,this._bluetoothApi.getBluetoothAdapterState()];case 3:return c.apply(void 0,[u.sent()]),[3,5];case 4:return s=u.sent(),this._available=!1,this._inited=!1,this._initPromise=null,i(this._normalizeError(s)),[3,5];case 5:return[2]}}))}))})))]}))}))},t.prototype.initProductIds=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"function"!=typeof this._actions.initProductIds?[3,2]:(e=this,[4,this._actions.initProductIds()]);case 1:e._productIdMap=t.sent(),t.label=2;case 2:return[2]}}))}))},t.prototype.onBleConnectionStateChange=function(e){var t=e.deviceId,i=e.connected;console.log("onBLEConnectionStateChange",t,i);var o=this.getDeviceAdapter(t);o?o.onBleConnectionStateChange({connected:i}):console.warn("on bLEConnectionStateChange, but no adapter")},t.prototype.onBLECharacteristicValueChange=function(e){var t=e.deviceId,i=e.serviceId,o=e.characteristicId,r=e.value;console.log("onBLECharacteristicValueChange",t,i,o,r);var n=this._deviceMap[t];if(n)return n.onBLECharacteristicValueChange({serviceId:i,characteristicId:o,value:r});console.warn("on onBLECharacteristicValueChange, but no adapter")},t.prototype.getBluetoothDevices=function(){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._bluetoothApi.getBluetoothDevices()];case 1:return[2,e.sent().devices.filter((function(e){return"未知设备"!==e.name}))]}}))}))},t.prototype.onBluetoothDeviceFound=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.getBluetoothDevices()];case 1:e=t.sent();try{"function"==typeof this._onBluetoothDeviceFoundHandler&&this._onBluetoothDeviceFoundHandler(e)}catch(e){console.error("_onBluetoothDeviceFoundHandler error",e)}return[2,e]}}))}))},t.prototype.startSearch=function(e){var t=e.serviceId,i=e.serviceIds,o=e.ignoreDeviceIds,r=void 0===o?[]:o,n=e.ignoreServiceIds,c=void 0===n?[]:n,s=e.onSearch,a=void 0===s?utillib_1.noop:s,u=e.onError,l=void 0===u?utillib_1.noop:u,d=e.timeout,h=void 0===d?2e4:d,v=e.extendInfo,p=void 0===v?{}:v;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,o,n,s,u=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:t&&!i&&(i=[t]),e=0,o=function(e){u.stopSearch(),l(e)},d.label=1;case 1:return d.trys.push([1,3,,4]),[4,this.startBluetoothDevicesDiscovery()];case 2:return d.sent(),this._onBluetoothDeviceFoundHandler=function(t){try{var n=u._filterDevices({devices:t,serviceIds:i,ignoreDeviceIds:r,ignoreServiceIds:c,extendInfo:p});e=n.length,a(n)}catch(e){console.log("onSearch error",e),o(u._normalizeError(e))}},this.onBluetoothDeviceFound(),n=function(e){e.available||o(u._normalizeError({errCode:10001}))},this.on("adapterStateChange",n),this.addCleanupTask("startSearch",(function(){u._onBluetoothDeviceFoundHandler=null,u.off("adapterStateChange",n)})),setTimeout((function(){e||o("未发现设备,请确认设备已开启")}),h),[3,4];case 3:throw s=d.sent(),this.cleanup("startSearch"),this._normalizeError(s);case 4:return[2]}}))}))},t.prototype.stopSearch=function(){this.cleanup("startSearch"),this.stopBluetoothDevicesDiscovery()},t.prototype.searchDevice=function(e){var t=this,i=e.serviceId,o=e.serviceIds,r=e.deviceName,n=e.explorerDeviceId,c=e.ignoreDeviceIds,s=void 0===c?[]:c,a=e.timeout,u=void 0===a?5e3:a,l=e.extendInfo,d=void 0===l?{}:l;if(i&&!o&&(o=[i]),!r&&n){var h=tslib_1.__read(n.split("/"),2)[1];r=h}return console.log("searching for explorerDeviceId => ",r),this._searchDevicePromise||(this._searchDevicePromise=new Promise((function(e,i){return tslib_1.__awaiter(t,void 0,void 0,(function(){var t,n,c,a=this;return tslib_1.__generator(this,(function(l){switch(l.label){case 0:t=function(e){a.stopBluetoothDevicesDiscovery(),i(a._normalizeError(e)),a._searchDevicePromise=null},n=function(t){a.stopBluetoothDevicesDiscovery(),e(t),a._searchDevicePromise=null},this._onBluetoothDeviceFoundHandler=function(e){try{var i=a._filterDevices({devices:e,serviceIds:o,deviceName:r,ignoreDeviceIds:s,extendInfo:d});console.log("matchedDevices: ",i),i.length>0&&(console.log("doFindDevice",i[0]),n(i[0]))}catch(e){t(e)}},l.label=1;case 1:return l.trys.push([1,3,,4]),[4,this.startBluetoothDevicesDiscovery()];case 2:return l.sent(),console.log("startBluetoothDevicesDiscovery succ"),this.onBluetoothDeviceFound(),setTimeout((function(){n(null)}),u),[3,4];case 3:return c=l.sent(),t(c),[3,4];case 4:return[2]}}))}))})))},t.prototype.getDeviceAdapter=function(e){return this._deviceMap[e]},t.prototype.connectDevice=function(e){var t=e.deviceId,i=e.serviceId,o=e.mac,r=e.deviceName,n=e.name,c=e.productId,s=e.autoNotify;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,a,u,l=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:o&&console.warn("[DEPRECATED] mac is deprecated, please use deviceName instead."),r=r||o,d.label=1;case 1:if(d.trys.push([1,3,,4]),!(e=this._deviceAdapterMap[i]))throw"无匹配serviceId为"+i+"的 deviceAdapter";return this._deviceMap[t]&&this._deviceMap[t].isConnected?(console.log("find device adapter",this._deviceMap[t]),[2,this._deviceMap[t]]):[4,(a=this._deviceMap[t]=new e({deviceId:t,deviceName:r,productId:c||this._productIdMap[i],name:n,actions:this._actions,bluetoothApi:this._bluetoothApi})).connectDevice({autoNotify:s})];case 2:return d.sent(),console.log("deviceConnected"),a.on("disconnect",(function(){console.log("ondisconnect, cleanup adapter",a),delete l._deviceMap[t]})),console.log("return adapter"),[2,a];case 3:return u=d.sent(),delete this._deviceMap[t],[2,Promise.reject(u)];case 4:return[2]}}))}))},t}(BlueToothBase_1.BlueToothBase);exports.BlueToothAdapter=BlueToothAdapter;
//# sourceMappingURL=BlueToothAdapter.js.map

@@ -14,3 +14,10 @@ /// <reference types="miniprogram-api-typings" />

export declare type DeviceAdapterActions = Omit<BlueToothActions, 'initProductIds'>;
export declare type DeviceFilterFunction = (deviceInfo: WechatMiniprogram.BlueToothDevice, extendInfo?: any) => DeviceInfo | void | false | null;
export interface DeviceFilterExtendInfo {
serviceIds?: string[];
deviceName?: string;
ignoreDeviceIds?: string[];
ignoreServiceIds?: string[];
extendInfo?: any;
}
export declare type DeviceFilterFunction = (deviceInfo: WechatMiniprogram.BlueToothDevice, extendInfo?: DeviceFilterExtendInfo) => DeviceInfo | void | false | null;
/**

@@ -17,0 +24,0 @@ * 设备适配器

{
"name": "qcloud-iotexplorer-bluetooth-adapter",
"version": "0.0.11",
"version": "0.0.12",
"description": "",

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

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