@iotize/device-com-ble.cordova 3.7.2 → 4.0.0-alpha.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.
Files changed (92) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/package.json +7 -21
  3. package/plugin.cjs +35 -0
  4. package/plugin.js +35 -0
  5. package/plugin.xml +8 -3
  6. package/src/android/build.gradle +2 -11
  7. package/src/android/libs/iotize-device-com-ble-1.0.0-alpha.9.aar +0 -0
  8. package/{lib → src/lib}/ble-com-protocol.d.ts +20 -20
  9. package/{lib → src/lib}/cordova-ble-error.d.ts +29 -29
  10. package/{lib → src/lib}/cordova-interface.d.ts +5 -5
  11. package/{lib → src/lib}/cordova-service-adapter.d.ts +58 -58
  12. package/{lib → src/lib}/definitions.d.ts +43 -43
  13. package/{lib → src/lib}/iotize-ble-cordova-plugin.d.ts +27 -27
  14. package/src/lib/logger.d.ts +2 -0
  15. package/{lib → src/lib}/scanner.d.ts +55 -55
  16. package/{lib → src/lib}/utility.d.ts +6 -6
  17. package/src/plugin.d.ts +8 -0
  18. package/src/windows/iotize-ble-com.js +11 -11
  19. package/LICENSE +0 -23
  20. package/README.md +0 -174
  21. package/bundles/iotize-device-com-ble.cordova.umd.js +0 -1418
  22. package/bundles/iotize-device-com-ble.cordova.umd.js.map +0 -1
  23. package/bundles/iotize-device-com-ble.cordova.umd.min.js +0 -2
  24. package/bundles/iotize-device-com-ble.cordova.umd.min.js.map +0 -1
  25. package/esm2015/iotize-device-com-ble.cordova.js +0 -6
  26. package/esm2015/iotize-device-com-ble.cordova.js.map +0 -1
  27. package/esm2015/iotize-device-com-ble.cordova.metadata.json +0 -1
  28. package/esm2015/iotize-device-com-ble.cordova.ngsummary.json +0 -1
  29. package/esm2015/lib/ble-com-protocol.js +0 -76
  30. package/esm2015/lib/ble-com-protocol.js.map +0 -1
  31. package/esm2015/lib/ble-com-protocol.metadata.json +0 -1
  32. package/esm2015/lib/ble-com-protocol.ngsummary.json +0 -1
  33. package/esm2015/lib/cordova-ble-error.js +0 -36
  34. package/esm2015/lib/cordova-ble-error.js.map +0 -1
  35. package/esm2015/lib/cordova-ble-error.metadata.json +0 -1
  36. package/esm2015/lib/cordova-ble-error.ngsummary.json +0 -1
  37. package/esm2015/lib/cordova-interface.js +0 -2
  38. package/esm2015/lib/cordova-interface.js.map +0 -1
  39. package/esm2015/lib/cordova-interface.metadata.json +0 -1
  40. package/esm2015/lib/cordova-interface.ngsummary.json +0 -1
  41. package/esm2015/lib/cordova-service-adapter.js +0 -214
  42. package/esm2015/lib/cordova-service-adapter.js.map +0 -1
  43. package/esm2015/lib/cordova-service-adapter.metadata.json +0 -1
  44. package/esm2015/lib/cordova-service-adapter.ngsummary.json +0 -1
  45. package/esm2015/lib/definitions.js +0 -2
  46. package/esm2015/lib/definitions.js.map +0 -1
  47. package/esm2015/lib/definitions.metadata.json +0 -1
  48. package/esm2015/lib/definitions.ngsummary.json +0 -1
  49. package/esm2015/lib/iotize-ble-cordova-plugin.js +0 -170
  50. package/esm2015/lib/iotize-ble-cordova-plugin.js.map +0 -1
  51. package/esm2015/lib/iotize-ble-cordova-plugin.metadata.json +0 -1
  52. package/esm2015/lib/iotize-ble-cordova-plugin.ngsummary.json +0 -1
  53. package/esm2015/lib/logger.js +0 -3
  54. package/esm2015/lib/logger.js.map +0 -1
  55. package/esm2015/lib/logger.metadata.json +0 -1
  56. package/esm2015/lib/logger.ngsummary.json +0 -1
  57. package/esm2015/lib/scanner.js +0 -151
  58. package/esm2015/lib/scanner.js.map +0 -1
  59. package/esm2015/lib/scanner.metadata.json +0 -1
  60. package/esm2015/lib/scanner.ngsummary.json +0 -1
  61. package/esm2015/lib/utility.js +0 -26
  62. package/esm2015/lib/utility.js.map +0 -1
  63. package/esm2015/lib/utility.metadata.json +0 -1
  64. package/esm2015/lib/utility.ngsummary.json +0 -1
  65. package/esm2015/public_api.js +0 -5
  66. package/esm2015/public_api.js.map +0 -1
  67. package/esm2015/public_api.metadata.json +0 -1
  68. package/esm2015/public_api.ngsummary.json +0 -1
  69. package/fesm2015/iotize-device-com-ble.cordova.js +0 -660
  70. package/fesm2015/iotize-device-com-ble.cordova.js.map +0 -1
  71. package/iotize-device-com-ble.cordova.d.ts +0 -6
  72. package/iotize-device-com-ble.cordova.metadata.json +0 -1
  73. package/lib/logger.d.ts +0 -1
  74. package/public_api.d.ts +0 -5
  75. package/src/android/.gradle/4.8.1/fileChanges/last-build.bin +0 -0
  76. package/src/android/.gradle/4.8.1/fileHashes/fileHashes.bin +0 -0
  77. package/src/android/.gradle/4.8.1/fileHashes/fileHashes.lock +0 -0
  78. package/src/android/.gradle/6.8.2/fileChanges/last-build.bin +0 -0
  79. package/src/android/.gradle/6.8.2/fileHashes/fileHashes.lock +0 -0
  80. package/src/android/.gradle/6.8.2/gc.properties +0 -0
  81. package/src/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  82. package/src/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  83. package/src/android/.gradle/checksums/checksums.lock +0 -0
  84. package/src/android/.gradle/configuration-cache/gc.properties +0 -0
  85. package/src/android/.gradle/vcs-1/gc.properties +0 -0
  86. package/src/android/.gradle/vcsWorkingDirs/gc.properties +0 -0
  87. package/src/android/.idea/android.iml +0 -9
  88. package/src/android/.idea/gradle.xml +0 -16
  89. package/src/android/.idea/modules.xml +0 -8
  90. package/src/android/.idea/vcs.xml +0 -6
  91. package/www/plugin.js +0 -2
  92. package/www/plugin.js.LICENSE.txt +0 -14
