@iotize/device-com-ble.cordova 3.3.2 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/iotize-device-com-ble.cordova.umd.js +20 -13
- package/bundles/iotize-device-com-ble.cordova.umd.js.map +1 -1
- package/bundles/iotize-device-com-ble.cordova.umd.min.js +2 -2
- package/bundles/iotize-device-com-ble.cordova.umd.min.js.map +1 -1
- package/esm2015/lib/ble-com-protocol.js +19 -11
- package/esm2015/lib/ble-com-protocol.js.map +1 -1
- package/esm2015/lib/ble-com-protocol.metadata.json +1 -1
- package/fesm2015/iotize-device-com-ble.cordova.js +17 -10
- package/fesm2015/iotize-device-com-ble.cordova.js.map +1 -1
- package/iotize-device-com-ble.cordova.metadata.json +1 -1
- package/lib/ble-com-protocol.d.ts +4 -4
- package/package.json +1 -1
- package/plugin.xml +5 -3
- package/src/android/.gradle/4.8.1/fileHashes/fileHashes.lock +0 -0
- package/src/android/build.gradle +1 -1
- package/src/android/src/ble/BLECom.java +120 -33
- package/src/android/src/ble/BLEComError.java +16 -2
- package/www/plugin.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iotize-device-com-ble.cordova.js","sources":["../../../../src/lib/logger.ts","../../../../src/lib/cordova-ble-error.ts","../../../../src/lib/utility.ts","../../../../src/lib/ble-com-protocol.ts","../../../../src/lib/cordova-service-adapter.ts","../../../../src/lib/scanner.ts","../../../../src/lib/iotize-ble-cordova-plugin.ts","../../../../src/iotize-device-com-ble.cordova.ts"],"sourcesContent":["import { createDebugger } from \"@iotize/common/debug\";\n\nexport const debug = createDebugger(`@iotize/device-com-ble.cordova`);\n","import { CodeError } from '@iotize/common/error';\n\nexport class CordovaBLEError extends CodeError {\n static invalidErrorResult(errObject: {\n code?: string | undefined;\n message?: string | undefined;\n }): CordovaBLEError {\n return new CordovaBLEError(\n `Internal error: ble cordova plugin returned an unexpected error object`,\n CordovaBLEError.Code.InternalError\n );\n }\n\n static invalidErrorCode(errObject: {\n code?: string | undefined;\n message?: string | undefined;\n }): CordovaBLEError {\n return new CordovaBLEError(\n `Internal error: ble cordova plugin returned an invalid error code ${errObject.code} with message ${errObject.message}`,\n CordovaBLEError.Code.InternalError\n );\n }\n\n static invalidNativeCallResult(result: any, cause: Error): CordovaBLEError {\n return new CordovaBLEError(\n `Internal error: native call returned an invalid data type. ${cause.message}`,\n CordovaBLEError.Code.InternalError\n );\n }\n\n static isValidErrorCode(\n code: string\n ): code is keyof typeof CordovaBLEError.Code {\n return code in CordovaBLEError.Code;\n }\n\n static iotizeBLEMissing() {\n return new CordovaBLEError(\n `iotizeBLE global variable does not exist. Are you sure app is running inside a Cordova application ?`,\n CordovaBLEError.Code.InternalError\n );\n }\n}\n\n/* istanbul ignore next */\nexport namespace CordovaBLEError {\n export enum Code {\n InternalError = 'CordovaBLEErrorInternalError',\n IllegalArgument = 'CordovaBLEErrorIllegalArgument',\n BLENotAvailable = 'CordovaBLEErrorBLENotAvailable',\n InvalidMacAddress = 'InvalidMacAddressInvalidMacAddress',\n ConnectionError = 'CordovaBLEErrorConnectionError',\n RequestError = 'CordovaBLEErrorRequestError',\n LocationServiceDisabled = 'CordovaBLEErrorLocationServiceDisabled',\n DisconnectError = 'CordovaBLEErrorDisconnectError',\n IllegalAction = 'CordovaBLEErrorIllegalAction',\n NotConnectedError = 'CordovaBLEErrorNotConnectedError',\n StatusCodeError = 'CordovaBLEErrorStatusCodeError',\n }\n}\n","import { CordovaBLEError } from \"./cordova-ble-error\";\nimport { IoTizeBleCordovaPlugin } from \"./iotize-ble-cordova-plugin\";\n\ndeclare var iotizeBLE: IoTizeBleCordovaPlugin;\n\nexport function getIoTizeBleCordovaPlugin(): IoTizeBleCordovaPlugin {\n if (typeof iotizeBLE !== \"object\") {\n throw CordovaBLEError.iotizeBLEMissing();\n }\n return iotizeBLE;\n}\n","//\n// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.\n//\n// ble-com-protocol.ts\n// device-com-ble.cordova BLE Cordova Plugin\n//\nimport {\n ComProtocolConnectOptions,\n ComProtocolDisconnectOptions,\n ComProtocolOptions,\n ComProtocolSendOptions,\n ConnectionState,\n} from \"@iotize/tap/protocol/api\";\nimport { QueueComProtocol } from \"@iotize/tap/protocol/core\";\nimport { defer, Observable } from \"rxjs\";\nimport { filter, first, tap } from \"rxjs/operators\";\nimport { IoTizeBleCordovaPlugin } from \"./iotize-ble-cordova-plugin\";\nimport { debug } from \"./logger\";\nimport { getIoTizeBleCordovaPlugin } from \"./utility\";\n\nexport class BLEComProtocol extends QueueComProtocol {\n /**\n * Lazy reference to iotizeBLE.\n * We don't want to reference iotizeBLE in constructor as it may be referenced\n * before cordova plugin is loaded\n */\n private get pluginInterface(): IoTizeBleCordovaPlugin {\n return this.cordovaInterfaceOverwrite || getIoTizeBleCordovaPlugin();\n }\n\n constructor(\n private deviceId: string,\n comProtocolOptions?: ComProtocolOptions,\n public readonly cordovaInterfaceOverwrite?: IoTizeBleCordovaPlugin\n ) {\n super();\n if (comProtocolOptions) {\n this.options = comProtocolOptions;\n } else {\n this.options.connect.timeout = 60000;\n }\n }\n\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\n debug(\"_connect\", options);\n return this.pluginInterface\n .connectAndDiscoverTapServices(this.deviceId)\n .pipe(\n tap((state) => {\n this.setConnectionState(state);\n }),\n filter((state) => state === ConnectionState.CONNECTED),\n first()\n );\n }\n\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\n debug(\"_disconnect\", options);\n return defer(() => this.pluginInterface.disConnect(this.deviceId));\n }\n\n async write(data: Uint8Array): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n async read(): Promise<Uint8Array> {\n throw new Error(\"Method not implemented.\");\n }\n\n send(\n data: Uint8Array,\n options?: ComProtocolSendOptions\n ): Observable<Uint8Array> {\n return defer(() => this.pluginInterface.send(this.deviceId, data));\n }\n}\n","import { ConnectionState } from \"@iotize/tap/protocol/api\";\nimport {\n CharacteristicAdapterInterface,\n PeripheralAdapterInterface,\n ServiceAdapterInterface,\n DescriptorAdapterInterface,\n BleComError,\n CharacteristicProperties,\n} from \"@iotize/tap/protocol/ble/common\";\nimport { BehaviorSubject, Observable, Subscription } from \"rxjs\";\nimport {\n distinctUntilChanged,\n filter,\n first,\n map,\n shareReplay,\n} from \"rxjs/operators\";\nimport {\n CharacteristicDescription,\n DescriptorDescription,\n ServiceDescription,\n ServiceList,\n} from \"./definitions\";\nimport { IoTizeBleCordovaPlugin } from \"./iotize-ble-cordova-plugin\";\nimport { getIoTizeBleCordovaPlugin } from \"./utility\";\n\nexport class CordovaPeripheralAdapter\n implements PeripheralAdapterInterface<CordovaServiceAdapter>\n{\n private _stateChange = new BehaviorSubject<ConnectionState>(\n ConnectionState.DISCONNECTED\n );\n private connectionStateSubscription?: Subscription;\n private serviceListCache?: ServiceList;\n\n get stateChange() {\n return this._stateChange.asObservable().pipe(distinctUntilChanged());\n }\n\n get name() {\n // TODO device name ?\n return this.id;\n }\n\n get id() {\n return this.deviceId;\n }\n\n constructor(\n public readonly deviceId: string,\n public readonly cordovaPlugin: IoTizeBleCordovaPlugin = getIoTizeBleCordovaPlugin()\n ) {}\n\n get state(): string {\n return ConnectionState[this._stateChange.value];\n }\n\n async discoverServices<Key extends string = string>(\n serviceUUIDs?: Key[]\n ): Promise<Partial<Record<Key, CordovaServiceAdapter>>> {\n this.serviceListCache = await this.cordovaPlugin.discoverServices(\n this.deviceId\n );\n const result: Partial<Record<Key, CordovaServiceAdapter>> = {};\n if (serviceUUIDs) {\n for (const uuid of serviceUUIDs) {\n const servicDefinition = this.serviceListCache.find(\n (def) => def.uuid === uuid\n );\n if (servicDefinition) {\n result[uuid] = new CordovaServiceAdapter(servicDefinition, this);\n }\n }\n } else {\n for (const serviceDefinition of this.serviceListCache) {\n result[serviceDefinition.uuid as Key] = new CordovaServiceAdapter(\n serviceDefinition,\n this\n );\n }\n }\n return result;\n }\n\n async connect(): Promise<void> {\n this.connectionStateSubscription?.unsubscribe();\n const connectObservable = this.cordovaPlugin\n .connect(this.deviceId)\n .pipe(shareReplay());\n this.connectionStateSubscription = connectObservable.subscribe((state) => {\n this._stateChange.next(state);\n });\n await connectObservable\n .pipe(\n filter((state) => state === ConnectionState.CONNECTED),\n first()\n )\n .toPromise();\n }\n\n async disconnect(): Promise<void> {\n await this.cordovaPlugin.disConnect(this.deviceId);\n this._stateChange.next(ConnectionState.DISCONNECTED);\n this.connectionStateSubscription?.unsubscribe();\n }\n\n async close(): Promise<void> {\n await this.cordovaPlugin.close(this.deviceId);\n this._stateChange.next(ConnectionState.DISCONNECTED);\n this.connectionStateSubscription?.unsubscribe();\n }\n\n async getService(uuid: string): Promise<CordovaServiceAdapter> {\n if (!this.serviceListCache) {\n await this.discoverServices([uuid]);\n }\n const serviceDefinition = this.serviceListCache!.find(\n (s) => s.uuid === uuid\n );\n if (!serviceDefinition) {\n throw BleComError.serviceNotFound(uuid);\n }\n return new CordovaServiceAdapter(serviceDefinition, this);\n }\n}\n\nexport class CordovaServiceAdapter implements ServiceAdapterInterface {\n get uuid() {\n return this.config.uuid;\n }\n\n constructor(\n private readonly config: ServiceDescription,\n public readonly peripheral: CordovaPeripheralAdapter\n ) {}\n\n async getCharacteristic(\n charcUUID: string\n ): Promise<CordovaCharacteristicAdapter> {\n const characteristicDescription = this.config.characteristics?.find(\n (c) => c.uuid === charcUUID\n );\n if (!characteristicDescription) {\n throw BleComError.charcacteristicNotFound(charcUUID);\n }\n return new CordovaCharacteristicAdapter(this, characteristicDescription);\n }\n\n async getCharacteristics(): Promise<CordovaCharacteristicAdapter[]> {\n if (!this.config.characteristics) {\n return [];\n }\n return this.config.characteristics.map(\n (c) => new CordovaCharacteristicAdapter(this, c)\n );\n }\n}\n\nexport class CordovaCharacteristicAdapter\n implements CharacteristicAdapterInterface\n{\n private _dataStream?: Observable<Uint8Array>;\n\n get uuid() {\n return this.config.uuid;\n }\n\n constructor(\n public readonly service: CordovaServiceAdapter,\n public readonly config: CharacteristicDescription\n ) {}\n\n get properties(): CharacteristicProperties {\n return this.config.properties;\n }\n\n get data(): Observable<{ data: Uint8Array; isNotification: boolean }> {\n return this.setupDataStreamIfRequired().pipe(\n map((data) => ({\n data,\n isNotification: true,\n }))\n );\n }\n\n protected get deviceId() {\n return this.service.peripheral.deviceId;\n }\n\n protected get pluginInterface() {\n return this.service.peripheral.cordovaPlugin;\n }\n\n async read(): Promise<Uint8Array> {\n return this.pluginInterface.characteristicReadValue(\n this.deviceId,\n this.service.uuid,\n this.uuid\n );\n }\n\n async getDescriptor(): Promise<CordovaDescriptorAdapter> {\n throw new Error(`Not implemented yet`);\n }\n\n async getDescriptors(): Promise<DescriptorAdapterInterface[]> {\n if (!this.config.descriptors) {\n return [];\n }\n return this.config.descriptors.map(\n (descriptor) => new CordovaDescriptorAdapter(descriptor, this)\n );\n }\n\n async write(\n data: Uint8Array,\n writeWithoutResponse: boolean\n ): Promise<Uint8Array> {\n if (writeWithoutResponse) {\n await this.pluginInterface.characteristicWriteWithoutResponse(\n this.deviceId,\n this.service.uuid,\n this.uuid,\n data\n );\n } else {\n await this.pluginInterface.characteristicWrite(\n this.deviceId,\n this.service.uuid,\n this.uuid,\n data\n );\n }\n return data;\n }\n\n async enableNotifications(enabled?: boolean): Promise<void> {\n if (enabled) {\n this.setupDataStreamIfRequired();\n await this.pluginInterface.characteristicStartNotification(\n this.deviceId,\n this.service.uuid,\n this.uuid\n );\n } else {\n await this.pluginInterface.characteristicStopNotification(\n this.deviceId,\n this.service.uuid,\n this.uuid\n );\n }\n }\n\n setupDataStreamIfRequired() {\n if (!this._dataStream) {\n this._dataStream = this.pluginInterface.characteristicChanged(\n this.deviceId,\n this.service.uuid,\n this.uuid\n );\n }\n return this._dataStream;\n }\n}\n\nexport class CordovaDescriptorAdapter implements DescriptorAdapterInterface {\n get uuid() {\n return this.config.uuid;\n }\n\n constructor(\n public readonly config: DescriptorDescription,\n public readonly characteristic: CordovaCharacteristicAdapter\n ) {}\n\n async readValue(): Promise<Uint8Array> {\n throw new Error(`Reading descriptor value is not implemented yet`);\n }\n\n async writeValue(data: Uint8Array): Promise<void> {\n throw new Error(`Writing descriptor value is not implemented yet`);\n }\n}\n","//\n// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.\n//\n// scanner.ts\n// device-com-ble.cordova BLE Cordova Plugin\n//\n\nimport { BleComError } from \"@iotize/tap/protocol/ble/common\";\nimport { DeviceScanner, DeviceScannerOptions } from \"@iotize/tap/scanner/api\";\nimport { BehaviorSubject, Observable, Subscription } from \"rxjs\";\nimport { CordovaBLEScanResult, RequestDeviceOptions } from \"./definitions\";\nimport { IoTizeBleCordovaPlugin } from \"./iotize-ble-cordova-plugin\";\nimport { debug } from \"./logger\";\nimport { getIoTizeBleCordovaPlugin } from \"./utility\";\n\n/**\n * BLE Tap scanner for cordova apps\n */\nexport class BLEScanner implements DeviceScanner<CordovaBLEScanResult> {\n private _results = new BehaviorSubject<CordovaBLEScanResult[]>([]);\n private _scanning$ = new BehaviorSubject<boolean>(false);\n private scanSubscription?: Subscription;\n\n /**\n * Lazy reference to iotizeBLE.\n * We don't want to reference iotizeBLE in constructor as it may be referenced\n * before cordova plugin is loaded\n */\n private get cordovaInterface(): IoTizeBleCordovaPlugin {\n return this.cordovaInterfaceOverwrite || getIoTizeBleCordovaPlugin();\n }\n\n /**\n *\n * @param cordovaInterfaceOverwrite overwrite cordova interface. Used for testing\n */\n constructor(\n private cordovaInterfaceOverwrite?: IoTizeBleCordovaPlugin,\n /**\n * Request device options used to filter scan results\n */\n readonly requestDeviceOptions?: RequestDeviceOptions\n ) {}\n\n get scanning(): Observable<boolean> {\n return this._scanning$.asObservable();\n }\n\n get isScanning(): boolean {\n return this._scanning$.value;\n }\n\n /**\n * Gets the observable on the devices$ Subject\n * @return\n */\n get results(): Observable<CordovaBLEScanResult[]> {\n return this._results.asObservable();\n }\n\n /**\n * Launches the scan for BLE devices\n * Throws if BLE is not available\n */\n async start(options?: DeviceScannerOptions): Promise<void> {\n this.scanSubscription?.unsubscribe();\n this.scanSubscription = undefined;\n this.clearResults();\n const isAvailable = await this.checkAvailable();\n if (!isAvailable) {\n throw BleComError.bleNotAvailable(\n `BLE is not available. Make sure that BLE is enabled on your device`\n );\n }\n debug(\"Start Scanning ...\");\n this._scanning$.next(true);\n return new Promise<void>((resolve, reject) => {\n this.scanSubscription = this.cordovaInterface\n .startScan(this.requestDeviceOptions)\n .subscribe(\n (result) => {\n if (result == \"Ok\") {\n resolve();\n return;\n }\n this.addOrRefreshDevice(result);\n },\n (error) => {\n debug(\"Start scan failed with error: \", error);\n this.cordovaInterface\n .getLastError()\n .then((lasterror) => {\n debug(\"Last BLE error \" + lasterror);\n })\n .catch((err) => {\n debug(\"Cannot get last BLE error: \", err);\n });\n reject(error);\n this._scanning$.next(false);\n }\n );\n });\n }\n\n /**\n *\n */\n async stop(): Promise<void> {\n debug(\"Stop Scanning ...\");\n try {\n this.scanSubscription?.unsubscribe();\n this.scanSubscription = undefined;\n await this.cordovaInterface.stopScan();\n this._scanning$.next(false);\n return;\n } catch (err) {\n this._scanning$.next(false);\n throw err;\n }\n }\n\n /**\n * Returns true if this scanner is available\n */\n checkAvailable(): Promise<boolean> {\n return this.cordovaInterface.checkAvailable();\n }\n\n private get devices() {\n return this._results.value;\n }\n\n private clearResults() {\n this._results.next([]);\n }\n\n private addOrRefreshDevice(newDevice: CordovaBLEScanResult) {\n let storedDeviceIndex = this.devices.findIndex(\n (entry) => entry.address == newDevice.address\n );\n if (storedDeviceIndex >= 0) {\n let storedDevice = this.devices[storedDeviceIndex];\n if (\n storedDevice.name != newDevice.name ||\n storedDevice.rssi != newDevice.rssi\n ) {\n debug(\n `Updating device at index ${storedDeviceIndex}, name=${storedDevice.name} with rssi=${storedDevice.rssi}`\n );\n this.devices[storedDeviceIndex] = newDevice;\n // this.devices = [...this.devices];\n this._results.next(this.devices);\n }\n } else {\n debug(\n `Adding new device name=${newDevice.name} with rssi=${newDevice.rssi}`\n );\n this.devices.push(newDevice);\n this._results.next(this.devices);\n }\n }\n}\n","import {\n bufferToHexString,\n hexStringToBuffer as hexStringToBufferCore,\n} from \"@iotize/common/byte-converter\";\nimport { safeEnumValue } from \"@iotize/common/utility\";\nimport { ConnectionState } from \"@iotize/tap/protocol/api\";\nimport { Observable, Subject, defer } from \"rxjs\";\nimport { switchMap } from \"rxjs/operators\";\nimport { map } from \"rxjs/operators\";\nimport { CordovaInterface } from \"./cordova-interface\";\nimport {\n CordovaBLEScanResult,\n RequestDeviceOptions,\n ServiceList,\n} from \"./definitions\";\nimport { CordovaBLEError } from \"./cordova-ble-error\";\n\nfunction hexStringToBuffer(str: string): Uint8Array {\n try {\n return hexStringToBufferCore(str);\n } catch (err) {\n throw CordovaBLEError.invalidNativeCallResult(str, err as Error);\n }\n}\n\ndeclare var cordova: CordovaInterface;\n\nexport class IoTizeBleCordovaPlugin {\n checkAvailable(): Promise<boolean> {\n return this.execSingleResult<boolean>(\"checkAvailable\", []);\n }\n\n requestEnableBle(): Promise<\"OK\"> {\n return this.execSingleResult<\"OK\">(\"enable\", []);\n }\n\n startScan(\n requestDeviceOptions: RequestDeviceOptions | undefined\n ): Observable<CordovaBLEScanResult | \"Ok\"> {\n return this.execMultipleResult<CordovaBLEScanResult | \"Ok\">(\"startScan\", [\n JSON.stringify(requestDeviceOptions),\n ]);\n }\n\n stopScan() {\n return this.execSingleResult<\"OK\">(\"stopScan\", []);\n }\n\n connect(\n deviceId: string,\n enableBleIfNot: boolean = true\n ): Observable<ConnectionState> {\n return this.askBleEnable(enableBleIfNot).pipe(\n switchMap(() => {\n return this.execMultipleResult<string>(\"connect\", [deviceId]).pipe(\n map((state) => {\n if (!(state in ConnectionState)) {\n console.warn(\n `Plugin native code returned an invalid connection state: \"${state}\".`\n );\n }\n return safeEnumValue(ConnectionState, state);\n })\n );\n })\n );\n }\n\n askBleEnable(askEnable: boolean): Observable<void> {\n return defer(async () => {\n if (askEnable) {\n if (!(await this.checkAvailable())) {\n await this.requestEnableBle();\n }\n }\n });\n }\n\n requestMTU(deviceId: string, mtu: number) {\n return this.execSingleResult<\"OK\">(\"requestMTU\", [deviceId, mtu]);\n }\n\n connectAndDiscoverTapServices(\n deviceId: string,\n enableBleIfNot: boolean = true\n ): Observable<ConnectionState> {\n return this.askBleEnable(enableBleIfNot).pipe(\n switchMap(() => {\n return this.execMultipleResult<string>(\n \"connectAndDiscoverTapServices\",\n [deviceId]\n ).pipe(\n map((state) => {\n if (!(state in ConnectionState)) {\n console.warn(\n `Plugin native code returned an invalid connection state: \"${state}\".`\n );\n }\n return safeEnumValue(ConnectionState, state);\n })\n );\n })\n );\n }\n\n disConnect(deviceId: string) {\n return this.execSingleResult<\"OK\">(\"disConnect\", [deviceId]);\n }\n\n close(deviceId: string) {\n return this.execSingleResult<\"OK\">(\"close\", [deviceId]);\n }\n\n isConnected(deviceId: string) {\n return this.execSingleResult<boolean>(\"isConnected\", [deviceId]);\n }\n\n async send(deviceId: string, data: Uint8Array) {\n const hexString = await this.execSingleResult<string>(\"sendRequest\", [\n deviceId,\n bufferToHexString(data),\n ]);\n return hexStringToBuffer(hexString);\n }\n\n getLastError() {\n return this.execSingleResult<string>(\"getLastError\", []);\n }\n\n characteristicStartNotification(\n deviceId: string,\n serviceId: string,\n characId: string\n ) {\n return this.execSingleResult<\"OK\">(\"characteristicStartNotification\", [\n deviceId,\n serviceId,\n characId,\n ]);\n }\n\n characteristicChanged(\n deviceId: string,\n serviceId: string,\n characId: string\n ): Observable<Uint8Array> {\n return this.execMultipleResult<string>(\"characteristicChanged\", [\n deviceId,\n serviceId,\n characId,\n ]).pipe(\n map((hexString) => {\n return hexStringToBuffer(hexString);\n })\n );\n }\n\n characteristicStopNotification(\n deviceId: string,\n serviceId: string,\n characId: string\n ) {\n return this.execSingleResult<\"OK\">(\"characteristicStopNotification\", [\n deviceId,\n serviceId,\n characId,\n ]);\n }\n\n async characteristicReadValue(\n deviceId: string,\n serviceId: string,\n characId: string\n ): Promise<Uint8Array> {\n const hexString = await this.execSingleResult<string>(\n \"characteristicRead\",\n [deviceId, serviceId, characId]\n );\n return hexStringToBuffer(hexString);\n }\n\n characteristicWrite(\n deviceId: string,\n serviceId: string,\n characId: string,\n data: Uint8Array\n ) {\n return this.execSingleResult<\"OK\">(\"characteristicWrite\", [\n deviceId,\n serviceId,\n characId,\n bufferToHexString(data),\n ]);\n }\n\n characteristicWriteWithoutResponse(\n deviceId: string,\n serviceId: string,\n characId: string,\n data: Uint8Array\n ) {\n return this.execSingleResult<\"OK\">(\"characteristicWriteWithoutResponse\", [\n deviceId,\n serviceId,\n characId,\n bufferToHexString(data),\n ]);\n }\n\n async discoverServices(deviceId: string): Promise<ServiceList> {\n const services = await this.execSingleResult<ServiceList>(\n \"discoverServices\",\n [deviceId]\n );\n return services;\n }\n\n private execSingleResult<T extends string | void | boolean | Object>(\n methodName: string,\n args: any[]\n ): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n cordova.exec(\n resolve,\n (errObject: { code?: string; message?: string }) => {\n reject(objectErrorToError(errObject));\n },\n \"BLECom\",\n methodName,\n args\n );\n });\n }\n\n private execMultipleResult<T>(\n methodName: string,\n args: any[]\n ): Observable<T> {\n const subject = new Subject<T>();\n cordova.exec<T>(\n (data) => {\n subject.next(data);\n },\n (err) => {\n subject.error(objectErrorToError(err));\n },\n \"BLECom\",\n methodName,\n args\n );\n return subject.asObservable();\n }\n}\n\nfunction objectErrorToError(errObject: { code?: string; message?: string }) {\n if (typeof errObject !== \"object\" || !errObject.code || !errObject.message) {\n return CordovaBLEError.invalidErrorResult(errObject);\n }\n if (!CordovaBLEError.isValidErrorCode(errObject.code)) {\n return CordovaBLEError.invalidErrorCode(errObject);\n }\n return new CordovaBLEError(\n errObject.message,\n CordovaBLEError.Code[errObject.code]\n );\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n\nexport {CharacteristicDescription as ɵb,ServiceDescription as ɵa} from './lib/definitions';\nexport {IoTizeBleCordovaPlugin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,EAAE;AACrD,QAAA,OAAO,eAAe,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACpD,KAAA;AACD,IAAA,OAAO,IAAI,eAAe,CACxB,SAAS,CAAC,OAAO,EACjB,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CACrC,CAAC;AACJ;;ACzQA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"iotize-device-com-ble.cordova.js","sources":["../../../../src/lib/cordova-ble-error.ts","../../../../src/lib/logger.ts","../../../../src/lib/utility.ts","../../../../src/lib/ble-com-protocol.ts","../../../../src/lib/cordova-service-adapter.ts","../../../../src/lib/scanner.ts","../../../../src/lib/iotize-ble-cordova-plugin.ts","../../../../src/iotize-device-com-ble.cordova.ts"],"sourcesContent":["import { CodeError } from '@iotize/common/error';\n\nexport class CordovaBLEError extends CodeError {\n static invalidErrorResult(errObject: {\n code?: string | undefined;\n message?: string | undefined;\n }): CordovaBLEError {\n return new CordovaBLEError(\n `Internal error: ble cordova plugin returned an unexpected error object`,\n CordovaBLEError.Code.InternalError\n );\n }\n\n static invalidErrorCode(errObject: {\n code?: string | undefined;\n message?: string | undefined;\n }): CordovaBLEError {\n return new CordovaBLEError(\n `Internal error: ble cordova plugin returned an invalid error code ${errObject.code} with message ${errObject.message}`,\n CordovaBLEError.Code.InternalError\n );\n }\n\n static invalidNativeCallResult(result: any, cause: Error): CordovaBLEError {\n return new CordovaBLEError(\n `Internal error: native call returned an invalid data type. ${cause.message}`,\n CordovaBLEError.Code.InternalError\n );\n }\n\n static isValidErrorCode(\n code: string\n ): code is keyof typeof CordovaBLEError.Code {\n return code in CordovaBLEError.Code;\n }\n\n static iotizeBLEMissing() {\n return new CordovaBLEError(\n `iotizeBLE global variable does not exist. Are you sure app is running inside a Cordova application ?`,\n CordovaBLEError.Code.InternalError\n );\n }\n}\n\n/* istanbul ignore next */\nexport namespace CordovaBLEError {\n export enum Code {\n InternalError = 'CordovaBLEErrorInternalError',\n IllegalArgument = 'CordovaBLEErrorIllegalArgument',\n BLENotAvailable = 'CordovaBLEErrorBLENotAvailable',\n InvalidMacAddress = 'InvalidMacAddressInvalidMacAddress',\n ConnectionError = 'CordovaBLEErrorConnectionError',\n RequestError = 'CordovaBLEErrorRequestError',\n LocationServiceDisabled = 'CordovaBLEErrorLocationServiceDisabled',\n DisconnectError = 'CordovaBLEErrorDisconnectError',\n IllegalAction = 'CordovaBLEErrorIllegalAction',\n NotConnectedError = 'CordovaBLEErrorNotConnectedError',\n StatusCodeError = 'CordovaBLEErrorStatusCodeError',\n }\n}\n","import { createDebugger } from \"@iotize/common/debug\";\n\nexport const debug = createDebugger(`@iotize/device-com-ble.cordova`);\n","import { CordovaBLEError } from \"./cordova-ble-error\";\nimport { IoTizeBleCordovaPlugin } from \"./iotize-ble-cordova-plugin\";\n\ndeclare var iotizeBLE: IoTizeBleCordovaPlugin;\n\nexport function getIoTizeBleCordovaPlugin(): IoTizeBleCordovaPlugin {\n if (typeof iotizeBLE !== \"object\") {\n throw CordovaBLEError.iotizeBLEMissing();\n }\n return iotizeBLE;\n}\n","//\n// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.\n//\n// ble-com-protocol.ts\n// device-com-ble.cordova BLE Cordova Plugin\n//\nimport {\n ComProtocolConnectOptions,\n ComProtocolDisconnectOptions,\n ComProtocolOptions,\n ComProtocolSendOptions,\n ConnectionState,\n} from '@iotize/tap/protocol/api';\nimport { QueueComProtocol } from '@iotize/tap/protocol/core';\nimport { defer, Observable, of, throwError } from 'rxjs';\nimport { catchError, filter, first, tap } from 'rxjs/operators';\nimport { CordovaBLEError } from './cordova-ble-error';\nimport { IoTizeBleCordovaPlugin } from './iotize-ble-cordova-plugin';\nimport { debug } from './logger';\nimport { getIoTizeBleCordovaPlugin } from './utility';\n\nexport class BLEComProtocol extends QueueComProtocol {\n /**\n * Lazy reference to iotizeBLE.\n * We don't want to reference iotizeBLE in constructor as it may be referenced\n * before cordova plugin is loaded\n */\n private get pluginInterface(): IoTizeBleCordovaPlugin {\n return this.cordovaInterfaceOverwrite || getIoTizeBleCordovaPlugin();\n }\n\n constructor(\n private deviceId: string,\n comProtocolOptions?: ComProtocolOptions,\n public readonly cordovaInterfaceOverwrite?: IoTizeBleCordovaPlugin\n ) {\n super();\n if (comProtocolOptions) {\n this.options = comProtocolOptions;\n } else {\n this.options.connect.timeout = 60000;\n }\n }\n\n _connect(options?: ComProtocolConnectOptions): Observable<any> {\n debug('_connect', options);\n return this.pluginInterface\n .connectAndDiscoverTapServices(this.deviceId)\n .pipe(\n tap((state) => {\n this.setConnectionState(state);\n }),\n filter((state) => state === ConnectionState.CONNECTED),\n first()\n );\n }\n\n _disconnect(options?: ComProtocolDisconnectOptions): Observable<any> {\n debug('_disconnect', options);\n return defer(() => this.pluginInterface.disConnect(this.deviceId));\n }\n\n async write(data: Uint8Array): Promise<any> {\n throw new Error('Method not implemented.');\n }\n\n async read(): Promise<Uint8Array> {\n throw new Error('Method not implemented.');\n }\n\n send(\n data: Uint8Array,\n options?: ComProtocolSendOptions\n ): Observable<Uint8Array> {\n return defer(() => this.pluginInterface.send(this.deviceId, data)).pipe(\n catchError((err) => {\n if (\n (err as CordovaBLEError)?.code ===\n CordovaBLEError.Code.NotConnectedError\n ) {\n this.setConnectionState(ConnectionState.DISCONNECTED);\n }\n return throwError(err);\n })\n );\n }\n}\n","import { ConnectionState } from \"@iotize/tap/protocol/api\";\nimport {\n CharacteristicAdapterInterface,\n PeripheralAdapterInterface,\n ServiceAdapterInterface,\n DescriptorAdapterInterface,\n BleComError,\n CharacteristicProperties,\n} from \"@iotize/tap/protocol/ble/common\";\nimport { BehaviorSubject, Observable, Subscription } from \"rxjs\";\nimport {\n distinctUntilChanged,\n filter,\n first,\n map,\n shareReplay,\n} from \"rxjs/operators\";\nimport {\n CharacteristicDescription,\n DescriptorDescription,\n ServiceDescription,\n ServiceList,\n} from \"./definitions\";\nimport { IoTizeBleCordovaPlugin } from \"./iotize-ble-cordova-plugin\";\nimport { getIoTizeBleCordovaPlugin } from \"./utility\";\n\nexport class CordovaPeripheralAdapter\n implements PeripheralAdapterInterface<CordovaServiceAdapter>\n{\n private _stateChange = new BehaviorSubject<ConnectionState>(\n ConnectionState.DISCONNECTED\n );\n private connectionStateSubscription?: Subscription;\n private serviceListCache?: ServiceList;\n\n get stateChange() {\n return this._stateChange.asObservable().pipe(distinctUntilChanged());\n }\n\n get name() {\n // TODO device name ?\n return this.id;\n }\n\n get id() {\n return this.deviceId;\n }\n\n constructor(\n public readonly deviceId: string,\n public readonly cordovaPlugin: IoTizeBleCordovaPlugin = getIoTizeBleCordovaPlugin()\n ) {}\n\n get state(): string {\n return ConnectionState[this._stateChange.value];\n }\n\n async discoverServices<Key extends string = string>(\n serviceUUIDs?: Key[]\n ): Promise<Partial<Record<Key, CordovaServiceAdapter>>> {\n this.serviceListCache = await this.cordovaPlugin.discoverServices(\n this.deviceId\n );\n const result: Partial<Record<Key, CordovaServiceAdapter>> = {};\n if (serviceUUIDs) {\n for (const uuid of serviceUUIDs) {\n const servicDefinition = this.serviceListCache.find(\n (def) => def.uuid === uuid\n );\n if (servicDefinition) {\n result[uuid] = new CordovaServiceAdapter(servicDefinition, this);\n }\n }\n } else {\n for (const serviceDefinition of this.serviceListCache) {\n result[serviceDefinition.uuid as Key] = new CordovaServiceAdapter(\n serviceDefinition,\n this\n );\n }\n }\n return result;\n }\n\n async connect(): Promise<void> {\n this.connectionStateSubscription?.unsubscribe();\n const connectObservable = this.cordovaPlugin\n .connect(this.deviceId)\n .pipe(shareReplay());\n this.connectionStateSubscription = connectObservable.subscribe((state) => {\n this._stateChange.next(state);\n });\n await connectObservable\n .pipe(\n filter((state) => state === ConnectionState.CONNECTED),\n first()\n )\n .toPromise();\n }\n\n async disconnect(): Promise<void> {\n await this.cordovaPlugin.disConnect(this.deviceId);\n this._stateChange.next(ConnectionState.DISCONNECTED);\n this.connectionStateSubscription?.unsubscribe();\n }\n\n async close(): Promise<void> {\n await this.cordovaPlugin.close(this.deviceId);\n this._stateChange.next(ConnectionState.DISCONNECTED);\n this.connectionStateSubscription?.unsubscribe();\n }\n\n async getService(uuid: string): Promise<CordovaServiceAdapter> {\n if (!this.serviceListCache) {\n await this.discoverServices([uuid]);\n }\n const serviceDefinition = this.serviceListCache!.find(\n (s) => s.uuid === uuid\n );\n if (!serviceDefinition) {\n throw BleComError.serviceNotFound(uuid);\n }\n return new CordovaServiceAdapter(serviceDefinition, this);\n }\n}\n\nexport class CordovaServiceAdapter implements ServiceAdapterInterface {\n get uuid() {\n return this.config.uuid;\n }\n\n constructor(\n private readonly config: ServiceDescription,\n public readonly peripheral: CordovaPeripheralAdapter\n ) {}\n\n async getCharacteristic(\n charcUUID: string\n ): Promise<CordovaCharacteristicAdapter> {\n const characteristicDescription = this.config.characteristics?.find(\n (c) => c.uuid === charcUUID\n );\n if (!characteristicDescription) {\n throw BleComError.charcacteristicNotFound(charcUUID);\n }\n return new CordovaCharacteristicAdapter(this, characteristicDescription);\n }\n\n async getCharacteristics(): Promise<CordovaCharacteristicAdapter[]> {\n if (!this.config.characteristics) {\n return [];\n }\n return this.config.characteristics.map(\n (c) => new CordovaCharacteristicAdapter(this, c)\n );\n }\n}\n\nexport class CordovaCharacteristicAdapter\n implements CharacteristicAdapterInterface\n{\n private _dataStream?: Observable<Uint8Array>;\n\n get uuid() {\n return this.config.uuid;\n }\n\n constructor(\n public readonly service: CordovaServiceAdapter,\n public readonly config: CharacteristicDescription\n ) {}\n\n get properties(): CharacteristicProperties {\n return this.config.properties;\n }\n\n get data(): Observable<{ data: Uint8Array; isNotification: boolean }> {\n return this.setupDataStreamIfRequired().pipe(\n map((data) => ({\n data,\n isNotification: true,\n }))\n );\n }\n\n protected get deviceId() {\n return this.service.peripheral.deviceId;\n }\n\n protected get pluginInterface() {\n return this.service.peripheral.cordovaPlugin;\n }\n\n async read(): Promise<Uint8Array> {\n return this.pluginInterface.characteristicReadValue(\n this.deviceId,\n this.service.uuid,\n this.uuid\n );\n }\n\n async getDescriptor(): Promise<CordovaDescriptorAdapter> {\n throw new Error(`Not implemented yet`);\n }\n\n async getDescriptors(): Promise<DescriptorAdapterInterface[]> {\n if (!this.config.descriptors) {\n return [];\n }\n return this.config.descriptors.map(\n (descriptor) => new CordovaDescriptorAdapter(descriptor, this)\n );\n }\n\n async write(\n data: Uint8Array,\n writeWithoutResponse: boolean\n ): Promise<Uint8Array> {\n if (writeWithoutResponse) {\n await this.pluginInterface.characteristicWriteWithoutResponse(\n this.deviceId,\n this.service.uuid,\n this.uuid,\n data\n );\n } else {\n await this.pluginInterface.characteristicWrite(\n this.deviceId,\n this.service.uuid,\n this.uuid,\n data\n );\n }\n return data;\n }\n\n async enableNotifications(enabled?: boolean): Promise<void> {\n if (enabled) {\n this.setupDataStreamIfRequired();\n await this.pluginInterface.characteristicStartNotification(\n this.deviceId,\n this.service.uuid,\n this.uuid\n );\n } else {\n await this.pluginInterface.characteristicStopNotification(\n this.deviceId,\n this.service.uuid,\n this.uuid\n );\n }\n }\n\n setupDataStreamIfRequired() {\n if (!this._dataStream) {\n this._dataStream = this.pluginInterface.characteristicChanged(\n this.deviceId,\n this.service.uuid,\n this.uuid\n );\n }\n return this._dataStream;\n }\n}\n\nexport class CordovaDescriptorAdapter implements DescriptorAdapterInterface {\n get uuid() {\n return this.config.uuid;\n }\n\n constructor(\n public readonly config: DescriptorDescription,\n public readonly characteristic: CordovaCharacteristicAdapter\n ) {}\n\n async readValue(): Promise<Uint8Array> {\n throw new Error(`Reading descriptor value is not implemented yet`);\n }\n\n async writeValue(data: Uint8Array): Promise<void> {\n throw new Error(`Writing descriptor value is not implemented yet`);\n }\n}\n","//\n// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.\n//\n// scanner.ts\n// device-com-ble.cordova BLE Cordova Plugin\n//\n\nimport { BleComError } from \"@iotize/tap/protocol/ble/common\";\nimport { DeviceScanner, DeviceScannerOptions } from \"@iotize/tap/scanner/api\";\nimport { BehaviorSubject, Observable, Subscription } from \"rxjs\";\nimport { CordovaBLEScanResult, RequestDeviceOptions } from \"./definitions\";\nimport { IoTizeBleCordovaPlugin } from \"./iotize-ble-cordova-plugin\";\nimport { debug } from \"./logger\";\nimport { getIoTizeBleCordovaPlugin } from \"./utility\";\n\n/**\n * BLE Tap scanner for cordova apps\n */\nexport class BLEScanner implements DeviceScanner<CordovaBLEScanResult> {\n private _results = new BehaviorSubject<CordovaBLEScanResult[]>([]);\n private _scanning$ = new BehaviorSubject<boolean>(false);\n private scanSubscription?: Subscription;\n\n /**\n * Lazy reference to iotizeBLE.\n * We don't want to reference iotizeBLE in constructor as it may be referenced\n * before cordova plugin is loaded\n */\n private get cordovaInterface(): IoTizeBleCordovaPlugin {\n return this.cordovaInterfaceOverwrite || getIoTizeBleCordovaPlugin();\n }\n\n /**\n *\n * @param cordovaInterfaceOverwrite overwrite cordova interface. Used for testing\n */\n constructor(\n private cordovaInterfaceOverwrite?: IoTizeBleCordovaPlugin,\n /**\n * Request device options used to filter scan results\n */\n readonly requestDeviceOptions?: RequestDeviceOptions\n ) {}\n\n get scanning(): Observable<boolean> {\n return this._scanning$.asObservable();\n }\n\n get isScanning(): boolean {\n return this._scanning$.value;\n }\n\n /**\n * Gets the observable on the devices$ Subject\n * @return\n */\n get results(): Observable<CordovaBLEScanResult[]> {\n return this._results.asObservable();\n }\n\n /**\n * Launches the scan for BLE devices\n * Throws if BLE is not available\n */\n async start(options?: DeviceScannerOptions): Promise<void> {\n this.scanSubscription?.unsubscribe();\n this.scanSubscription = undefined;\n this.clearResults();\n const isAvailable = await this.checkAvailable();\n if (!isAvailable) {\n throw BleComError.bleNotAvailable(\n `BLE is not available. Make sure that BLE is enabled on your device`\n );\n }\n debug(\"Start Scanning ...\");\n this._scanning$.next(true);\n return new Promise<void>((resolve, reject) => {\n this.scanSubscription = this.cordovaInterface\n .startScan(this.requestDeviceOptions)\n .subscribe(\n (result) => {\n if (result == \"Ok\") {\n resolve();\n return;\n }\n this.addOrRefreshDevice(result);\n },\n (error) => {\n debug(\"Start scan failed with error: \", error);\n this.cordovaInterface\n .getLastError()\n .then((lasterror) => {\n debug(\"Last BLE error \" + lasterror);\n })\n .catch((err) => {\n debug(\"Cannot get last BLE error: \", err);\n });\n reject(error);\n this._scanning$.next(false);\n }\n );\n });\n }\n\n /**\n *\n */\n async stop(): Promise<void> {\n debug(\"Stop Scanning ...\");\n try {\n this.scanSubscription?.unsubscribe();\n this.scanSubscription = undefined;\n await this.cordovaInterface.stopScan();\n this._scanning$.next(false);\n return;\n } catch (err) {\n this._scanning$.next(false);\n throw err;\n }\n }\n\n /**\n * Returns true if this scanner is available\n */\n checkAvailable(): Promise<boolean> {\n return this.cordovaInterface.checkAvailable();\n }\n\n private get devices() {\n return this._results.value;\n }\n\n private clearResults() {\n this._results.next([]);\n }\n\n private addOrRefreshDevice(newDevice: CordovaBLEScanResult) {\n let storedDeviceIndex = this.devices.findIndex(\n (entry) => entry.address == newDevice.address\n );\n if (storedDeviceIndex >= 0) {\n let storedDevice = this.devices[storedDeviceIndex];\n if (\n storedDevice.name != newDevice.name ||\n storedDevice.rssi != newDevice.rssi\n ) {\n debug(\n `Updating device at index ${storedDeviceIndex}, name=${storedDevice.name} with rssi=${storedDevice.rssi}`\n );\n this.devices[storedDeviceIndex] = newDevice;\n // this.devices = [...this.devices];\n this._results.next(this.devices);\n }\n } else {\n debug(\n `Adding new device name=${newDevice.name} with rssi=${newDevice.rssi}`\n );\n this.devices.push(newDevice);\n this._results.next(this.devices);\n }\n }\n}\n","import {\n bufferToHexString,\n hexStringToBuffer as hexStringToBufferCore,\n} from \"@iotize/common/byte-converter\";\nimport { safeEnumValue } from \"@iotize/common/utility\";\nimport { ConnectionState } from \"@iotize/tap/protocol/api\";\nimport { Observable, Subject, defer } from \"rxjs\";\nimport { switchMap } from \"rxjs/operators\";\nimport { map } from \"rxjs/operators\";\nimport { CordovaInterface } from \"./cordova-interface\";\nimport {\n CordovaBLEScanResult,\n RequestDeviceOptions,\n ServiceList,\n} from \"./definitions\";\nimport { CordovaBLEError } from \"./cordova-ble-error\";\n\nfunction hexStringToBuffer(str: string): Uint8Array {\n try {\n return hexStringToBufferCore(str);\n } catch (err) {\n throw CordovaBLEError.invalidNativeCallResult(str, err as Error);\n }\n}\n\ndeclare var cordova: CordovaInterface;\n\nexport class IoTizeBleCordovaPlugin {\n checkAvailable(): Promise<boolean> {\n return this.execSingleResult<boolean>(\"checkAvailable\", []);\n }\n\n requestEnableBle(): Promise<\"OK\"> {\n return this.execSingleResult<\"OK\">(\"enable\", []);\n }\n\n startScan(\n requestDeviceOptions: RequestDeviceOptions | undefined\n ): Observable<CordovaBLEScanResult | \"Ok\"> {\n return this.execMultipleResult<CordovaBLEScanResult | \"Ok\">(\"startScan\", [\n JSON.stringify(requestDeviceOptions),\n ]);\n }\n\n stopScan() {\n return this.execSingleResult<\"OK\">(\"stopScan\", []);\n }\n\n connect(\n deviceId: string,\n enableBleIfNot: boolean = true\n ): Observable<ConnectionState> {\n return this.askBleEnable(enableBleIfNot).pipe(\n switchMap(() => {\n return this.execMultipleResult<string>(\"connect\", [deviceId]).pipe(\n map((state) => {\n if (!(state in ConnectionState)) {\n console.warn(\n `Plugin native code returned an invalid connection state: \"${state}\".`\n );\n }\n return safeEnumValue(ConnectionState, state);\n })\n );\n })\n );\n }\n\n askBleEnable(askEnable: boolean): Observable<void> {\n return defer(async () => {\n if (askEnable) {\n if (!(await this.checkAvailable())) {\n await this.requestEnableBle();\n }\n }\n });\n }\n\n requestMTU(deviceId: string, mtu: number) {\n return this.execSingleResult<\"OK\">(\"requestMTU\", [deviceId, mtu]);\n }\n\n connectAndDiscoverTapServices(\n deviceId: string,\n enableBleIfNot: boolean = true\n ): Observable<ConnectionState> {\n return this.askBleEnable(enableBleIfNot).pipe(\n switchMap(() => {\n return this.execMultipleResult<string>(\n \"connectAndDiscoverTapServices\",\n [deviceId]\n ).pipe(\n map((state) => {\n if (!(state in ConnectionState)) {\n console.warn(\n `Plugin native code returned an invalid connection state: \"${state}\".`\n );\n }\n return safeEnumValue(ConnectionState, state);\n })\n );\n })\n );\n }\n\n disConnect(deviceId: string) {\n return this.execSingleResult<\"OK\">(\"disConnect\", [deviceId]);\n }\n\n close(deviceId: string) {\n return this.execSingleResult<\"OK\">(\"close\", [deviceId]);\n }\n\n isConnected(deviceId: string) {\n return this.execSingleResult<boolean>(\"isConnected\", [deviceId]);\n }\n\n async send(deviceId: string, data: Uint8Array) {\n const hexString = await this.execSingleResult<string>(\"sendRequest\", [\n deviceId,\n bufferToHexString(data),\n ]);\n return hexStringToBuffer(hexString);\n }\n\n getLastError() {\n return this.execSingleResult<string>(\"getLastError\", []);\n }\n\n characteristicStartNotification(\n deviceId: string,\n serviceId: string,\n characId: string\n ) {\n return this.execSingleResult<\"OK\">(\"characteristicStartNotification\", [\n deviceId,\n serviceId,\n characId,\n ]);\n }\n\n characteristicChanged(\n deviceId: string,\n serviceId: string,\n characId: string\n ): Observable<Uint8Array> {\n return this.execMultipleResult<string>(\"characteristicChanged\", [\n deviceId,\n serviceId,\n characId,\n ]).pipe(\n map((hexString) => {\n return hexStringToBuffer(hexString);\n })\n );\n }\n\n characteristicStopNotification(\n deviceId: string,\n serviceId: string,\n characId: string\n ) {\n return this.execSingleResult<\"OK\">(\"characteristicStopNotification\", [\n deviceId,\n serviceId,\n characId,\n ]);\n }\n\n async characteristicReadValue(\n deviceId: string,\n serviceId: string,\n characId: string\n ): Promise<Uint8Array> {\n const hexString = await this.execSingleResult<string>(\n \"characteristicRead\",\n [deviceId, serviceId, characId]\n );\n return hexStringToBuffer(hexString);\n }\n\n characteristicWrite(\n deviceId: string,\n serviceId: string,\n characId: string,\n data: Uint8Array\n ) {\n return this.execSingleResult<\"OK\">(\"characteristicWrite\", [\n deviceId,\n serviceId,\n characId,\n bufferToHexString(data),\n ]);\n }\n\n characteristicWriteWithoutResponse(\n deviceId: string,\n serviceId: string,\n characId: string,\n data: Uint8Array\n ) {\n return this.execSingleResult<\"OK\">(\"characteristicWriteWithoutResponse\", [\n deviceId,\n serviceId,\n characId,\n bufferToHexString(data),\n ]);\n }\n\n async discoverServices(deviceId: string): Promise<ServiceList> {\n const services = await this.execSingleResult<ServiceList>(\n \"discoverServices\",\n [deviceId]\n );\n return services;\n }\n\n private execSingleResult<T extends string | void | boolean | Object>(\n methodName: string,\n args: any[]\n ): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n cordova.exec(\n resolve,\n (errObject: { code?: string; message?: string }) => {\n reject(objectErrorToError(errObject));\n },\n \"BLECom\",\n methodName,\n args\n );\n });\n }\n\n private execMultipleResult<T>(\n methodName: string,\n args: any[]\n ): Observable<T> {\n const subject = new Subject<T>();\n cordova.exec<T>(\n (data) => {\n subject.next(data);\n },\n (err) => {\n subject.error(objectErrorToError(err));\n },\n \"BLECom\",\n methodName,\n args\n );\n return subject.asObservable();\n }\n}\n\nfunction objectErrorToError(errObject: { code?: string; message?: string }) {\n if (typeof errObject !== \"object\" || !errObject.code || !errObject.message) {\n return CordovaBLEError.invalidErrorResult(errObject);\n }\n if (!CordovaBLEError.isValidErrorCode(errObject.code)) {\n return CordovaBLEError.invalidErrorCode(errObject);\n }\n return new CordovaBLEError(\n errObject.message,\n CordovaBLEError.Code[errObject.code]\n );\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n\nexport {CharacteristicDescription as ɵb,ServiceDescription as ɵa} from './lib/definitions';\nexport {IoTizeBleCordovaPlugin as ɵc} from './lib/iotize-ble-cordova-plugin';"],"names":["hexStringToBufferCore"],"mappings":";;;;;;;;;;MAEa,eAAgB,SAAQ,SAAS;IAC5C,OAAO,kBAAkB,CAAC,SAGzB;QACC,OAAO,IAAI,eAAe,CACxB,wEAAwE,EACxE,eAAe,CAAC,IAAI,CAAC,aAAa,CACnC,CAAC;KACH;IAED,OAAO,gBAAgB,CAAC,SAGvB;QACC,OAAO,IAAI,eAAe,CACxB,qEAAqE,SAAS,CAAC,IAAI,iBAAiB,SAAS,CAAC,OAAO,EAAE,EACvH,eAAe,C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,EAAE,MAAM;YACpC,OAAO,CAAC,IAAI,CACV,OAAO,EACP,CAAC,SAA8C;gBAC7C,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAC;aACvC,EACD,QAAQ,EACR,UAAU,EACV,IAAI,CACL,CAAC;SACH,CAAC,CAAC;KACJ;IAEO,kBAAkB,CACxB,UAAkB,EAClB,IAAW;QAEX,MAAM,OAAO,GAAG,IAAI,OAAO,EAAK,CAAC;QACjC,OAAO,CAAC,IAAI,CACV,CAAC,IAAI;YACH,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACpB,EACD,CAAC,GAAG;YACF,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;SACxC,EACD,QAAQ,EACR,UAAU,EACV,IAAI,CACL,CAAC;QACF,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC;KAC/B;CACF;AAED,SAAS,kBAAkB,CAAC,SAA8C;IACxE,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;QAC1E,OAAO,eAAe,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;KACtD;IACD,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACrD,OAAO,eAAe,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;KACpD;IACD,OAAO,IAAI,eAAe,CACxB,SAAS,CAAC,OAAO,EACjB,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CACrC,CAAC;AACJ;;ACzQA;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"__symbolic":"module","version":4,"metadata":{"BLEComProtocol":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/tap/protocol/core","name":"QueueComProtocol","line":
|
|
1
|
+
{"__symbolic":"module","version":4,"metadata":{"BLEComProtocol":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/tap/protocol/core","name":"QueueComProtocol","line":21,"character":36},"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","module":"@iotize/tap/protocol/api","name":"ComProtocolOptions","line":33,"character":25},{"__symbolic":"reference","name":"ɵc"}]}],"_connect":[{"__symbolic":"method"}],"_disconnect":[{"__symbolic":"method"}],"write":[{"__symbolic":"method"}],"read":[{"__symbolic":"method"}],"send":[{"__symbolic":"method"}]}},"CordovaCharacteristicAdapter":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"CordovaServiceAdapter"},{"__symbolic":"reference","name":"ɵb"}]}],"read":[{"__symbolic":"method"}],"getDescriptor":[{"__symbolic":"method"}],"getDescriptors":[{"__symbolic":"method"}],"write":[{"__symbolic":"method"}],"enableNotifications":[{"__symbolic":"method"}],"setupDataStreamIfRequired":[{"__symbolic":"method"}]}},"CordovaPeripheralAdapter":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","name":"ɵc"}]}],"discoverServices":[{"__symbolic":"method"}],"connect":[{"__symbolic":"method"}],"disconnect":[{"__symbolic":"method"}],"close":[{"__symbolic":"method"}],"getService":[{"__symbolic":"method"}]}},"CordovaServiceAdapter":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"ɵa"},{"__symbolic":"reference","name":"CordovaPeripheralAdapter"}]}],"getCharacteristic":[{"__symbolic":"method"}],"getCharacteristics":[{"__symbolic":"method"}]}},"ɵa":{"__symbolic":"interface"},"ɵb":{"__symbolic":"interface"},"CordovaBLEScanResult":{"__symbolic":"interface"},"RequestDeviceOptions":{"__symbolic":"interface"},"BLEScanner":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"ɵc"},{"__symbolic":"reference","name":"RequestDeviceOptions"}]}],"start":[{"__symbolic":"method"}],"stop":[{"__symbolic":"method"}],"checkAvailable":[{"__symbolic":"method"}],"clearResults":[{"__symbolic":"method"}],"addOrRefreshDevice":[{"__symbolic":"method"}]}},"getIoTizeBleCordovaPlugin":{"__symbolic":"function"},"ɵc":{"__symbolic":"class","members":{"checkAvailable":[{"__symbolic":"method"}],"requestEnableBle":[{"__symbolic":"method"}],"startScan":[{"__symbolic":"method"}],"stopScan":[{"__symbolic":"method"}],"connect":[{"__symbolic":"method"}],"askBleEnable":[{"__symbolic":"method"}],"requestMTU":[{"__symbolic":"method"}],"connectAndDiscoverTapServices":[{"__symbolic":"method"}],"disConnect":[{"__symbolic":"method"}],"close":[{"__symbolic":"method"}],"isConnected":[{"__symbolic":"method"}],"send":[{"__symbolic":"method"}],"getLastError":[{"__symbolic":"method"}],"characteristicStartNotification":[{"__symbolic":"method"}],"characteristicChanged":[{"__symbolic":"method"}],"characteristicStopNotification":[{"__symbolic":"method"}],"characteristicReadValue":[{"__symbolic":"method"}],"characteristicWrite":[{"__symbolic":"method"}],"characteristicWriteWithoutResponse":[{"__symbolic":"method"}],"discoverServices":[{"__symbolic":"method"}],"execSingleResult":[{"__symbolic":"method"}],"execMultipleResult":[{"__symbolic":"method"}]}}},"origins":{"BLEComProtocol":"./lib/ble-com-protocol","CordovaCharacteristicAdapter":"./lib/cordova-service-adapter","CordovaPeripheralAdapter":"./lib/cordova-service-adapter","CordovaServiceAdapter":"./lib/cordova-service-adapter","ɵa":"./lib/definitions","ɵb":"./lib/definitions","CordovaBLEScanResult":"./lib/definitions","RequestDeviceOptions":"./lib/definitions","BLEScanner":"./lib/scanner","getIoTizeBleCordovaPlugin":"./lib/utility","ɵc":"./lib/iotize-ble-cordova-plugin"},"importAs":"@iotize/device-com-ble.cordova"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ComProtocolConnectOptions, ComProtocolDisconnectOptions, ComProtocolOptions, ComProtocolSendOptions } from
|
|
2
|
-
import { QueueComProtocol } from
|
|
3
|
-
import { Observable } from
|
|
4
|
-
import { IoTizeBleCordovaPlugin } from
|
|
1
|
+
import { ComProtocolConnectOptions, ComProtocolDisconnectOptions, ComProtocolOptions, ComProtocolSendOptions } from '@iotize/tap/protocol/api';
|
|
2
|
+
import { QueueComProtocol } from '@iotize/tap/protocol/core';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { IoTizeBleCordovaPlugin } from './iotize-ble-cordova-plugin';
|
|
5
5
|
export declare class BLEComProtocol extends QueueComProtocol {
|
|
6
6
|
private deviceId;
|
|
7
7
|
readonly cordovaInterfaceOverwrite?: IoTizeBleCordovaPlugin | undefined;
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
<framework src="src/android/build.gradle" custom="true" type="gradleReference" />
|
|
21
21
|
<source-file src="src/android/src/ble" target-dir="java/com/iotize/plugin/cordova"/>
|
|
22
22
|
<config-file target="AndroidManifest.xml" parent="/manifest">
|
|
23
|
+
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
|
|
24
|
+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
|
|
23
25
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
24
|
-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
|
|
25
|
-
<uses-permission android:name="android.permission.
|
|
26
|
-
<uses-permission android:name="android.permission.
|
|
26
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
|
27
|
+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
|
|
28
|
+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
|
27
29
|
</config-file>
|
|
28
30
|
</platform>
|
|
29
31
|
|
|
Binary file
|
package/src/android/build.gradle
CHANGED
|
@@ -11,7 +11,7 @@ repositories{
|
|
|
11
11
|
|
|
12
12
|
dependencies {
|
|
13
13
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.61"
|
|
14
|
-
implementation 'org.apache.commons:commons-collections4:4.
|
|
14
|
+
implementation 'org.apache.commons:commons-collections4:4.4'
|
|
15
15
|
implementation 'com.iotize.android:iotize-core:1.0.0-alpha.9'
|
|
16
16
|
implementation 'com.iotize.android:iotize-client:1.0.0-alpha.9'
|
|
17
17
|
implementation 'com.iotize.android:iotize-device-api:1.0.0-alpha.9'
|
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
package com.iotize.plugin.cordova.ble;
|
|
9
9
|
|
|
10
|
+
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
|
|
10
11
|
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
|
|
12
|
+
import static android.Manifest.permission.BLUETOOTH_CONNECT;
|
|
13
|
+
import static android.Manifest.permission.BLUETOOTH_SCAN;
|
|
11
14
|
|
|
12
15
|
import android.annotation.SuppressLint;
|
|
13
16
|
import android.app.Activity;
|
|
@@ -20,8 +23,11 @@ import android.bluetooth.BluetoothManager;
|
|
|
20
23
|
import android.content.Context;
|
|
21
24
|
import android.content.Intent;
|
|
22
25
|
import android.content.pm.PackageManager;
|
|
26
|
+
import android.os.Build;
|
|
23
27
|
import android.util.Log;
|
|
24
28
|
|
|
29
|
+
import com.iotize.android.communication.client.impl.protocol.ConnectionState;
|
|
30
|
+
import com.iotize.android.communication.client.impl.protocol.exception.ProtocolNotConnectedException;
|
|
25
31
|
import com.iotize.android.communication.protocol.ble.BLEProtocol;
|
|
26
32
|
import com.iotize.android.communication.protocol.ble.DeviceManager;
|
|
27
33
|
import com.iotize.android.communication.protocol.ble.characteristics.CharacteristicAdapter;
|
|
@@ -76,14 +82,15 @@ public class BLECom extends CordovaPlugin {
|
|
|
76
82
|
|
|
77
83
|
|
|
78
84
|
private static final int REQUEST_ENABLE_BLUETOOTH = 1;
|
|
79
|
-
private static final int
|
|
85
|
+
private static final int REQUEST_BLE_PERMISSIONS = 2;
|
|
80
86
|
|
|
81
87
|
private static final String TAG = "BLECom";
|
|
82
88
|
private DeviceManager<BLEProtocol> peripherals;
|
|
83
89
|
private BluetoothAdapter bluetoothAdapter;
|
|
84
90
|
private PluginResponse enableBluetoothCallback;
|
|
85
91
|
private PluginResponse pluginResponseDiscoverDevice;
|
|
86
|
-
|
|
92
|
+
@Nullable
|
|
93
|
+
private ConnectAndDiscoverTapServicesRequest pluginResponseConnectAndDiscoverTapServices;
|
|
87
94
|
private BLEScanner scanner;
|
|
88
95
|
private IOnDeviceDiscovered<BLEScanner.BLEScanData> onDeviceDiscoveredCallback;
|
|
89
96
|
@Nullable
|
|
@@ -108,7 +115,6 @@ public class BLECom extends CordovaPlugin {
|
|
|
108
115
|
|
|
109
116
|
@SuppressLint("MissingPermission")
|
|
110
117
|
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) {
|
|
111
|
-
|
|
112
118
|
PluginResponse pluginResponse = new PluginResponse(
|
|
113
119
|
action,
|
|
114
120
|
args,
|
|
@@ -139,7 +145,7 @@ public class BLECom extends CordovaPlugin {
|
|
|
139
145
|
} else if (action.equals(CONNECT_AND_DISCOVER_TAP_SERVICES)) {
|
|
140
146
|
Log.d(TAG, CONNECT_AND_DISCOVER_TAP_SERVICES);
|
|
141
147
|
String macAddress = argsHelper.getString(0);
|
|
142
|
-
this.connectAndDiscoverTapServices(pluginResponse, macAddress);
|
|
148
|
+
this.connectAndDiscoverTapServices(new ConnectAndDiscoverTapServicesRequest(pluginResponse, macAddress));
|
|
143
149
|
} else if (action.equals(DISCONNECT)) {
|
|
144
150
|
Log.d(TAG, DISCONNECT);
|
|
145
151
|
String macAddress = argsHelper.getString(0);
|
|
@@ -162,12 +168,7 @@ public class BLECom extends CordovaPlugin {
|
|
|
162
168
|
boolean isConnected = peripherals.get(macAddress).isConnected();
|
|
163
169
|
pluginResponse.success(isConnected);
|
|
164
170
|
} else if (action.equals(ENABLE)) {
|
|
165
|
-
|
|
166
|
-
Log.w(TAG, "There is already an enable request pending...");
|
|
167
|
-
}
|
|
168
|
-
enableBluetoothCallback = pluginResponse;
|
|
169
|
-
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
|
170
|
-
cordova.startActivityForResult(this, intent, REQUEST_ENABLE_BLUETOOTH);
|
|
171
|
+
this.enableBLE(pluginResponse);
|
|
171
172
|
} else if (action.equals(CHARACTERISTIC_READ)) {
|
|
172
173
|
String macAddress = argsHelper.getString(0);
|
|
173
174
|
UUID serviceUUID = argsHelper.getUUID(1);
|
|
@@ -217,8 +218,40 @@ public class BLECom extends CordovaPlugin {
|
|
|
217
218
|
|
|
218
219
|
}
|
|
219
220
|
|
|
221
|
+
private void enableBLE(PluginResponse pluginResponse) {
|
|
222
|
+
if (enableBluetoothCallback != null) {
|
|
223
|
+
Log.w(TAG, "There is already an enable request pending...");
|
|
224
|
+
}
|
|
225
|
+
enableBluetoothCallback = pluginResponse;
|
|
226
|
+
if (!this._checkPermissions()) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
|
230
|
+
cordova.startActivityForResult(this, intent, REQUEST_ENABLE_BLUETOOTH);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private boolean _checkPermissions() {
|
|
234
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
235
|
+
if (!PermissionHelper.hasPermission(this, BLUETOOTH_SCAN) || !PermissionHelper.hasPermission(this, BLUETOOTH_CONNECT)) {
|
|
236
|
+
PermissionHelper.requestPermissions(this, REQUEST_BLE_PERMISSIONS, new String[]{
|
|
237
|
+
BLUETOOTH_SCAN,
|
|
238
|
+
BLUETOOTH_CONNECT
|
|
239
|
+
});
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
if (!PermissionHelper.hasPermission(this, ACCESS_FINE_LOCATION)) {
|
|
244
|
+
PermissionHelper.requestPermissions(this, REQUEST_BLE_PERMISSIONS, new String[]{
|
|
245
|
+
ACCESS_COARSE_LOCATION,
|
|
246
|
+
ACCESS_FINE_LOCATION
|
|
247
|
+
});
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
|
|
220
254
|
private void discoverServices(PluginResponse pluginResponse, String macAddress) throws Exception {
|
|
221
|
-
// TODO async ?
|
|
222
255
|
BLEProtocol peripheral = peripherals.get(macAddress);
|
|
223
256
|
peripheral.discoverServices();
|
|
224
257
|
List<BluetoothGattService> services = peripheral.getGatt().getServices();
|
|
@@ -265,9 +298,7 @@ public class BLECom extends CordovaPlugin {
|
|
|
265
298
|
private void startBLEScanner(@Nullable RequestDeviceOptions options, @NonNull PluginResponse pluginResponse) {
|
|
266
299
|
pluginResponseDiscoverDevice = pluginResponse;
|
|
267
300
|
|
|
268
|
-
if (!
|
|
269
|
-
permissionCallback = pluginResponse;
|
|
270
|
-
PermissionHelper.requestPermission(this, REQUEST_SCAN_PERMISSIONS, ACCESS_FINE_LOCATION);
|
|
301
|
+
if (!this._checkPermissions()) {
|
|
271
302
|
return;
|
|
272
303
|
}
|
|
273
304
|
|
|
@@ -350,14 +381,11 @@ public class BLECom extends CordovaPlugin {
|
|
|
350
381
|
});
|
|
351
382
|
}
|
|
352
383
|
|
|
384
|
+
@SuppressLint("MissingPermission")
|
|
353
385
|
private void close(final PluginResponse pluginResponse, String macAddress) {
|
|
354
386
|
executeAsync(() -> {
|
|
355
387
|
try {
|
|
356
|
-
|
|
357
|
-
if (peripheral != null) {
|
|
358
|
-
peripheral.getGatt().close();
|
|
359
|
-
peripherals.remove(macAddress);
|
|
360
|
-
}
|
|
388
|
+
this._removePeripheral(macAddress);
|
|
361
389
|
pluginResponse.success();
|
|
362
390
|
} catch (Exception e) {
|
|
363
391
|
pluginResponse.error(new BLEComError(BLEComError.Code.DISCONNECTION_ERROR, e));
|
|
@@ -365,6 +393,17 @@ public class BLECom extends CordovaPlugin {
|
|
|
365
393
|
});
|
|
366
394
|
}
|
|
367
395
|
|
|
396
|
+
@SuppressLint("MissingPermission")
|
|
397
|
+
private void _removePeripheral(@NonNull String macAddress) {
|
|
398
|
+
BLEProtocol peripheral = peripherals.getIfExists(macAddress);
|
|
399
|
+
if (peripheral != null) {
|
|
400
|
+
if (PermissionHelper.hasPermission(this, BLUETOOTH_CONNECT)) {
|
|
401
|
+
peripheral.getGatt().close();
|
|
402
|
+
}
|
|
403
|
+
peripherals.remove(macAddress);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
368
407
|
private void requestMtu(final PluginResponse pluginResponse, String macAddress, int mtu) {
|
|
369
408
|
BLEProtocol peripheral = peripherals.get(macAddress);
|
|
370
409
|
BluetoothGatt gatt = peripheral.getGatt();
|
|
@@ -396,7 +435,17 @@ public class BLECom extends CordovaPlugin {
|
|
|
396
435
|
try {
|
|
397
436
|
byte[] response = peripheral.send(data);
|
|
398
437
|
pluginResponse.success(response);
|
|
399
|
-
}
|
|
438
|
+
}
|
|
439
|
+
catch (ProtocolNotConnectedException e) {
|
|
440
|
+
try {
|
|
441
|
+
this._removePeripheral(deviceId);
|
|
442
|
+
} catch (Throwable ignoredError){
|
|
443
|
+
Log.d(TAG, "Ignored remove peripheral error", ignoredError);
|
|
444
|
+
}
|
|
445
|
+
peripheral.setConnectionStatus(ConnectionState.DISCONNECTED);
|
|
446
|
+
pluginResponse.error(BLEComError.notConnectedError(deviceId));
|
|
447
|
+
}
|
|
448
|
+
catch (Exception e) {
|
|
400
449
|
pluginResponse.error(BLEComError.lwM2MTapRequestError(e, deviceId, data));
|
|
401
450
|
}
|
|
402
451
|
});
|
|
@@ -469,19 +518,24 @@ public class BLECom extends CordovaPlugin {
|
|
|
469
518
|
});
|
|
470
519
|
}
|
|
471
520
|
|
|
472
|
-
private void connectAndDiscoverTapServices(
|
|
473
|
-
|
|
474
|
-
|
|
521
|
+
private void connectAndDiscoverTapServices(@NonNull ConnectAndDiscoverTapServicesRequest info) throws BLEComError {
|
|
522
|
+
pluginResponseConnectAndDiscoverTapServices = info;
|
|
523
|
+
// If app targets Android 12 and higher: connect need android.permission.BLUETOOTH_CONNECT permission
|
|
524
|
+
if (!this._checkPermissions()) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
BLEProtocol finalPeripheral = this.getOrCreatePeripheral(info.macAddress, null);
|
|
528
|
+
setConnectionStateCallback(info.pluginResponse, info.macAddress);
|
|
475
529
|
if (finalPeripheral.isConnected()) {
|
|
476
|
-
pluginResponse.newResult("CONNECTED");
|
|
530
|
+
info.pluginResponse.newResult("CONNECTED");
|
|
477
531
|
return;
|
|
478
532
|
}
|
|
479
533
|
executeAsync(() -> {
|
|
480
534
|
try {
|
|
481
535
|
finalPeripheral.connect();
|
|
482
|
-
pluginResponse.newResult("CONNECTED");
|
|
536
|
+
info.pluginResponse.newResult("CONNECTED");
|
|
483
537
|
} catch (Exception e) {
|
|
484
|
-
pluginResponse.error(BLEComError.connectionError(e));
|
|
538
|
+
info.pluginResponse.error(BLEComError.connectionError(e));
|
|
485
539
|
}
|
|
486
540
|
});
|
|
487
541
|
}
|
|
@@ -507,19 +561,40 @@ public class BLECom extends CordovaPlugin {
|
|
|
507
561
|
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
508
562
|
for (int result : grantResults) {
|
|
509
563
|
if (result == PackageManager.PERMISSION_DENIED) {
|
|
510
|
-
LOG.d(TAG, "User *rejected*
|
|
511
|
-
if (
|
|
512
|
-
|
|
564
|
+
LOG.d(TAG, "User *rejected* permission ");
|
|
565
|
+
if (pluginResponseDiscoverDevice != null) {
|
|
566
|
+
pluginResponseDiscoverDevice.error(BLEComError.missingPermissionError());
|
|
567
|
+
pluginResponseDiscoverDevice = null;
|
|
568
|
+
}
|
|
569
|
+
if (enableBluetoothCallback != null) {
|
|
570
|
+
enableBluetoothCallback.error(BLEComError.missingPermissionError());
|
|
571
|
+
enableBluetoothCallback = null;
|
|
572
|
+
}
|
|
573
|
+
if (pluginResponseConnectAndDiscoverTapServices != null) {
|
|
574
|
+
pluginResponseConnectAndDiscoverTapServices.pluginResponse.error(BLEComError.missingPermissionError());
|
|
575
|
+
pluginResponseConnectAndDiscoverTapServices = null;
|
|
513
576
|
}
|
|
514
577
|
return;
|
|
515
578
|
}
|
|
516
579
|
}
|
|
517
580
|
|
|
518
581
|
switch (requestCode) {
|
|
519
|
-
case
|
|
582
|
+
case REQUEST_BLE_PERMISSIONS:
|
|
520
583
|
LOG.d(TAG, "User granted scan permissions");
|
|
521
|
-
|
|
522
|
-
|
|
584
|
+
if (pluginResponseDiscoverDevice != null) {
|
|
585
|
+
this.startScan(this.requestDeviceOptions, pluginResponseDiscoverDevice);
|
|
586
|
+
}
|
|
587
|
+
if (enableBluetoothCallback != null) {
|
|
588
|
+
this.enableBLE(enableBluetoothCallback);
|
|
589
|
+
}
|
|
590
|
+
if (pluginResponseConnectAndDiscoverTapServices != null) {
|
|
591
|
+
try {
|
|
592
|
+
this.connectAndDiscoverTapServices(pluginResponseConnectAndDiscoverTapServices);
|
|
593
|
+
} catch (com.iotize.plugin.cordova.ble.BLEComError e) {
|
|
594
|
+
pluginResponseConnectAndDiscoverTapServices.pluginResponse.error(e);
|
|
595
|
+
}
|
|
596
|
+
pluginResponseConnectAndDiscoverTapServices = null;
|
|
597
|
+
}
|
|
523
598
|
break;
|
|
524
599
|
}
|
|
525
600
|
}
|
|
@@ -537,7 +612,7 @@ public class BLECom extends CordovaPlugin {
|
|
|
537
612
|
} else {
|
|
538
613
|
LOG.d(TAG, "User did *NOT* enable Bluetooth");
|
|
539
614
|
if (enableBluetoothCallback != null) {
|
|
540
|
-
enableBluetoothCallback.error(
|
|
615
|
+
enableBluetoothCallback.error(BLEComError.bleNotEnabled());
|
|
541
616
|
}
|
|
542
617
|
}
|
|
543
618
|
|
|
@@ -557,4 +632,16 @@ public class BLECom extends CordovaPlugin {
|
|
|
557
632
|
pluginResponse.newResult(newConnectionState.toString());
|
|
558
633
|
});
|
|
559
634
|
}
|
|
635
|
+
|
|
636
|
+
private class ConnectAndDiscoverTapServicesRequest {
|
|
637
|
+
@NonNull
|
|
638
|
+
final PluginResponse pluginResponse;
|
|
639
|
+
@NonNull
|
|
640
|
+
final String macAddress;
|
|
641
|
+
|
|
642
|
+
public ConnectAndDiscoverTapServicesRequest(@NonNull PluginResponse pluginResponse, @NonNull String macAddress) {
|
|
643
|
+
this.pluginResponse = pluginResponse;
|
|
644
|
+
this.macAddress = macAddress;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
560
647
|
}
|
|
@@ -16,12 +16,12 @@ public class BLEComError extends Exception {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
public BLEComError(String code, Throwable cause) {
|
|
19
|
-
super(cause.getMessage()
|
|
19
|
+
super(cause.getMessage());
|
|
20
20
|
this.code = code;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
public BLEComError(String code, String message) {
|
|
24
|
-
super(message
|
|
24
|
+
super(message);
|
|
25
25
|
this.code = code;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -74,6 +74,20 @@ public class BLEComError extends Exception {
|
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
public static BLEComError bleNotEnabled() {
|
|
78
|
+
return new BLEComError(
|
|
79
|
+
Code.BLE_ADPATER_NOT_AVAILABLE,
|
|
80
|
+
"User did not enable BLE"
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public static BLEComError missingPermissionError() {
|
|
85
|
+
return new BLEComError(
|
|
86
|
+
Code.BLE_ADPATER_NOT_AVAILABLE,
|
|
87
|
+
"User has rejected BLE related permissions"
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
77
91
|
public String getCode() {
|
|
78
92
|
return code;
|
|
79
93
|
}
|