@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,1418 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@iotize/tap/protocol/api'), require('@iotize/tap/protocol/core'), require('rxjs'), require('rxjs/operators'), require('@iotize/common/error'), require('@iotize/common/debug'), require('@iotize/tap/protocol/ble/common'), require('@iotize/common/byte-converter'), require('@iotize/common/utility')) :
3
- typeof define === 'function' && define.amd ? define('@iotize/device-com-ble.cordova', ['exports', '@iotize/tap/protocol/api', '@iotize/tap/protocol/core', 'rxjs', 'rxjs/operators', '@iotize/common/error', '@iotize/common/debug', '@iotize/tap/protocol/ble/common', '@iotize/common/byte-converter', '@iotize/common/utility'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.iotize = global.iotize || {}, global.iotize["device-com-ble"] = global.iotize["device-com-ble"] || {}, global.iotize["device-com-ble"].cordova = {}), global.api, global.core, global.rxjs, global.rxjs.operators, global.error, global.debug$1, global.common, global.byteConverter, global.utility));
5
- })(this, (function (exports, api, core, rxjs, operators, error, debug$1, common, byteConverter, utility) { 'use strict';
6
-
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise, SuppressedError, Symbol */
22
- var extendStatics = function (d, b) {
23
- extendStatics = Object.setPrototypeOf ||
24
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25
- function (d, b) { for (var p in b)
26
- if (Object.prototype.hasOwnProperty.call(b, p))
27
- d[p] = b[p]; };
28
- return extendStatics(d, b);
29
- };
30
- function __extends(d, b) {
31
- if (typeof b !== "function" && b !== null)
32
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
33
- extendStatics(d, b);
34
- function __() { this.constructor = d; }
35
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36
- }
37
- var __assign = function () {
38
- __assign = Object.assign || function __assign(t) {
39
- for (var s, i = 1, n = arguments.length; i < n; i++) {
40
- s = arguments[i];
41
- for (var p in s)
42
- if (Object.prototype.hasOwnProperty.call(s, p))
43
- t[p] = s[p];
44
- }
45
- return t;
46
- };
47
- return __assign.apply(this, arguments);
48
- };
49
- function __rest(s, e) {
50
- var t = {};
51
- for (var p in s)
52
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
53
- t[p] = s[p];
54
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
55
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
56
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
57
- t[p[i]] = s[p[i]];
58
- }
59
- return t;
60
- }
61
- function __decorate(decorators, target, key, desc) {
62
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
63
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
64
- r = Reflect.decorate(decorators, target, key, desc);
65
- else
66
- for (var i = decorators.length - 1; i >= 0; i--)
67
- if (d = decorators[i])
68
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
69
- return c > 3 && r && Object.defineProperty(target, key, r), r;
70
- }
71
- function __param(paramIndex, decorator) {
72
- return function (target, key) { decorator(target, key, paramIndex); };
73
- }
74
- function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
75
- function accept(f) { if (f !== void 0 && typeof f !== "function")
76
- throw new TypeError("Function expected"); return f; }
77
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
78
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
79
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
80
- var _, done = false;
81
- for (var i = decorators.length - 1; i >= 0; i--) {
82
- var context = {};
83
- for (var p in contextIn)
84
- context[p] = p === "access" ? {} : contextIn[p];
85
- for (var p in contextIn.access)
86
- context.access[p] = contextIn.access[p];
87
- context.addInitializer = function (f) { if (done)
88
- throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
89
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
90
- if (kind === "accessor") {
91
- if (result === void 0)
92
- continue;
93
- if (result === null || typeof result !== "object")
94
- throw new TypeError("Object expected");
95
- if (_ = accept(result.get))
96
- descriptor.get = _;
97
- if (_ = accept(result.set))
98
- descriptor.set = _;
99
- if (_ = accept(result.init))
100
- initializers.unshift(_);
101
- }
102
- else if (_ = accept(result)) {
103
- if (kind === "field")
104
- initializers.unshift(_);
105
- else
106
- descriptor[key] = _;
107
- }
108
- }
109
- if (target)
110
- Object.defineProperty(target, contextIn.name, descriptor);
111
- done = true;
112
- }
113
- ;
114
- function __runInitializers(thisArg, initializers, value) {
115
- var useValue = arguments.length > 2;
116
- for (var i = 0; i < initializers.length; i++) {
117
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
118
- }
119
- return useValue ? value : void 0;
120
- }
121
- ;
122
- function __propKey(x) {
123
- return typeof x === "symbol" ? x : "".concat(x);
124
- }
125
- ;
126
- function __setFunctionName(f, name, prefix) {
127
- if (typeof name === "symbol")
128
- name = name.description ? "[".concat(name.description, "]") : "";
129
- return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
130
- }
131
- ;
132
- function __metadata(metadataKey, metadataValue) {
133
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
134
- return Reflect.metadata(metadataKey, metadataValue);
135
- }
136
- function __awaiter$4(thisArg, _arguments, P, generator) {
137
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
138
- return new (P || (P = Promise))(function (resolve, reject) {
139
- function fulfilled(value) { try {
140
- step(generator.next(value));
141
- }
142
- catch (e) {
143
- reject(e);
144
- } }
145
- function rejected(value) { try {
146
- step(generator["throw"](value));
147
- }
148
- catch (e) {
149
- reject(e);
150
- } }
151
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
152
- step((generator = generator.apply(thisArg, _arguments || [])).next());
153
- });
154
- }
155
- function __generator(thisArg, body) {
156
- var _ = { label: 0, sent: function () { if (t[0] & 1)
157
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
158
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
159
- function verb(n) { return function (v) { return step([n, v]); }; }
160
- function step(op) {
161
- if (f)
162
- throw new TypeError("Generator is already executing.");
163
- while (g && (g = 0, op[0] && (_ = 0)), _)
164
- try {
165
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
166
- return t;
167
- if (y = 0, t)
168
- op = [op[0] & 2, t.value];
169
- switch (op[0]) {
170
- case 0:
171
- case 1:
172
- t = op;
173
- break;
174
- case 4:
175
- _.label++;
176
- return { value: op[1], done: false };
177
- case 5:
178
- _.label++;
179
- y = op[1];
180
- op = [0];
181
- continue;
182
- case 7:
183
- op = _.ops.pop();
184
- _.trys.pop();
185
- continue;
186
- default:
187
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
188
- _ = 0;
189
- continue;
190
- }
191
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
192
- _.label = op[1];
193
- break;
194
- }
195
- if (op[0] === 6 && _.label < t[1]) {
196
- _.label = t[1];
197
- t = op;
198
- break;
199
- }
200
- if (t && _.label < t[2]) {
201
- _.label = t[2];
202
- _.ops.push(op);
203
- break;
204
- }
205
- if (t[2])
206
- _.ops.pop();
207
- _.trys.pop();
208
- continue;
209
- }
210
- op = body.call(thisArg, _);
211
- }
212
- catch (e) {
213
- op = [6, e];
214
- y = 0;
215
- }
216
- finally {
217
- f = t = 0;
218
- }
219
- if (op[0] & 5)
220
- throw op[1];
221
- return { value: op[0] ? op[1] : void 0, done: true };
222
- }
223
- }
224
- var __createBinding = Object.create ? (function (o, m, k, k2) {
225
- if (k2 === undefined)
226
- k2 = k;
227
- var desc = Object.getOwnPropertyDescriptor(m, k);
228
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
229
- desc = { enumerable: true, get: function () { return m[k]; } };
230
- }
231
- Object.defineProperty(o, k2, desc);
232
- }) : (function (o, m, k, k2) {
233
- if (k2 === undefined)
234
- k2 = k;
235
- o[k2] = m[k];
236
- });
237
- function __exportStar(m, o) {
238
- for (var p in m)
239
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
240
- __createBinding(o, m, p);
241
- }
242
- function __values(o) {
243
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
244
- if (m)
245
- return m.call(o);
246
- if (o && typeof o.length === "number")
247
- return {
248
- next: function () {
249
- if (o && i >= o.length)
250
- o = void 0;
251
- return { value: o && o[i++], done: !o };
252
- }
253
- };
254
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
255
- }
256
- function __read(o, n) {
257
- var m = typeof Symbol === "function" && o[Symbol.iterator];
258
- if (!m)
259
- return o;
260
- var i = m.call(o), r, ar = [], e;
261
- try {
262
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
263
- ar.push(r.value);
264
- }
265
- catch (error) {
266
- e = { error: error };
267
- }
268
- finally {
269
- try {
270
- if (r && !r.done && (m = i["return"]))
271
- m.call(i);
272
- }
273
- finally {
274
- if (e)
275
- throw e.error;
276
- }
277
- }
278
- return ar;
279
- }
280
- /** @deprecated */
281
- function __spread() {
282
- for (var ar = [], i = 0; i < arguments.length; i++)
283
- ar = ar.concat(__read(arguments[i]));
284
- return ar;
285
- }
286
- /** @deprecated */
287
- function __spreadArrays() {
288
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
289
- s += arguments[i].length;
290
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
291
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
292
- r[k] = a[j];
293
- return r;
294
- }
295
- function __spreadArray(to, from, pack) {
296
- if (pack || arguments.length === 2)
297
- for (var i = 0, l = from.length, ar; i < l; i++) {
298
- if (ar || !(i in from)) {
299
- if (!ar)
300
- ar = Array.prototype.slice.call(from, 0, i);
301
- ar[i] = from[i];
302
- }
303
- }
304
- return to.concat(ar || Array.prototype.slice.call(from));
305
- }
306
- function __await(v) {
307
- return this instanceof __await ? (this.v = v, this) : new __await(v);
308
- }
309
- function __asyncGenerator(thisArg, _arguments, generator) {
310
- if (!Symbol.asyncIterator)
311
- throw new TypeError("Symbol.asyncIterator is not defined.");
312
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
313
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
314
- function verb(n) { if (g[n])
315
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
316
- function resume(n, v) { try {
317
- step(g[n](v));
318
- }
319
- catch (e) {
320
- settle(q[0][3], e);
321
- } }
322
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
323
- function fulfill(value) { resume("next", value); }
324
- function reject(value) { resume("throw", value); }
325
- function settle(f, v) { if (f(v), q.shift(), q.length)
326
- resume(q[0][0], q[0][1]); }
327
- }
328
- function __asyncDelegator(o) {
329
- var i, p;
330
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
331
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
332
- }
333
- function __asyncValues(o) {
334
- if (!Symbol.asyncIterator)
335
- throw new TypeError("Symbol.asyncIterator is not defined.");
336
- var m = o[Symbol.asyncIterator], i;
337
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
338
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
339
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
340
- }
341
- function __makeTemplateObject(cooked, raw) {
342
- if (Object.defineProperty) {
343
- Object.defineProperty(cooked, "raw", { value: raw });
344
- }
345
- else {
346
- cooked.raw = raw;
347
- }
348
- return cooked;
349
- }
350
- ;
351
- var __setModuleDefault = Object.create ? (function (o, v) {
352
- Object.defineProperty(o, "default", { enumerable: true, value: v });
353
- }) : function (o, v) {
354
- o["default"] = v;
355
- };
356
- function __importStar(mod) {
357
- if (mod && mod.__esModule)
358
- return mod;
359
- var result = {};
360
- if (mod != null)
361
- for (var k in mod)
362
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
363
- __createBinding(result, mod, k);
364
- __setModuleDefault(result, mod);
365
- return result;
366
- }
367
- function __importDefault(mod) {
368
- return (mod && mod.__esModule) ? mod : { default: mod };
369
- }
370
- function __classPrivateFieldGet(receiver, state, kind, f) {
371
- if (kind === "a" && !f)
372
- throw new TypeError("Private accessor was defined without a getter");
373
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
374
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
375
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
376
- }
377
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
378
- if (kind === "m")
379
- throw new TypeError("Private method is not writable");
380
- if (kind === "a" && !f)
381
- throw new TypeError("Private accessor was defined without a setter");
382
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
383
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
384
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
385
- }
386
- function __classPrivateFieldIn(state, receiver) {
387
- if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
388
- throw new TypeError("Cannot use 'in' operator on non-object");
389
- return typeof state === "function" ? receiver === state : state.has(receiver);
390
- }
391
- function __addDisposableResource(env, value, async) {
392
- if (value !== null && value !== void 0) {
393
- if (typeof value !== "object" && typeof value !== "function")
394
- throw new TypeError("Object expected.");
395
- var dispose;
396
- if (async) {
397
- if (!Symbol.asyncDispose)
398
- throw new TypeError("Symbol.asyncDispose is not defined.");
399
- dispose = value[Symbol.asyncDispose];
400
- }
401
- if (dispose === void 0) {
402
- if (!Symbol.dispose)
403
- throw new TypeError("Symbol.dispose is not defined.");
404
- dispose = value[Symbol.dispose];
405
- }
406
- if (typeof dispose !== "function")
407
- throw new TypeError("Object not disposable.");
408
- env.stack.push({ value: value, dispose: dispose, async: async });
409
- }
410
- else if (async) {
411
- env.stack.push({ async: true });
412
- }
413
- return value;
414
- }
415
- var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
416
- var e = new Error(message);
417
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
418
- };
419
- function __disposeResources(env) {
420
- function fail(e) {
421
- env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
422
- env.hasError = true;
423
- }
424
- function next() {
425
- while (env.stack.length) {
426
- var rec = env.stack.pop();
427
- try {
428
- var result = rec.dispose && rec.dispose.call(rec.value);
429
- if (rec.async)
430
- return Promise.resolve(result).then(next, function (e) { fail(e); return next(); });
431
- }
432
- catch (e) {
433
- fail(e);
434
- }
435
- }
436
- if (env.hasError)
437
- throw env.error;
438
- }
439
- return next();
440
- }
441
- var tslib_es6 = {
442
- __extends: __extends,
443
- __assign: __assign,
444
- __rest: __rest,
445
- __decorate: __decorate,
446
- __param: __param,
447
- __metadata: __metadata,
448
- __awaiter: __awaiter$4,
449
- __generator: __generator,
450
- __createBinding: __createBinding,
451
- __exportStar: __exportStar,
452
- __values: __values,
453
- __read: __read,
454
- __spread: __spread,
455
- __spreadArrays: __spreadArrays,
456
- __spreadArray: __spreadArray,
457
- __await: __await,
458
- __asyncGenerator: __asyncGenerator,
459
- __asyncDelegator: __asyncDelegator,
460
- __asyncValues: __asyncValues,
461
- __makeTemplateObject: __makeTemplateObject,
462
- __importStar: __importStar,
463
- __importDefault: __importDefault,
464
- __classPrivateFieldGet: __classPrivateFieldGet,
465
- __classPrivateFieldSet: __classPrivateFieldSet,
466
- __classPrivateFieldIn: __classPrivateFieldIn,
467
- __addDisposableResource: __addDisposableResource,
468
- __disposeResources: __disposeResources,
469
- };
470
-
471
- var CordovaBLEError = /** @class */ (function (_super) {
472
- __extends(CordovaBLEError, _super);
473
- function CordovaBLEError() {
474
- return _super !== null && _super.apply(this, arguments) || this;
475
- }
476
- CordovaBLEError.invalidErrorResult = function (errObject) {
477
- return new CordovaBLEError("Internal error: ble cordova plugin returned an unexpected error object", CordovaBLEError.Code.InternalError);
478
- };
479
- CordovaBLEError.invalidErrorCode = function (errObject) {
480
- return new CordovaBLEError("Internal error: ble cordova plugin returned an invalid error code " + errObject.code + " with message " + errObject.message, CordovaBLEError.Code.InternalError);
481
- };
482
- CordovaBLEError.invalidNativeCallResult = function (result, cause) {
483
- return new CordovaBLEError("Internal error: native call returned an invalid data type. " + cause.message, CordovaBLEError.Code.InternalError);
484
- };
485
- CordovaBLEError.isValidErrorCode = function (code) {
486
- return code in CordovaBLEError.Code;
487
- };
488
- CordovaBLEError.iotizeBLEMissing = function () {
489
- return new CordovaBLEError("iotizeBLE global variable does not exist. Are you sure app is running inside a Cordova application ?", CordovaBLEError.Code.InternalError);
490
- };
491
- return CordovaBLEError;
492
- }(error.CodeError));
493
- /* istanbul ignore next */
494
- (function (CordovaBLEError) {
495
- var Code;
496
- (function (Code) {
497
- Code["InternalError"] = "CordovaBLEErrorInternalError";
498
- Code["IllegalArgument"] = "CordovaBLEErrorIllegalArgument";
499
- Code["BLENotAvailable"] = "CordovaBLEErrorBLENotAvailable";
500
- Code["InvalidMacAddress"] = "InvalidMacAddressInvalidMacAddress";
501
- Code["ConnectionError"] = "CordovaBLEErrorConnectionError";
502
- Code["RequestError"] = "CordovaBLEErrorRequestError";
503
- Code["LocationServiceDisabled"] = "CordovaBLEErrorLocationServiceDisabled";
504
- Code["DisconnectError"] = "CordovaBLEErrorDisconnectError";
505
- Code["IllegalAction"] = "CordovaBLEErrorIllegalAction";
506
- Code["NotConnectedError"] = "CordovaBLEErrorNotConnectedError";
507
- Code["StatusCodeError"] = "CordovaBLEErrorStatusCodeError";
508
- })(Code = CordovaBLEError.Code || (CordovaBLEError.Code = {}));
509
- })(CordovaBLEError || (CordovaBLEError = {}));
510
-
511
- var debug = debug$1.createDebugger("@iotize/device-com-ble.cordova");
512
-
513
- function getIoTizeBleCordovaPlugin() {
514
- if (typeof iotizeBLE !== "object") {
515
- throw CordovaBLEError.iotizeBLEMissing();
516
- }
517
- return iotizeBLE;
518
- }
519
- function getScanRecordsFromBytes(bytes) {
520
- //LTV encoding
521
- var records = [];
522
- for (var i = 0; i < bytes.length; i++) {
523
- //first byte is length
524
- var size = bytes[i];
525
- if (size == 0) {
526
- break;
527
- }
528
- var type = bytes[i + 1];
529
- records.push({
530
- type: type,
531
- data: bytes.slice(i + 2, i + size + 1)
532
- });
533
- i += size;
534
- }
535
- return records;
536
- }
537
-
538
- var __awaiter$3 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
539
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
540
- return new (P || (P = Promise))(function (resolve, reject) {
541
- function fulfilled(value) { try {
542
- step(generator.next(value));
543
- }
544
- catch (e) {
545
- reject(e);
546
- } }
547
- function rejected(value) { try {
548
- step(generator["throw"](value));
549
- }
550
- catch (e) {
551
- reject(e);
552
- } }
553
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
554
- step((generator = generator.apply(thisArg, _arguments || [])).next());
555
- });
556
- };
557
- var BLEComProtocol = /** @class */ (function (_super) {
558
- __extends(BLEComProtocol, _super);
559
- function BLEComProtocol(deviceId, comProtocolOptions, cordovaInterfaceOverwrite) {
560
- var _this = _super.call(this) || this;
561
- _this.deviceId = deviceId;
562
- _this.cordovaInterfaceOverwrite = cordovaInterfaceOverwrite;
563
- if (comProtocolOptions) {
564
- _this.options = comProtocolOptions;
565
- }
566
- else {
567
- _this.options.connect.timeout = 60000;
568
- }
569
- return _this;
570
- }
571
- Object.defineProperty(BLEComProtocol.prototype, "pluginInterface", {
572
- /**
573
- * Lazy reference to iotizeBLE.
574
- * We don't want to reference iotizeBLE in constructor as it may be referenced
575
- * before cordova plugin is loaded
576
- */
577
- get: function () {
578
- return this.cordovaInterfaceOverwrite || getIoTizeBleCordovaPlugin();
579
- },
580
- enumerable: false,
581
- configurable: true
582
- });
583
- BLEComProtocol.prototype._connect = function (options) {
584
- var _this = this;
585
- debug('_connect', options);
586
- return this.pluginInterface
587
- .connectAndDiscoverTapServices(this.deviceId)
588
- .pipe(operators.tap(function (state) {
589
- _this.setConnectionState(state);
590
- }), operators.filter(function (state) { return state === api.ConnectionState.CONNECTED; }), operators.first());
591
- };
592
- BLEComProtocol.prototype._disconnect = function (options) {
593
- var _this = this;
594
- debug('_disconnect', options);
595
- return rxjs.defer(function () { return _this.pluginInterface.disConnect(_this.deviceId); });
596
- };
597
- BLEComProtocol.prototype.write = function (data) {
598
- return __awaiter$3(this, void 0, void 0, function () {
599
- return __generator(this, function (_b) {
600
- throw new Error('Method not implemented.');
601
- });
602
- });
603
- };
604
- BLEComProtocol.prototype.read = function () {
605
- return __awaiter$3(this, void 0, void 0, function () {
606
- return __generator(this, function (_b) {
607
- throw new Error('Method not implemented.');
608
- });
609
- });
610
- };
611
- BLEComProtocol.prototype.send = function (data, options) {
612
- var _this = this;
613
- return rxjs.defer(function () { return _this.pluginInterface.send(_this.deviceId, data); }).pipe(operators.catchError(function (err) {
614
- var _a;
615
- if (((_a = err) === null || _a === void 0 ? void 0 : _a.code) ===
616
- CordovaBLEError.Code.NotConnectedError) {
617
- _this.setConnectionState(api.ConnectionState.DISCONNECTED);
618
- }
619
- return rxjs.throwError(err);
620
- }));
621
- };
622
- return BLEComProtocol;
623
- }(core.QueueComProtocol));
624
-
625
- var __awaiter$2 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
626
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
627
- return new (P || (P = Promise))(function (resolve, reject) {
628
- function fulfilled(value) { try {
629
- step(generator.next(value));
630
- }
631
- catch (e) {
632
- reject(e);
633
- } }
634
- function rejected(value) { try {
635
- step(generator["throw"](value));
636
- }
637
- catch (e) {
638
- reject(e);
639
- } }
640
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
641
- step((generator = generator.apply(thisArg, _arguments || [])).next());
642
- });
643
- };
644
- var CordovaPeripheralAdapter = /** @class */ (function () {
645
- function CordovaPeripheralAdapter(deviceId, cordovaPlugin) {
646
- if (cordovaPlugin === void 0) { cordovaPlugin = getIoTizeBleCordovaPlugin(); }
647
- this.deviceId = deviceId;
648
- this.cordovaPlugin = cordovaPlugin;
649
- this._stateChange = new rxjs.BehaviorSubject(api.ConnectionState.DISCONNECTED);
650
- }
651
- Object.defineProperty(CordovaPeripheralAdapter.prototype, "stateChange", {
652
- get: function () {
653
- return this._stateChange.asObservable().pipe(operators.distinctUntilChanged());
654
- },
655
- enumerable: false,
656
- configurable: true
657
- });
658
- Object.defineProperty(CordovaPeripheralAdapter.prototype, "name", {
659
- get: function () {
660
- // TODO device name ?
661
- return this.id;
662
- },
663
- enumerable: false,
664
- configurable: true
665
- });
666
- Object.defineProperty(CordovaPeripheralAdapter.prototype, "id", {
667
- get: function () {
668
- return this.deviceId;
669
- },
670
- enumerable: false,
671
- configurable: true
672
- });
673
- Object.defineProperty(CordovaPeripheralAdapter.prototype, "state", {
674
- get: function () {
675
- return api.ConnectionState[this._stateChange.value];
676
- },
677
- enumerable: false,
678
- configurable: true
679
- });
680
- CordovaPeripheralAdapter.prototype.discoverServices = function (serviceUUIDs) {
681
- return __awaiter$2(this, void 0, void 0, function () {
682
- var _b, result, _loop_1, this_1, serviceUUIDs_1, serviceUUIDs_1_1, uuid, _c, _d, serviceDefinition;
683
- var e_1, _e, e_2, _f;
684
- return __generator(this, function (_g) {
685
- switch (_g.label) {
686
- case 0:
687
- _b = this;
688
- return [4 /*yield*/, this.cordovaPlugin.discoverServices(this.deviceId)];
689
- case 1:
690
- _b.serviceListCache = _g.sent();
691
- result = {};
692
- if (serviceUUIDs) {
693
- _loop_1 = function (uuid) {
694
- var servicDefinition = this_1.serviceListCache.find(function (def) { return def.uuid === uuid; });
695
- if (servicDefinition) {
696
- result[uuid] = new CordovaServiceAdapter(servicDefinition, this_1);
697
- }
698
- };
699
- this_1 = this;
700
- try {
701
- for (serviceUUIDs_1 = __values(serviceUUIDs), serviceUUIDs_1_1 = serviceUUIDs_1.next(); !serviceUUIDs_1_1.done; serviceUUIDs_1_1 = serviceUUIDs_1.next()) {
702
- uuid = serviceUUIDs_1_1.value;
703
- _loop_1(uuid);
704
- }
705
- }
706
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
707
- finally {
708
- try {
709
- if (serviceUUIDs_1_1 && !serviceUUIDs_1_1.done && (_e = serviceUUIDs_1.return)) _e.call(serviceUUIDs_1);
710
- }
711
- finally { if (e_1) throw e_1.error; }
712
- }
713
- }
714
- else {
715
- try {
716
- for (_c = __values(this.serviceListCache), _d = _c.next(); !_d.done; _d = _c.next()) {
717
- serviceDefinition = _d.value;
718
- result[serviceDefinition.uuid] = new CordovaServiceAdapter(serviceDefinition, this);
719
- }
720
- }
721
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
722
- finally {
723
- try {
724
- if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
725
- }
726
- finally { if (e_2) throw e_2.error; }
727
- }
728
- }
729
- return [2 /*return*/, result];
730
- }
731
- });
732
- });
733
- };
734
- CordovaPeripheralAdapter.prototype.connect = function () {
735
- var _a;
736
- return __awaiter$2(this, void 0, void 0, function () {
737
- var connectObservable;
738
- var _this = this;
739
- return __generator(this, function (_b) {
740
- switch (_b.label) {
741
- case 0:
742
- (_a = this.connectionStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
743
- connectObservable = this.cordovaPlugin
744
- .connect(this.deviceId)
745
- .pipe(operators.shareReplay());
746
- this.connectionStateSubscription = connectObservable.subscribe(function (state) {
747
- _this._stateChange.next(state);
748
- });
749
- return [4 /*yield*/, connectObservable
750
- .pipe(operators.filter(function (state) { return state === api.ConnectionState.CONNECTED; }), operators.first())
751
- .toPromise()];
752
- case 1:
753
- _b.sent();
754
- return [2 /*return*/];
755
- }
756
- });
757
- });
758
- };
759
- CordovaPeripheralAdapter.prototype.disconnect = function () {
760
- var _a;
761
- return __awaiter$2(this, void 0, void 0, function () {
762
- return __generator(this, function (_b) {
763
- switch (_b.label) {
764
- case 0: return [4 /*yield*/, this.cordovaPlugin.disConnect(this.deviceId)];
765
- case 1:
766
- _b.sent();
767
- this._stateChange.next(api.ConnectionState.DISCONNECTED);
768
- (_a = this.connectionStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
769
- return [2 /*return*/];
770
- }
771
- });
772
- });
773
- };
774
- CordovaPeripheralAdapter.prototype.close = function () {
775
- var _a;
776
- return __awaiter$2(this, void 0, void 0, function () {
777
- return __generator(this, function (_b) {
778
- switch (_b.label) {
779
- case 0: return [4 /*yield*/, this.cordovaPlugin.close(this.deviceId)];
780
- case 1:
781
- _b.sent();
782
- this._stateChange.next(api.ConnectionState.DISCONNECTED);
783
- (_a = this.connectionStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
784
- return [2 /*return*/];
785
- }
786
- });
787
- });
788
- };
789
- CordovaPeripheralAdapter.prototype.getService = function (uuid) {
790
- return __awaiter$2(this, void 0, void 0, function () {
791
- var serviceDefinition;
792
- return __generator(this, function (_b) {
793
- switch (_b.label) {
794
- case 0:
795
- if (!!this.serviceListCache) return [3 /*break*/, 2];
796
- return [4 /*yield*/, this.discoverServices([uuid])];
797
- case 1:
798
- _b.sent();
799
- _b.label = 2;
800
- case 2:
801
- serviceDefinition = this.serviceListCache.find(function (s) { return s.uuid === uuid; });
802
- if (!serviceDefinition) {
803
- throw common.BleComError.serviceNotFound(uuid);
804
- }
805
- return [2 /*return*/, new CordovaServiceAdapter(serviceDefinition, this)];
806
- }
807
- });
808
- });
809
- };
810
- return CordovaPeripheralAdapter;
811
- }());
812
- var CordovaServiceAdapter = /** @class */ (function () {
813
- function CordovaServiceAdapter(config, peripheral) {
814
- this.config = config;
815
- this.peripheral = peripheral;
816
- }
817
- Object.defineProperty(CordovaServiceAdapter.prototype, "uuid", {
818
- get: function () {
819
- return this.config.uuid;
820
- },
821
- enumerable: false,
822
- configurable: true
823
- });
824
- CordovaServiceAdapter.prototype.getCharacteristic = function (charcUUID) {
825
- var _a;
826
- return __awaiter$2(this, void 0, void 0, function () {
827
- var characteristicDescription;
828
- return __generator(this, function (_b) {
829
- characteristicDescription = (_a = this.config.characteristics) === null || _a === void 0 ? void 0 : _a.find(function (c) { return c.uuid === charcUUID; });
830
- if (!characteristicDescription) {
831
- throw common.BleComError.charcacteristicNotFound(charcUUID);
832
- }
833
- return [2 /*return*/, new CordovaCharacteristicAdapter(this, characteristicDescription)];
834
- });
835
- });
836
- };
837
- CordovaServiceAdapter.prototype.getCharacteristics = function () {
838
- return __awaiter$2(this, void 0, void 0, function () {
839
- var _this = this;
840
- return __generator(this, function (_b) {
841
- if (!this.config.characteristics) {
842
- return [2 /*return*/, []];
843
- }
844
- return [2 /*return*/, this.config.characteristics.map(function (c) { return new CordovaCharacteristicAdapter(_this, c); })];
845
- });
846
- });
847
- };
848
- return CordovaServiceAdapter;
849
- }());
850
- var CordovaCharacteristicAdapter = /** @class */ (function () {
851
- function CordovaCharacteristicAdapter(service, config) {
852
- this.service = service;
853
- this.config = config;
854
- }
855
- Object.defineProperty(CordovaCharacteristicAdapter.prototype, "uuid", {
856
- get: function () {
857
- return this.config.uuid;
858
- },
859
- enumerable: false,
860
- configurable: true
861
- });
862
- Object.defineProperty(CordovaCharacteristicAdapter.prototype, "properties", {
863
- get: function () {
864
- return this.config.properties;
865
- },
866
- enumerable: false,
867
- configurable: true
868
- });
869
- Object.defineProperty(CordovaCharacteristicAdapter.prototype, "data", {
870
- get: function () {
871
- return this.setupDataStreamIfRequired().pipe(operators.map(function (data) { return ({
872
- data: data,
873
- isNotification: true,
874
- }); }));
875
- },
876
- enumerable: false,
877
- configurable: true
878
- });
879
- Object.defineProperty(CordovaCharacteristicAdapter.prototype, "deviceId", {
880
- get: function () {
881
- return this.service.peripheral.deviceId;
882
- },
883
- enumerable: false,
884
- configurable: true
885
- });
886
- Object.defineProperty(CordovaCharacteristicAdapter.prototype, "pluginInterface", {
887
- get: function () {
888
- return this.service.peripheral.cordovaPlugin;
889
- },
890
- enumerable: false,
891
- configurable: true
892
- });
893
- CordovaCharacteristicAdapter.prototype.read = function () {
894
- return __awaiter$2(this, void 0, void 0, function () {
895
- return __generator(this, function (_b) {
896
- return [2 /*return*/, this.pluginInterface.characteristicReadValue(this.deviceId, this.service.uuid, this.uuid)];
897
- });
898
- });
899
- };
900
- CordovaCharacteristicAdapter.prototype.getDescriptor = function () {
901
- return __awaiter$2(this, void 0, void 0, function () {
902
- return __generator(this, function (_b) {
903
- throw new Error("Not implemented yet");
904
- });
905
- });
906
- };
907
- CordovaCharacteristicAdapter.prototype.getDescriptors = function () {
908
- return __awaiter$2(this, void 0, void 0, function () {
909
- var _this = this;
910
- return __generator(this, function (_b) {
911
- if (!this.config.descriptors) {
912
- return [2 /*return*/, []];
913
- }
914
- return [2 /*return*/, this.config.descriptors.map(function (descriptor) { return new CordovaDescriptorAdapter(descriptor, _this); })];
915
- });
916
- });
917
- };
918
- CordovaCharacteristicAdapter.prototype.write = function (data, writeWithoutResponse) {
919
- return __awaiter$2(this, void 0, void 0, function () {
920
- return __generator(this, function (_b) {
921
- switch (_b.label) {
922
- case 0:
923
- if (!writeWithoutResponse) return [3 /*break*/, 2];
924
- return [4 /*yield*/, this.pluginInterface.characteristicWriteWithoutResponse(this.deviceId, this.service.uuid, this.uuid, data)];
925
- case 1:
926
- _b.sent();
927
- return [3 /*break*/, 4];
928
- case 2: return [4 /*yield*/, this.pluginInterface.characteristicWrite(this.deviceId, this.service.uuid, this.uuid, data)];
929
- case 3:
930
- _b.sent();
931
- _b.label = 4;
932
- case 4: return [2 /*return*/, data];
933
- }
934
- });
935
- });
936
- };
937
- CordovaCharacteristicAdapter.prototype.enableNotifications = function (enabled) {
938
- return __awaiter$2(this, void 0, void 0, function () {
939
- return __generator(this, function (_b) {
940
- switch (_b.label) {
941
- case 0:
942
- if (!enabled) return [3 /*break*/, 2];
943
- this.setupDataStreamIfRequired();
944
- return [4 /*yield*/, this.pluginInterface.characteristicStartNotification(this.deviceId, this.service.uuid, this.uuid)];
945
- case 1:
946
- _b.sent();
947
- return [3 /*break*/, 4];
948
- case 2: return [4 /*yield*/, this.pluginInterface.characteristicStopNotification(this.deviceId, this.service.uuid, this.uuid)];
949
- case 3:
950
- _b.sent();
951
- _b.label = 4;
952
- case 4: return [2 /*return*/];
953
- }
954
- });
955
- });
956
- };
957
- CordovaCharacteristicAdapter.prototype.setupDataStreamIfRequired = function () {
958
- if (!this._dataStream) {
959
- this._dataStream = this.pluginInterface.characteristicChanged(this.deviceId, this.service.uuid, this.uuid);
960
- }
961
- return this._dataStream;
962
- };
963
- return CordovaCharacteristicAdapter;
964
- }());
965
- var CordovaDescriptorAdapter = /** @class */ (function () {
966
- function CordovaDescriptorAdapter(config, characteristic) {
967
- this.config = config;
968
- this.characteristic = characteristic;
969
- }
970
- Object.defineProperty(CordovaDescriptorAdapter.prototype, "uuid", {
971
- get: function () {
972
- return this.config.uuid;
973
- },
974
- enumerable: false,
975
- configurable: true
976
- });
977
- CordovaDescriptorAdapter.prototype.readValue = function () {
978
- return __awaiter$2(this, void 0, void 0, function () {
979
- return __generator(this, function (_b) {
980
- throw new Error("Reading descriptor value is not implemented yet");
981
- });
982
- });
983
- };
984
- CordovaDescriptorAdapter.prototype.writeValue = function (data) {
985
- return __awaiter$2(this, void 0, void 0, function () {
986
- return __generator(this, function (_b) {
987
- throw new Error("Writing descriptor value is not implemented yet");
988
- });
989
- });
990
- };
991
- return CordovaDescriptorAdapter;
992
- }());
993
-
994
- //
995
- // Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.
996
- //
997
- // scanner.ts
998
- // device-com-ble.cordova BLE Cordova Plugin
999
- //
1000
- var __awaiter$1 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1001
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1002
- return new (P || (P = Promise))(function (resolve, reject) {
1003
- function fulfilled(value) { try {
1004
- step(generator.next(value));
1005
- }
1006
- catch (e) {
1007
- reject(e);
1008
- } }
1009
- function rejected(value) { try {
1010
- step(generator["throw"](value));
1011
- }
1012
- catch (e) {
1013
- reject(e);
1014
- } }
1015
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1016
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1017
- });
1018
- };
1019
- /**
1020
- * BLE Tap scanner for cordova apps
1021
- */
1022
- var BLEScanner = /** @class */ (function () {
1023
- /**
1024
- *
1025
- * @param cordovaInterfaceOverwrite overwrite cordova interface. Used for testing
1026
- */
1027
- function BLEScanner(cordovaInterfaceOverwrite,
1028
- /**
1029
- * Request device options used to filter scan results
1030
- */
1031
- requestDeviceOptions) {
1032
- this.cordovaInterfaceOverwrite = cordovaInterfaceOverwrite;
1033
- this.requestDeviceOptions = requestDeviceOptions;
1034
- this._results = new rxjs.BehaviorSubject([]);
1035
- this._scanning$ = new rxjs.BehaviorSubject(false);
1036
- }
1037
- Object.defineProperty(BLEScanner.prototype, "cordovaInterface", {
1038
- /**
1039
- * Lazy reference to iotizeBLE.
1040
- * We don't want to reference iotizeBLE in constructor as it may be referenced
1041
- * before cordova plugin is loaded
1042
- */
1043
- get: function () {
1044
- return this.cordovaInterfaceOverwrite || getIoTizeBleCordovaPlugin();
1045
- },
1046
- enumerable: false,
1047
- configurable: true
1048
- });
1049
- Object.defineProperty(BLEScanner.prototype, "scanning", {
1050
- get: function () {
1051
- return this._scanning$.asObservable();
1052
- },
1053
- enumerable: false,
1054
- configurable: true
1055
- });
1056
- Object.defineProperty(BLEScanner.prototype, "isScanning", {
1057
- get: function () {
1058
- return this._scanning$.value;
1059
- },
1060
- enumerable: false,
1061
- configurable: true
1062
- });
1063
- Object.defineProperty(BLEScanner.prototype, "results", {
1064
- /**
1065
- * Gets the observable on the devices$ Subject
1066
- * @return
1067
- */
1068
- get: function () {
1069
- return this._results.asObservable();
1070
- },
1071
- enumerable: false,
1072
- configurable: true
1073
- });
1074
- /**
1075
- * Launches the scan for BLE devices
1076
- * Throws if BLE is not available
1077
- */
1078
- BLEScanner.prototype.start = function (options) {
1079
- var _a;
1080
- return __awaiter$1(this, void 0, void 0, function () {
1081
- var isAvailable;
1082
- var _this = this;
1083
- return __generator(this, function (_b) {
1084
- switch (_b.label) {
1085
- case 0:
1086
- (_a = this.scanSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1087
- this.scanSubscription = undefined;
1088
- this.clearResults();
1089
- return [4 /*yield*/, this.checkAvailable()];
1090
- case 1:
1091
- isAvailable = _b.sent();
1092
- if (!isAvailable) {
1093
- throw common.BleComError.bleNotAvailable("BLE is not available. Make sure that BLE is enabled on your device");
1094
- }
1095
- debug("Start Scanning ...");
1096
- this._scanning$.next(true);
1097
- return [2 /*return*/, new Promise(function (resolve, reject) {
1098
- _this.scanSubscription = _this.cordovaInterface
1099
- .startScan(_this.requestDeviceOptions)
1100
- .subscribe(function (result) {
1101
- if (result == "Ok") {
1102
- resolve();
1103
- return;
1104
- }
1105
- _this.addOrRefreshDevice(result);
1106
- }, function (error) {
1107
- debug("Start scan failed with error: ", error);
1108
- _this.cordovaInterface
1109
- .getLastError()
1110
- .then(function (lasterror) {
1111
- debug("Last BLE error " + lasterror);
1112
- })
1113
- .catch(function (err) {
1114
- debug("Cannot get last BLE error: ", err);
1115
- });
1116
- reject(error);
1117
- _this._scanning$.next(false);
1118
- });
1119
- })];
1120
- }
1121
- });
1122
- });
1123
- };
1124
- /**
1125
- *
1126
- */
1127
- BLEScanner.prototype.stop = function () {
1128
- var _a;
1129
- return __awaiter$1(this, void 0, void 0, function () {
1130
- var err_1;
1131
- return __generator(this, function (_b) {
1132
- switch (_b.label) {
1133
- case 0:
1134
- debug("Stop Scanning ...");
1135
- _b.label = 1;
1136
- case 1:
1137
- _b.trys.push([1, 3, , 4]);
1138
- (_a = this.scanSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1139
- this.scanSubscription = undefined;
1140
- return [4 /*yield*/, this.cordovaInterface.stopScan()];
1141
- case 2:
1142
- _b.sent();
1143
- this._scanning$.next(false);
1144
- return [2 /*return*/];
1145
- case 3:
1146
- err_1 = _b.sent();
1147
- this._scanning$.next(false);
1148
- throw err_1;
1149
- case 4: return [2 /*return*/];
1150
- }
1151
- });
1152
- });
1153
- };
1154
- /**
1155
- * Returns true if this scanner is available
1156
- */
1157
- BLEScanner.prototype.checkAvailable = function () {
1158
- return this.cordovaInterface.checkAvailable();
1159
- };
1160
- Object.defineProperty(BLEScanner.prototype, "devices", {
1161
- get: function () {
1162
- return this._results.value;
1163
- },
1164
- enumerable: false,
1165
- configurable: true
1166
- });
1167
- BLEScanner.prototype.clearResults = function () {
1168
- this._results.next([]);
1169
- };
1170
- BLEScanner.prototype.addOrRefreshDevice = function (newDevice) {
1171
- var storedDeviceIndex = this.devices.findIndex(function (entry) { return entry.address == newDevice.address; });
1172
- if (storedDeviceIndex >= 0) {
1173
- var storedDevice = this.devices[storedDeviceIndex];
1174
- if (storedDevice.name != newDevice.name ||
1175
- storedDevice.rssi != newDevice.rssi) {
1176
- debug("Updating device at index " + storedDeviceIndex + ", name=" + storedDevice.name + " with rssi=" + storedDevice.rssi);
1177
- this.devices[storedDeviceIndex] = newDevice;
1178
- // this.devices = [...this.devices];
1179
- this._results.next(this.devices);
1180
- }
1181
- }
1182
- else {
1183
- debug("Adding new device name=" + newDevice.name + " with rssi=" + newDevice.rssi);
1184
- this.devices.push(newDevice);
1185
- this._results.next(this.devices);
1186
- }
1187
- };
1188
- return BLEScanner;
1189
- }());
1190
-
1191
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1192
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1193
- return new (P || (P = Promise))(function (resolve, reject) {
1194
- function fulfilled(value) { try {
1195
- step(generator.next(value));
1196
- }
1197
- catch (e) {
1198
- reject(e);
1199
- } }
1200
- function rejected(value) { try {
1201
- step(generator["throw"](value));
1202
- }
1203
- catch (e) {
1204
- reject(e);
1205
- } }
1206
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1207
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1208
- });
1209
- };
1210
- function hexStringToBuffer(str) {
1211
- try {
1212
- return byteConverter.hexStringToBuffer(str);
1213
- }
1214
- catch (err) {
1215
- throw CordovaBLEError.invalidNativeCallResult(str, err);
1216
- }
1217
- }
1218
- var IoTizeBleCordovaPlugin = /** @class */ (function () {
1219
- function IoTizeBleCordovaPlugin() {
1220
- }
1221
- IoTizeBleCordovaPlugin.prototype.checkAvailable = function () {
1222
- return this.execSingleResult("checkAvailable", []);
1223
- };
1224
- IoTizeBleCordovaPlugin.prototype.requestEnableBle = function () {
1225
- return this.execSingleResult("enable", []);
1226
- };
1227
- IoTizeBleCordovaPlugin.prototype.startScan = function (requestDeviceOptions) {
1228
- return this.execMultipleResult("startScan", [
1229
- JSON.stringify(requestDeviceOptions),
1230
- ]);
1231
- };
1232
- IoTizeBleCordovaPlugin.prototype.stopScan = function () {
1233
- return this.execSingleResult("stopScan", []);
1234
- };
1235
- IoTizeBleCordovaPlugin.prototype.connect = function (deviceId, enableBleIfNot) {
1236
- var _this = this;
1237
- if (enableBleIfNot === void 0) { enableBleIfNot = true; }
1238
- return this.askBleEnable(enableBleIfNot).pipe(operators.switchMap(function () {
1239
- return _this.execMultipleResult("connect", [deviceId]).pipe(operators.map(function (state) {
1240
- if (!(state in api.ConnectionState)) {
1241
- console.warn("Plugin native code returned an invalid connection state: \"" + state + "\".");
1242
- }
1243
- return utility.safeEnumValue(api.ConnectionState, state);
1244
- }));
1245
- }));
1246
- };
1247
- IoTizeBleCordovaPlugin.prototype.askBleEnable = function (askEnable) {
1248
- var _this = this;
1249
- return rxjs.defer(function () { return __awaiter(_this, void 0, void 0, function () {
1250
- return __generator(this, function (_a) {
1251
- switch (_a.label) {
1252
- case 0:
1253
- if (!askEnable) return [3 /*break*/, 3];
1254
- return [4 /*yield*/, this.checkAvailable()];
1255
- case 1:
1256
- if (!!(_a.sent())) return [3 /*break*/, 3];
1257
- return [4 /*yield*/, this.requestEnableBle()];
1258
- case 2:
1259
- _a.sent();
1260
- _a.label = 3;
1261
- case 3: return [2 /*return*/];
1262
- }
1263
- });
1264
- }); });
1265
- };
1266
- IoTizeBleCordovaPlugin.prototype.requestMTU = function (deviceId, mtu) {
1267
- return this.execSingleResult("requestMTU", [deviceId, mtu]);
1268
- };
1269
- IoTizeBleCordovaPlugin.prototype.connectAndDiscoverTapServices = function (deviceId, enableBleIfNot) {
1270
- var _this = this;
1271
- if (enableBleIfNot === void 0) { enableBleIfNot = true; }
1272
- return this.askBleEnable(enableBleIfNot).pipe(operators.switchMap(function () {
1273
- return _this.execMultipleResult("connectAndDiscoverTapServices", [deviceId]).pipe(operators.map(function (state) {
1274
- if (!(state in api.ConnectionState)) {
1275
- console.warn("Plugin native code returned an invalid connection state: \"" + state + "\".");
1276
- }
1277
- return utility.safeEnumValue(api.ConnectionState, state);
1278
- }));
1279
- }));
1280
- };
1281
- IoTizeBleCordovaPlugin.prototype.disConnect = function (deviceId) {
1282
- return this.execSingleResult("disConnect", [deviceId]);
1283
- };
1284
- IoTizeBleCordovaPlugin.prototype.close = function (deviceId) {
1285
- return this.execSingleResult("close", [deviceId]);
1286
- };
1287
- IoTizeBleCordovaPlugin.prototype.isConnected = function (deviceId) {
1288
- return this.execSingleResult("isConnected", [deviceId]);
1289
- };
1290
- IoTizeBleCordovaPlugin.prototype.send = function (deviceId, data) {
1291
- return __awaiter(this, void 0, void 0, function () {
1292
- var hexString;
1293
- return __generator(this, function (_a) {
1294
- switch (_a.label) {
1295
- case 0: return [4 /*yield*/, this.execSingleResult("sendRequest", [
1296
- deviceId,
1297
- byteConverter.bufferToHexString(data),
1298
- ])];
1299
- case 1:
1300
- hexString = _a.sent();
1301
- return [2 /*return*/, hexStringToBuffer(hexString)];
1302
- }
1303
- });
1304
- });
1305
- };
1306
- IoTizeBleCordovaPlugin.prototype.getLastError = function () {
1307
- return this.execSingleResult("getLastError", []);
1308
- };
1309
- IoTizeBleCordovaPlugin.prototype.characteristicStartNotification = function (deviceId, serviceId, characId) {
1310
- return this.execSingleResult("characteristicStartNotification", [
1311
- deviceId,
1312
- serviceId,
1313
- characId,
1314
- ]);
1315
- };
1316
- IoTizeBleCordovaPlugin.prototype.characteristicChanged = function (deviceId, serviceId, characId) {
1317
- return this.execMultipleResult("characteristicChanged", [
1318
- deviceId,
1319
- serviceId,
1320
- characId,
1321
- ]).pipe(operators.map(function (hexString) {
1322
- return hexStringToBuffer(hexString);
1323
- }));
1324
- };
1325
- IoTizeBleCordovaPlugin.prototype.characteristicStopNotification = function (deviceId, serviceId, characId) {
1326
- return this.execSingleResult("characteristicStopNotification", [
1327
- deviceId,
1328
- serviceId,
1329
- characId,
1330
- ]);
1331
- };
1332
- IoTizeBleCordovaPlugin.prototype.characteristicReadValue = function (deviceId, serviceId, characId) {
1333
- return __awaiter(this, void 0, void 0, function () {
1334
- var hexString;
1335
- return __generator(this, function (_a) {
1336
- switch (_a.label) {
1337
- case 0: return [4 /*yield*/, this.execSingleResult("characteristicRead", [deviceId, serviceId, characId])];
1338
- case 1:
1339
- hexString = _a.sent();
1340
- return [2 /*return*/, hexStringToBuffer(hexString)];
1341
- }
1342
- });
1343
- });
1344
- };
1345
- IoTizeBleCordovaPlugin.prototype.characteristicWrite = function (deviceId, serviceId, characId, data) {
1346
- return this.execSingleResult("characteristicWrite", [
1347
- deviceId,
1348
- serviceId,
1349
- characId,
1350
- byteConverter.bufferToHexString(data),
1351
- ]);
1352
- };
1353
- IoTizeBleCordovaPlugin.prototype.characteristicWriteWithoutResponse = function (deviceId, serviceId, characId, data) {
1354
- return this.execSingleResult("characteristicWriteWithoutResponse", [
1355
- deviceId,
1356
- serviceId,
1357
- characId,
1358
- byteConverter.bufferToHexString(data),
1359
- ]);
1360
- };
1361
- IoTizeBleCordovaPlugin.prototype.discoverServices = function (deviceId) {
1362
- return __awaiter(this, void 0, void 0, function () {
1363
- var services;
1364
- return __generator(this, function (_a) {
1365
- switch (_a.label) {
1366
- case 0: return [4 /*yield*/, this.execSingleResult("discoverServices", [deviceId])];
1367
- case 1:
1368
- services = _a.sent();
1369
- return [2 /*return*/, services];
1370
- }
1371
- });
1372
- });
1373
- };
1374
- IoTizeBleCordovaPlugin.prototype.execSingleResult = function (methodName, args) {
1375
- return new Promise(function (resolve, reject) {
1376
- cordova.exec(resolve, function (errObject) {
1377
- reject(objectErrorToError(errObject));
1378
- }, "BLECom", methodName, args);
1379
- });
1380
- };
1381
- IoTizeBleCordovaPlugin.prototype.execMultipleResult = function (methodName, args) {
1382
- var subject = new rxjs.Subject();
1383
- cordova.exec(function (data) {
1384
- subject.next(data);
1385
- }, function (err) {
1386
- subject.error(objectErrorToError(err));
1387
- }, "BLECom", methodName, args);
1388
- return subject.asObservable();
1389
- };
1390
- return IoTizeBleCordovaPlugin;
1391
- }());
1392
- function objectErrorToError(errObject) {
1393
- if (typeof errObject !== "object" || !errObject.code || !errObject.message) {
1394
- return CordovaBLEError.invalidErrorResult(errObject);
1395
- }
1396
- if (!CordovaBLEError.isValidErrorCode(errObject.code)) {
1397
- return CordovaBLEError.invalidErrorCode(errObject);
1398
- }
1399
- return new CordovaBLEError(errObject.message, CordovaBLEError.Code[errObject.code]);
1400
- }
1401
-
1402
- /**
1403
- * Generated bundle index. Do not edit.
1404
- */
1405
-
1406
- exports.BLEComProtocol = BLEComProtocol;
1407
- exports.BLEScanner = BLEScanner;
1408
- exports.CordovaCharacteristicAdapter = CordovaCharacteristicAdapter;
1409
- exports.CordovaPeripheralAdapter = CordovaPeripheralAdapter;
1410
- exports.CordovaServiceAdapter = CordovaServiceAdapter;
1411
- exports.getIoTizeBleCordovaPlugin = getIoTizeBleCordovaPlugin;
1412
- exports.getScanRecordsFromBytes = getScanRecordsFromBytes;
1413
- exports["ɵc"] = IoTizeBleCordovaPlugin;
1414
-
1415
- Object.defineProperty(exports, '__esModule', { value: true });
1416
-
1417
- }));
1418
- //# sourceMappingURL=iotize-device-com-ble.cordova.umd.js.map