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.10 to 0.0.11

2

lib/core/BlueToothAdapter.d.ts

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

*/
searchDevice({ serviceId, serviceIds, deviceName, explorerDeviceId, ignoreDeviceIds, timeout, extendInfo, }: SearchDeviceParams): any;
searchDevice({ serviceId, serviceIds, deviceName, explorerDeviceId, ignoreDeviceIds, timeout, extendInfo, }: SearchDeviceParams): Promise<DeviceInfo>;
getDeviceAdapter(deviceId: any): any;

@@ -135,0 +135,0 @@ connectDevice({ deviceId, serviceId, mac, deviceName, name, productId, autoNotify, }: {

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

import { BlueToothAdapter, BlueToothAdapterProps, SearchDeviceParams, StartSearchParams } from "../core";
import { BlueToothAdapter, BlueToothAdapterProps, DeviceInfo, SearchDeviceParams, StartSearchParams } from "../core";
/**

@@ -49,3 +49,3 @@ * 小程序版本在核心上拓展了:

startSearch(params: StartSearchParams): Promise<void>;
searchDevice(params: SearchDeviceParams): Promise<void>;
searchDevice(params: SearchDeviceParams): Promise<DeviceInfo>;
}

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlueToothAdapter4Mp=void 0;var tslib_1=require("tslib"),core_1=require("../core"),utillib_1=require("../libs/utillib"),parseAdvertisData=function(e){var t=tslib_1.__assign({},e);if(t.advertisData)try{t.advertisData=utillib_1.arrayBufferToHexStringArray(t.advertisData)}catch(e){console.error("Parse bluetoothe device advertisData fail",e)}return t},BlueToothAdapter4Mp=function(e){function t(t){var s=t.bluetoothApi,r=tslib_1.__rest(t,["bluetoothApi"]),o=e.call(this,tslib_1.__assign({bluetoothApi:s},r))||this;return o._h5ChanelOpened=!1,o._localDiscoveringInUse=!1,o._h5DiscoveringInUse=!1,o._cleanupTimer=null,o._currentProductId="",o._h5Websocket&&"function"==typeof o._h5Websocket.on&&(o.on("adapterStateChange",(function(e){var t=e.available,s=e.discovering;o.response2BlueToothChanel("onBluetoothAdapterStateChange",{available:t,discovering:s})})),o._h5Websocket.on("message",(function(e){var t=e.data,s=e.reqId;return tslib_1.__awaiter(o,void 0,void 0,(function(){var e,r,o,n,i,a,c,l,u,h,p,_,d,v=this;return tslib_1.__generator(this,(function(g){switch(g.label){case 0:switch(console.log("bluetooth ws on message",t),e=t.action,r=t.payload,e){case"bindDevice":return[3,1];case"registryDevice":return[3,5];case"connect":return[3,9];case"disconnect":return[3,10];case"init":return[3,11];case"callApi":return[3,15]}return[3,30];case 1:return g.trys.push([1,3,,4]),n=r.deviceName,i=r.productId,[4,this._actions.bindDevice({productId:this.devMode&&i?i:this._currentProductId,deviceName:n})];case 2:return g.sent(),this.response2BlueToothChanel("response",{code:0},s),[3,4];case 3:return o=g.sent(),this.response2BlueToothChanel("response",o,s),[3,4];case 4:return[3,30];case 5:return g.trys.push([5,7,,8]),n=r.deviceName,i=r.productId,[4,this._actions.registerDevice({productId:this.devMode&&i?i:this._currentProductId,deviceName:n})];case 6:return g.sent(),this.response2BlueToothChanel("response",{code:0},s),[3,8];case 7:return a=g.sent(),this.response2BlueToothChanel("response",a,s),[3,8];case 8:return[3,30];case 9:return console.log("h5chanel opened"),this._h5ChanelOpened=!0,[3,30];case 10:return console.log("h5chanel closed"),this._h5ChanelOpened=!1,this._h5DiscoveringInUse&&this.stopBluetoothDevicesDiscovery(!0),[3,30];case 11:return g.trys.push([11,13,,14]),[4,this.init()];case 12:return g.sent(),this.response2BlueToothChanel("response",{code:0},s),[3,14];case 13:return c=g.sent(),this.response2BlueToothChanel("response",c,s),[3,14];case 14:return[3,30];case 15:l=r.api,u=r.params,g.label=16;case 16:switch(g.trys.push([16,28,,29]),console.log("call api",l,u),l){case"createBLEConnection":return[3,17];case"getBluetoothDevices":return[3,19];case"writeBLECharacteristicValue":return[3,21];case"startBluetoothDevicesDiscovery":return[3,23];case"stopBluetoothDevicesDiscovery":return[3,25]}return[3,27];case 17:return[4,this._bluetoothApi.createBLEConnection(u)];case 18:return g.sent(),this.response2BlueToothChanel("response",{},s),[2];case 19:return[4,this.getBluetoothDevices()];case 20:return h=g.sent(),this.response2BlueToothChanel("response",{devices:h.map(parseAdvertisData)},s),[2];case 21:return p=u.value,console.log("calling writeBLECharacteristicValue",tslib_1.__assign(tslib_1.__assign({},u),{value:utillib_1.hexToArrayBuffer(p)})),[4,this._bluetoothApi.writeBLECharacteristicValue(tslib_1.__assign(tslib_1.__assign({},u),{value:utillib_1.hexToArrayBuffer(p)}))];case 22:return _=g.sent(),this.response2BlueToothChanel("response",_,s),[2];case 23:return[4,this.startBluetoothDevicesDiscovery(!0)];case 24:return _=g.sent(),this.response2BlueToothChanel("response",_,s),[2];case 25:return[4,this.stopBluetoothDevicesDiscovery(!0)];case 26:return _=g.sent(),this.response2BlueToothChanel("response",_,s),[2];case 27:return[3,29];case 28:return d=g.sent(),console.log("call api fail",d),this.response2BlueToothChanel("response",this._normalizeError(d),s),[3,29];case 29:return wx[l]&&wx[l](tslib_1.__assign(tslib_1.__assign({},u),{success:function(e){console.log("call api success",e),v.response2BlueToothChanel("response",e,s)},fail:function(e){console.log("call api fail",e),v.response2BlueToothChanel("response",v._normalizeError(e),s)}})),[3,30];case 30:return[2]}}))}))}))),o}return tslib_1.__extends(t,e),t.prototype.setCurrentProduct=function(e){this._currentProductId=e},t.prototype.startBluetoothDevicesDiscovery=function(t){return void 0===t&&(t=!1),t?this._h5DiscoveringInUse=!0:this._localDiscoveringInUse=!0,e.prototype.startBluetoothDevicesDiscovery.call(this)},t.prototype.stopBluetoothDevicesDiscovery=function(t){if(void 0===t&&(t=!1),console.log("try call stopBluetoothDevicesDiscovery, isFromH5: "+t+", _h5DiscoveringInUse: "+this._h5DiscoveringInUse+", _localDiscoveringInUse: "+this._localDiscoveringInUse),t?this._h5DiscoveringInUse=!1:this._localDiscoveringInUse=!1,this._h5DiscoveringInUse||!this._localDiscoveringInUse)return e.prototype.stopBluetoothDevicesDiscovery.call(this)},t.prototype.response2BlueToothChanel=function(e,t,s){return void 0===t&&(t={}),void 0===s&&(s=""),tslib_1.__awaiter(this,void 0,void 0,(function(){var r;return tslib_1.__generator(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),this._h5ChanelOpened?(console.log("response2BlueToothChanel",e,t),[4,this._h5Websocket.send("Response",{action:e,payload:t},{reqId:s})]):(console.log("h5 chanel not opened"),[2]);case 1:return o.sent(),[3,3];case 2:return r=o.sent(),console.warn("try send bluetooth message fail",r),[3,3];case 3:return[2]}}))}))},t.prototype.startCleanupTimer=function(){var e=this;clearTimeout(this._cleanupTimer),console.log("start cleanup timer"),this._cleanupTimer=setTimeout((function(){console.log("bluetooth searching or deviceMap not empty, reset cleanup timer",e._discovering,e._deviceMap),e._h5ChanelOpened||e._discovering||!utillib_1.isEmpty(e._deviceMap)?e.startCleanupTimer():e.cleanup()}),5e3)},t.prototype.init=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t=this;return tslib_1.__generator(this,(function(s){return[2,e.prototype.init.call(this).then((function(){return t.startCleanupTimer()}))]}))}))},t.prototype.onBleConnectionStateChange=function(t){var s=t.deviceId,r=t.connected;return this.response2BlueToothChanel("onBLEConnectionStateChange",{deviceId:s,connected:r}),e.prototype.onBleConnectionStateChange.call(this,{deviceId:s,connected:r})},t.prototype.onBLECharacteristicValueChange=function(t){var s=t.deviceId,r=t.serviceId,o=t.characteristicId,n=t.value;return this.response2BlueToothChanel("onBLECharacteristicValueChange",{deviceId:s,serviceId:r,characteristicId:o,value:utillib_1.arrayBufferToHexStringArray(n)}),e.prototype.onBLECharacteristicValueChange.call(this,{deviceId:s,serviceId:r,characteristicId:o,value:n})},t.prototype.onBluetoothDeviceFound=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return[4,e.prototype.onBluetoothDeviceFound.call(this)];case 1:return t=s.sent(),this.response2BlueToothChanel("onBluetoothDeviceFound",{devices:t.map(parseAdvertisData)}),[2]}}))}))},t.prototype.startSearch=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return[4,e.prototype.startSearch.call(this,t)];case 1:return s.sent(),this.startCleanupTimer(),[2]}}))}))},t.prototype.searchDevice=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return[4,e.prototype.searchDevice.call(this,t)];case 1:return s.sent(),this.startCleanupTimer(),[2]}}))}))},t}(core_1.BlueToothAdapter);exports.BlueToothAdapter4Mp=BlueToothAdapter4Mp;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlueToothAdapter4Mp=void 0;var tslib_1=require("tslib"),core_1=require("../core"),utillib_1=require("../libs/utillib"),parseAdvertisData=function(e){var t=tslib_1.__assign({},e);if(t.advertisData)try{t.advertisData=utillib_1.arrayBufferToHexStringArray(t.advertisData)}catch(e){console.error("Parse bluetoothe device advertisData fail",e)}return t},BlueToothAdapter4Mp=function(e){function t(t){var s=t.bluetoothApi,r=tslib_1.__rest(t,["bluetoothApi"]),o=e.call(this,tslib_1.__assign({bluetoothApi:s},r))||this;return o._h5ChanelOpened=!1,o._localDiscoveringInUse=!1,o._h5DiscoveringInUse=!1,o._cleanupTimer=null,o._currentProductId="",o._h5Websocket&&"function"==typeof o._h5Websocket.on&&(o.on("adapterStateChange",(function(e){var t=e.available,s=e.discovering;o.response2BlueToothChanel("onBluetoothAdapterStateChange",{available:t,discovering:s})})),o._h5Websocket.on("message",(function(e){var t=e.data,s=e.reqId;return tslib_1.__awaiter(o,void 0,void 0,(function(){var e,r,o,n,i,a,c,l,u,h,p,_,v,d=this;return tslib_1.__generator(this,(function(g){switch(g.label){case 0:switch(console.log("bluetooth ws on message",t),e=t.action,r=t.payload,e){case"bindDevice":return[3,1];case"registryDevice":return[3,5];case"connect":return[3,9];case"disconnect":return[3,10];case"init":return[3,11];case"callApi":return[3,15]}return[3,30];case 1:return g.trys.push([1,3,,4]),n=r.deviceName,i=r.productId,[4,this._actions.bindDevice({productId:this.devMode&&i?i:this._currentProductId,deviceName:n})];case 2:return g.sent(),this.response2BlueToothChanel("response",{code:0},s),[3,4];case 3:return o=g.sent(),this.response2BlueToothChanel("response",o,s),[3,4];case 4:return[3,30];case 5:return g.trys.push([5,7,,8]),n=r.deviceName,i=r.productId,[4,this._actions.registerDevice({productId:this.devMode&&i?i:this._currentProductId,deviceName:n})];case 6:return g.sent(),this.response2BlueToothChanel("response",{code:0},s),[3,8];case 7:return a=g.sent(),this.response2BlueToothChanel("response",a,s),[3,8];case 8:return[3,30];case 9:return console.log("h5chanel opened"),this._h5ChanelOpened=!0,[3,30];case 10:return console.log("h5chanel closed"),this._h5ChanelOpened=!1,this._h5DiscoveringInUse&&this.stopBluetoothDevicesDiscovery(!0),[3,30];case 11:return g.trys.push([11,13,,14]),[4,this.init()];case 12:return g.sent(),this.response2BlueToothChanel("response",{code:0},s),[3,14];case 13:return c=g.sent(),this.response2BlueToothChanel("response",c,s),[3,14];case 14:return[3,30];case 15:l=r.api,u=r.params,g.label=16;case 16:switch(g.trys.push([16,28,,29]),console.log("call api",l,u),l){case"createBLEConnection":return[3,17];case"getBluetoothDevices":return[3,19];case"writeBLECharacteristicValue":return[3,21];case"startBluetoothDevicesDiscovery":return[3,23];case"stopBluetoothDevicesDiscovery":return[3,25]}return[3,27];case 17:return[4,this._bluetoothApi.createBLEConnection(u)];case 18:return g.sent(),this.response2BlueToothChanel("response",{},s),[2];case 19:return[4,this.getBluetoothDevices()];case 20:return h=g.sent(),this.response2BlueToothChanel("response",{devices:h.map(parseAdvertisData)},s),[2];case 21:return p=u.value,console.log("calling writeBLECharacteristicValue",tslib_1.__assign(tslib_1.__assign({},u),{value:utillib_1.hexToArrayBuffer(p)})),[4,this._bluetoothApi.writeBLECharacteristicValue(tslib_1.__assign(tslib_1.__assign({},u),{value:utillib_1.hexToArrayBuffer(p)}))];case 22:return _=g.sent(),this.response2BlueToothChanel("response",_,s),[2];case 23:return[4,this.startBluetoothDevicesDiscovery(!0)];case 24:return _=g.sent(),this.response2BlueToothChanel("response",_,s),[2];case 25:return[4,this.stopBluetoothDevicesDiscovery(!0)];case 26:return _=g.sent(),this.response2BlueToothChanel("response",_,s),[2];case 27:return[3,29];case 28:return v=g.sent(),console.log("call api fail",v),this.response2BlueToothChanel("response",this._normalizeError(v),s),[3,29];case 29:return wx[l]&&wx[l](tslib_1.__assign(tslib_1.__assign({},u),{success:function(e){console.log("call api success",e),d.response2BlueToothChanel("response",e,s)},fail:function(e){console.log("call api fail",e),d.response2BlueToothChanel("response",d._normalizeError(e),s)}})),[3,30];case 30:return[2]}}))}))}))),o}return tslib_1.__extends(t,e),t.prototype.setCurrentProduct=function(e){this._currentProductId=e},t.prototype.startBluetoothDevicesDiscovery=function(t){return void 0===t&&(t=!1),t?this._h5DiscoveringInUse=!0:this._localDiscoveringInUse=!0,e.prototype.startBluetoothDevicesDiscovery.call(this)},t.prototype.stopBluetoothDevicesDiscovery=function(t){if(void 0===t&&(t=!1),console.log("try call stopBluetoothDevicesDiscovery, isFromH5: "+t+", _h5DiscoveringInUse: "+this._h5DiscoveringInUse+", _localDiscoveringInUse: "+this._localDiscoveringInUse),t?this._h5DiscoveringInUse=!1:this._localDiscoveringInUse=!1,this._h5DiscoveringInUse||!this._localDiscoveringInUse)return e.prototype.stopBluetoothDevicesDiscovery.call(this)},t.prototype.response2BlueToothChanel=function(e,t,s){return void 0===t&&(t={}),void 0===s&&(s=""),tslib_1.__awaiter(this,void 0,void 0,(function(){var r;return tslib_1.__generator(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),this._h5ChanelOpened?(console.log("response2BlueToothChanel",e,t),[4,this._h5Websocket.send("Response",{action:e,payload:t},{reqId:s})]):(console.log("h5 chanel not opened"),[2]);case 1:return o.sent(),[3,3];case 2:return r=o.sent(),console.warn("try send bluetooth message fail",r),[3,3];case 3:return[2]}}))}))},t.prototype.startCleanupTimer=function(){var e=this;clearTimeout(this._cleanupTimer),console.log("start cleanup timer"),this._cleanupTimer=setTimeout((function(){console.log("bluetooth searching or deviceMap not empty, reset cleanup timer",e._discovering,e._deviceMap),e._h5ChanelOpened||e._discovering||!utillib_1.isEmpty(e._deviceMap)?e.startCleanupTimer():e.cleanup()}),5e3)},t.prototype.init=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t=this;return tslib_1.__generator(this,(function(s){return[2,e.prototype.init.call(this).then((function(){return t.startCleanupTimer()}))]}))}))},t.prototype.onBleConnectionStateChange=function(t){var s=t.deviceId,r=t.connected;return this.response2BlueToothChanel("onBLEConnectionStateChange",{deviceId:s,connected:r}),e.prototype.onBleConnectionStateChange.call(this,{deviceId:s,connected:r})},t.prototype.onBLECharacteristicValueChange=function(t){var s=t.deviceId,r=t.serviceId,o=t.characteristicId,n=t.value;return this.response2BlueToothChanel("onBLECharacteristicValueChange",{deviceId:s,serviceId:r,characteristicId:o,value:utillib_1.arrayBufferToHexStringArray(n)}),e.prototype.onBLECharacteristicValueChange.call(this,{deviceId:s,serviceId:r,characteristicId:o,value:n})},t.prototype.onBluetoothDeviceFound=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return[4,e.prototype.onBluetoothDeviceFound.call(this)];case 1:return t=s.sent(),this.response2BlueToothChanel("onBluetoothDeviceFound",{devices:t.map(parseAdvertisData)}),[2]}}))}))},t.prototype.startSearch=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return[4,e.prototype.startSearch.call(this,t)];case 1:return s.sent(),this.startCleanupTimer(),[2]}}))}))},t.prototype.searchDevice=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var s;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,e.prototype.searchDevice.call(this,t)];case 1:return s=r.sent(),this.startCleanupTimer(),[2,s]}}))}))},t}(core_1.BlueToothAdapter);exports.BlueToothAdapter4Mp=BlueToothAdapter4Mp;
//# sourceMappingURL=BlueToothAdapter4Mp.js.map
{
"name": "qcloud-iotexplorer-bluetooth-adapter",
"version": "0.0.10",
"version": "0.0.11",
"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