qcloud-iotexplorer-bluetooth-adapter
Advanced tools
Comparing version 0.4.7 to 0.5.0
@@ -21,2 +21,3 @@ import { BlueToothAdapter } from '../base'; | ||
onBluetoothDeviceFound({ devices }?: any): Promise<any>; | ||
private syncDeviceConnectStatus; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlueToothAdapter4H5=void 0;var tslib_1=require("tslib"),base_1=require("../base"),BlueToothBridge_1=require("./BlueToothBridge"),BlueToothAdapter4H5=function(e){function t(t){var o=t.h5Websocket,r=t.devMode,i=t.actions,n=tslib_1.__rest(t,["h5Websocket","devMode","actions"]),s=this,u=new BlueToothBridge_1.BlueToothBridge({h5Websocket:o});return(s=e.call(this,tslib_1.__assign({actions:tslib_1.__assign({registerDevice:function(e){var t=e.deviceName,o=e.productId;return tslib_1.__awaiter(s,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return[4,u.control("registryDevice",{deviceName:t,productId:this.devMode?o:""})];case 1:return e.sent(),[2]}}))}))},bindDevice:function(e){var t=e.deviceName,o=e.productId;return tslib_1.__awaiter(s,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return[4,u.control("bindDevice",{deviceName:t,productId:this.devMode?o:""})];case 1:return e.sent(),[2]}}))}))}},i),devMode:r,h5Websocket:o,bluetoothApi:u},n))||this)._onDeviceFoundThrottle=0,s._blueToothBridge=u,s}return tslib_1.__extends(t,e),t.prototype.onBluetoothDeviceFound=function(e){var t=(void 0===e?{}:e).devices;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return t?[3,2]:[4,this.getBluetoothDevices()];case 1:return t=e.sent(),console.log("onBluetoothDeviceFound from getBluetoothDevices",t),[3,3];case 2:console.log("onBluetoothDeviceFound from mp event",t),e.label=3;case 3:try{"function"==typeof this._onBluetoothDeviceFoundHandler&&this._onBluetoothDeviceFoundHandler(t)}catch(e){console.error("_onBluetoothDeviceFoundHandler error",e)}return[2,t]}}))}))},t}(base_1.BlueToothAdapter);exports.BlueToothAdapter4H5=BlueToothAdapter4H5; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlueToothAdapter4H5=void 0;var tslib_1=require("tslib"),base_1=require("../base"),BlueToothBridge_1=require("./BlueToothBridge"),BlueToothAdapter4H5=function(e){function t(t){var o=t.h5Websocket,n=t.devMode,i=t.actions,r=tslib_1.__rest(t,["h5Websocket","devMode","actions"]),c=this,s=new BlueToothBridge_1.BlueToothBridge({h5Websocket:o});return(c=e.call(this,tslib_1.__assign({actions:tslib_1.__assign({registerDevice:function(e){var t=e.deviceName,o=e.productId;return tslib_1.__awaiter(c,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return[4,s.control("registryDevice",{deviceName:t,productId:this.devMode?o:""})];case 1:return e.sent(),[2]}}))}))},bindDevice:function(e){var t=e.deviceName,o=e.productId;return tslib_1.__awaiter(c,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return[4,s.control("bindDevice",{deviceName:t,productId:this.devMode?o:""})];case 1:return e.sent(),[2]}}))}))}},i),devMode:n,h5Websocket:o,bluetoothApi:s},r))||this)._onDeviceFoundThrottle=0,c._blueToothBridge=s,c._h5Websocket.on("connect",(function(){c.syncDeviceConnectStatus()})),c._h5Websocket.on("message",(function(e){e&&"connect"===e.action&&c.syncDeviceConnectStatus()})),c}return tslib_1.__extends(t,e),t.prototype.onBluetoothDeviceFound=function(e){var t=(void 0===e?{}:e).devices;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){switch(e.label){case 0:return t?[3,2]:[4,this.getBluetoothDevices()];case 1:return t=e.sent(),console.log("onBluetoothDeviceFound from getBluetoothDevices",t),[3,3];case 2:console.log("onBluetoothDeviceFound from mp event",t),e.label=3;case 3:try{"function"==typeof this._onBluetoothDeviceFoundHandler&&this._onBluetoothDeviceFoundHandler(t)}catch(e){console.error("_onBluetoothDeviceFoundHandler error",e)}return[2,t]}}))}))},t.prototype.syncDeviceConnectStatus=function(){var e=this._deviceAdapterStore.getAll().filter((function(e){return e.isConnected})).map((function(e){return{deviceId:e.deviceId,connected:e.isConnected}}));e.length&&this._blueToothBridge.control("syncDeviceConnectStatus",{devices:e})},t}(base_1.BlueToothAdapter);exports.BlueToothAdapter4H5=BlueToothAdapter4H5; | ||
//# sourceMappingURL=BlueToothAdapter4H5.js.map |
@@ -23,2 +23,3 @@ import { BlueToothAdapter, BlueToothDeviceInfo } from '../base'; | ||
}[]; | ||
_mpBleConnectionStateCache: Record<string, boolean>; | ||
constructor({ bluetoothApi, ...props }: BlueToothAdapterProps); | ||
@@ -65,2 +66,3 @@ tryCancelDisconnectDevice(deviceId: any): boolean; | ||
searchDevice(params: SearchDeviceParams): Promise<BlueToothDeviceInfo>; | ||
cleanup(action?: string): void; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlueToothAdapter4Mp=void 0;var tslib_1=require("tslib"),base_1=require("../base"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,arrayBufferToHexStringArray=_a.arrayBufferToHexStringArray,hexToArrayBuffer=_a.hexToArrayBuffer,parseAdvertisData=function(e){var t=tslib_1.__assign({},e);if(t.advertisData)try{t.advertisData=arrayBufferToHexStringArray(t.advertisData)}catch(e){console.error("Parse bluetoothe device advertisData fail",e)}return t},BlueToothAdapter4Mp=function(e){function t(t){var o=t.bluetoothApi,r=tslib_1.__rest(t,["bluetoothApi"]),s=e.call(this,tslib_1.__assign({bluetoothApi:o},r))||this;return s._h5ChanelOpened=!1,s._localDiscoveringInUse=!1,s._h5DiscoveringInUse=!1,s._cleanupTimer=null,s._currentProductId="",s.handleH5WsMessage=null,s.deviceDelayDisconnectQueue=[],s._h5Websocket&&"function"==typeof s._h5Websocket.on&&(s.on("adapterStateChange",(function(e){var t=e.available,o=e.discovering;s.response2BlueToothChanel("onBluetoothAdapterStateChange",{available:t,discovering:o})})),s._h5Websocket.on("message",(function(e){var t=e.data,o=e.reqId;return tslib_1.__awaiter(s,void 0,void 0,(function(){var e,r,s,n,i,c,a,l,u,h,d,p,v,_,g,f,D=this;return tslib_1.__generator(this,(function(y){switch(y.label){case 0:if(console.log("bluetooth ws on message",t),"function"==typeof this.handleH5WsMessage)try{if(this.handleH5WsMessage({data:t,reqId:o}))return console.log("h5 message already handled by handleH5WsMessage implement."),[2]}catch(e){console.error("call handleH5WsMessage error",e)}switch(e=t.action,r=t.payload,e){case"reportDeviceConnectStatus":return[3,1];case"bindDevice":return[3,2];case"registryDevice":return[3,6];case"connect":return[3,10];case"disconnect":return[3,11];case"init":return[3,12];case"callApi":return[3,16]}return[3,31];case 1:return s=r.connected,n=r.explorerDeviceId,i=r.deviceId,this.onDeviceConnectStatusChange({connected:s,explorerDeviceId:n,deviceId:i}),[3,31];case 2:return y.trys.push([2,4,,5]),a=r.deviceName,l=r.productId,[4,this._actions.bindDevice({productId:this.devMode&&l?l:this._currentProductId,deviceName:a})];case 3:return y.sent(),this.response2BlueToothChanel("response",{code:0},o),[3,5];case 4:return c=y.sent(),this.response2BlueToothChanel("response",c,o),[3,5];case 5:return[3,31];case 6:return y.trys.push([6,8,,9]),a=r.deviceName,l=r.productId,[4,this._actions.registerDevice({productId:this.devMode&&l?l:this._currentProductId,deviceName:a})];case 7:return y.sent(),this.response2BlueToothChanel("response",{code:0},o),[3,9];case 8:return u=y.sent(),this.response2BlueToothChanel("response",u,o),[3,9];case 9:return[3,31];case 10:return console.log("h5chanel opened"),this._h5ChanelOpened=!0,[3,31];case 11:return console.log("h5chanel closed"),this._h5ChanelOpened=!1,this._h5DiscoveringInUse&&this.stopBluetoothDevicesDiscovery(!0),[3,31];case 12:return y.trys.push([12,14,,15]),[4,this.init()];case 13:return y.sent(),this.response2BlueToothChanel("response",{code:0},o),[3,15];case 14:return h=y.sent(),this.response2BlueToothChanel("response",h,o),[3,15];case 15:return[3,31];case 16:d=r.api,p=r.params,y.label=17;case 17:switch(y.trys.push([17,29,,30]),console.log("call api",d,p),d){case"createBLEConnection":return[3,18];case"getBluetoothDevices":return[3,20];case"writeBLECharacteristicValue":return[3,22];case"startBluetoothDevicesDiscovery":return[3,24];case"stopBluetoothDevicesDiscovery":return[3,26]}return[3,28];case 18:return this.tryCancelDisconnectDevice(p.deviceId),[4,this._bluetoothApi.createBLEConnection(p)];case 19:return y.sent(),this.response2BlueToothChanel("response",{},o),[2];case 20:return[4,this.getBluetoothDevices()];case 21:return v=y.sent(),this.response2BlueToothChanel("response",{devices:v.map(parseAdvertisData)},o),[2];case 22:return _=p.value,console.log("calling writeBLECharacteristicValue",tslib_1.__assign(tslib_1.__assign({},p),{value:hexToArrayBuffer(_)})),[4,this._bluetoothApi.writeBLECharacteristicValue(tslib_1.__assign(tslib_1.__assign({},p),{value:hexToArrayBuffer(_)}))];case 23:return g=y.sent(),this.response2BlueToothChanel("response",g,o),[2];case 24:return[4,this.startBluetoothDevicesDiscovery(!0)];case 25:return g=y.sent(),this.response2BlueToothChanel("response",g,o),[2];case 26:return[4,this.stopBluetoothDevicesDiscovery(!0)];case 27:return g=y.sent(),this.response2BlueToothChanel("response",g,o),[2];case 28:return[3,30];case 29:return f=y.sent(),console.error("[BlueToothAdapter4Mp] call bluetoothApi fail",f),this.response2BlueToothChanel("response",this._normalizeError(f),o),[3,30];case 30:return wx[d]&&wx[d](tslib_1.__assign(tslib_1.__assign({},p),{success:function(e){console.log("[BlueToothAdapter4Mp] call wx api success",e),D.response2BlueToothChanel("response",e,o)},fail:function(e){console.log("call api fail",e),D.response2BlueToothChanel("response",D._normalizeError(e),o)}})),[3,31];case 31:return[2]}}))}))}))),s}return tslib_1.__extends(t,e),t.prototype.tryCancelDisconnectDevice=function(e){var t=this.deviceDelayDisconnectQueue.findIndex((function(t){return t.deviceId===e}));if(t>-1){var o=this.deviceDelayDisconnectQueue[t];return clearTimeout(o.timer),this.deviceDelayDisconnectQueue.splice(t,1),console.log("Cancel disconnect device: "+e),!0}return console.log("Try cancel disconnect device: "+e+", but not found in queue, maybe it's already disconnected"),!1},t.prototype.disconnectDevice=function(e,t){var o=this,r=e.deviceId,s=e.explorerDeviceId;void 0===t&&(t=0),console.log("call disconnectDevice",{deviceId:r,explorerDeviceId:s});var n=this._deviceConnectStatusStore.get({deviceId:r,explorerDeviceId:s});if(null==n?void 0:n.connected)if(t>0){var i=setTimeout((function(){console.log("execute closeBLEConnection for deviceId: "+r+" after "+t+"ms"),o._bluetoothApi.closeBLEConnection({deviceId:r})}),t);console.log("Will disconnect device: "+r+" after "+t+"ms..."),this.deviceDelayDisconnectQueue.push({deviceId:r,timer:i})}else this._bluetoothApi.closeBLEConnection({deviceId:r});else console.log("call disconnectDevice, but device maybe not connected",n,this._deviceConnectStatusStore.getAll())},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,\n isFromH5: "+t+", _h5DiscoveringInUse: "+this._h5DiscoveringInUse+",\n _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,o){return void 0===t&&(t={}),void 0===o&&(o=""),tslib_1.__awaiter(this,void 0,void 0,(function(){var r;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),this._h5ChanelOpened?(console.log("response2BlueToothChanel",e,t),[4,this._h5Websocket.send("Response",{action:e,payload:t},{reqId:o})]):(console.log("h5 chanel not opened"),[2]);case 1:return s.sent(),[3,3];case 2:return r=s.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(){var t=e._deviceAdapterStore.getAll().filter((function(e){return e.isConnected}));console.log("bluetooth searching or deviceMap not empty, reset cleanup timer",e._discovering,t),e._h5ChanelOpened||e._discovering||t.length?e.startCleanupTimer():e.cleanup()}),3e4)},t.prototype.init=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t=this;return tslib_1.__generator(this,(function(o){return[2,e.prototype.init.call(this).then((function(){return t.startCleanupTimer()}))]}))}))},t.prototype.onBleConnectionStateChange=function(t){var o=t.deviceId,r=t.connected;return this.response2BlueToothChanel("onBLEConnectionStateChange",{deviceId:o,connected:r}),e.prototype.onBleConnectionStateChange.call(this,{deviceId:o,connected:r})},t.prototype.onBLECharacteristicValueChange=function(t){var o=t.deviceId,r=t.serviceId,s=t.characteristicId,n=t.value;return this.response2BlueToothChanel("onBLECharacteristicValueChange",{deviceId:o,serviceId:r,characteristicId:s,value:arrayBufferToHexStringArray(n)}),e.prototype.onBLECharacteristicValueChange.call(this,{deviceId:o,serviceId:r,characteristicId:s,value:n})},t.prototype.onBluetoothDeviceFound=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var o;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,e.prototype.onBluetoothDeviceFound.call(this,t)];case 1:return o=r.sent(),this.response2BlueToothChanel("onBluetoothDeviceFound",{devices:o.map(parseAdvertisData)}),[2]}}))}))},t.prototype.startSearch=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(o){switch(o.label){case 0:return[4,e.prototype.startSearch.call(this,t)];case 1:return o.sent(),this.startCleanupTimer(),[2]}}))}))},t.prototype.searchDevice=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var o;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,e.prototype.searchDevice.call(this,t)];case 1:return o=r.sent(),this.startCleanupTimer(),[2,o]}}))}))},t}(base_1.BlueToothAdapter);exports.BlueToothAdapter4Mp=BlueToothAdapter4Mp; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BlueToothAdapter4Mp=void 0;var tslib_1=require("tslib"),base_1=require("../base"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,arrayBufferToHexStringArray=_a.arrayBufferToHexStringArray,hexToArrayBuffer=_a.hexToArrayBuffer,parseAdvertisData=function(e){var t=tslib_1.__assign({},e);if(t.advertisData)try{t.advertisData=arrayBufferToHexStringArray(t.advertisData)}catch(e){console.error("Parse bluetoothe device advertisData fail",e)}return t},BlueToothAdapter4Mp=function(e){function t(t){var o=t.bluetoothApi,n=tslib_1.__rest(t,["bluetoothApi"]),s=e.call(this,tslib_1.__assign({bluetoothApi:o},n))||this;return s._h5ChanelOpened=!1,s._localDiscoveringInUse=!1,s._h5DiscoveringInUse=!1,s._cleanupTimer=null,s._currentProductId="",s.handleH5WsMessage=null,s.deviceDelayDisconnectQueue=[],s._mpBleConnectionStateCache={},s._h5Websocket&&"function"==typeof s._h5Websocket.on&&(s.on("adapterStateChange",(function(e){var t=e.available,o=e.discovering;s.response2BlueToothChanel("onBluetoothAdapterStateChange",{available:t,discovering:o})})),s._h5Websocket.on("message",(function(e){var t=e.data,o=e.reqId;return tslib_1.__awaiter(s,void 0,void 0,(function(){var e,n,s,r,i,c,a,l,u,h,d,p,v,_,g,f,D,y=this;return tslib_1.__generator(this,(function(C){switch(C.label){case 0:if(console.log("bluetooth ws on message",t),"function"==typeof this.handleH5WsMessage)try{if(this.handleH5WsMessage({data:t,reqId:o}))return console.log("h5 message already handled by handleH5WsMessage implement."),[2]}catch(e){console.error("call handleH5WsMessage error",e)}switch(e=t.action,n=t.payload,e){case"reportDeviceConnectStatus":return[3,1];case"syncDeviceConnectStatus":return[3,2];case"bindDevice":return[3,3];case"registryDevice":return[3,7];case"connect":return[3,11];case"disconnect":return[3,12];case"init":return[3,13];case"callApi":return[3,17]}return[3,32];case 1:return s=n.connected,r=n.explorerDeviceId,i=n.deviceId,this.onDeviceConnectStatusChange({connected:s,explorerDeviceId:r,deviceId:i}),[3,32];case 2:c=n.devices,(_=void 0===c?[]:c).forEach((function(e){var t=e.deviceId,o=e.connected,n=y._mpBleConnectionStateCache[t]||!1;n!==o&&(console.log("[syncDeviceConnectStatus] deviceId="+t+",","h5.connected="+o+", actualConnected="+n),y.response2BlueToothChanel("onBLEConnectionStateChange",{deviceId:t,connected:n}))})),C.label=3;case 3:return C.trys.push([3,5,,6]),l=n.deviceName,u=n.productId,[4,this._actions.bindDevice({productId:this.devMode&&u?u:this._currentProductId,deviceName:l})];case 4:return C.sent(),this.response2BlueToothChanel("response",{code:0},o),[3,6];case 5:return a=C.sent(),this.response2BlueToothChanel("response",a,o),[3,6];case 6:return[3,32];case 7:return C.trys.push([7,9,,10]),l=n.deviceName,u=n.productId,[4,this._actions.registerDevice({productId:this.devMode&&u?u:this._currentProductId,deviceName:l})];case 8:return C.sent(),this.response2BlueToothChanel("response",{code:0},o),[3,10];case 9:return h=C.sent(),this.response2BlueToothChanel("response",h,o),[3,10];case 10:return[3,32];case 11:return console.log("h5chanel opened"),this._h5ChanelOpened=!0,[3,32];case 12:return console.log("h5chanel closed"),this._h5ChanelOpened=!1,this._h5DiscoveringInUse&&this.stopBluetoothDevicesDiscovery(!0),[3,32];case 13:return C.trys.push([13,15,,16]),[4,this.init()];case 14:return C.sent(),this.response2BlueToothChanel("response",{code:0},o),[3,16];case 15:return d=C.sent(),this.response2BlueToothChanel("response",d,o),[3,16];case 16:return[3,32];case 17:p=n.api,v=n.params,C.label=18;case 18:switch(C.trys.push([18,30,,31]),console.log("call api",p,v),p){case"createBLEConnection":return[3,19];case"getBluetoothDevices":return[3,21];case"writeBLECharacteristicValue":return[3,23];case"startBluetoothDevicesDiscovery":return[3,25];case"stopBluetoothDevicesDiscovery":return[3,27]}return[3,29];case 19:return this.tryCancelDisconnectDevice(v.deviceId),[4,this._bluetoothApi.createBLEConnection(v)];case 20:return C.sent(),this.response2BlueToothChanel("response",{},o),[2];case 21:return[4,this.getBluetoothDevices()];case 22:return _=C.sent(),this.response2BlueToothChanel("response",{devices:_.map(parseAdvertisData)},o),[2];case 23:return g=v.value,console.log("calling writeBLECharacteristicValue",tslib_1.__assign(tslib_1.__assign({},v),{value:hexToArrayBuffer(g)})),[4,this._bluetoothApi.writeBLECharacteristicValue(tslib_1.__assign(tslib_1.__assign({},v),{value:hexToArrayBuffer(g)}))];case 24:return f=C.sent(),this.response2BlueToothChanel("response",f,o),[2];case 25:return[4,this.startBluetoothDevicesDiscovery(!0)];case 26:return f=C.sent(),this.response2BlueToothChanel("response",f,o),[2];case 27:return[4,this.stopBluetoothDevicesDiscovery(!0)];case 28:return f=C.sent(),this.response2BlueToothChanel("response",f,o),[2];case 29:return[3,31];case 30:return D=C.sent(),console.error("[BlueToothAdapter4Mp] call bluetoothApi fail",D),this.response2BlueToothChanel("response",this._normalizeError(D),o),[3,31];case 31:return wx[p]&&wx[p](tslib_1.__assign(tslib_1.__assign({},v),{success:function(e){console.log("[BlueToothAdapter4Mp] call wx api success",e),y.response2BlueToothChanel("response",e,o)},fail:function(e){console.log("call api fail",e),y.response2BlueToothChanel("response",y._normalizeError(e),o)}})),[3,32];case 32:return[2]}}))}))}))),s}return tslib_1.__extends(t,e),t.prototype.tryCancelDisconnectDevice=function(e){var t=this.deviceDelayDisconnectQueue.findIndex((function(t){return t.deviceId===e}));if(t>-1){var o=this.deviceDelayDisconnectQueue[t];return clearTimeout(o.timer),this.deviceDelayDisconnectQueue.splice(t,1),console.log("Cancel disconnect device: "+e),!0}return console.log("Try cancel disconnect device: "+e+", but not found in queue, maybe it's already disconnected"),!1},t.prototype.disconnectDevice=function(e,t){var o=this,n=e.deviceId,s=e.explorerDeviceId;void 0===t&&(t=0),console.log("call disconnectDevice",{deviceId:n,explorerDeviceId:s});var r=this._deviceConnectStatusStore.get({deviceId:n,explorerDeviceId:s});if(null==r?void 0:r.connected)if(t>0){var i=setTimeout((function(){console.log("execute closeBLEConnection for deviceId: "+n+" after "+t+"ms"),o._bluetoothApi.closeBLEConnection({deviceId:n})}),t);console.log("Will disconnect device: "+n+" after "+t+"ms..."),this.deviceDelayDisconnectQueue.push({deviceId:n,timer:i})}else this._bluetoothApi.closeBLEConnection({deviceId:n});else console.log("call disconnectDevice, but device maybe not connected",r,this._deviceConnectStatusStore.getAll())},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,\n isFromH5: "+t+", _h5DiscoveringInUse: "+this._h5DiscoveringInUse+",\n _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,o){return void 0===t&&(t={}),void 0===o&&(o=""),tslib_1.__awaiter(this,void 0,void 0,(function(){var n;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),this._h5ChanelOpened?(console.log("response2BlueToothChanel",e,t),[4,this._h5Websocket.send("Response",{action:e,payload:t},{reqId:o})]):(console.log("h5 chanel not opened"),[2]);case 1:return s.sent(),[3,3];case 2:return n=s.sent(),console.warn("try send bluetooth message fail",n),[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(){var t=e._deviceAdapterStore.getAll().filter((function(e){return e.isConnected}));console.log("bluetooth searching or deviceMap not empty, reset cleanup timer",e._discovering,t),e._h5ChanelOpened||e._discovering||t.length?e.startCleanupTimer():e.cleanup()}),3e4)},t.prototype.init=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t=this;return tslib_1.__generator(this,(function(o){return[2,e.prototype.init.call(this).then((function(){return t.startCleanupTimer()}))]}))}))},t.prototype.onBleConnectionStateChange=function(t){var o=t.deviceId,n=t.connected;return this.response2BlueToothChanel("onBLEConnectionStateChange",{deviceId:o,connected:n}),this._mpBleConnectionStateCache[o]=n,e.prototype.onBleConnectionStateChange.call(this,{deviceId:o,connected:n})},t.prototype.onBLECharacteristicValueChange=function(t){var o=t.deviceId,n=t.serviceId,s=t.characteristicId,r=t.value;return this.response2BlueToothChanel("onBLECharacteristicValueChange",{deviceId:o,serviceId:n,characteristicId:s,value:arrayBufferToHexStringArray(r)}),e.prototype.onBLECharacteristicValueChange.call(this,{deviceId:o,serviceId:n,characteristicId:s,value:r})},t.prototype.onBluetoothDeviceFound=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var o;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return[4,e.prototype.onBluetoothDeviceFound.call(this,t)];case 1:return o=n.sent(),this.response2BlueToothChanel("onBluetoothDeviceFound",{devices:o.map(parseAdvertisData)}),[2]}}))}))},t.prototype.startSearch=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(o){switch(o.label){case 0:return[4,e.prototype.startSearch.call(this,t)];case 1:return o.sent(),this.startCleanupTimer(),[2]}}))}))},t.prototype.searchDevice=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var o;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return[4,e.prototype.searchDevice.call(this,t)];case 1:return o=n.sent(),this.startCleanupTimer(),[2,o]}}))}))},t.prototype.cleanup=function(t){e.prototype.cleanup.call(this,t),this._mpBleConnectionStateCache={}},t}(base_1.BlueToothAdapter);exports.BlueToothAdapter4Mp=BlueToothAdapter4Mp; | ||
//# sourceMappingURL=BlueToothAdapter4Mp.js.map |
{ | ||
"name": "qcloud-iotexplorer-bluetooth-adapter", | ||
"version": "0.4.7", | ||
"version": "0.5.0", | ||
"description": "", | ||
@@ -17,9 +17,9 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"event-emitter-for-miniprogram": "^0.4.7", | ||
"event-emitter-for-miniprogram": "^0.4.8", | ||
"lodash.uniqwith": "^4.5.0", | ||
"qcloud-iotexplorer-appdev-sdk": "^1.4.7", | ||
"qcloud-iotexplorer-common-libs": "^0.4.7", | ||
"qcloud-iotexplorer-appdev-sdk": "^1.5.0", | ||
"qcloud-iotexplorer-common-libs": "^0.5.0", | ||
"tslib": "^2.0.1" | ||
}, | ||
"gitHead": "685a0f8f4af5c9c951b80164ceb093eb3e246f53" | ||
"gitHead": "f03807d371775b909231323905b97f8a853eb48a" | ||
} |
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
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
180275
1213
+ Addedqcloud-iotexplorer-common-libs@0.5.1(transitive)
- Removedqcloud-iotexplorer-common-libs@0.4.7(transitive)