@iotize/device-com-ble.cordova 3.2.1 → 3.3.2
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/README.md +174 -177
- package/bundles/iotize-device-com-ble.cordova.umd.js +102 -69
- package/bundles/iotize-device-com-ble.cordova.umd.js.map +1 -1
- package/bundles/iotize-device-com-ble.cordova.umd.min.js +16 -0
- package/bundles/iotize-device-com-ble.cordova.umd.min.js.map +1 -0
- package/esm2015/lib/ble-com-protocol.js +10 -10
- package/esm2015/lib/ble-com-protocol.js.map +1 -1
- package/esm2015/lib/cordova-ble-error.js +11 -2
- package/esm2015/lib/cordova-ble-error.js.map +1 -1
- package/esm2015/lib/cordova-interface.js.map +1 -1
- package/esm2015/lib/cordova-service-adapter.js +15 -14
- package/esm2015/lib/cordova-service-adapter.js.map +1 -1
- package/esm2015/lib/cordova-service-adapter.metadata.json +1 -1
- package/esm2015/lib/definitions.js +0 -2
- package/esm2015/lib/definitions.js.map +1 -1
- package/esm2015/lib/iotize-ble-cordova-plugin.js +59 -51
- package/esm2015/lib/iotize-ble-cordova-plugin.js.map +1 -1
- package/esm2015/lib/iotize-ble-cordova-plugin.metadata.json +1 -1
- package/esm2015/lib/iotize-ble-cordova-plugin.ngsummary.json +1 -1
- package/esm2015/lib/logger.js +1 -1
- package/esm2015/lib/logger.js.map +1 -1
- package/esm2015/lib/scanner.js +14 -12
- package/esm2015/lib/scanner.js.map +1 -1
- package/esm2015/lib/scanner.metadata.json +1 -1
- package/esm2015/lib/utility.js +1 -1
- package/esm2015/lib/utility.js.map +1 -1
- package/esm2015/public_api.js +4 -4
- package/esm2015/public_api.js.map +1 -1
- package/fesm2015/iotize-device-com-ble.cordova.js +93 -74
- 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/lib/cordova-ble-error.d.ts +12 -3
- package/lib/cordova-service-adapter.d.ts +1 -1
- package/lib/definitions.d.ts +1 -1
- package/lib/iotize-ble-cordova-plugin.d.ts +4 -3
- package/lib/scanner.d.ts +4 -4
- package/package.json +1 -1
- package/plugin.xml +66 -63
- package/public_api.d.ts +5 -5
- package/src/android/.gradle/4.8.1/fileHashes/fileHashes.bin +0 -0
- package/src/android/.gradle/4.8.1/fileHashes/fileHashes.lock +0 -0
- package/src/android/build.gradle +1 -0
- package/src/android/src/ble/BLECom.java +559 -558
- package/src/ios/BLECom.swift +732 -732
- package/src/windows/IoTizeBLE.pdb +0 -0
- package/src/windows/IoTizeBLE.pri +0 -0
- package/src/windows/iotize-ble-com.js +159 -179
- package/www/plugin.js +1 -1
package/esm2015/lib/scanner.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//
|
|
2
|
-
// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.
|
|
2
|
+
// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.
|
|
3
3
|
//
|
|
4
4
|
// scanner.ts
|
|
5
5
|
// device-com-ble.cordova BLE Cordova Plugin
|
|
@@ -13,10 +13,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
13
13
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
-
import { BleComError } from
|
|
17
|
-
import { BehaviorSubject } from
|
|
18
|
-
import { debug } from
|
|
19
|
-
import { getIoTizeBleCordovaPlugin } from
|
|
16
|
+
import { BleComError } from "@iotize/tap/protocol/ble/common";
|
|
17
|
+
import { BehaviorSubject } from "rxjs";
|
|
18
|
+
import { debug } from "./logger";
|
|
19
|
+
import { getIoTizeBleCordovaPlugin } from "./utility";
|
|
20
20
|
/**
|
|
21
21
|
* BLE Tap scanner for cordova apps
|
|
22
22
|
*/
|
|
@@ -73,22 +73,23 @@ export class BLEScanner {
|
|
|
73
73
|
debug("Start Scanning ...");
|
|
74
74
|
this._scanning$.next(true);
|
|
75
75
|
return new Promise((resolve, reject) => {
|
|
76
|
-
this.scanSubscription = this.cordovaInterface
|
|
77
|
-
.
|
|
78
|
-
|
|
76
|
+
this.scanSubscription = this.cordovaInterface
|
|
77
|
+
.startScan(this.requestDeviceOptions)
|
|
78
|
+
.subscribe((result) => {
|
|
79
|
+
if (result == "Ok") {
|
|
79
80
|
resolve();
|
|
80
81
|
return;
|
|
81
82
|
}
|
|
82
83
|
this.addOrRefreshDevice(result);
|
|
83
|
-
}, error => {
|
|
84
|
-
debug(
|
|
84
|
+
}, (error) => {
|
|
85
|
+
debug("Start scan failed with error: ", error);
|
|
85
86
|
this.cordovaInterface
|
|
86
87
|
.getLastError()
|
|
87
88
|
.then((lasterror) => {
|
|
88
89
|
debug("Last BLE error " + lasterror);
|
|
89
90
|
})
|
|
90
91
|
.catch((err) => {
|
|
91
|
-
debug(
|
|
92
|
+
debug("Cannot get last BLE error: ", err);
|
|
92
93
|
});
|
|
93
94
|
reject(error);
|
|
94
95
|
this._scanning$.next(false);
|
|
@@ -132,7 +133,8 @@ export class BLEScanner {
|
|
|
132
133
|
let storedDeviceIndex = this.devices.findIndex((entry) => entry.address == newDevice.address);
|
|
133
134
|
if (storedDeviceIndex >= 0) {
|
|
134
135
|
let storedDevice = this.devices[storedDeviceIndex];
|
|
135
|
-
if (storedDevice.name != newDevice.name ||
|
|
136
|
+
if (storedDevice.name != newDevice.name ||
|
|
137
|
+
storedDevice.rssi != newDevice.rssi) {
|
|
136
138
|
debug(`Updating device at index ${storedDeviceIndex}, name=${storedDevice.name} with rssi=${storedDevice.rssi}`);
|
|
137
139
|
this.devices[storedDeviceIndex] = newDevice;
|
|
138
140
|
// this.devices = [...this.devices];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../../../../src/lib/scanner.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../../../../src/lib/scanner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,IAAI,EAAE,CACvE,CAAC;YACF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAClC;IACH,CAAC;CACF","sourcesContent":["//\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"__symbolic":"module","version":4,"metadata":{"BLEScanner":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./iotize-ble-cordova-plugin","name":"IoTizeBleCordovaPlugin","line":37,"character":
|
|
1
|
+
[{"__symbolic":"module","version":4,"metadata":{"BLEScanner":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./iotize-ble-cordova-plugin","name":"IoTizeBleCordovaPlugin","line":37,"character":40},{"__symbolic":"reference","module":"./definitions","name":"RequestDeviceOptions","line":41,"character":36}]}],"start":[{"__symbolic":"method"}],"stop":[{"__symbolic":"method"}],"checkAvailable":[{"__symbolic":"method"}],"clearResults":[{"__symbolic":"method"}],"addOrRefreshDevice":[{"__symbolic":"method"}]}}}}]
|
package/esm2015/lib/utility.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utility.js","sourceRoot":"","sources":["../../../../../src/lib/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAKtD,MAAM,UAAU,yBAAyB;
|
|
1
|
+
{"version":3,"file":"utility.js","sourceRoot":"","sources":["../../../../../src/lib/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAKtD,MAAM,UAAU,yBAAyB;IACvC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACjC,MAAM,eAAe,CAAC,gBAAgB,EAAE,CAAC;KAC1C;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["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"]}
|
package/esm2015/public_api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { BLEComProtocol } from
|
|
2
|
-
export { CordovaCharacteristicAdapter, CordovaPeripheralAdapter, CordovaServiceAdapter } from
|
|
3
|
-
export { BLEScanner } from
|
|
4
|
-
export { getIoTizeBleCordovaPlugin } from
|
|
1
|
+
export { BLEComProtocol } from "./lib/ble-com-protocol";
|
|
2
|
+
export { CordovaCharacteristicAdapter, CordovaPeripheralAdapter, CordovaServiceAdapter, } from "./lib/cordova-service-adapter";
|
|
3
|
+
export { BLEScanner } from "./lib/scanner";
|
|
4
|
+
export { getIoTizeBleCordovaPlugin } from "./lib/utility";
|
|
5
5
|
//# sourceMappingURL=public_api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_api.js","sourceRoot":"","sources":["../../../../src/public_api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,
|
|
1
|
+
{"version":3,"file":"public_api.js","sourceRoot":"","sources":["../../../../src/public_api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["export { BLEComProtocol } from \"./lib/ble-com-protocol\";\nexport {\n CordovaCharacteristicAdapter,\n CordovaPeripheralAdapter,\n CordovaServiceAdapter,\n} from \"./lib/cordova-service-adapter\";\nexport { CordovaBLEScanResult, RequestDeviceOptions } from \"./lib/definitions\";\nexport { BLEScanner } from \"./lib/scanner\";\nexport { getIoTizeBleCordovaPlugin } from \"./lib/utility\";\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ConnectionState } from '@iotize/tap/protocol/api';
|
|
2
2
|
import { QueueComProtocol } from '@iotize/tap/protocol/core';
|
|
3
3
|
import { defer, BehaviorSubject, Subject } from 'rxjs';
|
|
4
|
-
import { tap, filter, first, distinctUntilChanged, shareReplay, map } from 'rxjs/operators';
|
|
4
|
+
import { tap, filter, first, distinctUntilChanged, shareReplay, map, switchMap } from 'rxjs/operators';
|
|
5
5
|
import { createDebugger } from '@iotize/common/debug';
|
|
6
6
|
import { CodeError } from '@iotize/common/error';
|
|
7
7
|
import { BleComError } from '@iotize/tap/protocol/ble/common';
|
|
@@ -21,7 +21,7 @@ class CordovaBLEError extends CodeError {
|
|
|
21
21
|
return new CordovaBLEError(`Internal error: native call returned an invalid data type. ${cause.message}`, CordovaBLEError.Code.InternalError);
|
|
22
22
|
}
|
|
23
23
|
static isValidErrorCode(code) {
|
|
24
|
-
return
|
|
24
|
+
return code in CordovaBLEError.Code;
|
|
25
25
|
}
|
|
26
26
|
static iotizeBLEMissing() {
|
|
27
27
|
return new CordovaBLEError(`iotizeBLE global variable does not exist. Are you sure app is running inside a Cordova application ?`, CordovaBLEError.Code.InternalError);
|
|
@@ -33,11 +33,20 @@ class CordovaBLEError extends CodeError {
|
|
|
33
33
|
(function (Code) {
|
|
34
34
|
Code["InternalError"] = "CordovaBLEErrorInternalError";
|
|
35
35
|
Code["IllegalArgument"] = "CordovaBLEErrorIllegalArgument";
|
|
36
|
+
Code["BLENotAvailable"] = "CordovaBLEErrorBLENotAvailable";
|
|
37
|
+
Code["InvalidMacAddress"] = "InvalidMacAddressInvalidMacAddress";
|
|
38
|
+
Code["ConnectionError"] = "CordovaBLEErrorConnectionError";
|
|
39
|
+
Code["RequestError"] = "CordovaBLEErrorRequestError";
|
|
40
|
+
Code["LocationServiceDisabled"] = "CordovaBLEErrorLocationServiceDisabled";
|
|
41
|
+
Code["DisconnectError"] = "CordovaBLEErrorDisconnectError";
|
|
42
|
+
Code["IllegalAction"] = "CordovaBLEErrorIllegalAction";
|
|
43
|
+
Code["NotConnectedError"] = "CordovaBLEErrorNotConnectedError";
|
|
44
|
+
Code["StatusCodeError"] = "CordovaBLEErrorStatusCodeError";
|
|
36
45
|
})(Code = CordovaBLEError.Code || (CordovaBLEError.Code = {}));
|
|
37
46
|
})(CordovaBLEError || (CordovaBLEError = {}));
|
|
38
47
|
|
|
39
48
|
function getIoTizeBleCordovaPlugin() {
|
|
40
|
-
if (typeof iotizeBLE !==
|
|
49
|
+
if (typeof iotizeBLE !== "object") {
|
|
41
50
|
throw CordovaBLEError.iotizeBLEMissing();
|
|
42
51
|
}
|
|
43
52
|
return iotizeBLE;
|
|
@@ -73,7 +82,7 @@ class BLEComProtocol extends QueueComProtocol {
|
|
|
73
82
|
return this.cordovaInterfaceOverwrite || getIoTizeBleCordovaPlugin();
|
|
74
83
|
}
|
|
75
84
|
_connect(options) {
|
|
76
|
-
debug(
|
|
85
|
+
debug("_connect", options);
|
|
77
86
|
return this.pluginInterface
|
|
78
87
|
.connectAndDiscoverTapServices(this.deviceId)
|
|
79
88
|
.pipe(tap((state) => {
|
|
@@ -81,17 +90,17 @@ class BLEComProtocol extends QueueComProtocol {
|
|
|
81
90
|
}), filter((state) => state === ConnectionState.CONNECTED), first());
|
|
82
91
|
}
|
|
83
92
|
_disconnect(options) {
|
|
84
|
-
debug(
|
|
93
|
+
debug("_disconnect", options);
|
|
85
94
|
return defer(() => this.pluginInterface.disConnect(this.deviceId));
|
|
86
95
|
}
|
|
87
96
|
write(data) {
|
|
88
97
|
return __awaiter$3(this, void 0, void 0, function* () {
|
|
89
|
-
throw new Error(
|
|
98
|
+
throw new Error("Method not implemented.");
|
|
90
99
|
});
|
|
91
100
|
}
|
|
92
101
|
read() {
|
|
93
102
|
return __awaiter$3(this, void 0, void 0, function* () {
|
|
94
|
-
throw new Error(
|
|
103
|
+
throw new Error("Method not implemented.");
|
|
95
104
|
});
|
|
96
105
|
}
|
|
97
106
|
send(data, options) {
|
|
@@ -118,7 +127,7 @@ class CordovaPeripheralAdapter {
|
|
|
118
127
|
return this._stateChange.asObservable().pipe(distinctUntilChanged());
|
|
119
128
|
}
|
|
120
129
|
get name() {
|
|
121
|
-
// TODO device name ?
|
|
130
|
+
// TODO device name ?
|
|
122
131
|
return this.id;
|
|
123
132
|
}
|
|
124
133
|
get id() {
|
|
@@ -133,7 +142,7 @@ class CordovaPeripheralAdapter {
|
|
|
133
142
|
const result = {};
|
|
134
143
|
if (serviceUUIDs) {
|
|
135
144
|
for (const uuid of serviceUUIDs) {
|
|
136
|
-
const servicDefinition = this.serviceListCache.find(def => def.uuid === uuid);
|
|
145
|
+
const servicDefinition = this.serviceListCache.find((def) => def.uuid === uuid);
|
|
137
146
|
if (servicDefinition) {
|
|
138
147
|
result[uuid] = new CordovaServiceAdapter(servicDefinition, this);
|
|
139
148
|
}
|
|
@@ -151,13 +160,14 @@ class CordovaPeripheralAdapter {
|
|
|
151
160
|
var _a;
|
|
152
161
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
153
162
|
(_a = this.connectionStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
154
|
-
const connectObservable = this.cordovaPlugin
|
|
155
|
-
|
|
156
|
-
.
|
|
163
|
+
const connectObservable = this.cordovaPlugin
|
|
164
|
+
.connect(this.deviceId)
|
|
165
|
+
.pipe(shareReplay());
|
|
166
|
+
this.connectionStateSubscription = connectObservable.subscribe((state) => {
|
|
157
167
|
this._stateChange.next(state);
|
|
158
168
|
});
|
|
159
169
|
yield connectObservable
|
|
160
|
-
.pipe(filter(state => state === ConnectionState.CONNECTED), first())
|
|
170
|
+
.pipe(filter((state) => state === ConnectionState.CONNECTED), first())
|
|
161
171
|
.toPromise();
|
|
162
172
|
});
|
|
163
173
|
}
|
|
@@ -182,7 +192,7 @@ class CordovaPeripheralAdapter {
|
|
|
182
192
|
if (!this.serviceListCache) {
|
|
183
193
|
yield this.discoverServices([uuid]);
|
|
184
194
|
}
|
|
185
|
-
const serviceDefinition = this.serviceListCache.find(s => s.uuid === uuid);
|
|
195
|
+
const serviceDefinition = this.serviceListCache.find((s) => s.uuid === uuid);
|
|
186
196
|
if (!serviceDefinition) {
|
|
187
197
|
throw BleComError.serviceNotFound(uuid);
|
|
188
198
|
}
|
|
@@ -201,7 +211,7 @@ class CordovaServiceAdapter {
|
|
|
201
211
|
getCharacteristic(charcUUID) {
|
|
202
212
|
var _a;
|
|
203
213
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
204
|
-
const characteristicDescription = (_a = this.config.characteristics) === null || _a === void 0 ? void 0 : _a.find(c => c.uuid === charcUUID);
|
|
214
|
+
const characteristicDescription = (_a = this.config.characteristics) === null || _a === void 0 ? void 0 : _a.find((c) => c.uuid === charcUUID);
|
|
205
215
|
if (!characteristicDescription) {
|
|
206
216
|
throw BleComError.charcacteristicNotFound(charcUUID);
|
|
207
217
|
}
|
|
@@ -213,7 +223,7 @@ class CordovaServiceAdapter {
|
|
|
213
223
|
if (!this.config.characteristics) {
|
|
214
224
|
return [];
|
|
215
225
|
}
|
|
216
|
-
return this.config.characteristics.map(c => new CordovaCharacteristicAdapter(this, c));
|
|
226
|
+
return this.config.characteristics.map((c) => new CordovaCharacteristicAdapter(this, c));
|
|
217
227
|
});
|
|
218
228
|
}
|
|
219
229
|
}
|
|
@@ -229,9 +239,9 @@ class CordovaCharacteristicAdapter {
|
|
|
229
239
|
return this.config.properties;
|
|
230
240
|
}
|
|
231
241
|
get data() {
|
|
232
|
-
return this.setupDataStreamIfRequired().pipe(map(data => ({
|
|
242
|
+
return this.setupDataStreamIfRequired().pipe(map((data) => ({
|
|
233
243
|
data,
|
|
234
|
-
isNotification: true
|
|
244
|
+
isNotification: true,
|
|
235
245
|
})));
|
|
236
246
|
}
|
|
237
247
|
get deviceId() {
|
|
@@ -255,7 +265,7 @@ class CordovaCharacteristicAdapter {
|
|
|
255
265
|
if (!this.config.descriptors) {
|
|
256
266
|
return [];
|
|
257
267
|
}
|
|
258
|
-
return this.config.descriptors.map(descriptor => new CordovaDescriptorAdapter(descriptor, this));
|
|
268
|
+
return this.config.descriptors.map((descriptor) => new CordovaDescriptorAdapter(descriptor, this));
|
|
259
269
|
});
|
|
260
270
|
}
|
|
261
271
|
write(data, writeWithoutResponse) {
|
|
@@ -308,7 +318,7 @@ class CordovaDescriptorAdapter {
|
|
|
308
318
|
}
|
|
309
319
|
|
|
310
320
|
//
|
|
311
|
-
// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.
|
|
321
|
+
// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.
|
|
312
322
|
//
|
|
313
323
|
// scanner.ts
|
|
314
324
|
// device-com-ble.cordova BLE Cordova Plugin
|
|
@@ -378,22 +388,23 @@ class BLEScanner {
|
|
|
378
388
|
debug("Start Scanning ...");
|
|
379
389
|
this._scanning$.next(true);
|
|
380
390
|
return new Promise((resolve, reject) => {
|
|
381
|
-
this.scanSubscription = this.cordovaInterface
|
|
382
|
-
.
|
|
383
|
-
|
|
391
|
+
this.scanSubscription = this.cordovaInterface
|
|
392
|
+
.startScan(this.requestDeviceOptions)
|
|
393
|
+
.subscribe((result) => {
|
|
394
|
+
if (result == "Ok") {
|
|
384
395
|
resolve();
|
|
385
396
|
return;
|
|
386
397
|
}
|
|
387
398
|
this.addOrRefreshDevice(result);
|
|
388
|
-
}, error => {
|
|
389
|
-
debug(
|
|
399
|
+
}, (error) => {
|
|
400
|
+
debug("Start scan failed with error: ", error);
|
|
390
401
|
this.cordovaInterface
|
|
391
402
|
.getLastError()
|
|
392
403
|
.then((lasterror) => {
|
|
393
404
|
debug("Last BLE error " + lasterror);
|
|
394
405
|
})
|
|
395
406
|
.catch((err) => {
|
|
396
|
-
debug(
|
|
407
|
+
debug("Cannot get last BLE error: ", err);
|
|
397
408
|
});
|
|
398
409
|
reject(error);
|
|
399
410
|
this._scanning$.next(false);
|
|
@@ -437,7 +448,8 @@ class BLEScanner {
|
|
|
437
448
|
let storedDeviceIndex = this.devices.findIndex((entry) => entry.address == newDevice.address);
|
|
438
449
|
if (storedDeviceIndex >= 0) {
|
|
439
450
|
let storedDevice = this.devices[storedDeviceIndex];
|
|
440
|
-
if (storedDevice.name != newDevice.name ||
|
|
451
|
+
if (storedDevice.name != newDevice.name ||
|
|
452
|
+
storedDevice.rssi != newDevice.rssi) {
|
|
441
453
|
debug(`Updating device at index ${storedDeviceIndex}, name=${storedDevice.name} with rssi=${storedDevice.rssi}`);
|
|
442
454
|
this.devices[storedDeviceIndex] = newDevice;
|
|
443
455
|
// this.devices = [...this.devices];
|
|
@@ -471,113 +483,120 @@ function hexStringToBuffer(str) {
|
|
|
471
483
|
}
|
|
472
484
|
class IoTizeBleCordovaPlugin {
|
|
473
485
|
checkAvailable() {
|
|
474
|
-
return this.execSingleResult(
|
|
486
|
+
return this.execSingleResult("checkAvailable", []);
|
|
475
487
|
}
|
|
476
488
|
requestEnableBle() {
|
|
477
|
-
return this.execSingleResult(
|
|
489
|
+
return this.execSingleResult("enable", []);
|
|
478
490
|
}
|
|
479
491
|
startScan(requestDeviceOptions) {
|
|
480
|
-
return this.execMultipleResult(
|
|
481
|
-
JSON.stringify(requestDeviceOptions)
|
|
492
|
+
return this.execMultipleResult("startScan", [
|
|
493
|
+
JSON.stringify(requestDeviceOptions),
|
|
482
494
|
]);
|
|
483
495
|
}
|
|
484
496
|
stopScan() {
|
|
485
|
-
return this.execSingleResult(
|
|
497
|
+
return this.execSingleResult("stopScan", []);
|
|
486
498
|
}
|
|
487
|
-
connect(deviceId) {
|
|
488
|
-
return this.
|
|
489
|
-
.pipe(map(state => {
|
|
490
|
-
|
|
491
|
-
|
|
499
|
+
connect(deviceId, enableBleIfNot = true) {
|
|
500
|
+
return this.askBleEnable(enableBleIfNot).pipe(switchMap(() => {
|
|
501
|
+
return this.execMultipleResult("connect", [deviceId]).pipe(map((state) => {
|
|
502
|
+
if (!(state in ConnectionState)) {
|
|
503
|
+
console.warn(`Plugin native code returned an invalid connection state: "${state}".`);
|
|
504
|
+
}
|
|
505
|
+
return safeEnumValue(ConnectionState, state);
|
|
506
|
+
}));
|
|
507
|
+
}));
|
|
508
|
+
}
|
|
509
|
+
askBleEnable(askEnable) {
|
|
510
|
+
return defer(() => __awaiter(this, void 0, void 0, function* () {
|
|
511
|
+
if (askEnable) {
|
|
512
|
+
if (!(yield this.checkAvailable())) {
|
|
513
|
+
yield this.requestEnableBle();
|
|
514
|
+
}
|
|
492
515
|
}
|
|
493
|
-
return safeEnumValue(ConnectionState, state);
|
|
494
516
|
}));
|
|
495
517
|
}
|
|
496
518
|
requestMTU(deviceId, mtu) {
|
|
497
|
-
return this.execSingleResult(
|
|
519
|
+
return this.execSingleResult("requestMTU", [deviceId, mtu]);
|
|
498
520
|
}
|
|
499
|
-
connectAndDiscoverTapServices(deviceId) {
|
|
500
|
-
return this.
|
|
501
|
-
.pipe(map(state => {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
521
|
+
connectAndDiscoverTapServices(deviceId, enableBleIfNot = true) {
|
|
522
|
+
return this.askBleEnable(enableBleIfNot).pipe(switchMap(() => {
|
|
523
|
+
return this.execMultipleResult("connectAndDiscoverTapServices", [deviceId]).pipe(map((state) => {
|
|
524
|
+
if (!(state in ConnectionState)) {
|
|
525
|
+
console.warn(`Plugin native code returned an invalid connection state: "${state}".`);
|
|
526
|
+
}
|
|
527
|
+
return safeEnumValue(ConnectionState, state);
|
|
528
|
+
}));
|
|
506
529
|
}));
|
|
507
530
|
}
|
|
508
531
|
disConnect(deviceId) {
|
|
509
|
-
return this.execSingleResult(
|
|
532
|
+
return this.execSingleResult("disConnect", [deviceId]);
|
|
510
533
|
}
|
|
511
534
|
close(deviceId) {
|
|
512
|
-
return this.execSingleResult(
|
|
535
|
+
return this.execSingleResult("close", [deviceId]);
|
|
513
536
|
}
|
|
514
537
|
isConnected(deviceId) {
|
|
515
|
-
return this.execSingleResult(
|
|
538
|
+
return this.execSingleResult("isConnected", [deviceId]);
|
|
516
539
|
}
|
|
517
540
|
send(deviceId, data) {
|
|
518
541
|
return __awaiter(this, void 0, void 0, function* () {
|
|
519
|
-
const hexString = yield this.execSingleResult(
|
|
542
|
+
const hexString = yield this.execSingleResult("sendRequest", [
|
|
543
|
+
deviceId,
|
|
544
|
+
bufferToHexString(data),
|
|
545
|
+
]);
|
|
520
546
|
return hexStringToBuffer(hexString);
|
|
521
547
|
});
|
|
522
548
|
}
|
|
523
549
|
getLastError() {
|
|
524
|
-
return this.execSingleResult(
|
|
550
|
+
return this.execSingleResult("getLastError", []);
|
|
525
551
|
}
|
|
526
552
|
characteristicStartNotification(deviceId, serviceId, characId) {
|
|
527
|
-
return this.execSingleResult(
|
|
553
|
+
return this.execSingleResult("characteristicStartNotification", [
|
|
528
554
|
deviceId,
|
|
529
555
|
serviceId,
|
|
530
|
-
characId
|
|
556
|
+
characId,
|
|
531
557
|
]);
|
|
532
558
|
}
|
|
533
559
|
characteristicChanged(deviceId, serviceId, characId) {
|
|
534
|
-
return this.execMultipleResult(
|
|
560
|
+
return this.execMultipleResult("characteristicChanged", [
|
|
535
561
|
deviceId,
|
|
536
562
|
serviceId,
|
|
537
|
-
characId
|
|
538
|
-
])
|
|
539
|
-
.pipe(map(hexString => {
|
|
563
|
+
characId,
|
|
564
|
+
]).pipe(map((hexString) => {
|
|
540
565
|
return hexStringToBuffer(hexString);
|
|
541
566
|
}));
|
|
542
567
|
}
|
|
543
568
|
characteristicStopNotification(deviceId, serviceId, characId) {
|
|
544
|
-
return this.execSingleResult(
|
|
569
|
+
return this.execSingleResult("characteristicStopNotification", [
|
|
545
570
|
deviceId,
|
|
546
571
|
serviceId,
|
|
547
|
-
characId
|
|
572
|
+
characId,
|
|
548
573
|
]);
|
|
549
574
|
}
|
|
550
575
|
characteristicReadValue(deviceId, serviceId, characId) {
|
|
551
576
|
return __awaiter(this, void 0, void 0, function* () {
|
|
552
|
-
const hexString = yield this.execSingleResult(
|
|
553
|
-
deviceId,
|
|
554
|
-
serviceId,
|
|
555
|
-
characId
|
|
556
|
-
]);
|
|
577
|
+
const hexString = yield this.execSingleResult("characteristicRead", [deviceId, serviceId, characId]);
|
|
557
578
|
return hexStringToBuffer(hexString);
|
|
558
579
|
});
|
|
559
580
|
}
|
|
560
581
|
characteristicWrite(deviceId, serviceId, characId, data) {
|
|
561
|
-
return this.execSingleResult(
|
|
582
|
+
return this.execSingleResult("characteristicWrite", [
|
|
562
583
|
deviceId,
|
|
563
584
|
serviceId,
|
|
564
585
|
characId,
|
|
565
|
-
bufferToHexString(data)
|
|
586
|
+
bufferToHexString(data),
|
|
566
587
|
]);
|
|
567
588
|
}
|
|
568
589
|
characteristicWriteWithoutResponse(deviceId, serviceId, characId, data) {
|
|
569
|
-
return this.execSingleResult(
|
|
590
|
+
return this.execSingleResult("characteristicWriteWithoutResponse", [
|
|
570
591
|
deviceId,
|
|
571
592
|
serviceId,
|
|
572
593
|
characId,
|
|
573
|
-
bufferToHexString(data)
|
|
594
|
+
bufferToHexString(data),
|
|
574
595
|
]);
|
|
575
596
|
}
|
|
576
597
|
discoverServices(deviceId) {
|
|
577
598
|
return __awaiter(this, void 0, void 0, function* () {
|
|
578
|
-
const services = yield this.execSingleResult(
|
|
579
|
-
deviceId
|
|
580
|
-
]);
|
|
599
|
+
const services = yield this.execSingleResult("discoverServices", [deviceId]);
|
|
581
600
|
return services;
|
|
582
601
|
});
|
|
583
602
|
}
|
|
@@ -585,7 +604,7 @@ class IoTizeBleCordovaPlugin {
|
|
|
585
604
|
return new Promise((resolve, reject) => {
|
|
586
605
|
cordova.exec(resolve, (errObject) => {
|
|
587
606
|
reject(objectErrorToError(errObject));
|
|
588
|
-
},
|
|
607
|
+
}, "BLECom", methodName, args);
|
|
589
608
|
});
|
|
590
609
|
}
|
|
591
610
|
execMultipleResult(methodName, args) {
|
|
@@ -594,12 +613,12 @@ class IoTizeBleCordovaPlugin {
|
|
|
594
613
|
subject.next(data);
|
|
595
614
|
}, (err) => {
|
|
596
615
|
subject.error(objectErrorToError(err));
|
|
597
|
-
},
|
|
616
|
+
}, "BLECom", methodName, args);
|
|
598
617
|
return subject.asObservable();
|
|
599
618
|
}
|
|
600
619
|
}
|
|
601
620
|
function objectErrorToError(errObject) {
|
|
602
|
-
if (typeof errObject !==
|
|
621
|
+
if (typeof errObject !== "object" || !errObject.code || !errObject.message) {
|
|
603
622
|
return CordovaBLEError.invalidErrorResult(errObject);
|
|
604
623
|
}
|
|
605
624
|
if (!CordovaBLEError.isValidErrorCode(errObject.code)) {
|