react-native-ble-manager 8.8.0 → 9.0.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 +93 -44
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.4/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.4/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/7.4/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/.name +1 -0
- package/android/.idea/compiler.xml +6 -0
- package/android/.idea/gradle.xml +18 -0
- package/android/.idea/jarRepositories.xml +40 -0
- package/android/.idea/misc.xml +10 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +17 -17
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +3 -1
- package/android/gradlew +234 -0
- package/android/gradlew.bat +89 -0
- package/android/local.properties +8 -0
- package/android/src/main/java/it/innove/BleManager.java +18 -17
- package/android/src/main/java/it/innove/LegacyScanManager.java +33 -28
- package/android/src/main/java/it/innove/LollipopPeripheral.java +66 -65
- package/android/src/main/java/it/innove/LollipopScanManager.java +52 -25
- package/android/src/main/java/it/innove/Peripheral.java +889 -837
- package/android/src/main/java/it/innove/ScanManager.java +24 -23
- package/dist/cjs/index.d.ts +147 -0
- package/dist/cjs/index.js +487 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types.d.ts +311 -0
- package/dist/cjs/types.js +110 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/index.d.ts +147 -0
- package/dist/esm/index.js +471 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.d.ts +311 -0
- package/dist/esm/types.js +107 -0
- package/dist/esm/types.js.map +1 -0
- package/ios/BleManager.m +87 -110
- package/ios/BleManager.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/package.json +31 -4
- package/src/index.ts +569 -0
- package/src/types.ts +336 -0
- package/.github/FUNDING.yml +0 -3
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/BleManager.js +0 -427
- package/index.d.ts +0 -294
package/BleManager.js
DELETED
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var React = require("react-native");
|
|
3
|
-
var bleManager = React.NativeModules.BleManager;
|
|
4
|
-
|
|
5
|
-
class BleManager {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.isPeripheralConnected = this.isPeripheralConnected.bind(this);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
read(peripheralId, serviceUUID, characteristicUUID) {
|
|
11
|
-
return new Promise((fulfill, reject) => {
|
|
12
|
-
bleManager.read(
|
|
13
|
-
peripheralId,
|
|
14
|
-
serviceUUID,
|
|
15
|
-
characteristicUUID,
|
|
16
|
-
(error, data) => {
|
|
17
|
-
if (error) {
|
|
18
|
-
reject(error);
|
|
19
|
-
} else {
|
|
20
|
-
fulfill(data);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
readRSSI(peripheralId) {
|
|
28
|
-
return new Promise((fulfill, reject) => {
|
|
29
|
-
bleManager.readRSSI(peripheralId, (error, rssi) => {
|
|
30
|
-
if (error) {
|
|
31
|
-
reject(error);
|
|
32
|
-
} else {
|
|
33
|
-
fulfill(rssi);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
refreshCache(peripheralId) {
|
|
40
|
-
return new Promise((fulfill, reject) => {
|
|
41
|
-
bleManager.refreshCache(peripheralId, (error, result) => {
|
|
42
|
-
if (error) {
|
|
43
|
-
reject(error);
|
|
44
|
-
} else {
|
|
45
|
-
fulfill(result);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
retrieveServices(peripheralId, services) {
|
|
52
|
-
return new Promise((fulfill, reject) => {
|
|
53
|
-
bleManager.retrieveServices(
|
|
54
|
-
peripheralId,
|
|
55
|
-
services,
|
|
56
|
-
(error, peripheral) => {
|
|
57
|
-
if (error) {
|
|
58
|
-
reject(error);
|
|
59
|
-
} else {
|
|
60
|
-
fulfill(peripheral);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
write(peripheralId, serviceUUID, characteristicUUID, data, maxByteSize) {
|
|
68
|
-
if (maxByteSize == null) {
|
|
69
|
-
maxByteSize = 20;
|
|
70
|
-
}
|
|
71
|
-
return new Promise((fulfill, reject) => {
|
|
72
|
-
bleManager.write(
|
|
73
|
-
peripheralId,
|
|
74
|
-
serviceUUID,
|
|
75
|
-
characteristicUUID,
|
|
76
|
-
data,
|
|
77
|
-
maxByteSize,
|
|
78
|
-
error => {
|
|
79
|
-
if (error) {
|
|
80
|
-
reject(error);
|
|
81
|
-
} else {
|
|
82
|
-
fulfill();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
writeWithoutResponse(
|
|
90
|
-
peripheralId,
|
|
91
|
-
serviceUUID,
|
|
92
|
-
characteristicUUID,
|
|
93
|
-
data,
|
|
94
|
-
maxByteSize,
|
|
95
|
-
queueSleepTime
|
|
96
|
-
) {
|
|
97
|
-
if (maxByteSize == null) {
|
|
98
|
-
maxByteSize = 20;
|
|
99
|
-
}
|
|
100
|
-
if (queueSleepTime == null) {
|
|
101
|
-
queueSleepTime = 10;
|
|
102
|
-
}
|
|
103
|
-
return new Promise((fulfill, reject) => {
|
|
104
|
-
bleManager.writeWithoutResponse(
|
|
105
|
-
peripheralId,
|
|
106
|
-
serviceUUID,
|
|
107
|
-
characteristicUUID,
|
|
108
|
-
data,
|
|
109
|
-
maxByteSize,
|
|
110
|
-
queueSleepTime,
|
|
111
|
-
error => {
|
|
112
|
-
if (error) {
|
|
113
|
-
reject(error);
|
|
114
|
-
} else {
|
|
115
|
-
fulfill();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
connect(peripheralId) {
|
|
123
|
-
return new Promise((fulfill, reject) => {
|
|
124
|
-
bleManager.connect(peripheralId, error => {
|
|
125
|
-
if (error) {
|
|
126
|
-
reject(error);
|
|
127
|
-
} else {
|
|
128
|
-
fulfill();
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
createBond(peripheralId,peripheralPin=null) {
|
|
135
|
-
return new Promise((fulfill, reject) => {
|
|
136
|
-
bleManager.createBond(peripheralId,peripheralPin, error => {
|
|
137
|
-
if (error) {
|
|
138
|
-
reject(error);
|
|
139
|
-
} else {
|
|
140
|
-
fulfill();
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
removeBond(peripheralId) {
|
|
147
|
-
return new Promise((fulfill, reject) => {
|
|
148
|
-
bleManager.removeBond(peripheralId, error => {
|
|
149
|
-
if (error) {
|
|
150
|
-
reject(error);
|
|
151
|
-
} else {
|
|
152
|
-
fulfill();
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
disconnect(peripheralId, force = true) {
|
|
159
|
-
return new Promise((fulfill, reject) => {
|
|
160
|
-
bleManager.disconnect(peripheralId, force, error => {
|
|
161
|
-
if (error) {
|
|
162
|
-
reject(error);
|
|
163
|
-
} else {
|
|
164
|
-
fulfill();
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
startNotification(peripheralId, serviceUUID, characteristicUUID) {
|
|
171
|
-
return new Promise((fulfill, reject) => {
|
|
172
|
-
bleManager.startNotification(
|
|
173
|
-
peripheralId,
|
|
174
|
-
serviceUUID,
|
|
175
|
-
characteristicUUID,
|
|
176
|
-
error => {
|
|
177
|
-
if (error) {
|
|
178
|
-
reject(error);
|
|
179
|
-
} else {
|
|
180
|
-
fulfill();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
);
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
startNotificationUseBuffer(
|
|
188
|
-
peripheralId,
|
|
189
|
-
serviceUUID,
|
|
190
|
-
characteristicUUID,
|
|
191
|
-
buffer
|
|
192
|
-
) {
|
|
193
|
-
return new Promise((fulfill, reject) => {
|
|
194
|
-
bleManager.startNotificationUseBuffer(
|
|
195
|
-
peripheralId,
|
|
196
|
-
serviceUUID,
|
|
197
|
-
characteristicUUID,
|
|
198
|
-
buffer,
|
|
199
|
-
error => {
|
|
200
|
-
if (error) {
|
|
201
|
-
reject(error);
|
|
202
|
-
} else {
|
|
203
|
-
fulfill();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
stopNotification(peripheralId, serviceUUID, characteristicUUID) {
|
|
211
|
-
return new Promise((fulfill, reject) => {
|
|
212
|
-
bleManager.stopNotification(
|
|
213
|
-
peripheralId,
|
|
214
|
-
serviceUUID,
|
|
215
|
-
characteristicUUID,
|
|
216
|
-
error => {
|
|
217
|
-
if (error) {
|
|
218
|
-
reject(error);
|
|
219
|
-
} else {
|
|
220
|
-
fulfill();
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
);
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
checkState() {
|
|
228
|
-
bleManager.checkState();
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
start(options) {
|
|
232
|
-
return new Promise((fulfill, reject) => {
|
|
233
|
-
if (options == null) {
|
|
234
|
-
options = {};
|
|
235
|
-
}
|
|
236
|
-
bleManager.start(options, error => {
|
|
237
|
-
if (error) {
|
|
238
|
-
reject(error);
|
|
239
|
-
} else {
|
|
240
|
-
fulfill();
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
scan(serviceUUIDs, seconds, allowDuplicates, scanningOptions = {}) {
|
|
247
|
-
return new Promise((fulfill, reject) => {
|
|
248
|
-
if (allowDuplicates == null) {
|
|
249
|
-
allowDuplicates = false;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// (ANDROID) Match as many advertisement per filter as hw could allow
|
|
253
|
-
// depends on current capability and availability of the resources in hw.
|
|
254
|
-
if (scanningOptions.numberOfMatches == null) {
|
|
255
|
-
scanningOptions.numberOfMatches = 3;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// (ANDROID) Defaults to MATCH_MODE_AGGRESSIVE
|
|
259
|
-
if (scanningOptions.matchMode == null) {
|
|
260
|
-
scanningOptions.matchMode = 1;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// (ANDROID) Defaults to SCAN_MODE_LOW_POWER
|
|
264
|
-
if (scanningOptions.scanMode == null) {
|
|
265
|
-
scanningOptions.scanMode = 0;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// (ANDROID) Defaults to CALLBACK_TYPE_ALL_MATCHES
|
|
269
|
-
// WARN: sometimes, setting a scanSetting instead of leaving it untouched might result in unexpected behaviors.
|
|
270
|
-
// https://github.com/dariuszseweryn/RxAndroidBle/issues/462
|
|
271
|
-
if (scanningOptions.callbackType == null) {
|
|
272
|
-
scanningOptions.callbackType = 1;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// (ANDROID) Defaults to 0ms (report results immediately).
|
|
276
|
-
if (scanningOptions.reportDelay == null) {
|
|
277
|
-
scanningOptions.reportDelay = 0;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
bleManager.scan(
|
|
281
|
-
serviceUUIDs,
|
|
282
|
-
seconds,
|
|
283
|
-
allowDuplicates,
|
|
284
|
-
scanningOptions,
|
|
285
|
-
error => {
|
|
286
|
-
if (error) {
|
|
287
|
-
reject(error);
|
|
288
|
-
} else {
|
|
289
|
-
fulfill();
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
);
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
stopScan() {
|
|
297
|
-
return new Promise((fulfill, reject) => {
|
|
298
|
-
bleManager.stopScan(error => {
|
|
299
|
-
if (error != null) {
|
|
300
|
-
reject(error);
|
|
301
|
-
} else {
|
|
302
|
-
fulfill();
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
enableBluetooth() {
|
|
309
|
-
return new Promise((fulfill, reject) => {
|
|
310
|
-
bleManager.enableBluetooth(error => {
|
|
311
|
-
if (error != null) {
|
|
312
|
-
reject(error);
|
|
313
|
-
} else {
|
|
314
|
-
fulfill();
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
getConnectedPeripherals(serviceUUIDs) {
|
|
321
|
-
return new Promise((fulfill, reject) => {
|
|
322
|
-
bleManager.getConnectedPeripherals(serviceUUIDs, (error, result) => {
|
|
323
|
-
if (error) {
|
|
324
|
-
reject(error);
|
|
325
|
-
} else {
|
|
326
|
-
if (result != null) {
|
|
327
|
-
fulfill(result);
|
|
328
|
-
} else {
|
|
329
|
-
fulfill([]);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
getBondedPeripherals() {
|
|
337
|
-
return new Promise((fulfill, reject) => {
|
|
338
|
-
bleManager.getBondedPeripherals((error, result) => {
|
|
339
|
-
if (error) {
|
|
340
|
-
reject(error);
|
|
341
|
-
} else {
|
|
342
|
-
if (result != null) {
|
|
343
|
-
fulfill(result);
|
|
344
|
-
} else {
|
|
345
|
-
fulfill([]);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
getDiscoveredPeripherals() {
|
|
353
|
-
return new Promise((fulfill, reject) => {
|
|
354
|
-
bleManager.getDiscoveredPeripherals((error, result) => {
|
|
355
|
-
if (error) {
|
|
356
|
-
reject(error);
|
|
357
|
-
} else {
|
|
358
|
-
if (result != null) {
|
|
359
|
-
fulfill(result);
|
|
360
|
-
} else {
|
|
361
|
-
fulfill([]);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
removePeripheral(peripheralId) {
|
|
369
|
-
return new Promise((fulfill, reject) => {
|
|
370
|
-
bleManager.removePeripheral(peripheralId, error => {
|
|
371
|
-
if (error) {
|
|
372
|
-
reject(error);
|
|
373
|
-
} else {
|
|
374
|
-
fulfill();
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
isPeripheralConnected(peripheralId, serviceUUIDs) {
|
|
381
|
-
return this.getConnectedPeripherals(serviceUUIDs).then(result => {
|
|
382
|
-
if (
|
|
383
|
-
result.find(p => {
|
|
384
|
-
return p.id === peripheralId;
|
|
385
|
-
})
|
|
386
|
-
) {
|
|
387
|
-
return true;
|
|
388
|
-
} else {
|
|
389
|
-
return false;
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
requestConnectionPriority(peripheralId, connectionPriority) {
|
|
395
|
-
return new Promise((fulfill, reject) => {
|
|
396
|
-
bleManager.requestConnectionPriority(
|
|
397
|
-
peripheralId,
|
|
398
|
-
connectionPriority,
|
|
399
|
-
(error, status) => {
|
|
400
|
-
if (error) {
|
|
401
|
-
reject(error);
|
|
402
|
-
} else {
|
|
403
|
-
fulfill(status);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
);
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
requestMTU(peripheralId, mtu) {
|
|
411
|
-
return new Promise((fulfill, reject) => {
|
|
412
|
-
bleManager.requestMTU(peripheralId, mtu, (error, mtu) => {
|
|
413
|
-
if (error) {
|
|
414
|
-
reject(error);
|
|
415
|
-
} else {
|
|
416
|
-
fulfill(mtu);
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
setName(name) {
|
|
423
|
-
bleManager.setName(name);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
module.exports = new BleManager();
|
package/index.d.ts
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
declare module "react-native-ble-manager" {
|
|
2
|
-
|
|
3
|
-
// android states: https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#EXTRA_STATE
|
|
4
|
-
// ios states: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerstate
|
|
5
|
-
export enum BleState {
|
|
6
|
-
Unknown = 'unknown', // [iOS only]
|
|
7
|
-
Resetting = 'resetting', // [iOS only]
|
|
8
|
-
Unsupported = 'unsupported',
|
|
9
|
-
Unauthorized = 'unauthorized', // [iOS only]
|
|
10
|
-
On = 'on',
|
|
11
|
-
Off = 'off',
|
|
12
|
-
TurningOn = 'turning_on', // [android only]
|
|
13
|
-
TurningOff = 'turning_off', // [android only]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface Peripheral {
|
|
17
|
-
id: string;
|
|
18
|
-
rssi: number;
|
|
19
|
-
name?: string;
|
|
20
|
-
advertising: AdvertisingData;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface AdvertisingData {
|
|
24
|
-
isConnectable?: boolean;
|
|
25
|
-
localName?: string;
|
|
26
|
-
manufacturerData?: CustomAdvertisingData,
|
|
27
|
-
serviceData?: CustomAdvertisingData,
|
|
28
|
-
serviceUUIDs?: string[];
|
|
29
|
-
txPowerLevel?: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface CustomAdvertisingData {
|
|
33
|
-
CDVType : 'ArrayBuffer',
|
|
34
|
-
bytes: Uint8Array,
|
|
35
|
-
data: string // base64-encoded string of the data
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface StartOptions {
|
|
39
|
-
showAlert?: boolean; // [iOS only]
|
|
40
|
-
restoreIdentifierKey?: string; // [iOS only]
|
|
41
|
-
queueIdentifierKey?: string; // [iOS only]
|
|
42
|
-
forceLegacy?: boolean; // [android only]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function start(options?: StartOptions): Promise<void>;
|
|
46
|
-
|
|
47
|
-
// [android only]
|
|
48
|
-
// https://developer.android.com/reference/android/bluetooth/le/ScanSettings
|
|
49
|
-
export interface ScanOptions {
|
|
50
|
-
numberOfMatches?: BleScanMatchCount;
|
|
51
|
-
matchMode?: BleScanMatchMode;
|
|
52
|
-
callbackType?: BleScanCallbackType;
|
|
53
|
-
scanMode?: BleScanMode;
|
|
54
|
-
reportDelay?: number;
|
|
55
|
-
phy?: BleScanPhyMode;
|
|
56
|
-
legacy?: boolean;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// [android only]
|
|
60
|
-
export enum BleScanMode {
|
|
61
|
-
Opportunistic = -1,
|
|
62
|
-
LowPower = 0,
|
|
63
|
-
Balanced = 1,
|
|
64
|
-
LowLatency = 2,
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// [android only]
|
|
68
|
-
export enum BleScanMatchMode {
|
|
69
|
-
Aggressive = 1,
|
|
70
|
-
Sticky = 2,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// [android only]
|
|
74
|
-
export enum BleScanCallbackType {
|
|
75
|
-
AllMatches = 1,
|
|
76
|
-
FirstMatch = 2,
|
|
77
|
-
MatchLost = 4,
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// [android only]
|
|
81
|
-
export enum BleScanMatchCount {
|
|
82
|
-
OneAdvertisement = 1,
|
|
83
|
-
FewAdvertisements = 2,
|
|
84
|
-
MaxAdvertisements = 3,
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// [android only]
|
|
88
|
-
export enum BleScanPhyMode {
|
|
89
|
-
LE_1M = 1,
|
|
90
|
-
LE_2M = 2,
|
|
91
|
-
LE_CODED = 3,
|
|
92
|
-
ALL_SUPPORTED = 255,
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function scan(
|
|
96
|
-
serviceUUIDs: string[],
|
|
97
|
-
seconds: number,
|
|
98
|
-
allowDuplicates?: boolean,
|
|
99
|
-
options?: ScanOptions
|
|
100
|
-
): Promise<void>;
|
|
101
|
-
export function stopScan(): Promise<void>;
|
|
102
|
-
export function connect(peripheralID: string): Promise<void>;
|
|
103
|
-
export function disconnect(
|
|
104
|
-
peripheralID: string,
|
|
105
|
-
force?: boolean
|
|
106
|
-
): Promise<void>;
|
|
107
|
-
|
|
108
|
-
export function checkState(): void;
|
|
109
|
-
|
|
110
|
-
export function startNotification(
|
|
111
|
-
peripheralID: string,
|
|
112
|
-
serviceUUID: string,
|
|
113
|
-
characteristicUUID: string
|
|
114
|
-
): Promise<void>;
|
|
115
|
-
|
|
116
|
-
// [android only]
|
|
117
|
-
export function startNotificationUseBuffer(
|
|
118
|
-
peripheralID: string,
|
|
119
|
-
serviceUUID: string,
|
|
120
|
-
characteristicUUID: string,
|
|
121
|
-
buffer: number
|
|
122
|
-
): Promise<void>;
|
|
123
|
-
|
|
124
|
-
export function stopNotification(
|
|
125
|
-
peripheralID: string,
|
|
126
|
-
serviceUUID: string,
|
|
127
|
-
characteristicUUID: string
|
|
128
|
-
): Promise<void>;
|
|
129
|
-
|
|
130
|
-
export function read(
|
|
131
|
-
peripheralID: string,
|
|
132
|
-
serviceUUID: string,
|
|
133
|
-
characteristicUUID: string
|
|
134
|
-
): Promise<any>;
|
|
135
|
-
|
|
136
|
-
export function write(
|
|
137
|
-
peripheralID: string,
|
|
138
|
-
serviceUUID: string,
|
|
139
|
-
characteristicUUID: string,
|
|
140
|
-
data: any,
|
|
141
|
-
maxByteSize?: number
|
|
142
|
-
): Promise<void>;
|
|
143
|
-
|
|
144
|
-
export function writeWithoutResponse(
|
|
145
|
-
peripheralID: string,
|
|
146
|
-
serviceUUID: string,
|
|
147
|
-
characteristicUUID: string,
|
|
148
|
-
data: any,
|
|
149
|
-
maxByteSize?: number,
|
|
150
|
-
queueSleepTime?: number
|
|
151
|
-
): Promise<void>;
|
|
152
|
-
|
|
153
|
-
export function readRSSI(peripheralID: string): Promise<number>;
|
|
154
|
-
|
|
155
|
-
export function getConnectedPeripherals(
|
|
156
|
-
serviceUUIDs: string[]
|
|
157
|
-
): Promise<Peripheral[]>;
|
|
158
|
-
|
|
159
|
-
export function getDiscoveredPeripherals(): Promise<Peripheral[]>;
|
|
160
|
-
|
|
161
|
-
export function isPeripheralConnected(
|
|
162
|
-
peripheralID: string,
|
|
163
|
-
serviceUUIDs: string[]
|
|
164
|
-
): Promise<boolean>;
|
|
165
|
-
|
|
166
|
-
// [Android only API 21+]
|
|
167
|
-
export enum ConnectionPriority {
|
|
168
|
-
balanced = 0,
|
|
169
|
-
high = 1,
|
|
170
|
-
low = 2,
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// [Android only 21+]
|
|
174
|
-
export function requestConnectionPriority(
|
|
175
|
-
peripheralID: string,
|
|
176
|
-
connectionPriority: ConnectionPriority
|
|
177
|
-
): Promise<boolean>;
|
|
178
|
-
|
|
179
|
-
// [Android only]
|
|
180
|
-
export function enableBluetooth(): Promise<void>;
|
|
181
|
-
|
|
182
|
-
// [Android only]
|
|
183
|
-
export function refreshCache(peripheralID: string): Promise<void>;
|
|
184
|
-
|
|
185
|
-
// [Android only API 21+]
|
|
186
|
-
export function requestMTU(peripheralID: string, mtu: number): Promise<number>;
|
|
187
|
-
|
|
188
|
-
export function createBond(
|
|
189
|
-
peripheralID: string,
|
|
190
|
-
peripheralPin?: string
|
|
191
|
-
): Promise<void>;
|
|
192
|
-
|
|
193
|
-
export function removeBond(peripheralID: string): Promise<void>;
|
|
194
|
-
|
|
195
|
-
export function getBondedPeripherals(): Promise<Peripheral[]>;
|
|
196
|
-
|
|
197
|
-
export function removePeripheral(peripheralID: string): Promise<void>;
|
|
198
|
-
|
|
199
|
-
// [Android only]
|
|
200
|
-
export function setName(name: string): void;
|
|
201
|
-
|
|
202
|
-
export interface Service {
|
|
203
|
-
uuid: string;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export interface Descriptor {
|
|
207
|
-
value: string;
|
|
208
|
-
uuid: string;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export interface Characteristic {
|
|
212
|
-
// See https://developer.apple.com/documentation/corebluetooth/cbcharacteristicproperties
|
|
213
|
-
properties: {
|
|
214
|
-
Broadcast?: "Broadcast";
|
|
215
|
-
Read?: "Read";
|
|
216
|
-
WriteWithoutResponse?: "WriteWithoutResponse";
|
|
217
|
-
Write?: "Write";
|
|
218
|
-
Notify?: "Notify";
|
|
219
|
-
Indicate?: "Indicate";
|
|
220
|
-
AuthenticatedSignedWrites?: "AuthenticatedSignedWrites";
|
|
221
|
-
ExtendedProperties?: "ExtendedProperties";
|
|
222
|
-
NotifyEncryptionRequired?: "NotifyEncryptionRequired";
|
|
223
|
-
IndicateEncryptionRequired?: "IndicateEncryptionRequired";
|
|
224
|
-
}
|
|
225
|
-
characteristic: string;
|
|
226
|
-
service: string;
|
|
227
|
-
descriptors?: Descriptor[];
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export interface PeripheralInfo extends Peripheral {
|
|
232
|
-
serviceUUIDs?: string[];
|
|
233
|
-
characteristics?: Characteristic[];
|
|
234
|
-
services?: Service[];
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export function retrieveServices(
|
|
238
|
-
peripheralID: string,
|
|
239
|
-
serviceUUIDs?: string[]
|
|
240
|
-
): Promise<PeripheralInfo>;
|
|
241
|
-
|
|
242
|
-
export enum BleEventType {
|
|
243
|
-
BleManagerDidUpdateState = 'BleManagerDidUpdateState',
|
|
244
|
-
BleManagerStopScan = 'BleManagerStopScan',
|
|
245
|
-
BleManagerDiscoverPeripheral = 'BleManagerDiscoverPeripheral',
|
|
246
|
-
BleManagerDidUpdateValueForCharacteristic = 'BleManagerDidUpdateValueForCharacteristic',
|
|
247
|
-
BleManagerConnectPeripheral = 'BleManagerConnectPeripheral',
|
|
248
|
-
BleManagerDisconnectPeripheral = 'BleManagerDisconnectPeripheral',
|
|
249
|
-
BleManagerPeripheralDidBond = 'BleManagerPeripheralDidBond', // [Android only]
|
|
250
|
-
BleManagerCentralManagerWillRestoreState = 'BleManagerCentralManagerWillRestoreState', // [iOS only]
|
|
251
|
-
BleManagerDidUpdateNotificationStateFor = 'BleManagerDidUpdateNotificationStateFor', // [iOS only]
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export interface BleStopScanEvent {
|
|
255
|
-
status?: number; // [iOS only]
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export interface BleManagerDidUpdateStateEvent {
|
|
259
|
-
state: BleState;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export interface BleConnectPeripheralEvent {
|
|
263
|
-
readonly peripheral: string; // peripheral id
|
|
264
|
-
readonly status?: number; // [android only]
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export type BleDiscoverPeripheralEvent = Peripheral;
|
|
268
|
-
|
|
269
|
-
// [Android only]
|
|
270
|
-
export type BleBondedPeripheralEvent = Peripheral;
|
|
271
|
-
|
|
272
|
-
export interface BleDisconnectPeripheralEvent {
|
|
273
|
-
readonly peripheral: string; // peripheral id
|
|
274
|
-
readonly status?: number; // [android only] disconnect reason.
|
|
275
|
-
readonly domain?: string; // [iOS only] disconnect error domain.
|
|
276
|
-
readonly code?: number; // [iOS only] disconnect error code.
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export interface BleManagerDidUpdateValueForCharacteristicEvent {
|
|
280
|
-
readonly characteristic: string; // characteristic UUID
|
|
281
|
-
readonly peripheral: string; // peripheral id
|
|
282
|
-
readonly service: string; // service UUID
|
|
283
|
-
readonly value: Uint8Array;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// [iOS only]
|
|
287
|
-
export interface BleManagerDidUpdateNotificationStateForEvent {
|
|
288
|
-
readonly peripheral: string; // peripheral id
|
|
289
|
-
readonly characteristic: string; // characteristic UUID
|
|
290
|
-
readonly isNotifying: boolean; // is the characteristic notifying or not
|
|
291
|
-
readonly domain: string; // error domain.
|
|
292
|
-
readonly code: number; // error code.
|
|
293
|
-
}
|
|
294
|
-
}
|