@onekeyfe/hd-transport-react-native 1.0.6 → 1.0.7-alpha.2
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 +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -2
- package/package.json +4 -4
- package/src/index.ts +12 -3
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ declare class ReactNativeBleTransport {
|
|
|
30
30
|
acquire(input: BleAcquireInput): Promise<{
|
|
31
31
|
uuid: string;
|
|
32
32
|
}>;
|
|
33
|
-
_monitorCharacteristic(characteristic: Characteristic): () => void;
|
|
33
|
+
_monitorCharacteristic(characteristic: Characteristic, deviceId: string): () => void;
|
|
34
34
|
release(uuid: string): Promise<boolean>;
|
|
35
35
|
call(uuid: string, name: string, data: Record<string, unknown>): Promise<transport.MessageFromOneKey | undefined>;
|
|
36
36
|
stop(): void;
|
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,gCAAgC,CAAC;AAExC,OAAO,SAAkD,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAkB,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;
|
|
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,gCAAgC,CAAC;AAExC,OAAO,SAAkD,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAkB,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAkBvC,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;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;gBAEX,OAAO,EAAE,gBAAgB;IAIrC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY;IAKvC,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAIN,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAYjC,SAAS;IA6FT,OAAO,CAAC,KAAK,EAAE,eAAe;;;IA2MpC,sBAAsB,CAAC,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM;IAmEjE,OAAO,CAAC,IAAI,EAAE,MAAM;IAepB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IA+FpE,IAAI;IAIJ,MAAM;CAOP"}
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,17 @@ const getBondedDevices = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
61
61
|
return Object.assign({ id, name }, advertising);
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
|
+
const refreshCache = (peripheralId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
try {
|
|
66
|
+
yield BleManager__default["default"].connect(peripheralId);
|
|
67
|
+
yield BleManager__default["default"].refreshCache(peripheralId);
|
|
68
|
+
yield BleManager__default["default"].disconnect(peripheralId, true);
|
|
69
|
+
console.log('refreshCache success');
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.log('refreshCache error: ', error);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
64
75
|
|
|
65
76
|
const timer = process.env.NODE_ENV === 'development'
|
|
66
77
|
? {
|
|
@@ -436,7 +447,7 @@ class ReactNativeBleTransport {
|
|
|
436
447
|
throw hdShared.ERRORS.TypedError('BLECharacteristicNotNotifiable: notify characteristic not notifiable');
|
|
437
448
|
}
|
|
438
449
|
const transport = new BleTransport(device, writeCharacteristic, notifyCharacteristic);
|
|
439
|
-
transport.nofitySubscription = this._monitorCharacteristic(transport.notifyCharacteristic);
|
|
450
|
+
transport.nofitySubscription = this._monitorCharacteristic(transport.notifyCharacteristic, device.id);
|
|
440
451
|
transportCache[uuid] = transport;
|
|
441
452
|
(_c = this.emitter) === null || _c === void 0 ? void 0 : _c.emit('device-connect', {
|
|
442
453
|
name: device.name,
|
|
@@ -457,7 +468,7 @@ class ReactNativeBleTransport {
|
|
|
457
468
|
return { uuid };
|
|
458
469
|
});
|
|
459
470
|
}
|
|
460
|
-
_monitorCharacteristic(characteristic) {
|
|
471
|
+
_monitorCharacteristic(characteristic, deviceId) {
|
|
461
472
|
let bufferLength = 0;
|
|
462
473
|
let buffer$1 = [];
|
|
463
474
|
const subscription = characteristic.monitor((error, c) => {
|
|
@@ -472,6 +483,7 @@ class ReactNativeBleTransport {
|
|
|
472
483
|
if ((_b = error.reason) === null || _b === void 0 ? void 0 : _b.includes('Encryption is insufficient')) {
|
|
473
484
|
ERROR = hdShared.HardwareErrorCode.BleDeviceBondError;
|
|
474
485
|
}
|
|
486
|
+
refreshCache(deviceId);
|
|
475
487
|
this.runPromise.reject(hdShared.ERRORS.TypedError(ERROR, (_c = error.reason) !== null && _c !== void 0 ? _c : error.message));
|
|
476
488
|
this.Log.debug(': monitor notify error, and has unreleased Promise');
|
|
477
489
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7-alpha.2",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"lint:fix": "eslint . --fix"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@onekeyfe/hd-shared": "^1.0.
|
|
23
|
-
"@onekeyfe/hd-transport": "^1.0.
|
|
22
|
+
"@onekeyfe/hd-shared": "^1.0.7-alpha.2",
|
|
23
|
+
"@onekeyfe/hd-transport": "^1.0.7-alpha.2",
|
|
24
24
|
"@onekeyfe/react-native-ble-plx": "3.0.0",
|
|
25
25
|
"react-native-ble-manager": "^8.1.0"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "220798f8e3b49640651e919c92403aa6d2b9b813"
|
|
28
28
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,12 @@ import ByteBuffer from 'bytebuffer';
|
|
|
11
11
|
import transport, { COMMON_HEADER_SIZE, LogBlockCommand } from '@onekeyfe/hd-transport';
|
|
12
12
|
import { createDeferred, Deferred, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
13
13
|
import type EventEmitter from 'events';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
initializeBleManager,
|
|
16
|
+
getConnectedDeviceIds,
|
|
17
|
+
getBondedDevices,
|
|
18
|
+
refreshCache,
|
|
19
|
+
} from './BleManager';
|
|
15
20
|
import { subscribeBleOn } from './subscribeBleOn';
|
|
16
21
|
import {
|
|
17
22
|
isOnekeyDevice,
|
|
@@ -360,7 +365,10 @@ export default class ReactNativeBleTransport {
|
|
|
360
365
|
}
|
|
361
366
|
|
|
362
367
|
const transport = new BleTransport(device, writeCharacteristic, notifyCharacteristic);
|
|
363
|
-
transport.nofitySubscription = this._monitorCharacteristic(
|
|
368
|
+
transport.nofitySubscription = this._monitorCharacteristic(
|
|
369
|
+
transport.notifyCharacteristic,
|
|
370
|
+
device.id
|
|
371
|
+
);
|
|
364
372
|
transportCache[uuid] = transport;
|
|
365
373
|
|
|
366
374
|
this.emitter?.emit('device-connect', {
|
|
@@ -383,7 +391,7 @@ export default class ReactNativeBleTransport {
|
|
|
383
391
|
return { uuid };
|
|
384
392
|
}
|
|
385
393
|
|
|
386
|
-
_monitorCharacteristic(characteristic: Characteristic) {
|
|
394
|
+
_monitorCharacteristic(characteristic: Characteristic, deviceId: string) {
|
|
387
395
|
let bufferLength = 0;
|
|
388
396
|
let buffer: any[] = [];
|
|
389
397
|
const subscription = characteristic.monitor((error, c) => {
|
|
@@ -405,6 +413,7 @@ export default class ReactNativeBleTransport {
|
|
|
405
413
|
if (error.reason?.includes('Encryption is insufficient')) {
|
|
406
414
|
ERROR = HardwareErrorCode.BleDeviceBondError;
|
|
407
415
|
}
|
|
416
|
+
refreshCache(deviceId);
|
|
408
417
|
this.runPromise.reject(ERRORS.TypedError(ERROR, error.reason ?? error.message));
|
|
409
418
|
this.Log.debug(': monitor notify error, and has unreleased Promise');
|
|
410
419
|
}
|