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

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.23 to 0.0.24

4

lib/core/BlueToothAdapter.d.ts

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

}) => Promise<any>;
connectDevice: any;
bindDevice: (params: {

@@ -138,3 +139,3 @@ deviceId?: string;

getDeviceAdapter(deviceId: any): any;
connectDevice({ deviceId, serviceId, mac, deviceName, name, productId, autoNotify, }: {
connectDevice({ deviceId, serviceId, mac, deviceName, name, productId, }: {
deviceId: string;

@@ -146,4 +147,5 @@ serviceId: string;

productId?: string;
}, { autoNotify }?: {
autoNotify?: boolean;
}): Promise<any>;
}

@@ -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.productId,s=e.ignoreDeviceIds,a=void 0===s?[]:s,u=e.ignoreServiceIds,l=void 0===u?[]:u,d=e.extendInfo,h=void 0===d?{}:d;r&&r.length||(r=this._getSupportServiceIds());var v={};l&&l.length&&(l.forEach((function(e){return v[e]=!0})),r=r.filter((function(e){return!v[e]}))),console.log("support serviceIds",r);for(var p=[],_=r.map((function(e){return t._deviceAdapterMap[e].deviceFilter})),f=function(e,t){if(a.find((function(t){return i[e].deviceId===t})))return{value:void 0};for(var o=void 0,s=0,u=_.length;s<u;s++)if(o=_[s](i[e],{serviceIds:r,deviceName:n,productId:c,ignoreDeviceIds:a,ignoreServiceIds:l,extendInfo:h}),n){if(o&&o.deviceName===n)return{value:[o]}}else if(o){p.push(o);break}},b=0,g=i.length;b<g;b++){var D=f(b);if("object"==typeof D)return D.value}return p},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.productId,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;return o&&!i&&(i=[o]),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,c,a,l=this;return tslib_1.__generator(this,(function(h){switch(h.label){case 0:t=function(e){l.stopBluetoothDevicesDiscovery(),o(l._normalizeError(e)),l._searchDevicePromise=null},c=function(t){l.stopBluetoothDevicesDiscovery(),e(t),l._searchDevicePromise=null},this._onBluetoothDeviceFoundHandler=function(e){try{var o=l._filterDevices({devices:e,serviceIds:i,deviceName:r,productId:n,ignoreDeviceIds:s,extendInfo:d});console.log("matchedDevices: ",o),o.length>0&&(console.log("doFindDevice",o[0]),c(o[0]))}catch(e){t(e)}},h.label=1;case 1:return h.trys.push([1,3,,4]),[4,this.startBluetoothDevicesDiscovery()];case 2:return h.sent(),console.log("startBluetoothDevicesDiscovery succ"),this.onBluetoothDeviceFound(),setTimeout((function(){c(null)}),u),[3,4];case 3:return a=h.sent(),t(a),[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 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.productId,s=e.ignoreDeviceIds,a=void 0===s?[]:s,u=e.ignoreServiceIds,l=void 0===u?[]:u,d=e.extendInfo,h=void 0===d?{}:d;r&&r.length||(r=this._getSupportServiceIds());var v={};l&&l.length&&(l.forEach((function(e){return v[e]=!0})),r=r.filter((function(e){return!v[e]}))),console.log("support serviceIds",r);for(var p=[],_=r.map((function(e){return t._deviceAdapterMap[e].deviceFilter})),f=function(e,t){if(a.find((function(t){return i[e].deviceId===t})))return{value:void 0};for(var o=void 0,s=0,u=_.length;s<u;s++)if(o=_[s](i[e],{serviceIds:r,deviceName:n,productId:c,ignoreDeviceIds:a,ignoreServiceIds:l,extendInfo:h}),n){if(o&&o.deviceName===n)return{value:[o]}}else if(o){p.push(o);break}},b=0,g=i.length;b<g;b++){var D=f(b);if("object"==typeof D)return D.value}return p},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.productId,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;return o&&!i&&(i=[o]),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,c,a,l=this;return tslib_1.__generator(this,(function(h){switch(h.label){case 0:t=function(e){l.stopBluetoothDevicesDiscovery(),o(l._normalizeError(e)),l._searchDevicePromise=null},c=function(t){l.stopBluetoothDevicesDiscovery(),e(t),l._searchDevicePromise=null},this._onBluetoothDeviceFoundHandler=function(e){try{var o=l._filterDevices({devices:e,serviceIds:i,deviceName:r,productId:n,ignoreDeviceIds:s,extendInfo:d});console.log("matchedDevices: ",o),o.length>0&&(console.log("doFindDevice",o[0]),c(o[0]))}catch(e){t(e)}},h.label=1;case 1:return h.trys.push([1,3,,4]),[4,this.startBluetoothDevicesDiscovery()];case 2:return h.sent(),console.log("startBluetoothDevicesDiscovery succ"),this.onBluetoothDeviceFound(),setTimeout((function(){c(null)}),u),[3,4];case 3:return a=h.sent(),t(a),[3,4];case 4:return[2]}}))}))})))},t.prototype.getDeviceAdapter=function(e){return this._deviceMap[e]},t.prototype.connectDevice=function(e,t){var o=e.deviceId,i=e.serviceId,r=e.mac,n=e.deviceName,c=e.name,s=e.productId,a=(void 0===t?{}:t).autoNotify;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,u,l=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:r&&console.warn("[DEPRECATED] mac is deprecated, please use deviceName instead."),n=n||r,d.label=1;case 1:if(d.trys.push([1,3,,4]),!(e=this._deviceAdapterMap[i]))throw"无匹配serviceId为"+i+"的 deviceAdapter";return this._deviceMap[o]&&this._deviceMap[o].isConnected?(console.log("find device adapter",this._deviceMap[o]),[2,this._deviceMap[o]]):[4,(t=this._deviceMap[o]=new e({deviceId:o,deviceName:n,productId:s||this._productIdMap[i],name:c,actions:this._actions,bluetoothApi:this._bluetoothApi})).connectDevice({autoNotify:a})];case 2:return d.sent(),console.log("deviceConnected"),t.on("disconnect",(function(){console.log("ondisconnect, cleanup adapter",t),delete l._deviceMap[o]})),console.log("return adapter"),[2,t];case 3:return u=d.sent(),delete this._deviceMap[o],[2,Promise.reject(u)];case 4:return[2]}}))}))},t}(BlueToothBase_1.BlueToothBase);exports.BlueToothAdapter=BlueToothAdapter;
//# sourceMappingURL=BlueToothAdapter.js.map
{
"name": "qcloud-iotexplorer-bluetooth-adapter",
"version": "0.0.23",
"version": "0.0.24",
"description": "",

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

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