@onekeyfe/hd-transport-react-native 0.1.13 → 0.1.17
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/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -31
- package/package.json +4 -4
- package/src/index.ts +36 -40
package/dist/index.d.ts
CHANGED
|
@@ -16,8 +16,9 @@ declare class ReactNativeBleTransport {
|
|
|
16
16
|
stopped: boolean;
|
|
17
17
|
scanTimeout: number;
|
|
18
18
|
runPromise: Deferred<any> | null;
|
|
19
|
+
Log?: any;
|
|
19
20
|
constructor(options: TransportOptions);
|
|
20
|
-
init(): void;
|
|
21
|
+
init(logger: any): void;
|
|
21
22
|
configure(signedData: any): void;
|
|
22
23
|
listen(): void;
|
|
23
24
|
getPlxManager(): Promise<BleManager>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,IAAI,aAAa,EAC3B,MAAM,EAEN,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAiC,MAAM,wBAAwB,CAAC;AACvE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,IAAI,aAAa,EAC3B,MAAM,EAEN,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAiC,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAkB,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAa1F,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAmBjE,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,SAAS,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,UAAU,UAAS;IAEnB,OAAO,UAAS;IAEhB,WAAW,SAAQ;IAEnB,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAExC,GAAG,CAAC,EAAE,GAAG,CAAC;gBAEE,OAAO,EAAE,gBAAgB;IAIrC,IAAI,CAAC,MAAM,EAAE,GAAG;IAIhB,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAIN,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAYjC,SAAS;IAsET,OAAO,CAAC,KAAK,EAAE,eAAe;;;IA+JpC,sBAAsB,CAAC,cAAc,EAAE,cAAc;IA4D/C,OAAO,CAAC,IAAI,EAAE,MAAM;IAcpB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IA+EpE,IAAI;IAIJ,MAAM;CAOP"}
|
package/dist/index.js
CHANGED
|
@@ -166,7 +166,6 @@ class BleTransport {
|
|
|
166
166
|
|
|
167
167
|
const { check, buildBuffers, receiveOne, parseConfigure } = transport__default["default"];
|
|
168
168
|
const transportCache = {};
|
|
169
|
-
const Log = hdShared.initLog('@onekey/hd-ble-sdk');
|
|
170
169
|
let connectOptions = {
|
|
171
170
|
requestMTU: 512,
|
|
172
171
|
timeout: 3000,
|
|
@@ -188,9 +187,10 @@ class ReactNativeBleTransport {
|
|
|
188
187
|
this.scanTimeout = 3000;
|
|
189
188
|
this.runPromise = null;
|
|
190
189
|
this.scanTimeout = (_a = options.scanTimeout) !== null && _a !== void 0 ? _a : 3000;
|
|
191
|
-
hdShared.enableLog(true);
|
|
192
190
|
}
|
|
193
|
-
init() {
|
|
191
|
+
init(logger) {
|
|
192
|
+
this.Log = logger;
|
|
193
|
+
}
|
|
194
194
|
configure(signedData) {
|
|
195
195
|
const messages = parseConfigure(signedData);
|
|
196
196
|
this.configured = true;
|
|
@@ -214,7 +214,7 @@ class ReactNativeBleTransport {
|
|
|
214
214
|
yield subscribeBleOn(blePlxManager);
|
|
215
215
|
}
|
|
216
216
|
catch (error) {
|
|
217
|
-
Log.debug('subscribeBleOn error: ', error);
|
|
217
|
+
this.Log.debug('subscribeBleOn error: ', error);
|
|
218
218
|
reject(error);
|
|
219
219
|
return;
|
|
220
220
|
}
|
|
@@ -223,8 +223,8 @@ class ReactNativeBleTransport {
|
|
|
223
223
|
}, (error, device) => {
|
|
224
224
|
var _a, _b;
|
|
225
225
|
if (error) {
|
|
226
|
-
Log.debug('ble scan manager: ', blePlxManager);
|
|
227
|
-
Log.debug('ble scan error: ', error);
|
|
226
|
+
this.Log.debug('ble scan manager: ', blePlxManager);
|
|
227
|
+
this.Log.debug('ble scan error: ', error);
|
|
228
228
|
if ([reactNativeBlePlx.BleErrorCode.BluetoothPoweredOff, reactNativeBlePlx.BleErrorCode.BluetoothInUnknownState].includes(error.errorCode)) {
|
|
229
229
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));
|
|
230
230
|
}
|
|
@@ -237,16 +237,16 @@ class ReactNativeBleTransport {
|
|
|
237
237
|
return;
|
|
238
238
|
}
|
|
239
239
|
if (isOnekeyDevice((_b = device === null || device === void 0 ? void 0 : device.name) !== null && _b !== void 0 ? _b : null, device === null || device === void 0 ? void 0 : device.id)) {
|
|
240
|
-
Log.debug('search device start ======================');
|
|
240
|
+
this.Log.debug('search device start ======================');
|
|
241
241
|
const { name, localName, id } = device !== null && device !== void 0 ? device : {};
|
|
242
|
-
Log.debug(`device name: ${name !== null && name !== void 0 ? name : ''}\nlocalName: ${localName !== null && localName !== void 0 ? localName : ''}\nid: ${id !== null && id !== void 0 ? id : ''}`);
|
|
242
|
+
this.Log.debug(`device name: ${name !== null && name !== void 0 ? name : ''}\nlocalName: ${localName !== null && localName !== void 0 ? localName : ''}\nid: ${id !== null && id !== void 0 ? id : ''}`);
|
|
243
243
|
addDevice(device);
|
|
244
|
-
Log.debug('search device end ======================\n');
|
|
244
|
+
this.Log.debug('search device end ======================\n');
|
|
245
245
|
}
|
|
246
246
|
});
|
|
247
247
|
getConnectedDeviceIds(getBluetoothServiceUuids()).then(devices => {
|
|
248
248
|
for (const device of devices) {
|
|
249
|
-
Log.debug('search connected peripheral: ', device.id);
|
|
249
|
+
this.Log.debug('search connected peripheral: ', device.id);
|
|
250
250
|
addDevice(device);
|
|
251
251
|
}
|
|
252
252
|
});
|
|
@@ -271,7 +271,7 @@ class ReactNativeBleTransport {
|
|
|
271
271
|
}
|
|
272
272
|
let device = null;
|
|
273
273
|
if (transportCache[uuid]) {
|
|
274
|
-
Log.debug('transport not be released, will release: ', uuid);
|
|
274
|
+
this.Log.debug('transport not be released, will release: ', uuid);
|
|
275
275
|
yield this.release(uuid);
|
|
276
276
|
}
|
|
277
277
|
const blePlxManager = yield this.getPlxManager();
|
|
@@ -279,7 +279,7 @@ class ReactNativeBleTransport {
|
|
|
279
279
|
yield subscribeBleOn(blePlxManager);
|
|
280
280
|
}
|
|
281
281
|
catch (error) {
|
|
282
|
-
Log.debug('subscribeBleOn error: ', error);
|
|
282
|
+
this.Log.debug('subscribeBleOn error: ', error);
|
|
283
283
|
throw error;
|
|
284
284
|
}
|
|
285
285
|
if (!device) {
|
|
@@ -289,16 +289,16 @@ class ReactNativeBleTransport {
|
|
|
289
289
|
if (!device) {
|
|
290
290
|
const connectedDevice = yield blePlxManager.connectedDevices(getBluetoothServiceUuids());
|
|
291
291
|
const deviceFilter = connectedDevice.filter(device => device.id === uuid);
|
|
292
|
-
Log.debug(`found connected device count: ${deviceFilter.length}`);
|
|
292
|
+
this.Log.debug(`found connected device count: ${deviceFilter.length}`);
|
|
293
293
|
[device] = deviceFilter;
|
|
294
294
|
}
|
|
295
295
|
if (!device) {
|
|
296
|
-
Log.debug('try to connect to device: ', uuid);
|
|
296
|
+
this.Log.debug('try to connect to device: ', uuid);
|
|
297
297
|
try {
|
|
298
298
|
device = yield blePlxManager.connectToDevice(uuid, connectOptions);
|
|
299
299
|
}
|
|
300
300
|
catch (e) {
|
|
301
|
-
Log.debug('try to connect to device has error: ', e);
|
|
301
|
+
this.Log.debug('try to connect to device has error: ', e);
|
|
302
302
|
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
|
|
303
303
|
e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
|
|
304
304
|
connectOptions = {};
|
|
@@ -313,12 +313,12 @@ class ReactNativeBleTransport {
|
|
|
313
313
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, 'unable to connect to device');
|
|
314
314
|
}
|
|
315
315
|
if (!(yield device.isConnected())) {
|
|
316
|
-
Log.debug('not connected, try to connect to device: ', uuid);
|
|
316
|
+
this.Log.debug('not connected, try to connect to device: ', uuid);
|
|
317
317
|
try {
|
|
318
318
|
yield device.connect(connectOptions);
|
|
319
319
|
}
|
|
320
320
|
catch (e) {
|
|
321
|
-
Log.debug('try to connect to device has error: ', e);
|
|
321
|
+
this.Log.debug('try to connect to device has error: ', e);
|
|
322
322
|
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
|
|
323
323
|
e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
|
|
324
324
|
connectOptions = {};
|
|
@@ -347,7 +347,7 @@ class ReactNativeBleTransport {
|
|
|
347
347
|
break;
|
|
348
348
|
}
|
|
349
349
|
catch (e) {
|
|
350
|
-
Log.error(e);
|
|
350
|
+
this.Log.error(e);
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
}
|
|
@@ -387,7 +387,7 @@ class ReactNativeBleTransport {
|
|
|
387
387
|
transport.nofitySubscription = this._monitorCharacteristic(transport.notifyCharacteristic);
|
|
388
388
|
transportCache[uuid] = transport;
|
|
389
389
|
const disconnectSubscription = device.onDisconnected(() => {
|
|
390
|
-
Log.debug('device disconnect: ', device === null || device === void 0 ? void 0 : device.id);
|
|
390
|
+
this.Log.debug('device disconnect: ', device === null || device === void 0 ? void 0 : device.id);
|
|
391
391
|
this.release(uuid);
|
|
392
392
|
disconnectSubscription === null || disconnectSubscription === void 0 ? void 0 : disconnectSubscription.remove();
|
|
393
393
|
});
|
|
@@ -400,10 +400,10 @@ class ReactNativeBleTransport {
|
|
|
400
400
|
const subscription = characteristic.monitor((error, c) => {
|
|
401
401
|
var _a, _b, _c;
|
|
402
402
|
if (error) {
|
|
403
|
-
Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
|
|
403
|
+
this.Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
|
|
404
404
|
if (this.runPromise) {
|
|
405
405
|
this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyError, (_a = error.reason) !== null && _a !== void 0 ? _a : error.message));
|
|
406
|
-
Log.debug(': monitor notify error, and has unreleased Promise');
|
|
406
|
+
this.Log.debug(': monitor notify error, and has unreleased Promise');
|
|
407
407
|
}
|
|
408
408
|
return;
|
|
409
409
|
}
|
|
@@ -427,12 +427,12 @@ class ReactNativeBleTransport {
|
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
429
|
catch (error) {
|
|
430
|
-
Log.debug('monitor data error: ', error);
|
|
430
|
+
this.Log.debug('monitor data error: ', error);
|
|
431
431
|
(_c = this.runPromise) === null || _c === void 0 ? void 0 : _c.reject(error);
|
|
432
432
|
}
|
|
433
433
|
});
|
|
434
434
|
return () => {
|
|
435
|
-
Log.debug('remove characteristic monitor: ', characteristic.uuid);
|
|
435
|
+
this.Log.debug('remove characteristic monitor: ', characteristic.uuid);
|
|
436
436
|
subscription.remove();
|
|
437
437
|
};
|
|
438
438
|
}
|
|
@@ -467,7 +467,7 @@ class ReactNativeBleTransport {
|
|
|
467
467
|
}
|
|
468
468
|
this.runPromise = hdShared.createDeferred();
|
|
469
469
|
const messages = this._messages;
|
|
470
|
-
Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
|
|
470
|
+
this.Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
|
|
471
471
|
const buffers = buildBuffers(messages, name, data);
|
|
472
472
|
if (name === 'FirmwareUpload') {
|
|
473
473
|
const packetCapacity = reactNative.Platform.OS === 'ios' ? IOS_PACKET_LENGTH : ANDROID_PACKET_LENGTH;
|
|
@@ -479,14 +479,14 @@ class ReactNativeBleTransport {
|
|
|
479
479
|
index += 1;
|
|
480
480
|
if (chunk.offset === packetCapacity || index >= buffers.length) {
|
|
481
481
|
chunk.reset();
|
|
482
|
-
Log.debug('send more packet hex strting: ', chunk.toString('hex'));
|
|
482
|
+
this.Log.debug('send more packet hex strting: ', chunk.toString('hex'));
|
|
483
483
|
try {
|
|
484
484
|
yield transport.writeCharacteristic.writeWithoutResponse(chunk.toString('base64'));
|
|
485
485
|
chunk = ByteBuffer__default["default"].allocate(packetCapacity);
|
|
486
486
|
}
|
|
487
487
|
catch (e) {
|
|
488
488
|
this.runPromise = null;
|
|
489
|
-
Log.error('writeCharacteristic write error: ', e);
|
|
489
|
+
this.Log.error('writeCharacteristic write error: ', e);
|
|
490
490
|
return;
|
|
491
491
|
}
|
|
492
492
|
}
|
|
@@ -495,7 +495,7 @@ class ReactNativeBleTransport {
|
|
|
495
495
|
else {
|
|
496
496
|
for (const o of buffers) {
|
|
497
497
|
const outData = o.toString('base64');
|
|
498
|
-
Log.debug('send hex strting: ', o.toString('hex'));
|
|
498
|
+
this.Log.debug('send hex strting: ', o.toString('hex'));
|
|
499
499
|
try {
|
|
500
500
|
yield transport.writeCharacteristic.writeWithoutResponse(outData);
|
|
501
501
|
}
|
|
@@ -504,7 +504,7 @@ class ReactNativeBleTransport {
|
|
|
504
504
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded);
|
|
505
505
|
}
|
|
506
506
|
this.runPromise = null;
|
|
507
|
-
Log.debug('writeCharacteristic write error: ', e);
|
|
507
|
+
this.Log.debug('writeCharacteristic write error: ', e);
|
|
508
508
|
return;
|
|
509
509
|
}
|
|
510
510
|
}
|
|
@@ -514,12 +514,12 @@ class ReactNativeBleTransport {
|
|
|
514
514
|
if (typeof response !== 'string') {
|
|
515
515
|
throw new Error('Returning data is not string.');
|
|
516
516
|
}
|
|
517
|
-
Log.debug('receive data: ', response);
|
|
517
|
+
this.Log.debug('receive data: ', response);
|
|
518
518
|
const jsonData = receiveOne(messages, response);
|
|
519
519
|
return check.call(jsonData);
|
|
520
520
|
}
|
|
521
521
|
catch (e) {
|
|
522
|
-
Log.error('call error: ', e);
|
|
522
|
+
this.Log.error('call error: ', e);
|
|
523
523
|
return e;
|
|
524
524
|
}
|
|
525
525
|
finally {
|
|
@@ -531,7 +531,7 @@ class ReactNativeBleTransport {
|
|
|
531
531
|
this.stopped = true;
|
|
532
532
|
}
|
|
533
533
|
cancel() {
|
|
534
|
-
Log.debug('transport-react-native canceled');
|
|
534
|
+
this.Log.debug('transport-react-native canceled');
|
|
535
535
|
if (this.runPromise) ;
|
|
536
536
|
this.runPromise = null;
|
|
537
537
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"lint:fix": "eslint . --fix"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-shared": "^0.1.
|
|
24
|
-
"@onekeyfe/hd-transport": "^0.1.
|
|
23
|
+
"@onekeyfe/hd-shared": "^0.1.17",
|
|
24
|
+
"@onekeyfe/hd-transport": "^0.1.17",
|
|
25
25
|
"react-native-ble-manager": "^8.1.0",
|
|
26
26
|
"react-native-ble-plx": "^2.0.3"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "65350a66c7f2b1e80cb1d413ee56da4aef507fa3"
|
|
29
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,14 +9,7 @@ import {
|
|
|
9
9
|
} from 'react-native-ble-plx';
|
|
10
10
|
import ByteBuffer from 'bytebuffer';
|
|
11
11
|
import transport, { COMMON_HEADER_SIZE } from '@onekeyfe/hd-transport';
|
|
12
|
-
import {
|
|
13
|
-
createDeferred,
|
|
14
|
-
Deferred,
|
|
15
|
-
ERRORS,
|
|
16
|
-
HardwareErrorCode,
|
|
17
|
-
enableLog,
|
|
18
|
-
initLog,
|
|
19
|
-
} from '@onekeyfe/hd-shared';
|
|
12
|
+
import { createDeferred, Deferred, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
20
13
|
import { initializeBleManager, getConnectedDeviceIds, getBondedDevices } from './BleManager';
|
|
21
14
|
import { subscribeBleOn } from './subscribeBleOn';
|
|
22
15
|
import {
|
|
@@ -35,8 +28,6 @@ const { check, buildBuffers, receiveOne, parseConfigure } = transport;
|
|
|
35
28
|
|
|
36
29
|
const transportCache: Record<string, any> = {};
|
|
37
30
|
|
|
38
|
-
const Log = initLog('@onekey/hd-ble-sdk');
|
|
39
|
-
|
|
40
31
|
let connectOptions: Record<string, unknown> = {
|
|
41
32
|
requestMTU: 512,
|
|
42
33
|
timeout: 3000,
|
|
@@ -63,12 +54,15 @@ export default class ReactNativeBleTransport {
|
|
|
63
54
|
|
|
64
55
|
runPromise: Deferred<any> | null = null;
|
|
65
56
|
|
|
57
|
+
Log?: any;
|
|
58
|
+
|
|
66
59
|
constructor(options: TransportOptions) {
|
|
67
60
|
this.scanTimeout = options.scanTimeout ?? 3000;
|
|
68
|
-
enableLog(true);
|
|
69
61
|
}
|
|
70
62
|
|
|
71
|
-
init() {
|
|
63
|
+
init(logger: any) {
|
|
64
|
+
this.Log = logger;
|
|
65
|
+
}
|
|
72
66
|
|
|
73
67
|
configure(signedData: any) {
|
|
74
68
|
const messages = parseConfigure(signedData);
|
|
@@ -100,7 +94,7 @@ export default class ReactNativeBleTransport {
|
|
|
100
94
|
try {
|
|
101
95
|
await subscribeBleOn(blePlxManager);
|
|
102
96
|
} catch (error) {
|
|
103
|
-
Log.debug('subscribeBleOn error: ', error);
|
|
97
|
+
this.Log.debug('subscribeBleOn error: ', error);
|
|
104
98
|
reject(error);
|
|
105
99
|
return;
|
|
106
100
|
}
|
|
@@ -112,8 +106,8 @@ export default class ReactNativeBleTransport {
|
|
|
112
106
|
},
|
|
113
107
|
(error, device) => {
|
|
114
108
|
if (error) {
|
|
115
|
-
Log.debug('ble scan manager: ', blePlxManager);
|
|
116
|
-
Log.debug('ble scan error: ', error);
|
|
109
|
+
this.Log.debug('ble scan manager: ', blePlxManager);
|
|
110
|
+
this.Log.debug('ble scan error: ', error);
|
|
117
111
|
if (
|
|
118
112
|
[BleErrorCode.BluetoothPoweredOff, BleErrorCode.BluetoothInUnknownState].includes(
|
|
119
113
|
error.errorCode
|
|
@@ -129,20 +123,22 @@ export default class ReactNativeBleTransport {
|
|
|
129
123
|
}
|
|
130
124
|
|
|
131
125
|
if (isOnekeyDevice(device?.name ?? null, device?.id)) {
|
|
132
|
-
Log.debug('search device start ======================');
|
|
126
|
+
this.Log.debug('search device start ======================');
|
|
133
127
|
|
|
134
128
|
const { name, localName, id } = device ?? {};
|
|
135
|
-
Log.debug(
|
|
129
|
+
this.Log.debug(
|
|
130
|
+
`device name: ${name ?? ''}\nlocalName: ${localName ?? ''}\nid: ${id ?? ''}`
|
|
131
|
+
);
|
|
136
132
|
addDevice(device as unknown as Device);
|
|
137
133
|
|
|
138
|
-
Log.debug('search device end ======================\n');
|
|
134
|
+
this.Log.debug('search device end ======================\n');
|
|
139
135
|
}
|
|
140
136
|
}
|
|
141
137
|
);
|
|
142
138
|
|
|
143
139
|
getConnectedDeviceIds(getBluetoothServiceUuids()).then(devices => {
|
|
144
140
|
for (const device of devices) {
|
|
145
|
-
Log.debug('search connected peripheral: ', device.id);
|
|
141
|
+
this.Log.debug('search connected peripheral: ', device.id);
|
|
146
142
|
addDevice(device as unknown as Device);
|
|
147
143
|
}
|
|
148
144
|
});
|
|
@@ -174,7 +170,7 @@ export default class ReactNativeBleTransport {
|
|
|
174
170
|
* If the transport is not released due to an exception operation
|
|
175
171
|
* it will be handled again here
|
|
176
172
|
*/
|
|
177
|
-
Log.debug('transport not be released, will release: ', uuid);
|
|
173
|
+
this.Log.debug('transport not be released, will release: ', uuid);
|
|
178
174
|
await this.release(uuid);
|
|
179
175
|
}
|
|
180
176
|
|
|
@@ -182,7 +178,7 @@ export default class ReactNativeBleTransport {
|
|
|
182
178
|
try {
|
|
183
179
|
await subscribeBleOn(blePlxManager);
|
|
184
180
|
} catch (error) {
|
|
185
|
-
Log.debug('subscribeBleOn error: ', error);
|
|
181
|
+
this.Log.debug('subscribeBleOn error: ', error);
|
|
186
182
|
throw error;
|
|
187
183
|
}
|
|
188
184
|
|
|
@@ -194,16 +190,16 @@ export default class ReactNativeBleTransport {
|
|
|
194
190
|
if (!device) {
|
|
195
191
|
const connectedDevice = await blePlxManager.connectedDevices(getBluetoothServiceUuids());
|
|
196
192
|
const deviceFilter = connectedDevice.filter(device => device.id === uuid);
|
|
197
|
-
Log.debug(`found connected device count: ${deviceFilter.length}`);
|
|
193
|
+
this.Log.debug(`found connected device count: ${deviceFilter.length}`);
|
|
198
194
|
[device] = deviceFilter;
|
|
199
195
|
}
|
|
200
196
|
|
|
201
197
|
if (!device) {
|
|
202
|
-
Log.debug('try to connect to device: ', uuid);
|
|
198
|
+
this.Log.debug('try to connect to device: ', uuid);
|
|
203
199
|
try {
|
|
204
200
|
device = await blePlxManager.connectToDevice(uuid, connectOptions);
|
|
205
201
|
} catch (e) {
|
|
206
|
-
Log.debug('try to connect to device has error: ', e);
|
|
202
|
+
this.Log.debug('try to connect to device has error: ', e);
|
|
207
203
|
if (
|
|
208
204
|
e.errorCode === BleErrorCode.DeviceMTUChangeFailed ||
|
|
209
205
|
e.errorCode === BleErrorCode.OperationCancelled
|
|
@@ -221,12 +217,12 @@ export default class ReactNativeBleTransport {
|
|
|
221
217
|
}
|
|
222
218
|
|
|
223
219
|
if (!(await device.isConnected())) {
|
|
224
|
-
Log.debug('not connected, try to connect to device: ', uuid);
|
|
220
|
+
this.Log.debug('not connected, try to connect to device: ', uuid);
|
|
225
221
|
|
|
226
222
|
try {
|
|
227
223
|
await device.connect(connectOptions);
|
|
228
224
|
} catch (e) {
|
|
229
|
-
Log.debug('try to connect to device has error: ', e);
|
|
225
|
+
this.Log.debug('try to connect to device has error: ', e);
|
|
230
226
|
if (
|
|
231
227
|
e.errorCode === BleErrorCode.DeviceMTUChangeFailed ||
|
|
232
228
|
e.errorCode === BleErrorCode.OperationCancelled
|
|
@@ -259,7 +255,7 @@ export default class ReactNativeBleTransport {
|
|
|
259
255
|
infos = getInfosForServiceUuid(serviceUuid, 'classic');
|
|
260
256
|
break;
|
|
261
257
|
} catch (e) {
|
|
262
|
-
Log.error(e);
|
|
258
|
+
this.Log.error(e);
|
|
263
259
|
}
|
|
264
260
|
}
|
|
265
261
|
}
|
|
@@ -311,7 +307,7 @@ export default class ReactNativeBleTransport {
|
|
|
311
307
|
transportCache[uuid] = transport;
|
|
312
308
|
|
|
313
309
|
const disconnectSubscription = device.onDisconnected(() => {
|
|
314
|
-
Log.debug('device disconnect: ', device?.id);
|
|
310
|
+
this.Log.debug('device disconnect: ', device?.id);
|
|
315
311
|
this.release(uuid);
|
|
316
312
|
disconnectSubscription?.remove();
|
|
317
313
|
});
|
|
@@ -324,7 +320,7 @@ export default class ReactNativeBleTransport {
|
|
|
324
320
|
let buffer: any[] = [];
|
|
325
321
|
const subscription = characteristic.monitor((error, c) => {
|
|
326
322
|
if (error) {
|
|
327
|
-
Log.debug(
|
|
323
|
+
this.Log.debug(
|
|
328
324
|
`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${
|
|
329
325
|
error as unknown as string
|
|
330
326
|
}`
|
|
@@ -336,7 +332,7 @@ export default class ReactNativeBleTransport {
|
|
|
336
332
|
error.reason ?? error.message
|
|
337
333
|
)
|
|
338
334
|
);
|
|
339
|
-
Log.debug(': monitor notify error, and has unreleased Promise');
|
|
335
|
+
this.Log.debug(': monitor notify error, and has unreleased Promise');
|
|
340
336
|
}
|
|
341
337
|
return;
|
|
342
338
|
}
|
|
@@ -368,13 +364,13 @@ export default class ReactNativeBleTransport {
|
|
|
368
364
|
this.runPromise?.resolve(value.toString('hex'));
|
|
369
365
|
}
|
|
370
366
|
} catch (error) {
|
|
371
|
-
Log.debug('monitor data error: ', error);
|
|
367
|
+
this.Log.debug('monitor data error: ', error);
|
|
372
368
|
this.runPromise?.reject(error);
|
|
373
369
|
}
|
|
374
370
|
});
|
|
375
371
|
|
|
376
372
|
return () => {
|
|
377
|
-
Log.debug('remove characteristic monitor: ', characteristic.uuid);
|
|
373
|
+
this.Log.debug('remove characteristic monitor: ', characteristic.uuid);
|
|
378
374
|
subscription.remove();
|
|
379
375
|
};
|
|
380
376
|
}
|
|
@@ -413,7 +409,7 @@ export default class ReactNativeBleTransport {
|
|
|
413
409
|
|
|
414
410
|
this.runPromise = createDeferred();
|
|
415
411
|
const messages = this._messages;
|
|
416
|
-
Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
|
|
412
|
+
this.Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
|
|
417
413
|
const buffers = buildBuffers(messages, name, data);
|
|
418
414
|
|
|
419
415
|
if (name === 'FirmwareUpload') {
|
|
@@ -426,13 +422,13 @@ export default class ReactNativeBleTransport {
|
|
|
426
422
|
index += 1;
|
|
427
423
|
if (chunk.offset === packetCapacity || index >= buffers.length) {
|
|
428
424
|
chunk.reset();
|
|
429
|
-
Log.debug('send more packet hex strting: ', chunk.toString('hex'));
|
|
425
|
+
this.Log.debug('send more packet hex strting: ', chunk.toString('hex'));
|
|
430
426
|
try {
|
|
431
427
|
await transport.writeCharacteristic.writeWithoutResponse(chunk.toString('base64'));
|
|
432
428
|
chunk = ByteBuffer.allocate(packetCapacity);
|
|
433
429
|
} catch (e) {
|
|
434
430
|
this.runPromise = null;
|
|
435
|
-
Log.error('writeCharacteristic write error: ', e);
|
|
431
|
+
this.Log.error('writeCharacteristic write error: ', e);
|
|
436
432
|
return;
|
|
437
433
|
}
|
|
438
434
|
}
|
|
@@ -440,7 +436,7 @@ export default class ReactNativeBleTransport {
|
|
|
440
436
|
} else {
|
|
441
437
|
for (const o of buffers) {
|
|
442
438
|
const outData = o.toString('base64');
|
|
443
|
-
Log.debug('send hex strting: ', o.toString('hex'));
|
|
439
|
+
this.Log.debug('send hex strting: ', o.toString('hex'));
|
|
444
440
|
try {
|
|
445
441
|
await transport.writeCharacteristic.writeWithoutResponse(outData);
|
|
446
442
|
} catch (e) {
|
|
@@ -448,7 +444,7 @@ export default class ReactNativeBleTransport {
|
|
|
448
444
|
throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded);
|
|
449
445
|
}
|
|
450
446
|
this.runPromise = null;
|
|
451
|
-
Log.debug('writeCharacteristic write error: ', e);
|
|
447
|
+
this.Log.debug('writeCharacteristic write error: ', e);
|
|
452
448
|
return;
|
|
453
449
|
}
|
|
454
450
|
}
|
|
@@ -461,11 +457,11 @@ export default class ReactNativeBleTransport {
|
|
|
461
457
|
throw new Error('Returning data is not string.');
|
|
462
458
|
}
|
|
463
459
|
|
|
464
|
-
Log.debug('receive data: ', response);
|
|
460
|
+
this.Log.debug('receive data: ', response);
|
|
465
461
|
const jsonData = receiveOne(messages, response);
|
|
466
462
|
return check.call(jsonData);
|
|
467
463
|
} catch (e) {
|
|
468
|
-
Log.error('call error: ', e);
|
|
464
|
+
this.Log.error('call error: ', e);
|
|
469
465
|
return e;
|
|
470
466
|
} finally {
|
|
471
467
|
this.runPromise = null;
|
|
@@ -477,7 +473,7 @@ export default class ReactNativeBleTransport {
|
|
|
477
473
|
}
|
|
478
474
|
|
|
479
475
|
cancel() {
|
|
480
|
-
Log.debug('transport-react-native canceled');
|
|
476
|
+
this.Log.debug('transport-react-native canceled');
|
|
481
477
|
if (this.runPromise) {
|
|
482
478
|
// this.runPromise.reject(new Error('Transport_CallCanceled'));
|
|
483
479
|
}
|