@iotize/device-com-ble.cordova 3.0.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -177
- package/bundles/iotize-device-com-ble.cordova.umd.js +1113 -129
- package/bundles/iotize-device-com-ble.cordova.umd.js.map +1 -1
- package/bundles/iotize-device-com-ble.cordova.umd.min.js +15 -1
- package/bundles/iotize-device-com-ble.cordova.umd.min.js.map +1 -1
- package/esm2015/iotize-device-com-ble.cordova.js +5 -1
- package/esm2015/iotize-device-com-ble.cordova.js.map +1 -0
- package/esm2015/iotize-device-com-ble.cordova.metadata.json +1 -0
- package/esm2015/iotize-device-com-ble.cordova.ngsummary.json +1 -1
- package/esm2015/lib/ble-com-protocol.js +68 -0
- package/esm2015/lib/ble-com-protocol.js.map +1 -0
- package/esm2015/lib/ble-com-protocol.metadata.json +1 -0
- package/esm2015/lib/ble-com-protocol.ngsummary.json +1 -0
- package/esm2015/lib/cordova-ble-error.js +36 -0
- package/esm2015/lib/cordova-ble-error.js.map +1 -0
- package/esm2015/lib/cordova-ble-error.metadata.json +1 -0
- package/esm2015/lib/cordova-ble-error.ngsummary.json +1 -0
- package/esm2015/lib/cordova-interface.js +2 -0
- package/esm2015/lib/cordova-interface.js.map +1 -0
- package/esm2015/lib/cordova-interface.metadata.json +1 -0
- package/esm2015/lib/cordova-interface.ngsummary.json +1 -0
- package/esm2015/lib/cordova-service-adapter.js +214 -0
- package/esm2015/lib/cordova-service-adapter.js.map +1 -0
- package/esm2015/lib/cordova-service-adapter.metadata.json +1 -0
- package/esm2015/lib/cordova-service-adapter.ngsummary.json +1 -0
- package/esm2015/lib/definitions.js +2 -0
- package/esm2015/lib/definitions.js.map +1 -0
- package/esm2015/lib/definitions.metadata.json +1 -0
- package/esm2015/lib/definitions.ngsummary.json +1 -0
- package/esm2015/lib/iotize-ble-cordova-plugin.js +170 -0
- package/esm2015/lib/iotize-ble-cordova-plugin.js.map +1 -0
- package/esm2015/lib/iotize-ble-cordova-plugin.metadata.json +1 -0
- package/esm2015/lib/iotize-ble-cordova-plugin.ngsummary.json +1 -0
- package/esm2015/lib/logger.js +3 -0
- package/esm2015/lib/logger.js.map +1 -0
- package/esm2015/lib/logger.metadata.json +1 -0
- package/esm2015/{www → lib}/logger.ngsummary.json +1 -1
- package/esm2015/lib/scanner.js +151 -0
- package/esm2015/lib/scanner.js.map +1 -0
- package/esm2015/lib/scanner.metadata.json +1 -0
- package/esm2015/lib/scanner.ngsummary.json +1 -0
- package/esm2015/lib/utility.js +8 -0
- package/esm2015/lib/utility.js.map +1 -0
- package/esm2015/lib/utility.metadata.json +1 -0
- package/esm2015/lib/utility.ngsummary.json +1 -0
- package/esm2015/public_api.js +5 -2
- package/esm2015/public_api.js.map +1 -0
- package/esm2015/public_api.metadata.json +1 -0
- package/esm2015/public_api.ngsummary.json +1 -1
- package/fesm2015/iotize-device-com-ble.cordova.js +543 -75
- package/fesm2015/iotize-device-com-ble.cordova.js.map +1 -1
- package/iotize-device-com-ble.cordova.d.ts +5 -0
- package/iotize-device-com-ble.cordova.metadata.json +1 -1
- package/lib/ble-com-protocol.d.ts +20 -0
- package/lib/cordova-ble-error.d.ts +29 -0
- package/lib/cordova-interface.d.ts +5 -0
- package/lib/cordova-service-adapter.d.ts +58 -0
- package/lib/definitions.d.ts +39 -0
- package/lib/iotize-ble-cordova-plugin.d.ts +27 -0
- package/lib/logger.d.ts +1 -0
- package/lib/scanner.d.ts +55 -0
- package/lib/utility.d.ts +2 -0
- package/package.json +10 -11
- package/plugin.xml +9 -11
- package/public_api.d.ts +5 -1
- package/src/android/.gradle/4.8.1/fileChanges/last-build.bin +0 -0
- package/src/android/.gradle/4.8.1/fileHashes/fileHashes.bin +0 -0
- package/src/android/.gradle/4.8.1/fileHashes/fileHashes.lock +0 -0
- package/src/android/.gradle/6.8.2/fileChanges/last-build.bin +0 -0
- package/src/android/.gradle/6.8.2/fileHashes/fileHashes.lock +0 -0
- package/src/android/.gradle/6.8.2/gc.properties +0 -0
- package/src/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/src/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/src/android/.gradle/checksums/checksums.lock +0 -0
- package/src/android/.gradle/configuration-cache/gc.properties +0 -0
- package/src/android/.gradle/vcs-1/gc.properties +0 -0
- package/src/android/.gradle/vcsWorkingDirs/gc.properties +0 -0
- package/src/android/.idea/android.iml +9 -0
- package/src/android/.idea/gradle.xml +16 -0
- package/src/android/.idea/modules.xml +8 -0
- package/src/android/.idea/vcs.xml +6 -0
- package/src/android/build.gradle +5 -4
- package/src/android/gradle/wrapper/gradle-wrapper.properties +1 -2
- package/src/android/src/ble/ArgsHelper.java +73 -0
- package/src/android/src/ble/BLECom.java +559 -0
- package/src/android/src/{BLEComError.java → ble/BLEComError.java} +22 -10
- package/src/android/src/{JSONBuilder.java → ble/JSONBuilder.java} +20 -5
- package/src/android/src/{PluginResponse.java → ble/PluginResponse.java} +51 -2
- package/src/android/src/ble/UUIDHelper.java +33 -0
- package/src/android/src/ble/models/CharacteristicDescription.java +39 -0
- package/src/android/src/ble/models/CharacteristicProperties.java +41 -0
- package/src/android/src/ble/models/DescriptorDescription.java +21 -0
- package/src/android/src/ble/models/RequestDeviceOptions.java +45 -0
- package/src/android/src/ble/models/ServiceDescription.java +51 -0
- package/src/ios/BLECom.swift +562 -124
- package/src/ios/BLEGenericPeripheral.swift +479 -0
- package/src/ios/BLEManager.swift +142 -47
- package/src/ios/{BLEPeripheral.swift → BLETapPeripheral.swift} +22 -85
- package/src/ios/CBPeripheralConverter.swift +86 -1
- package/src/ios/Queue.swift +71 -0
- package/src/windows/iotize-ble-com.js +159 -179
- package/www/plugin.js +2 -0
- package/www/plugin.js.LICENSE.txt +14 -0
- package/CHANGELOG.md +0 -42
- package/esm2015/www/ble-com-protocol.js +0 -75
- package/esm2015/www/ble-com-protocol.ngsummary.json +0 -1
- package/esm2015/www/cordova-interface.js +0 -1
- package/esm2015/www/cordova-interface.ngsummary.json +0 -1
- package/esm2015/www/definitions.js +0 -1
- package/esm2015/www/definitions.ngsummary.json +0 -1
- package/esm2015/www/index.js +0 -3
- package/esm2015/www/index.ngsummary.json +0 -1
- package/esm2015/www/logger.js +0 -3
- package/esm2015/www/scanner.js +0 -89
- package/esm2015/www/scanner.ngsummary.json +0 -1
- package/esm5/iotize-device-com-ble.cordova.js +0 -2
- package/esm5/public_api.js +0 -2
- package/esm5/www/ble-com-protocol.js +0 -121
- package/esm5/www/cordova-interface.js +0 -1
- package/esm5/www/definitions.js +0 -1
- package/esm5/www/index.js +0 -3
- package/esm5/www/logger.js +0 -3
- package/esm5/www/scanner.js +0 -111
- package/fesm5/iotize-device-com-ble.cordova.js +0 -233
- package/fesm5/iotize-device-com-ble.cordova.js.map +0 -1
- package/src/android/.project +0 -17
- package/src/android/.settings/org.eclipse.buildship.core.prefs +0 -13
- package/src/android/src/ArgsHelper.java +0 -30
- package/src/android/src/BLECom.java +0 -375
- package/src/public_api.ts +0 -1
- package/src/www/ble-com-protocol.spec.ts +0 -9
- package/src/www/ble-com-protocol.ts +0 -114
- package/src/www/cordova-interface.ts +0 -29
- package/src/www/definitions.ts +0 -11
- package/src/www/index.ts +0 -4
- package/src/www/logger.ts +0 -3
- package/src/www/scanner.spec.ts +0 -98
- package/src/www/scanner.ts +0 -132
- package/www/ble-com-protocol.d.ts +0 -16
- package/www/cordova-interface.d.ts +0 -11
- package/www/definitions.d.ts +0 -6
- package/www/index.d.ts +0 -4
- package/www/iotize-ble.js +0 -55
- package/www/logger.d.ts +0 -2
- package/www/scanner.d.ts +0 -18
|
@@ -1,50 +1,375 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@iotize/
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@iotize/device-com-ble.cordova', ['exports', '@iotize/
|
|
4
|
-
(global = global || self, factory((global.iotize = global.iotize || {}, global.iotize[
|
|
5
|
-
}(this, (function (exports,
|
|
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/debug'), require('@iotize/common/error'), 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/debug', '@iotize/common/error', '@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.debug$1, global.error, global.common, global.byteConverter, global.utility));
|
|
5
|
+
})(this, (function (exports, api, core, rxjs, operators, debug$1, error, common, byteConverter, utility) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var
|
|
7
|
+
/*! *****************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise */
|
|
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) {
|
|
23
189
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
24
|
-
if (!m)
|
|
190
|
+
if (!m)
|
|
191
|
+
return o;
|
|
25
192
|
var i = m.call(o), r, ar = [], e;
|
|
26
193
|
try {
|
|
27
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
194
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
195
|
+
ar.push(r.value);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
e = { error: error };
|
|
28
199
|
}
|
|
29
|
-
catch (error) { e = { error: error }; }
|
|
30
200
|
finally {
|
|
31
201
|
try {
|
|
32
|
-
if (r && !r.done && (m = i["return"]))
|
|
202
|
+
if (r && !r.done && (m = i["return"]))
|
|
203
|
+
m.call(i);
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
if (e)
|
|
207
|
+
throw e.error;
|
|
33
208
|
}
|
|
34
|
-
finally { if (e) throw e.error; }
|
|
35
209
|
}
|
|
36
210
|
return ar;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
211
|
+
}
|
|
212
|
+
function __spread() {
|
|
213
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
214
|
+
ar = ar.concat(__read(arguments[i]));
|
|
40
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
|
+
}
|
|
298
|
+
|
|
299
|
+
var debug = debug$1.createDebugger("@iotize/device-com-ble.cordova");
|
|
300
|
+
|
|
301
|
+
var CordovaBLEError = /** @class */ (function (_super) {
|
|
302
|
+
__extends(CordovaBLEError, _super);
|
|
303
|
+
function CordovaBLEError() {
|
|
304
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
305
|
+
}
|
|
306
|
+
CordovaBLEError.invalidErrorResult = function (errObject) {
|
|
307
|
+
return new CordovaBLEError("Internal error: ble cordova plugin returned an unexpected error object", CordovaBLEError.Code.InternalError);
|
|
308
|
+
};
|
|
309
|
+
CordovaBLEError.invalidErrorCode = function (errObject) {
|
|
310
|
+
return new CordovaBLEError("Internal error: ble cordova plugin returned an invalid error code " + errObject.code + " with message " + errObject.message, CordovaBLEError.Code.InternalError);
|
|
311
|
+
};
|
|
312
|
+
CordovaBLEError.invalidNativeCallResult = function (result, cause) {
|
|
313
|
+
return new CordovaBLEError("Internal error: native call returned an invalid data type. " + cause.message, CordovaBLEError.Code.InternalError);
|
|
314
|
+
};
|
|
315
|
+
CordovaBLEError.isValidErrorCode = function (code) {
|
|
316
|
+
return code in CordovaBLEError.Code;
|
|
317
|
+
};
|
|
318
|
+
CordovaBLEError.iotizeBLEMissing = function () {
|
|
319
|
+
return new CordovaBLEError("iotizeBLE global variable does not exist. Are you sure app is running inside a Cordova application ?", CordovaBLEError.Code.InternalError);
|
|
320
|
+
};
|
|
321
|
+
return CordovaBLEError;
|
|
322
|
+
}(error.CodeError));
|
|
323
|
+
/* istanbul ignore next */
|
|
324
|
+
(function (CordovaBLEError) {
|
|
325
|
+
var Code;
|
|
326
|
+
(function (Code) {
|
|
327
|
+
Code["InternalError"] = "CordovaBLEErrorInternalError";
|
|
328
|
+
Code["IllegalArgument"] = "CordovaBLEErrorIllegalArgument";
|
|
329
|
+
Code["BLENotAvailable"] = "CordovaBLEErrorBLENotAvailable";
|
|
330
|
+
Code["InvalidMacAddress"] = "InvalidMacAddressInvalidMacAddress";
|
|
331
|
+
Code["ConnectionError"] = "CordovaBLEErrorConnectionError";
|
|
332
|
+
Code["RequestError"] = "CordovaBLEErrorRequestError";
|
|
333
|
+
Code["LocationServiceDisabled"] = "CordovaBLEErrorLocationServiceDisabled";
|
|
334
|
+
Code["DisconnectError"] = "CordovaBLEErrorDisconnectError";
|
|
335
|
+
Code["IllegalAction"] = "CordovaBLEErrorIllegalAction";
|
|
336
|
+
Code["NotConnectedError"] = "CordovaBLEErrorNotConnectedError";
|
|
337
|
+
Code["StatusCodeError"] = "CordovaBLEErrorStatusCodeError";
|
|
338
|
+
})(Code = CordovaBLEError.Code || (CordovaBLEError.Code = {}));
|
|
339
|
+
})(CordovaBLEError || (CordovaBLEError = {}));
|
|
340
|
+
|
|
341
|
+
function getIoTizeBleCordovaPlugin() {
|
|
342
|
+
if (typeof iotizeBLE !== "object") {
|
|
343
|
+
throw CordovaBLEError.iotizeBLEMissing();
|
|
344
|
+
}
|
|
345
|
+
return iotizeBLE;
|
|
346
|
+
}
|
|
347
|
+
|
|
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
|
+
});
|
|
41
366
|
};
|
|
42
|
-
var BLEComProtocol = (function (_super) {
|
|
367
|
+
var BLEComProtocol = /** @class */ (function (_super) {
|
|
43
368
|
__extends(BLEComProtocol, _super);
|
|
44
|
-
function BLEComProtocol(deviceId, comProtocolOptions) {
|
|
369
|
+
function BLEComProtocol(deviceId, comProtocolOptions, cordovaInterfaceOverwrite) {
|
|
45
370
|
var _this = _super.call(this) || this;
|
|
46
|
-
_this.deviceId = "";
|
|
47
371
|
_this.deviceId = deviceId;
|
|
372
|
+
_this.cordovaInterfaceOverwrite = cordovaInterfaceOverwrite;
|
|
48
373
|
if (comProtocolOptions) {
|
|
49
374
|
_this.options = comProtocolOptions;
|
|
50
375
|
}
|
|
@@ -53,168 +378,607 @@
|
|
|
53
378
|
}
|
|
54
379
|
return _this;
|
|
55
380
|
}
|
|
56
|
-
Object.defineProperty(BLEComProtocol.prototype, "
|
|
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
|
+
*/
|
|
57
387
|
get: function () {
|
|
58
|
-
|
|
59
|
-
this._connectionStateSubject = new rxjs.Subject();
|
|
60
|
-
}
|
|
61
|
-
return this._connectionStateSubject;
|
|
388
|
+
return this.cordovaInterfaceOverwrite || getIoTizeBleCordovaPlugin();
|
|
62
389
|
},
|
|
63
|
-
enumerable:
|
|
390
|
+
enumerable: false,
|
|
64
391
|
configurable: true
|
|
65
392
|
});
|
|
66
393
|
BLEComProtocol.prototype._connect = function (options) {
|
|
67
394
|
var _this = this;
|
|
68
|
-
debug(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
var onError = function (error) {
|
|
76
|
-
debug('_connect observable: onError', error);
|
|
77
|
-
connectionStateSubject.error(error);
|
|
78
|
-
};
|
|
79
|
-
iotizeBLE.connect(this.deviceId, onConnectionStateChange, onError);
|
|
80
|
-
return connectionStateSubject.pipe(operators.filter(function (state) { return state === api.ConnectionState.CONNECTED; }), operators.first());
|
|
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());
|
|
81
401
|
};
|
|
82
402
|
BLEComProtocol.prototype._disconnect = function (options) {
|
|
83
|
-
|
|
84
|
-
|
|
403
|
+
var _this = this;
|
|
404
|
+
debug("_disconnect", options);
|
|
405
|
+
return rxjs.defer(function () { return _this.pluginInterface.disConnect(_this.deviceId); });
|
|
85
406
|
};
|
|
86
407
|
BLEComProtocol.prototype.write = function (data) {
|
|
87
|
-
|
|
408
|
+
return __awaiter$3(this, void 0, void 0, function () {
|
|
409
|
+
return __generator(this, function (_a) {
|
|
410
|
+
throw new Error("Method not implemented.");
|
|
411
|
+
});
|
|
412
|
+
});
|
|
88
413
|
};
|
|
89
414
|
BLEComProtocol.prototype.read = function () {
|
|
90
|
-
|
|
415
|
+
return __awaiter$3(this, void 0, void 0, function () {
|
|
416
|
+
return __generator(this, function (_a) {
|
|
417
|
+
throw new Error("Method not implemented.");
|
|
418
|
+
});
|
|
419
|
+
});
|
|
91
420
|
};
|
|
92
421
|
BLEComProtocol.prototype.send = function (data, options) {
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
return rxjs.from(promise);
|
|
422
|
+
var _this = this;
|
|
423
|
+
return rxjs.defer(function () { return _this.pluginInterface.send(_this.deviceId, data); });
|
|
96
424
|
};
|
|
97
|
-
BLEComProtocol
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
425
|
+
return BLEComProtocol;
|
|
426
|
+
}(core.QueueComProtocol));
|
|
427
|
+
|
|
428
|
+
var __awaiter$2 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
429
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
430
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
431
|
+
function fulfilled(value) { try {
|
|
432
|
+
step(generator.next(value));
|
|
101
433
|
}
|
|
102
|
-
|
|
103
|
-
|
|
434
|
+
catch (e) {
|
|
435
|
+
reject(e);
|
|
436
|
+
} }
|
|
437
|
+
function rejected(value) { try {
|
|
438
|
+
step(generator["throw"](value));
|
|
104
439
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
440
|
+
catch (e) {
|
|
441
|
+
reject(e);
|
|
442
|
+
} }
|
|
443
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
444
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
var CordovaPeripheralAdapter = /** @class */ (function () {
|
|
448
|
+
function CordovaPeripheralAdapter(deviceId, cordovaPlugin) {
|
|
449
|
+
if (cordovaPlugin === void 0) { cordovaPlugin = getIoTizeBleCordovaPlugin(); }
|
|
450
|
+
this.deviceId = deviceId;
|
|
451
|
+
this.cordovaPlugin = cordovaPlugin;
|
|
452
|
+
this._stateChange = new rxjs.BehaviorSubject(api.ConnectionState.DISCONNECTED);
|
|
453
|
+
}
|
|
454
|
+
Object.defineProperty(CordovaPeripheralAdapter.prototype, "stateChange", {
|
|
455
|
+
get: function () {
|
|
456
|
+
return this._stateChange.asObservable().pipe(operators.distinctUntilChanged());
|
|
457
|
+
},
|
|
458
|
+
enumerable: false,
|
|
459
|
+
configurable: true
|
|
460
|
+
});
|
|
461
|
+
Object.defineProperty(CordovaPeripheralAdapter.prototype, "name", {
|
|
462
|
+
get: function () {
|
|
463
|
+
// TODO device name ?
|
|
464
|
+
return this.id;
|
|
465
|
+
},
|
|
466
|
+
enumerable: false,
|
|
467
|
+
configurable: true
|
|
468
|
+
});
|
|
469
|
+
Object.defineProperty(CordovaPeripheralAdapter.prototype, "id", {
|
|
470
|
+
get: function () {
|
|
471
|
+
return this.deviceId;
|
|
472
|
+
},
|
|
473
|
+
enumerable: false,
|
|
474
|
+
configurable: true
|
|
475
|
+
});
|
|
476
|
+
Object.defineProperty(CordovaPeripheralAdapter.prototype, "state", {
|
|
477
|
+
get: function () {
|
|
478
|
+
return api.ConnectionState[this._stateChange.value];
|
|
479
|
+
},
|
|
480
|
+
enumerable: false,
|
|
481
|
+
configurable: true
|
|
482
|
+
});
|
|
483
|
+
CordovaPeripheralAdapter.prototype.discoverServices = function (serviceUUIDs) {
|
|
484
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
485
|
+
var _b, result, _loop_1, this_1, serviceUUIDs_1, serviceUUIDs_1_1, uuid, _c, _d, serviceDefinition;
|
|
486
|
+
var e_1, _e, e_2, _f;
|
|
487
|
+
return __generator(this, function (_g) {
|
|
488
|
+
switch (_g.label) {
|
|
489
|
+
case 0:
|
|
490
|
+
_b = this;
|
|
491
|
+
return [4 /*yield*/, this.cordovaPlugin.discoverServices(this.deviceId)];
|
|
492
|
+
case 1:
|
|
493
|
+
_b.serviceListCache = _g.sent();
|
|
494
|
+
result = {};
|
|
495
|
+
if (serviceUUIDs) {
|
|
496
|
+
_loop_1 = function (uuid) {
|
|
497
|
+
var servicDefinition = this_1.serviceListCache.find(function (def) { return def.uuid === uuid; });
|
|
498
|
+
if (servicDefinition) {
|
|
499
|
+
result[uuid] = new CordovaServiceAdapter(servicDefinition, this_1);
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
this_1 = this;
|
|
503
|
+
try {
|
|
504
|
+
for (serviceUUIDs_1 = __values(serviceUUIDs), serviceUUIDs_1_1 = serviceUUIDs_1.next(); !serviceUUIDs_1_1.done; serviceUUIDs_1_1 = serviceUUIDs_1.next()) {
|
|
505
|
+
uuid = serviceUUIDs_1_1.value;
|
|
506
|
+
_loop_1(uuid);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
510
|
+
finally {
|
|
511
|
+
try {
|
|
512
|
+
if (serviceUUIDs_1_1 && !serviceUUIDs_1_1.done && (_e = serviceUUIDs_1.return)) _e.call(serviceUUIDs_1);
|
|
513
|
+
}
|
|
514
|
+
finally { if (e_1) throw e_1.error; }
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
try {
|
|
519
|
+
for (_c = __values(this.serviceListCache), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
520
|
+
serviceDefinition = _d.value;
|
|
521
|
+
result[serviceDefinition.uuid] = new CordovaServiceAdapter(serviceDefinition, this);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
525
|
+
finally {
|
|
526
|
+
try {
|
|
527
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
528
|
+
}
|
|
529
|
+
finally { if (e_2) throw e_2.error; }
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return [2 /*return*/, result];
|
|
533
|
+
}
|
|
110
534
|
});
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
535
|
+
});
|
|
536
|
+
};
|
|
537
|
+
CordovaPeripheralAdapter.prototype.connect = function () {
|
|
538
|
+
var _a;
|
|
539
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
540
|
+
var connectObservable;
|
|
541
|
+
var _this = this;
|
|
542
|
+
return __generator(this, function (_b) {
|
|
543
|
+
switch (_b.label) {
|
|
544
|
+
case 0:
|
|
545
|
+
(_a = this.connectionStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
546
|
+
connectObservable = this.cordovaPlugin
|
|
547
|
+
.connect(this.deviceId)
|
|
548
|
+
.pipe(operators.shareReplay());
|
|
549
|
+
this.connectionStateSubscription = connectObservable.subscribe(function (state) {
|
|
550
|
+
_this._stateChange.next(state);
|
|
551
|
+
});
|
|
552
|
+
return [4 /*yield*/, connectObservable
|
|
553
|
+
.pipe(operators.filter(function (state) { return state === api.ConnectionState.CONNECTED; }), operators.first())
|
|
554
|
+
.toPromise()];
|
|
555
|
+
case 1:
|
|
556
|
+
_b.sent();
|
|
557
|
+
return [2 /*return*/];
|
|
558
|
+
}
|
|
114
559
|
});
|
|
115
|
-
cordovaFct.apply(iotizeBLE, args);
|
|
116
560
|
});
|
|
117
561
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
562
|
+
CordovaPeripheralAdapter.prototype.disconnect = function () {
|
|
563
|
+
var _a;
|
|
564
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
565
|
+
return __generator(this, function (_b) {
|
|
566
|
+
switch (_b.label) {
|
|
567
|
+
case 0: return [4 /*yield*/, this.cordovaPlugin.disConnect(this.deviceId)];
|
|
568
|
+
case 1:
|
|
569
|
+
_b.sent();
|
|
570
|
+
this._stateChange.next(api.ConnectionState.DISCONNECTED);
|
|
571
|
+
(_a = this.connectionStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
572
|
+
return [2 /*return*/];
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
};
|
|
577
|
+
CordovaPeripheralAdapter.prototype.close = function () {
|
|
578
|
+
var _a;
|
|
579
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
580
|
+
return __generator(this, function (_b) {
|
|
581
|
+
switch (_b.label) {
|
|
582
|
+
case 0: return [4 /*yield*/, this.cordovaPlugin.close(this.deviceId)];
|
|
583
|
+
case 1:
|
|
584
|
+
_b.sent();
|
|
585
|
+
this._stateChange.next(api.ConnectionState.DISCONNECTED);
|
|
586
|
+
(_a = this.connectionStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
587
|
+
return [2 /*return*/];
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
CordovaPeripheralAdapter.prototype.getService = function (uuid) {
|
|
593
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
594
|
+
var serviceDefinition;
|
|
595
|
+
return __generator(this, function (_b) {
|
|
596
|
+
switch (_b.label) {
|
|
597
|
+
case 0:
|
|
598
|
+
if (!!this.serviceListCache) return [3 /*break*/, 2];
|
|
599
|
+
return [4 /*yield*/, this.discoverServices([uuid])];
|
|
600
|
+
case 1:
|
|
601
|
+
_b.sent();
|
|
602
|
+
_b.label = 2;
|
|
603
|
+
case 2:
|
|
604
|
+
serviceDefinition = this.serviceListCache.find(function (s) { return s.uuid === uuid; });
|
|
605
|
+
if (!serviceDefinition) {
|
|
606
|
+
throw common.BleComError.serviceNotFound(uuid);
|
|
607
|
+
}
|
|
608
|
+
return [2 /*return*/, new CordovaServiceAdapter(serviceDefinition, this)];
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
};
|
|
613
|
+
return CordovaPeripheralAdapter;
|
|
614
|
+
}());
|
|
615
|
+
var CordovaServiceAdapter = /** @class */ (function () {
|
|
616
|
+
function CordovaServiceAdapter(config, peripheral) {
|
|
617
|
+
this.config = config;
|
|
618
|
+
this.peripheral = peripheral;
|
|
619
|
+
}
|
|
620
|
+
Object.defineProperty(CordovaServiceAdapter.prototype, "uuid", {
|
|
621
|
+
get: function () {
|
|
622
|
+
return this.config.uuid;
|
|
623
|
+
},
|
|
624
|
+
enumerable: false,
|
|
625
|
+
configurable: true
|
|
626
|
+
});
|
|
627
|
+
CordovaServiceAdapter.prototype.getCharacteristic = function (charcUUID) {
|
|
628
|
+
var _a;
|
|
629
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
630
|
+
var characteristicDescription;
|
|
631
|
+
return __generator(this, function (_b) {
|
|
632
|
+
characteristicDescription = (_a = this.config.characteristics) === null || _a === void 0 ? void 0 : _a.find(function (c) { return c.uuid === charcUUID; });
|
|
633
|
+
if (!characteristicDescription) {
|
|
634
|
+
throw common.BleComError.charcacteristicNotFound(charcUUID);
|
|
635
|
+
}
|
|
636
|
+
return [2 /*return*/, new CordovaCharacteristicAdapter(this, characteristicDescription)];
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
};
|
|
640
|
+
CordovaServiceAdapter.prototype.getCharacteristics = function () {
|
|
641
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
642
|
+
var _this = this;
|
|
643
|
+
return __generator(this, function (_b) {
|
|
644
|
+
if (!this.config.characteristics) {
|
|
645
|
+
return [2 /*return*/, []];
|
|
646
|
+
}
|
|
647
|
+
return [2 /*return*/, this.config.characteristics.map(function (c) { return new CordovaCharacteristicAdapter(_this, c); })];
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
};
|
|
651
|
+
return CordovaServiceAdapter;
|
|
652
|
+
}());
|
|
653
|
+
var CordovaCharacteristicAdapter = /** @class */ (function () {
|
|
654
|
+
function CordovaCharacteristicAdapter(service, config) {
|
|
655
|
+
this.service = service;
|
|
656
|
+
this.config = config;
|
|
657
|
+
}
|
|
658
|
+
Object.defineProperty(CordovaCharacteristicAdapter.prototype, "uuid", {
|
|
659
|
+
get: function () {
|
|
660
|
+
return this.config.uuid;
|
|
661
|
+
},
|
|
662
|
+
enumerable: false,
|
|
663
|
+
configurable: true
|
|
664
|
+
});
|
|
665
|
+
Object.defineProperty(CordovaCharacteristicAdapter.prototype, "properties", {
|
|
666
|
+
get: function () {
|
|
667
|
+
return this.config.properties;
|
|
668
|
+
},
|
|
669
|
+
enumerable: false,
|
|
670
|
+
configurable: true
|
|
671
|
+
});
|
|
672
|
+
Object.defineProperty(CordovaCharacteristicAdapter.prototype, "data", {
|
|
673
|
+
get: function () {
|
|
674
|
+
return this.setupDataStreamIfRequired().pipe(operators.map(function (data) { return ({
|
|
675
|
+
data: data,
|
|
676
|
+
isNotification: true,
|
|
677
|
+
}); }));
|
|
678
|
+
},
|
|
679
|
+
enumerable: false,
|
|
680
|
+
configurable: true
|
|
681
|
+
});
|
|
682
|
+
Object.defineProperty(CordovaCharacteristicAdapter.prototype, "deviceId", {
|
|
683
|
+
get: function () {
|
|
684
|
+
return this.service.peripheral.deviceId;
|
|
685
|
+
},
|
|
686
|
+
enumerable: false,
|
|
687
|
+
configurable: true
|
|
688
|
+
});
|
|
689
|
+
Object.defineProperty(CordovaCharacteristicAdapter.prototype, "pluginInterface", {
|
|
690
|
+
get: function () {
|
|
691
|
+
return this.service.peripheral.cordovaPlugin;
|
|
692
|
+
},
|
|
693
|
+
enumerable: false,
|
|
694
|
+
configurable: true
|
|
695
|
+
});
|
|
696
|
+
CordovaCharacteristicAdapter.prototype.read = function () {
|
|
697
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
698
|
+
return __generator(this, function (_b) {
|
|
699
|
+
return [2 /*return*/, this.pluginInterface.characteristicReadValue(this.deviceId, this.service.uuid, this.uuid)];
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
};
|
|
703
|
+
CordovaCharacteristicAdapter.prototype.getDescriptor = function () {
|
|
704
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
705
|
+
return __generator(this, function (_b) {
|
|
706
|
+
throw new Error("Not implemented yet");
|
|
707
|
+
});
|
|
708
|
+
});
|
|
709
|
+
};
|
|
710
|
+
CordovaCharacteristicAdapter.prototype.getDescriptors = function () {
|
|
711
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
712
|
+
var _this = this;
|
|
713
|
+
return __generator(this, function (_b) {
|
|
714
|
+
if (!this.config.descriptors) {
|
|
715
|
+
return [2 /*return*/, []];
|
|
716
|
+
}
|
|
717
|
+
return [2 /*return*/, this.config.descriptors.map(function (descriptor) { return new CordovaDescriptorAdapter(descriptor, _this); })];
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
};
|
|
721
|
+
CordovaCharacteristicAdapter.prototype.write = function (data, writeWithoutResponse) {
|
|
722
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
723
|
+
return __generator(this, function (_b) {
|
|
724
|
+
switch (_b.label) {
|
|
725
|
+
case 0:
|
|
726
|
+
if (!writeWithoutResponse) return [3 /*break*/, 2];
|
|
727
|
+
return [4 /*yield*/, this.pluginInterface.characteristicWriteWithoutResponse(this.deviceId, this.service.uuid, this.uuid, data)];
|
|
728
|
+
case 1:
|
|
729
|
+
_b.sent();
|
|
730
|
+
return [3 /*break*/, 4];
|
|
731
|
+
case 2: return [4 /*yield*/, this.pluginInterface.characteristicWrite(this.deviceId, this.service.uuid, this.uuid, data)];
|
|
732
|
+
case 3:
|
|
733
|
+
_b.sent();
|
|
734
|
+
_b.label = 4;
|
|
735
|
+
case 4: return [2 /*return*/, data];
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
});
|
|
739
|
+
};
|
|
740
|
+
CordovaCharacteristicAdapter.prototype.enableNotifications = function (enabled) {
|
|
741
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
742
|
+
return __generator(this, function (_b) {
|
|
743
|
+
switch (_b.label) {
|
|
744
|
+
case 0:
|
|
745
|
+
if (!enabled) return [3 /*break*/, 2];
|
|
746
|
+
this.setupDataStreamIfRequired();
|
|
747
|
+
return [4 /*yield*/, this.pluginInterface.characteristicStartNotification(this.deviceId, this.service.uuid, this.uuid)];
|
|
748
|
+
case 1:
|
|
749
|
+
_b.sent();
|
|
750
|
+
return [3 /*break*/, 4];
|
|
751
|
+
case 2: return [4 /*yield*/, this.pluginInterface.characteristicStopNotification(this.deviceId, this.service.uuid, this.uuid)];
|
|
752
|
+
case 3:
|
|
753
|
+
_b.sent();
|
|
754
|
+
_b.label = 4;
|
|
755
|
+
case 4: return [2 /*return*/];
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
};
|
|
760
|
+
CordovaCharacteristicAdapter.prototype.setupDataStreamIfRequired = function () {
|
|
761
|
+
if (!this._dataStream) {
|
|
762
|
+
this._dataStream = this.pluginInterface.characteristicChanged(this.deviceId, this.service.uuid, this.uuid);
|
|
763
|
+
}
|
|
764
|
+
return this._dataStream;
|
|
765
|
+
};
|
|
766
|
+
return CordovaCharacteristicAdapter;
|
|
767
|
+
}());
|
|
768
|
+
var CordovaDescriptorAdapter = /** @class */ (function () {
|
|
769
|
+
function CordovaDescriptorAdapter(config, characteristic) {
|
|
770
|
+
this.config = config;
|
|
771
|
+
this.characteristic = characteristic;
|
|
772
|
+
}
|
|
773
|
+
Object.defineProperty(CordovaDescriptorAdapter.prototype, "uuid", {
|
|
774
|
+
get: function () {
|
|
775
|
+
return this.config.uuid;
|
|
776
|
+
},
|
|
777
|
+
enumerable: false,
|
|
778
|
+
configurable: true
|
|
779
|
+
});
|
|
780
|
+
CordovaDescriptorAdapter.prototype.readValue = function () {
|
|
781
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
782
|
+
return __generator(this, function (_b) {
|
|
783
|
+
throw new Error("Reading descriptor value is not implemented yet");
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
};
|
|
787
|
+
CordovaDescriptorAdapter.prototype.writeValue = function (data) {
|
|
788
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
789
|
+
return __generator(this, function (_b) {
|
|
790
|
+
throw new Error("Writing descriptor value is not implemented yet");
|
|
791
|
+
});
|
|
792
|
+
});
|
|
793
|
+
};
|
|
794
|
+
return CordovaDescriptorAdapter;
|
|
795
|
+
}());
|
|
121
796
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
797
|
+
//
|
|
798
|
+
// Copyright 2018 IoTize SAS Inc. Licensed under the MIT license.
|
|
799
|
+
//
|
|
800
|
+
// scanner.ts
|
|
801
|
+
// device-com-ble.cordova BLE Cordova Plugin
|
|
802
|
+
//
|
|
803
|
+
var __awaiter$1 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
804
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
805
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
806
|
+
function fulfilled(value) { try {
|
|
807
|
+
step(generator.next(value));
|
|
808
|
+
}
|
|
809
|
+
catch (e) {
|
|
810
|
+
reject(e);
|
|
811
|
+
} }
|
|
812
|
+
function rejected(value) { try {
|
|
813
|
+
step(generator["throw"](value));
|
|
814
|
+
}
|
|
815
|
+
catch (e) {
|
|
816
|
+
reject(e);
|
|
817
|
+
} }
|
|
818
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
819
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
820
|
+
});
|
|
821
|
+
};
|
|
822
|
+
/**
|
|
823
|
+
* BLE Tap scanner for cordova apps
|
|
824
|
+
*/
|
|
825
|
+
var BLEScanner = /** @class */ (function () {
|
|
826
|
+
/**
|
|
827
|
+
*
|
|
828
|
+
* @param cordovaInterfaceOverwrite overwrite cordova interface. Used for testing
|
|
829
|
+
*/
|
|
830
|
+
function BLEScanner(cordovaInterfaceOverwrite,
|
|
831
|
+
/**
|
|
832
|
+
* Request device options used to filter scan results
|
|
833
|
+
*/
|
|
834
|
+
requestDeviceOptions) {
|
|
835
|
+
this.cordovaInterfaceOverwrite = cordovaInterfaceOverwrite;
|
|
836
|
+
this.requestDeviceOptions = requestDeviceOptions;
|
|
126
837
|
this._results = new rxjs.BehaviorSubject([]);
|
|
127
838
|
this._scanning$ = new rxjs.BehaviorSubject(false);
|
|
128
839
|
}
|
|
840
|
+
Object.defineProperty(BLEScanner.prototype, "cordovaInterface", {
|
|
841
|
+
/**
|
|
842
|
+
* Lazy reference to iotizeBLE.
|
|
843
|
+
* We don't want to reference iotizeBLE in constructor as it may be referenced
|
|
844
|
+
* before cordova plugin is loaded
|
|
845
|
+
*/
|
|
846
|
+
get: function () {
|
|
847
|
+
return this.cordovaInterfaceOverwrite || getIoTizeBleCordovaPlugin();
|
|
848
|
+
},
|
|
849
|
+
enumerable: false,
|
|
850
|
+
configurable: true
|
|
851
|
+
});
|
|
129
852
|
Object.defineProperty(BLEScanner.prototype, "scanning", {
|
|
130
853
|
get: function () {
|
|
131
854
|
return this._scanning$.asObservable();
|
|
132
855
|
},
|
|
133
|
-
enumerable:
|
|
856
|
+
enumerable: false,
|
|
134
857
|
configurable: true
|
|
135
858
|
});
|
|
136
859
|
Object.defineProperty(BLEScanner.prototype, "isScanning", {
|
|
137
860
|
get: function () {
|
|
138
861
|
return this._scanning$.value;
|
|
139
862
|
},
|
|
140
|
-
enumerable:
|
|
863
|
+
enumerable: false,
|
|
141
864
|
configurable: true
|
|
142
865
|
});
|
|
143
866
|
Object.defineProperty(BLEScanner.prototype, "results", {
|
|
867
|
+
/**
|
|
868
|
+
* Gets the observable on the devices$ Subject
|
|
869
|
+
* @return
|
|
870
|
+
*/
|
|
144
871
|
get: function () {
|
|
145
872
|
return this._results.asObservable();
|
|
146
873
|
},
|
|
147
|
-
enumerable:
|
|
874
|
+
enumerable: false,
|
|
148
875
|
configurable: true
|
|
149
876
|
});
|
|
877
|
+
/**
|
|
878
|
+
* Launches the scan for BLE devices
|
|
879
|
+
* Throws if BLE is not available
|
|
880
|
+
*/
|
|
150
881
|
BLEScanner.prototype.start = function (options) {
|
|
151
|
-
var
|
|
152
|
-
return this
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
882
|
+
var _a;
|
|
883
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
884
|
+
var isAvailable;
|
|
885
|
+
var _this = this;
|
|
886
|
+
return __generator(this, function (_b) {
|
|
887
|
+
switch (_b.label) {
|
|
888
|
+
case 0:
|
|
889
|
+
(_a = this.scanSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
890
|
+
this.scanSubscription = undefined;
|
|
891
|
+
this.clearResults();
|
|
892
|
+
return [4 /*yield*/, this.checkAvailable()];
|
|
893
|
+
case 1:
|
|
894
|
+
isAvailable = _b.sent();
|
|
895
|
+
if (!isAvailable) {
|
|
896
|
+
throw common.BleComError.bleNotAvailable("BLE is not available. Make sure that BLE is enabled on your device");
|
|
897
|
+
}
|
|
898
|
+
debug("Start Scanning ...");
|
|
899
|
+
this._scanning$.next(true);
|
|
900
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
901
|
+
_this.scanSubscription = _this.cordovaInterface
|
|
902
|
+
.startScan(_this.requestDeviceOptions)
|
|
903
|
+
.subscribe(function (result) {
|
|
904
|
+
if (result == "Ok") {
|
|
905
|
+
resolve();
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
_this.addOrRefreshDevice(result);
|
|
909
|
+
}, function (error) {
|
|
910
|
+
debug("Start scan failed with error: ", error);
|
|
911
|
+
_this.cordovaInterface
|
|
912
|
+
.getLastError()
|
|
913
|
+
.then(function (lasterror) {
|
|
914
|
+
debug("Last BLE error " + lasterror);
|
|
915
|
+
})
|
|
916
|
+
.catch(function (err) {
|
|
917
|
+
debug("Cannot get last BLE error: ", err);
|
|
918
|
+
});
|
|
919
|
+
reject(error);
|
|
920
|
+
_this._scanning$.next(false);
|
|
921
|
+
});
|
|
922
|
+
})];
|
|
923
|
+
}
|
|
176
924
|
});
|
|
177
925
|
});
|
|
178
926
|
};
|
|
927
|
+
/**
|
|
928
|
+
*
|
|
929
|
+
*/
|
|
179
930
|
BLEScanner.prototype.stop = function () {
|
|
180
|
-
var
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
931
|
+
var _a;
|
|
932
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
933
|
+
var err_1;
|
|
934
|
+
return __generator(this, function (_b) {
|
|
935
|
+
switch (_b.label) {
|
|
936
|
+
case 0:
|
|
937
|
+
debug("Stop Scanning ...");
|
|
938
|
+
_b.label = 1;
|
|
939
|
+
case 1:
|
|
940
|
+
_b.trys.push([1, 3, , 4]);
|
|
941
|
+
(_a = this.scanSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
942
|
+
this.scanSubscription = undefined;
|
|
943
|
+
return [4 /*yield*/, this.cordovaInterface.stopScan()];
|
|
944
|
+
case 2:
|
|
945
|
+
_b.sent();
|
|
946
|
+
this._scanning$.next(false);
|
|
947
|
+
return [2 /*return*/];
|
|
948
|
+
case 3:
|
|
949
|
+
err_1 = _b.sent();
|
|
950
|
+
this._scanning$.next(false);
|
|
951
|
+
throw err_1;
|
|
952
|
+
case 4: return [2 /*return*/];
|
|
953
|
+
}
|
|
190
954
|
});
|
|
191
955
|
});
|
|
192
956
|
};
|
|
957
|
+
/**
|
|
958
|
+
* Returns true if this scanner is available
|
|
959
|
+
*/
|
|
193
960
|
BLEScanner.prototype.checkAvailable = function () {
|
|
194
|
-
|
|
195
|
-
return new Promise(function (resolve, reject) {
|
|
196
|
-
_this.cordovaInterface.checkAvailable(function (result) {
|
|
197
|
-
debug('checkAvailable result', result);
|
|
198
|
-
resolve(result);
|
|
199
|
-
}, function (error) {
|
|
200
|
-
reject(error);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
961
|
+
return this.cordovaInterface.checkAvailable();
|
|
203
962
|
};
|
|
204
963
|
Object.defineProperty(BLEScanner.prototype, "devices", {
|
|
205
964
|
get: function () {
|
|
206
965
|
return this._results.value;
|
|
207
966
|
},
|
|
208
|
-
enumerable:
|
|
967
|
+
enumerable: false,
|
|
209
968
|
configurable: true
|
|
210
969
|
});
|
|
970
|
+
BLEScanner.prototype.clearResults = function () {
|
|
971
|
+
this._results.next([]);
|
|
972
|
+
};
|
|
211
973
|
BLEScanner.prototype.addOrRefreshDevice = function (newDevice) {
|
|
212
974
|
var storedDeviceIndex = this.devices.findIndex(function (entry) { return entry.address == newDevice.address; });
|
|
213
975
|
if (storedDeviceIndex >= 0) {
|
|
214
976
|
var storedDevice = this.devices[storedDeviceIndex];
|
|
215
|
-
if (storedDevice.name != newDevice.name ||
|
|
977
|
+
if (storedDevice.name != newDevice.name ||
|
|
978
|
+
storedDevice.rssi != newDevice.rssi) {
|
|
216
979
|
debug("Updating device at index " + storedDeviceIndex + ", name=" + storedDevice.name + " with rssi=" + storedDevice.rssi);
|
|
217
980
|
this.devices[storedDeviceIndex] = newDevice;
|
|
981
|
+
// this.devices = [...this.devices];
|
|
218
982
|
this._results.next(this.devices);
|
|
219
983
|
}
|
|
220
984
|
}
|
|
@@ -227,10 +991,230 @@
|
|
|
227
991
|
return BLEScanner;
|
|
228
992
|
}());
|
|
229
993
|
|
|
994
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
995
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
996
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
997
|
+
function fulfilled(value) { try {
|
|
998
|
+
step(generator.next(value));
|
|
999
|
+
}
|
|
1000
|
+
catch (e) {
|
|
1001
|
+
reject(e);
|
|
1002
|
+
} }
|
|
1003
|
+
function rejected(value) { try {
|
|
1004
|
+
step(generator["throw"](value));
|
|
1005
|
+
}
|
|
1006
|
+
catch (e) {
|
|
1007
|
+
reject(e);
|
|
1008
|
+
} }
|
|
1009
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1010
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1011
|
+
});
|
|
1012
|
+
};
|
|
1013
|
+
function hexStringToBuffer(str) {
|
|
1014
|
+
try {
|
|
1015
|
+
return byteConverter.hexStringToBuffer(str);
|
|
1016
|
+
}
|
|
1017
|
+
catch (err) {
|
|
1018
|
+
throw CordovaBLEError.invalidNativeCallResult(str, err);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
var IoTizeBleCordovaPlugin = /** @class */ (function () {
|
|
1022
|
+
function IoTizeBleCordovaPlugin() {
|
|
1023
|
+
}
|
|
1024
|
+
IoTizeBleCordovaPlugin.prototype.checkAvailable = function () {
|
|
1025
|
+
return this.execSingleResult("checkAvailable", []);
|
|
1026
|
+
};
|
|
1027
|
+
IoTizeBleCordovaPlugin.prototype.requestEnableBle = function () {
|
|
1028
|
+
return this.execSingleResult("enable", []);
|
|
1029
|
+
};
|
|
1030
|
+
IoTizeBleCordovaPlugin.prototype.startScan = function (requestDeviceOptions) {
|
|
1031
|
+
return this.execMultipleResult("startScan", [
|
|
1032
|
+
JSON.stringify(requestDeviceOptions),
|
|
1033
|
+
]);
|
|
1034
|
+
};
|
|
1035
|
+
IoTizeBleCordovaPlugin.prototype.stopScan = function () {
|
|
1036
|
+
return this.execSingleResult("stopScan", []);
|
|
1037
|
+
};
|
|
1038
|
+
IoTizeBleCordovaPlugin.prototype.connect = function (deviceId, enableBleIfNot) {
|
|
1039
|
+
var _this = this;
|
|
1040
|
+
if (enableBleIfNot === void 0) { enableBleIfNot = true; }
|
|
1041
|
+
return this.askBleEnable(enableBleIfNot).pipe(operators.switchMap(function () {
|
|
1042
|
+
return _this.execMultipleResult("connect", [deviceId]).pipe(operators.map(function (state) {
|
|
1043
|
+
if (!(state in api.ConnectionState)) {
|
|
1044
|
+
console.warn("Plugin native code returned an invalid connection state: \"" + state + "\".");
|
|
1045
|
+
}
|
|
1046
|
+
return utility.safeEnumValue(api.ConnectionState, state);
|
|
1047
|
+
}));
|
|
1048
|
+
}));
|
|
1049
|
+
};
|
|
1050
|
+
IoTizeBleCordovaPlugin.prototype.askBleEnable = function (askEnable) {
|
|
1051
|
+
var _this = this;
|
|
1052
|
+
return rxjs.defer(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1053
|
+
return __generator(this, function (_a) {
|
|
1054
|
+
switch (_a.label) {
|
|
1055
|
+
case 0:
|
|
1056
|
+
if (!askEnable) return [3 /*break*/, 3];
|
|
1057
|
+
return [4 /*yield*/, this.checkAvailable()];
|
|
1058
|
+
case 1:
|
|
1059
|
+
if (!!(_a.sent())) return [3 /*break*/, 3];
|
|
1060
|
+
return [4 /*yield*/, this.requestEnableBle()];
|
|
1061
|
+
case 2:
|
|
1062
|
+
_a.sent();
|
|
1063
|
+
_a.label = 3;
|
|
1064
|
+
case 3: return [2 /*return*/];
|
|
1065
|
+
}
|
|
1066
|
+
});
|
|
1067
|
+
}); });
|
|
1068
|
+
};
|
|
1069
|
+
IoTizeBleCordovaPlugin.prototype.requestMTU = function (deviceId, mtu) {
|
|
1070
|
+
return this.execSingleResult("requestMTU", [deviceId, mtu]);
|
|
1071
|
+
};
|
|
1072
|
+
IoTizeBleCordovaPlugin.prototype.connectAndDiscoverTapServices = function (deviceId, enableBleIfNot) {
|
|
1073
|
+
var _this = this;
|
|
1074
|
+
if (enableBleIfNot === void 0) { enableBleIfNot = true; }
|
|
1075
|
+
return this.askBleEnable(enableBleIfNot).pipe(operators.switchMap(function () {
|
|
1076
|
+
return _this.execMultipleResult("connectAndDiscoverTapServices", [deviceId]).pipe(operators.map(function (state) {
|
|
1077
|
+
if (!(state in api.ConnectionState)) {
|
|
1078
|
+
console.warn("Plugin native code returned an invalid connection state: \"" + state + "\".");
|
|
1079
|
+
}
|
|
1080
|
+
return utility.safeEnumValue(api.ConnectionState, state);
|
|
1081
|
+
}));
|
|
1082
|
+
}));
|
|
1083
|
+
};
|
|
1084
|
+
IoTizeBleCordovaPlugin.prototype.disConnect = function (deviceId) {
|
|
1085
|
+
return this.execSingleResult("disConnect", [deviceId]);
|
|
1086
|
+
};
|
|
1087
|
+
IoTizeBleCordovaPlugin.prototype.close = function (deviceId) {
|
|
1088
|
+
return this.execSingleResult("close", [deviceId]);
|
|
1089
|
+
};
|
|
1090
|
+
IoTizeBleCordovaPlugin.prototype.isConnected = function (deviceId) {
|
|
1091
|
+
return this.execSingleResult("isConnected", [deviceId]);
|
|
1092
|
+
};
|
|
1093
|
+
IoTizeBleCordovaPlugin.prototype.send = function (deviceId, data) {
|
|
1094
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1095
|
+
var hexString;
|
|
1096
|
+
return __generator(this, function (_a) {
|
|
1097
|
+
switch (_a.label) {
|
|
1098
|
+
case 0: return [4 /*yield*/, this.execSingleResult("sendRequest", [
|
|
1099
|
+
deviceId,
|
|
1100
|
+
byteConverter.bufferToHexString(data),
|
|
1101
|
+
])];
|
|
1102
|
+
case 1:
|
|
1103
|
+
hexString = _a.sent();
|
|
1104
|
+
return [2 /*return*/, hexStringToBuffer(hexString)];
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
});
|
|
1108
|
+
};
|
|
1109
|
+
IoTizeBleCordovaPlugin.prototype.getLastError = function () {
|
|
1110
|
+
return this.execSingleResult("getLastError", []);
|
|
1111
|
+
};
|
|
1112
|
+
IoTizeBleCordovaPlugin.prototype.characteristicStartNotification = function (deviceId, serviceId, characId) {
|
|
1113
|
+
return this.execSingleResult("characteristicStartNotification", [
|
|
1114
|
+
deviceId,
|
|
1115
|
+
serviceId,
|
|
1116
|
+
characId,
|
|
1117
|
+
]);
|
|
1118
|
+
};
|
|
1119
|
+
IoTizeBleCordovaPlugin.prototype.characteristicChanged = function (deviceId, serviceId, characId) {
|
|
1120
|
+
return this.execMultipleResult("characteristicChanged", [
|
|
1121
|
+
deviceId,
|
|
1122
|
+
serviceId,
|
|
1123
|
+
characId,
|
|
1124
|
+
]).pipe(operators.map(function (hexString) {
|
|
1125
|
+
return hexStringToBuffer(hexString);
|
|
1126
|
+
}));
|
|
1127
|
+
};
|
|
1128
|
+
IoTizeBleCordovaPlugin.prototype.characteristicStopNotification = function (deviceId, serviceId, characId) {
|
|
1129
|
+
return this.execSingleResult("characteristicStopNotification", [
|
|
1130
|
+
deviceId,
|
|
1131
|
+
serviceId,
|
|
1132
|
+
characId,
|
|
1133
|
+
]);
|
|
1134
|
+
};
|
|
1135
|
+
IoTizeBleCordovaPlugin.prototype.characteristicReadValue = function (deviceId, serviceId, characId) {
|
|
1136
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1137
|
+
var hexString;
|
|
1138
|
+
return __generator(this, function (_a) {
|
|
1139
|
+
switch (_a.label) {
|
|
1140
|
+
case 0: return [4 /*yield*/, this.execSingleResult("characteristicRead", [deviceId, serviceId, characId])];
|
|
1141
|
+
case 1:
|
|
1142
|
+
hexString = _a.sent();
|
|
1143
|
+
return [2 /*return*/, hexStringToBuffer(hexString)];
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
});
|
|
1147
|
+
};
|
|
1148
|
+
IoTizeBleCordovaPlugin.prototype.characteristicWrite = function (deviceId, serviceId, characId, data) {
|
|
1149
|
+
return this.execSingleResult("characteristicWrite", [
|
|
1150
|
+
deviceId,
|
|
1151
|
+
serviceId,
|
|
1152
|
+
characId,
|
|
1153
|
+
byteConverter.bufferToHexString(data),
|
|
1154
|
+
]);
|
|
1155
|
+
};
|
|
1156
|
+
IoTizeBleCordovaPlugin.prototype.characteristicWriteWithoutResponse = function (deviceId, serviceId, characId, data) {
|
|
1157
|
+
return this.execSingleResult("characteristicWriteWithoutResponse", [
|
|
1158
|
+
deviceId,
|
|
1159
|
+
serviceId,
|
|
1160
|
+
characId,
|
|
1161
|
+
byteConverter.bufferToHexString(data),
|
|
1162
|
+
]);
|
|
1163
|
+
};
|
|
1164
|
+
IoTizeBleCordovaPlugin.prototype.discoverServices = function (deviceId) {
|
|
1165
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1166
|
+
var services;
|
|
1167
|
+
return __generator(this, function (_a) {
|
|
1168
|
+
switch (_a.label) {
|
|
1169
|
+
case 0: return [4 /*yield*/, this.execSingleResult("discoverServices", [deviceId])];
|
|
1170
|
+
case 1:
|
|
1171
|
+
services = _a.sent();
|
|
1172
|
+
return [2 /*return*/, services];
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
});
|
|
1176
|
+
};
|
|
1177
|
+
IoTizeBleCordovaPlugin.prototype.execSingleResult = function (methodName, args) {
|
|
1178
|
+
return new Promise(function (resolve, reject) {
|
|
1179
|
+
cordova.exec(resolve, function (errObject) {
|
|
1180
|
+
reject(objectErrorToError(errObject));
|
|
1181
|
+
}, "BLECom", methodName, args);
|
|
1182
|
+
});
|
|
1183
|
+
};
|
|
1184
|
+
IoTizeBleCordovaPlugin.prototype.execMultipleResult = function (methodName, args) {
|
|
1185
|
+
var subject = new rxjs.Subject();
|
|
1186
|
+
cordova.exec(function (data) {
|
|
1187
|
+
subject.next(data);
|
|
1188
|
+
}, function (err) {
|
|
1189
|
+
subject.error(objectErrorToError(err));
|
|
1190
|
+
}, "BLECom", methodName, args);
|
|
1191
|
+
return subject.asObservable();
|
|
1192
|
+
};
|
|
1193
|
+
return IoTizeBleCordovaPlugin;
|
|
1194
|
+
}());
|
|
1195
|
+
function objectErrorToError(errObject) {
|
|
1196
|
+
if (typeof errObject !== "object" || !errObject.code || !errObject.message) {
|
|
1197
|
+
return CordovaBLEError.invalidErrorResult(errObject);
|
|
1198
|
+
}
|
|
1199
|
+
if (!CordovaBLEError.isValidErrorCode(errObject.code)) {
|
|
1200
|
+
return CordovaBLEError.invalidErrorCode(errObject);
|
|
1201
|
+
}
|
|
1202
|
+
return new CordovaBLEError(errObject.message, CordovaBLEError.Code[errObject.code]);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* Generated bundle index. Do not edit.
|
|
1207
|
+
*/
|
|
1208
|
+
|
|
230
1209
|
exports.BLEComProtocol = BLEComProtocol;
|
|
231
1210
|
exports.BLEScanner = BLEScanner;
|
|
1211
|
+
exports.CordovaCharacteristicAdapter = CordovaCharacteristicAdapter;
|
|
1212
|
+
exports.CordovaPeripheralAdapter = CordovaPeripheralAdapter;
|
|
1213
|
+
exports.CordovaServiceAdapter = CordovaServiceAdapter;
|
|
1214
|
+
exports.getIoTizeBleCordovaPlugin = getIoTizeBleCordovaPlugin;
|
|
1215
|
+
exports["ɵc"] = IoTizeBleCordovaPlugin;
|
|
232
1216
|
|
|
233
1217
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
234
1218
|
|
|
235
|
-
}))
|
|
1219
|
+
}));
|
|
236
1220
|
//# sourceMappingURL=iotize-device-com-ble.cordova.umd.js.map
|