@iotize/device-com-ble.cordova 3.4.2 → 3.5.1

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