@@ -1 +0,0 @@
1
- {"version":3,"file":"cordova-ble-error.js","sourceRoot":"","sources":["../../../../../src/lib/cordova-ble-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,MAAM,CAAC,kBAAkB,CAAC,SAGzB;QACC,OAAO,IAAI,eAAe,CACxB,wEAAwE,EACxE,eAAe,CAAC,IAAI,CAAC,aAAa,CACnC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,SAGvB;QACC,OAAO,IAAI,eAAe,CACxB,qEAAqE,SAAS,CAAC,IAAI,iBAAiB,SAAS,CAAC,OAAO,EAAE,EACvH,eAAe,CAAC,IAAI,CAAC,aAAa,CACnC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,uBAAuB,CAAC,MAAW,EAAE,KAAY;QACtD,OAAO,IAAI,eAAe,CACxB,8DAA8D,KAAK,CAAC,OAAO,EAAE,EAC7E,eAAe,CAAC,IAAI,CAAC,aAAa,CACnC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,gBAAgB,CACrB,IAAY;QAEZ,OAAO,IAAI,IAAI,eAAe,CAAC,IAAI,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,gBAAgB;QACrB,OAAO,IAAI,eAAe,CACxB,sGAAsG,EACtG,eAAe,CAAC,IAAI,CAAC,aAAa,CACnC,CAAC;IACJ,CAAC;CACF;AAED,0BAA0B;AAC1B,WAAiB,eAAe;IAC9B,IAAY,IAYX;IAZD,WAAY,IAAI;QACd,sDAA8C,CAAA;QAC9C,0DAAkD,CAAA;QAClD,0DAAkD,CAAA;QAClD,gEAAwD,CAAA;QACxD,0DAAkD,CAAA;QAClD,oDAA4C,CAAA;QAC5C,0EAAkE,CAAA;QAClE,0DAAkD,CAAA;QAClD,sDAA8C,CAAA;QAC9C,8DAAsD,CAAA;QACtD,0DAAkD,CAAA;IACpD,CAAC,EAZW,IAAI,GAAJ,oBAAI,KAAJ,oBAAI,QAYf;AACH,CAAC,EAdgB,eAAe,KAAf,eAAe,QAc/B","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"]}
@@ -1 +0,0 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"CordovaBLEError":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@iotize/common/error","name":"CodeError","line":2,"character":37},"statics":{"invalidErrorResult":{"__symbolic":"function","parameters":["errObject"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"CordovaBLEError"},"arguments":["Internal error: ble cordova plugin returned an unexpected error object",{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"CordovaBLEError"},"member":"Code"},"member":"InternalError"}]}},"invalidErrorCode":{"__symbolic":"function","parameters":["errObject"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"CordovaBLEError"},"arguments":[{"__symbolic":"binop","operator":"+","left":{"__symbolic":"binop","operator":"+","left":{"__symbolic":"binop","operator":"+","left":"Internal error: ble cordova plugin returned an invalid error code ","right":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"errObject"},"member":"code"}},"right":" with message "},"right":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"errObject"},"member":"message"}},{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"CordovaBLEError"},"member":"Code"},"member":"InternalError"}]}},"invalidNativeCallResult":{"__symbolic":"function","parameters":["result","cause"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"CordovaBLEError"},"arguments":[{"__symbolic":"binop","operator":"+","left":"Internal error: native call returned an invalid data type. ","right":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"cause"},"member":"message"}},{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"CordovaBLEError"},"member":"Code"},"member":"InternalError"}]}},"isValidErrorCode":{"__symbolic":"function","parameters":["code"],"value":{"__symbolic":"binop","operator":"in","left":{"__symbolic":"reference","name":"code"},"right":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"CordovaBLEError"},"member":"Code"}}},"iotizeBLEMissing":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"CordovaBLEError"},"arguments":["iotizeBLE global variable does not exist. Are you sure app is running inside a Cordova application ?",{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"CordovaBLEError"},"member":"Code"},"member":"InternalError"}]}}}}}}]
@@ -1 +0,0 @@
1
- {"moduleName":null,"summaries":[{"symbol":{"__symbol":0,"members":[]},"metadata":{"__symbolic":"class","extends":{"__symbol":1,"members":[]},"statics":{"invalidErrorResult":{"__symbolic":"function","parameters":["errObject"],"value":{"__symbolic":"new","expression":{"__symbol":0,"members":[]},"arguments":["Internal error: ble cordova plugin returned an unexpected error object",{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbol":0,"members":[]},"member":"Code"},"member":"InternalError"}]}},"invalidErrorCode":{"__symbolic":"function","parameters":["errObject"],"value":{"__symbolic":"new","expression":{"__symbol":0,"members":[]},"arguments":[{"__symbolic":"binop","operator":"+","left":{"__symbolic":"binop","operator":"+","left":{"__symbolic":"binop","operator":"+","left":"Internal error: ble cordova plugin returned an invalid error code ","right":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"errObject"},"member":"code"}},"right":" with message "},"right":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"errObject"},"member":"message"}},{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbol":0,"members":[]},"member":"Code"},"member":"InternalError"}]}},"invalidNativeCallResult":{"__symbolic":"function","parameters":["result","cause"],"value":{"__symbolic":"new","expression":{"__symbol":0,"members":[]},"arguments":[{"__symbolic":"binop","operator":"+","left":"Internal error: native call returned an invalid data type. ","right":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"cause"},"member":"message"}},{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbol":0,"members":[]},"member":"Code"},"member":"InternalError"}]}},"isValidErrorCode":{"__symbolic":"function","parameters":["code"],"value":{"__symbolic":"binop","operator":"in","left":{"__symbolic":"reference","name":"code"},"right":{"__symbolic":"select","expression":{"__symbol":0,"members":[]},"member":"Code"}}},"iotizeBLEMissing":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"new","expression":{"__symbol":0,"members":[]},"arguments":["iotizeBLE global variable does not exist. Are you sure app is running inside a Cordova application ?",{"__symbolic":"select","expression":{"__symbolic":"select","expression":{"__symbol":0,"members":[]},"member":"Code"},"member":"InternalError"}]}}}}}],"symbols":[{"__symbol":0,"name":"CordovaBLEError","filePath":"./cordova-ble-error"},{"__symbol":1,"name":"CodeError","filePath":"@iotize/common/error/iotize-common-error"}]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=cordova-interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cordova-interface.js","sourceRoot":"","sources":["../../../../../src/lib/cordova-interface.ts"],"names":[],"mappings":"","sourcesContent":["export interface CordovaInterface {\n exec<T>(\n success: SuccessCallback<T>,\n error: ErrorCallback,\n className: string,\n action: string,\n ...args: any[]\n ): void;\n}\n\nexport type ErrorCallback = (err: Error) => void;\n\nexport type SuccessCallback<T> = (data: T) => void;\n"]}
@@ -1 +0,0 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"CordovaInterface":{"__symbolic":"interface"},"ErrorCallback":{"__symbolic":"interface"},"SuccessCallback":{"__symbolic":"interface"}}}]
@@ -1 +0,0 @@
1
- {"moduleName":null,"summaries":[{"symbol":{"__symbol":0,"members":[]},"metadata":{"__symbolic":"interface"}},{"symbol":{"__symbol":1,"members":[]},"metadata":{"__symbolic":"interface"}},{"symbol":{"__symbol":2,"members":[]},"metadata":{"__symbolic":"interface"}}],"symbols":[{"__symbol":0,"name":"CordovaInterface","filePath":"./cordova-interface"},{"__symbol":1,"name":"ErrorCallback","filePath":"./cordova-interface"},{"__symbol":2,"name":"SuccessCallback","filePath":"./cordova-interface"}]}
@@ -1,214 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { ConnectionState } from "@iotize/tap/protocol/api";
11
- import { BleComError, } from "@iotize/tap/protocol/ble/common";
12
- import { BehaviorSubject } from "rxjs";
13
- import { distinctUntilChanged, filter, first, map, shareReplay, } from "rxjs/operators";
14
- import { getIoTizeBleCordovaPlugin } from "./utility";
15
- export class CordovaPeripheralAdapter {
16
- constructor(deviceId, cordovaPlugin = getIoTizeBleCordovaPlugin()) {
17
- this.deviceId = deviceId;
18
- this.cordovaPlugin = cordovaPlugin;
19
- this._stateChange = new BehaviorSubject(ConnectionState.DISCONNECTED);
20
- }
21
- get stateChange() {
22
- return this._stateChange.asObservable().pipe(distinctUntilChanged());
23
- }
24
- get name() {
25
- // TODO device name ?
26
- return this.id;
27
- }
28
- get id() {
29
- return this.deviceId;
30
- }
31
- get state() {
32
- return ConnectionState[this._stateChange.value];
33
- }
34
- discoverServices(serviceUUIDs) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- this.serviceListCache = yield this.cordovaPlugin.discoverServices(this.deviceId);
37
- const result = {};
38
- if (serviceUUIDs) {
39
- for (const uuid of serviceUUIDs) {
40
- const servicDefinition = this.serviceListCache.find((def) => def.uuid === uuid);
41
- if (servicDefinition) {
42
- result[uuid] = new CordovaServiceAdapter(servicDefinition, this);
43
- }
44
- }
45
- }
46
- else {
47
- for (const serviceDefinition of this.serviceListCache) {
48
- result[serviceDefinition.uuid] = new CordovaServiceAdapter(serviceDefinition, this);
49
- }
50
- }
51
- return result;
52
- });
53
- }
54
- connect() {
55
- var _a;
56
- return __awaiter(this, void 0, void 0, function* () {
57
- (_a = this.connectionStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
58
- const connectObservable = this.cordovaPlugin
59
- .connect(this.deviceId)
60
- .pipe(shareReplay());
61
- this.connectionStateSubscription = connectObservable.subscribe((state) => {
62
- this._stateChange.next(state);
63
- });
64
- yield connectObservable
65
- .pipe(filter((state) => state === ConnectionState.CONNECTED), first())
66
- .toPromise();
67
- });
68
- }
69
- disconnect() {
70
- var _a;
71
- return __awaiter(this, void 0, void 0, function* () {
72
- yield this.cordovaPlugin.disConnect(this.deviceId);
73
- this._stateChange.next(ConnectionState.DISCONNECTED);
74
- (_a = this.connectionStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
75
- });
76
- }
77
- close() {
78
- var _a;
79
- return __awaiter(this, void 0, void 0, function* () {
80
- yield this.cordovaPlugin.close(this.deviceId);
81
- this._stateChange.next(ConnectionState.DISCONNECTED);
82
- (_a = this.connectionStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
83
- });
84
- }
85
- getService(uuid) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- if (!this.serviceListCache) {
88
- yield this.discoverServices([uuid]);
89
- }
90
- const serviceDefinition = this.serviceListCache.find((s) => s.uuid === uuid);
91
- if (!serviceDefinition) {
92
- throw BleComError.serviceNotFound(uuid);
93
- }
94
- return new CordovaServiceAdapter(serviceDefinition, this);
95
- });
96
- }
97
- }
98
- export class CordovaServiceAdapter {
99
- constructor(config, peripheral) {
100
- this.config = config;
101
- this.peripheral = peripheral;
102
- }
103
- get uuid() {
104
- return this.config.uuid;
105
- }
106
- getCharacteristic(charcUUID) {
107
- var _a;
108
- return __awaiter(this, void 0, void 0, function* () {
109
- const characteristicDescription = (_a = this.config.characteristics) === null || _a === void 0 ? void 0 : _a.find((c) => c.uuid === charcUUID);
110
- if (!characteristicDescription) {
111
- throw BleComError.charcacteristicNotFound(charcUUID);
112
- }
113
- return new CordovaCharacteristicAdapter(this, characteristicDescription);
114
- });
115
- }
116
- getCharacteristics() {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- if (!this.config.characteristics) {
119
- return [];
120
- }
121
- return this.config.characteristics.map((c) => new CordovaCharacteristicAdapter(this, c));
122
- });
123
- }
124
- }
125
- export class CordovaCharacteristicAdapter {
126
- constructor(service, config) {
127
- this.service = service;
128
- this.config = config;
129
- }
130
- get uuid() {
131
- return this.config.uuid;
132
- }
133
- get properties() {
134
- return this.config.properties;
135
- }
136
- get data() {
137
- return this.setupDataStreamIfRequired().pipe(map((data) => ({
138
- data,
139
- isNotification: true,
140
- })));
141
- }
142
- get deviceId() {
143
- return this.service.peripheral.deviceId;
144
- }
145
- get pluginInterface() {
146
- return this.service.peripheral.cordovaPlugin;
147
- }
148
- read() {
149
- return __awaiter(this, void 0, void 0, function* () {
150
- return this.pluginInterface.characteristicReadValue(this.deviceId, this.service.uuid, this.uuid);
151
- });
152
- }
153
- getDescriptor() {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- throw new Error(`Not implemented yet`);
156
- });
157
- }
158
- getDescriptors() {
159
- return __awaiter(this, void 0, void 0, function* () {
160
- if (!this.config.descriptors) {
161
- return [];
162
- }
163
- return this.config.descriptors.map((descriptor) => new CordovaDescriptorAdapter(descriptor, this));
164
- });
165
- }
166
- write(data, writeWithoutResponse) {
167
- return __awaiter(this, void 0, void 0, function* () {
168
- if (writeWithoutResponse) {
169
- yield this.pluginInterface.characteristicWriteWithoutResponse(this.deviceId, this.service.uuid, this.uuid, data);
170
- }
171
- else {
172
- yield this.pluginInterface.characteristicWrite(this.deviceId, this.service.uuid, this.uuid, data);
173
- }
174
- return data;
175
- });
176
- }
177
- enableNotifications(enabled) {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- if (enabled) {
180
- this.setupDataStreamIfRequired();
181
- yield this.pluginInterface.characteristicStartNotification(this.deviceId, this.service.uuid, this.uuid);
182
- }
183
- else {
184
- yield this.pluginInterface.characteristicStopNotification(this.deviceId, this.service.uuid, this.uuid);
185
- }
186
- });
187
- }
188
- setupDataStreamIfRequired() {
189
- if (!this._dataStream) {
190
- this._dataStream = this.pluginInterface.characteristicChanged(this.deviceId, this.service.uuid, this.uuid);
191
- }
192
- return this._dataStream;
193
- }
194
- }
195
- export class CordovaDescriptorAdapter {
196
- constructor(config, characteristic) {
197
- this.config = config;
198
- this.characteristic = characteristic;
199
- }
200
- get uuid() {
201
- return this.config.uuid;
202
- }
203
- readValue() {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- throw new Error(`Reading descriptor value is not implemented yet`);
206
- });
207
- }
208
- writeValue(data) {
209
- return __awaiter(this, void 0, void 0, function* () {
210
- throw new Error(`Writing descriptor value is not implemented yet`);
211
- });
212
- }
213
- }
214
- //# sourceMappingURL=cordova-service-adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cordova-service-adapter.js","sourceRoot":"","sources":["../../../../../src/lib/cordova-service-adapter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAKL,WAAW,GAEZ,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,eAAe,EAA4B,MAAM,MAAM,CAAC;AACjE,OAAO,EACL,oBAAoB,EACpB,MAAM,EACN,KAAK,EACL,GAAG,EACH,WAAW,GACZ,MAAM,gBAAgB,CAAC;AAQxB,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAEtD,MAAM,OAAO,wBAAwB;IAsBnC,YACkB,QAAgB,EAChB,gBAAwC,yBAAyB,EAAE;QADnE,aAAQ,GAAR,QAAQ,CAAQ;QAChB,kBAAa,GAAb,aAAa,CAAsD;QArB7E,iBAAY,GAAG,IAAI,eAAe,CACxC,eAAe,CAAC,YAAY,CAC7B,CAAC;IAoBC,CAAC;IAhBJ,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,IAAI;QACN,qBAAqB;QACrB,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAOD,IAAI,KAAK;QACP,OAAO,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAEK,gBAAgB,CACpB,YAAoB;;YAEpB,IAAI,CAAC,gBAAgB,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAC/D,IAAI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,CAAC;aACH;QACH,CAAC;KAAA;IAED,yBAAyB;QACvB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,eAAe,CAAC,qBAAqB,CAC3D,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,OAAO,CAAC,IAAI,EACjB,IAAI,CAAC,IAAI,CACV,CAAC;SACH;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,OAAO,wBAAwB;IAKnC,YACkB,MAA6B,EAC7B,cAA4C;QAD5C,WAAM,GAAN,MAAM,CAAuB;QAC7B,mBAAc,GAAd,cAAc,CAA8B;IAC3D,CAAC;IAPJ,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAOK,SAAS;;YACb,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;KAAA;IAEK,UAAU,CAAC,IAAgB;;YAC/B,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;KAAA;CACF","sourcesContent":["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"]}
@@ -1 +0,0 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"CordovaPeripheralAdapter":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","module":"./iotize-ble-cordova-plugin","name":"IoTizeBleCordovaPlugin","line":50,"character":35}]}],"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","module":"./definitions","name":"ServiceDescription","line":132,"character":29},{"__symbolic":"reference","name":"CordovaPeripheralAdapter"}]}],"getCharacteristic":[{"__symbolic":"method"}],"getCharacteristics":[{"__symbolic":"method"}]}},"CordovaCharacteristicAdapter":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"CordovaServiceAdapter"},{"__symbolic":"reference","module":"./definitions","name":"CharacteristicDescription","line":169,"character":28}]}],"read":[{"__symbolic":"method"}],"getDescriptor":[{"__symbolic":"method"}],"getDescriptors":[{"__symbolic":"method"}],"write":[{"__symbolic":"method"}],"enableNotifications":[{"__symbolic":"method"}],"setupDataStreamIfRequired":[{"__symbolic":"method"}]}},"CordovaDescriptorAdapter":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"./definitions","name":"DescriptorDescription","line":271,"character":28},{"__symbolic":"reference","name":"CordovaCharacteristicAdapter"}]}],"readValue":[{"__symbolic":"method"}],"writeValue":[{"__symbolic":"method"}]}}}}]
@@ -1 +0,0 @@
1
- {"moduleName":null,"summaries":[{"symbol":{"__symbol":0,"members":[]},"metadata":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[null,{"__symbol":1,"members":[]}]}],"discoverServices":[{"__symbolic":"method"}],"connect":[{"__symbolic":"method"}],"disconnect":[{"__symbolic":"method"}],"close":[{"__symbolic":"method"}],"getService":[{"__symbolic":"method"}]}}},{"symbol":{"__symbol":2,"members":[]},"metadata":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbol":3,"members":[]},{"__symbol":0,"members":[]}]}],"getCharacteristic":[{"__symbolic":"method"}],"getCharacteristics":[{"__symbolic":"method"}]}}},{"symbol":{"__symbol":4,"members":[]},"metadata":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbol":2,"members":[]},{"__symbol":5,"members":[]}]}],"read":[{"__symbolic":"method"}],"getDescriptor":[{"__symbolic":"method"}],"getDescriptors":[{"__symbolic":"method"}],"write":[{"__symbolic":"method"}],"enableNotifications":[{"__symbolic":"method"}],"setupDataStreamIfRequired":[{"__symbolic":"method"}]}}},{"symbol":{"__symbol":6,"members":[]},"metadata":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbol":7,"members":[]},{"__symbol":4,"members":[]}]}],"readValue":[{"__symbolic":"method"}],"writeValue":[{"__symbolic":"method"}]}}}],"symbols":[{"__symbol":0,"name":"CordovaPeripheralAdapter","filePath":"./cordova-service-adapter"},{"__symbol":1,"name":"IoTizeBleCordovaPlugin","filePath":"./iotize-ble-cordova-plugin"},{"__symbol":2,"name":"CordovaServiceAdapter","filePath":"./cordova-service-adapter"},{"__symbol":3,"name":"ServiceDescription","filePath":"./definitions"},{"__symbol":4,"name":"CordovaCharacteristicAdapter","filePath":"./cordova-service-adapter"},{"__symbol":5,"name":"CharacteristicDescription","filePath":"./definitions"},{"__symbol":6,"name":"CordovaDescriptorAdapter","filePath":"./cordova-service-adapter"},{"__symbol":7,"name":"DescriptorDescription","filePath":"./definitions"}]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=definitions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../../../../src/lib/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import { CharacteristicProperties } from '@iotize/tap/protocol/ble/common';\n\nexport interface CordovaBLEScanResult {\n name: string;\n address: string;\n rssi?: number;\n txPower?: number;\n scanRecord?: number[];\n}\n\n/**\n * @deprecated\n * use CordovaBLEScanResult instead\n */\nexport type DiscoveredDeviceType = CordovaBLEScanResult;\n\nexport interface RequestDeviceOptions {\n filters: BluetoothLEScanFilter[];\n optionalServices?: BluetoothServiceUUID[] | undefined;\n optionalManufacturerData?: number[] | undefined;\n}\n\ninterface BluetoothLEScanFilter {\n // readonly name?: string | undefined;\n // readonly namePrefix?: string | undefined;\n readonly services?: BluetoothServiceUUID[] | undefined;\n // readonly manufacturerData?: BluetoothManufacturerDataFilter[] | undefined;\n // readonly serviceData?: BluetoothServiceDataFilter[] | undefined;\n}\n\ntype BluetoothServiceUUID = string;\n\ntype BluetoothCharacteristicUUID = string;\n\ntype BluetoothDescriptorUUID = string;\n\nexport interface ServiceDescription {\n uuid: BluetoothServiceUUID;\n characteristics?: CharacteristicList;\n [key: string]: any;\n}\n\nexport type ServiceList = ServiceDescription[];\n\nexport interface CharacteristicDescription {\n uuid: BluetoothCharacteristicUUID;\n descriptors?: DescriptorList;\n properties: CharacteristicProperties;\n [key: string]: any;\n}\n\nexport type CharacteristicList = CharacteristicDescription[];\n\nexport interface DescriptorDescription {\n uuid: BluetoothDescriptorUUID;\n [key: string]: any;\n}\n\nexport type DescriptorList = DescriptorDescription[];\n"]}
@@ -1 +0,0 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"CordovaBLEScanResult":{"__symbolic":"interface"},"DiscoveredDeviceType":{"__symbolic":"interface"},"RequestDeviceOptions":{"__symbolic":"interface"},"ServiceDescription":{"__symbolic":"interface"},"ServiceList":{"__symbolic":"interface"},"CharacteristicDescription":{"__symbolic":"interface"},"CharacteristicList":{"__symbolic":"interface"},"DescriptorDescription":{"__symbolic":"interface"},"DescriptorList":{"__symbolic":"interface"}}}]
@@ -1 +0,0 @@
1
- {"moduleName":null,"summaries":[{"symbol":{"__symbol":0,"members":[]},"metadata":{"__symbolic":"interface"}},{"symbol":{"__symbol":1,"members":[]},"metadata":{"__symbolic":"interface"}},{"symbol":{"__symbol":2,"members":[]},"metadata":{"__symbolic":"interface"}},{"symbol":{"__symbol":3,"members":[]},"metadata":{"__symbolic":"interface"}},{"symbol":{"__symbol":4,"members":[]},"metadata":{"__symbolic":"interface"}},{"symbol":{"__symbol":5,"members":[]},"metadata":{"__symbolic":"interface"}},{"symbol":{"__symbol":6,"members":[]},"metadata":{"__symbolic":"interface"}},{"symbol":{"__symbol":7,"members":[]},"metadata":{"__symbolic":"interface"}},{"symbol":{"__symbol":8,"members":[]},"metadata":{"__symbolic":"interface"}}],"symbols":[{"__symbol":0,"name":"CordovaBLEScanResult","filePath":"./definitions"},{"__symbol":1,"name":"DiscoveredDeviceType","filePath":"./definitions"},{"__symbol":2,"name":"RequestDeviceOptions","filePath":"./definitions"},{"__symbol":3,"name":"ServiceDescription","filePath":"./definitions"},{"__symbol":4,"name":"ServiceList","filePath":"./definitions"},{"__symbol":5,"name":"CharacteristicDescription","filePath":"./definitions"},{"__symbol":6,"name":"CharacteristicList","filePath":"./definitions"},{"__symbol":7,"name":"DescriptorDescription","filePath":"./definitions"},{"__symbol":8,"name":"DescriptorList","filePath":"./definitions"}]}
@@ -1,170 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { bufferToHexString, hexStringToBuffer as hexStringToBufferCore, } from "@iotize/common/byte-converter";
11
- import { safeEnumValue } from "@iotize/common/utility";
12
- import { ConnectionState } from "@iotize/tap/protocol/api";
13
- import { Subject, defer } from "rxjs";
14
- import { switchMap } from "rxjs/operators";
15
- import { map } from "rxjs/operators";
16
- import { CordovaBLEError } from "./cordova-ble-error";
17
- function hexStringToBuffer(str) {
18
- try {
19
- return hexStringToBufferCore(str);
20
- }
21
- catch (err) {
22
- throw CordovaBLEError.invalidNativeCallResult(str, err);
23
- }
24
- }
25
- export class IoTizeBleCordovaPlugin {
26
- checkAvailable() {
27
- return this.execSingleResult("checkAvailable", []);
28
- }
29
- requestEnableBle() {
30
- return this.execSingleResult("enable", []);
31
- }
32
- startScan(requestDeviceOptions) {
33
- return this.execMultipleResult("startScan", [
34
- JSON.stringify(requestDeviceOptions),
35
- ]);
36
- }
37
- stopScan() {
38
- return this.execSingleResult("stopScan", []);
39
- }
40
- connect(deviceId, enableBleIfNot = true) {
41
- return this.askBleEnable(enableBleIfNot).pipe(switchMap(() => {
42
- return this.execMultipleResult("connect", [deviceId]).pipe(map((state) => {
43
- if (!(state in ConnectionState)) {
44
- console.warn(`Plugin native code returned an invalid connection state: "${state}".`);
45
- }
46
- return safeEnumValue(ConnectionState, state);
47
- }));
48
- }));
49
- }
50
- askBleEnable(askEnable) {
51
- return defer(() => __awaiter(this, void 0, void 0, function* () {
52
- if (askEnable) {
53
- if (!(yield this.checkAvailable())) {
54
- yield this.requestEnableBle();
55
- }
56
- }
57
- }));
58
- }
59
- requestMTU(deviceId, mtu) {
60
- return this.execSingleResult("requestMTU", [deviceId, mtu]);
61
- }
62
- connectAndDiscoverTapServices(deviceId, enableBleIfNot = true) {
63
- return this.askBleEnable(enableBleIfNot).pipe(switchMap(() => {
64
- return this.execMultipleResult("connectAndDiscoverTapServices", [deviceId]).pipe(map((state) => {
65
- if (!(state in ConnectionState)) {
66
- console.warn(`Plugin native code returned an invalid connection state: "${state}".`);
67
- }
68
- return safeEnumValue(ConnectionState, state);
69
- }));
70
- }));
71
- }
72
- disConnect(deviceId) {
73
- return this.execSingleResult("disConnect", [deviceId]);
74
- }
75
- close(deviceId) {
76
- return this.execSingleResult("close", [deviceId]);
77
- }
78
- isConnected(deviceId) {
79
- return this.execSingleResult("isConnected", [deviceId]);
80
- }
81
- send(deviceId, data) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- const hexString = yield this.execSingleResult("sendRequest", [
84
- deviceId,
85
- bufferToHexString(data),
86
- ]);
87
- return hexStringToBuffer(hexString);
88
- });
89
- }
90
- getLastError() {
91
- return this.execSingleResult("getLastError", []);
92
- }
93
- characteristicStartNotification(deviceId, serviceId, characId) {
94
- return this.execSingleResult("characteristicStartNotification", [
95
- deviceId,
96
- serviceId,
97
- characId,
98
- ]);
99
- }
100
- characteristicChanged(deviceId, serviceId, characId) {
101
- return this.execMultipleResult("characteristicChanged", [
102
- deviceId,
103
- serviceId,
104
- characId,
105
- ]).pipe(map((hexString) => {
106
- return hexStringToBuffer(hexString);
107
- }));
108
- }
109
- characteristicStopNotification(deviceId, serviceId, characId) {
110
- return this.execSingleResult("characteristicStopNotification", [
111
- deviceId,
112
- serviceId,
113
- characId,
114
- ]);
115
- }
116
- characteristicReadValue(deviceId, serviceId, characId) {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- const hexString = yield this.execSingleResult("characteristicRead", [deviceId, serviceId, characId]);
119
- return hexStringToBuffer(hexString);
120
- });
121
- }
122
- characteristicWrite(deviceId, serviceId, characId, data) {
123
- return this.execSingleResult("characteristicWrite", [
124
- deviceId,
125
- serviceId,
126
- characId,
127
- bufferToHexString(data),
128
- ]);
129
- }
130
- characteristicWriteWithoutResponse(deviceId, serviceId, characId, data) {
131
- return this.execSingleResult("characteristicWriteWithoutResponse", [
132
- deviceId,
133
- serviceId,
134
- characId,
135
- bufferToHexString(data),
136
- ]);
137
- }
138
- discoverServices(deviceId) {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- const services = yield this.execSingleResult("discoverServices", [deviceId]);
141
- return services;
142
- });
143
- }
144
- execSingleResult(methodName, args) {
145
- return new Promise((resolve, reject) => {
146
- cordova.exec(resolve, (errObject) => {
147
- reject(objectErrorToError(errObject));
148
- }, "BLECom", methodName, args);
149
- });
150
- }
151
- execMultipleResult(methodName, args) {
152
- const subject = new Subject();
153
- cordova.exec((data) => {
154
- subject.next(data);
155
- }, (err) => {
156
- subject.error(objectErrorToError(err));
157
- }, "BLECom", methodName, args);
158
- return subject.asObservable();
159
- }
160
- }
161
- function objectErrorToError(errObject) {
162
- if (typeof errObject !== "object" || !errObject.code || !errObject.message) {
163
- return CordovaBLEError.invalidErrorResult(errObject);
164
- }
165
- if (!CordovaBLEError.isValidErrorCode(errObject.code)) {
166
- return CordovaBLEError.invalidErrorCode(errObject);
167
- }
168
- return new CordovaBLEError(errObject.message, CordovaBLEError.Code[errObject.code]);
169
- }
170
- //# sourceMappingURL=iotize-ble-cordova-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"iotize-ble-cordova-plugin.js","sourceRoot":"","sources":["../../../../../src/lib/iotize-ble-cordova-plugin.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,iBAAiB,EACjB,iBAAiB,IAAI,qBAAqB,GAC3C,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAc,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAOrC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,SAAS,iBAAiB,CAAC,GAAW;IACpC,IAAI;QACF,OAAO,qBAAqB,CAAC,GAAG,CAAC,CAAC;KACnC;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,eAAe,CAAC,uBAAuB,CAAC,GAAG,EAAE,GAAY,CAAC,CAAC;KAClE;AACH,CAAC;AAID,MAAM,OAAO,sBAAsB;IACjC,cAAc;QACZ,OAAO,IAAI,CAAC,gBAAgB,CAAU,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,gBAAgB,CAAO,QAAQ,EAAE,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,SAAS,CACP,oBAAsD;QAEtD,OAAO,IAAI,CAAC,kBAAkB,CAA8B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,SAAS,CAAC,IAAI,CAAC,CACrC,CAAC;AACJ,CAAC","sourcesContent":["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"]}
@@ -1 +0,0 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"IoTizeBleCordovaPlugin":{"__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"}]}}}}]
@@ -1 +0,0 @@
1
- {"moduleName":null,"summaries":[{"symbol":{"__symbol":0,"members":[]},"metadata":{"__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"}]}}}],"symbols":[{"__symbol":0,"name":"IoTizeBleCordovaPlugin","filePath":"./iotize-ble-cordova-plugin"}]}
@@ -1,3 +0,0 @@
1
- import { createDebugger } from "@iotize/common/debug";
2
- export const debug = createDebugger(`@iotize/device-com-ble.cordova`);
3
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,CAAC,MAAM,KAAK,GAAG,cAAc,CAAC,gCAAgC,CAAC,CAAC","sourcesContent":["import { createDebugger } from \"@iotize/common/debug\";\n\nexport const debug = createDebugger(`@iotize/device-com-ble.cordova`);\n"]}
@@ -1 +0,0 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"debug":{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@iotize/common/debug","name":"createDebugger","line":2,"character":21},"arguments":["@iotize/device-com-ble.cordova"]}}}]
@@ -1 +0,0 @@
1
- {"moduleName":null,"summaries":[{"symbol":{"__symbol":0,"members":[]},"metadata":{"__symbolic":"call","expression":{"__symbol":1,"members":[]},"arguments":["@iotize/device-com-ble.cordova"]}}],"symbols":[{"__symbol":0,"name":"debug","filePath":"./logger"},{"__symbol":1,"name":"createDebugger","filePath":"@iotize/common/debug/iotize-common-debug"}]}