@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.
- package/bundles/iotize-device-com-ble.cordova.umd.js +1381 -1209
- package/bundles/iotize-device-com-ble.cordova.umd.js.map +1 -1
- package/bundles/iotize-device-com-ble.cordova.umd.min.js +1 -15
- package/bundles/iotize-device-com-ble.cordova.umd.min.js.map +1 -1
- package/package.json +6 -6
- package/plugin.xml +1 -1
- package/www/plugin.js +1 -1
|
@@ -1,1227 +1,1399 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
511
|
+
var debug = debug$1.createDebugger("@iotize/device-com-ble.cordova");
|
|
340
512
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
513
|
+
function getIoTizeBleCordovaPlugin() {
|
|
514
|
+
if (typeof iotizeBLE !== "object") {
|
|
515
|
+
throw CordovaBLEError.iotizeBLEMissing();
|
|
516
|
+
}
|
|
517
|
+
return iotizeBLE;
|
|
518
|
+
}
|
|
347
519
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
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
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
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
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
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
|
-
|
|
1214
|
-
|
|
1384
|
+
/**
|
|
1385
|
+
* Generated bundle index. Do not edit.
|
|
1386
|
+
*/
|
|
1215
1387
|
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
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
|
-
|
|
1396
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1225
1397
|
|
|
1226
1398
|
}));
|
|
1227
1399
|
//# sourceMappingURL=iotize-device-com-ble.cordova.umd.js.map
|