@onekeyfe/hd-transport-react-native 1.1.27-alpha.38 → 1.1.27-alpha.39
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 +31 -14
- package/package.json +5 -5
- package/src/index.ts +34 -9
package/dist/index.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ declare class ReactNativeBleTransport {
|
|
|
63
63
|
protocolType: ProtocolType;
|
|
64
64
|
}>;
|
|
65
65
|
_monitorCharacteristic(characteristic: Characteristic, uuid: string, monitorToken: number, notifyTransactionId: string): Subscription;
|
|
66
|
-
release(uuid: string): Promise<boolean>;
|
|
66
|
+
release(uuid: string, onclose?: boolean): Promise<boolean>;
|
|
67
67
|
post(session: string, name: string, data: Record<string, unknown>): Promise<void>;
|
|
68
68
|
call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<transport.MessageFromOneKey>;
|
|
69
69
|
private callProtocolV1;
|
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,EAIL,UAAU,IAAI,aAAa,EAE5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAEhB,KAAK,oBAAoB,EAGzB,KAAK,YAAY,EAGjB,KAAK,oBAAoB,EAE1B,MAAM,wBAAwB,CAAC;AAuBhC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAsBjE,MAAM,MAAM,mBAAmB,GAAG;I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,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;YAoDlB,cAAc;IA6H5B,IAAI;IAIE,UAAU,CAAC,OAAO,EAAE,MAAM;IAiFhC,MAAM;IAQN,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;YAMZ,cAAc;YAwDd,iCAAiC;YAmDjC,eAAe;YAgBf,eAAe;IAwB7B,OAAO,CAAC,4BAA4B;IA0BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,yBAAyB;IAQjC,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,sBAAsB;YAIhB,mBAAmB;YAiBnB,oBAAoB;YA4DpB,cAAc;IAyG5B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
|
@@ -511,11 +511,20 @@ class ReactNativeBleTransport {
|
|
|
511
511
|
if (!uuid) {
|
|
512
512
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleRequiredUUID);
|
|
513
513
|
}
|
|
514
|
-
|
|
515
|
-
if (
|
|
516
|
-
|
|
517
|
-
yield
|
|
514
|
+
const cachedTransport = transportCache[uuid];
|
|
515
|
+
if (cachedTransport) {
|
|
516
|
+
const cachedProtocol = this.deviceProtocol.get(uuid);
|
|
517
|
+
const isCachedDeviceConnected = yield cachedTransport.device.isConnected().catch(() => false);
|
|
518
|
+
if (isCachedDeviceConnected &&
|
|
519
|
+
cachedProtocol &&
|
|
520
|
+
(!expectedProtocol || cachedProtocol === expectedProtocol)) {
|
|
521
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
|
|
522
|
+
return { uuid, protocolType: cachedProtocol };
|
|
523
|
+
}
|
|
524
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
|
|
525
|
+
yield this.release(uuid, true);
|
|
518
526
|
}
|
|
527
|
+
let device = null;
|
|
519
528
|
if (forceCleanRunPromise && this.runPromise) {
|
|
520
529
|
const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleForceCleanRunPromise);
|
|
521
530
|
this.runPromise.reject(error);
|
|
@@ -678,7 +687,7 @@ class ReactNativeBleTransport {
|
|
|
678
687
|
const protocolHint = expectedProtocol
|
|
679
688
|
? undefined
|
|
680
689
|
: (_e = this.deviceProtocolHints.get(uuid)) !== null && _e !== void 0 ? _e : inferProtocolHintFromDeviceName(getDeviceDisplayName(device));
|
|
681
|
-
yield this.release(uuid);
|
|
690
|
+
yield this.release(uuid, true);
|
|
682
691
|
if (protocolHint) {
|
|
683
692
|
this.deviceProtocolHints.set(uuid, protocolHint);
|
|
684
693
|
}
|
|
@@ -732,7 +741,7 @@ class ReactNativeBleTransport {
|
|
|
732
741
|
Log === null || Log === void 0 ? void 0 : Log.debug('device disconnect error: ', e);
|
|
733
742
|
}
|
|
734
743
|
finally {
|
|
735
|
-
this.release(uuid);
|
|
744
|
+
this.release(uuid, true);
|
|
736
745
|
}
|
|
737
746
|
});
|
|
738
747
|
return { uuid, protocolType };
|
|
@@ -817,8 +826,8 @@ class ReactNativeBleTransport {
|
|
|
817
826
|
}, notifyTransactionId);
|
|
818
827
|
return subscription;
|
|
819
828
|
}
|
|
820
|
-
release(uuid) {
|
|
821
|
-
var _a, _b, _c, _d, _e, _f;
|
|
829
|
+
release(uuid, onclose = false) {
|
|
830
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
822
831
|
return __awaiter(this, void 0, void 0, function* () {
|
|
823
832
|
const transport = transportCache[uuid];
|
|
824
833
|
if (this.runPromise) {
|
|
@@ -831,19 +840,27 @@ class ReactNativeBleTransport {
|
|
|
831
840
|
else {
|
|
832
841
|
this.resetProtocolV2Frames(uuid);
|
|
833
842
|
}
|
|
843
|
+
if (reactNative.Platform.OS === 'android' && !onclose && transport) {
|
|
844
|
+
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
845
|
+
this.resetProtocolV2Frames(uuid);
|
|
846
|
+
if (((_b = this.activeProtocolV2Call) === null || _b === void 0 ? void 0 : _b.uuid) === uuid) {
|
|
847
|
+
this.activeProtocolV2Call = null;
|
|
848
|
+
}
|
|
849
|
+
return Promise.resolve(true);
|
|
850
|
+
}
|
|
834
851
|
if (transport) {
|
|
835
852
|
if (this.monitorTokens.get(uuid) === transport.monitorToken) {
|
|
836
853
|
this.monitorTokens.delete(uuid);
|
|
837
854
|
}
|
|
838
855
|
Log === null || Log === void 0 ? void 0 : Log.debug('release: removing disconnect subscription for device: ', uuid);
|
|
839
|
-
(
|
|
856
|
+
(_c = transport.disconnectSubscription) === null || _c === void 0 ? void 0 : _c.remove();
|
|
840
857
|
transport.disconnectSubscription = undefined;
|
|
841
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('release: removing notify subscription, characteristic: ', (
|
|
842
|
-
(
|
|
858
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('release: removing notify subscription, characteristic: ', (_d = transport.notifyCharacteristic) === null || _d === void 0 ? void 0 : _d.uuid);
|
|
859
|
+
(_e = transport.notifySubscription) === null || _e === void 0 ? void 0 : _e.remove();
|
|
843
860
|
transport.notifySubscription = undefined;
|
|
844
861
|
if (transport.notifyTransactionId) {
|
|
845
862
|
try {
|
|
846
|
-
yield ((
|
|
863
|
+
yield ((_f = this.blePlxManager) === null || _f === void 0 ? void 0 : _f.cancelTransaction(transport.notifyTransactionId));
|
|
847
864
|
}
|
|
848
865
|
catch (e) {
|
|
849
866
|
Log === null || Log === void 0 ? void 0 : Log.debug('release: cancel notify transaction error (ignored): ', (e === null || e === void 0 ? void 0 : e.message) || e);
|
|
@@ -853,11 +870,11 @@ class ReactNativeBleTransport {
|
|
|
853
870
|
}
|
|
854
871
|
this.deviceProtocol.delete(uuid);
|
|
855
872
|
this.deviceProtocolHints.delete(uuid);
|
|
856
|
-
(
|
|
873
|
+
(_g = this.protocolV2Assemblers.get(uuid)) === null || _g === void 0 ? void 0 : _g.reset();
|
|
857
874
|
this.protocolV2Assemblers.delete(uuid);
|
|
858
875
|
this.resetProtocolV2Frames(uuid);
|
|
859
876
|
try {
|
|
860
|
-
yield ((
|
|
877
|
+
yield ((_h = this.blePlxManager) === null || _h === void 0 ? void 0 : _h.cancelTransaction(uuid));
|
|
861
878
|
}
|
|
862
879
|
catch (e) {
|
|
863
880
|
Log === null || Log === void 0 ? void 0 : Log.debug('release: cancel transaction error (ignored): ', (e === null || e === void 0 ? void 0 : e.message) || e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.1.27-alpha.
|
|
3
|
+
"version": "1.1.27-alpha.39",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"lint:fix": "eslint . --fix"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@onekeyfe/hd-core": "1.1.27-alpha.
|
|
23
|
-
"@onekeyfe/hd-shared": "1.1.27-alpha.
|
|
24
|
-
"@onekeyfe/hd-transport": "1.1.27-alpha.
|
|
22
|
+
"@onekeyfe/hd-core": "1.1.27-alpha.39",
|
|
23
|
+
"@onekeyfe/hd-shared": "1.1.27-alpha.39",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.1.27-alpha.39",
|
|
25
25
|
"@onekeyfe/react-native-ble-utils": "^0.1.4",
|
|
26
26
|
"react-native-ble-plx": "3.5.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "e439aa105f1a898a8050037430ba23a5e31203b1"
|
|
29
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -408,17 +408,33 @@ export default class ReactNativeBleTransport {
|
|
|
408
408
|
throw ERRORS.TypedError(HardwareErrorCode.BleRequiredUUID);
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
|
|
411
|
+
const cachedTransport = transportCache[uuid];
|
|
412
|
+
if (cachedTransport) {
|
|
413
|
+
const cachedProtocol = this.deviceProtocol.get(uuid);
|
|
414
|
+
const isCachedDeviceConnected = await cachedTransport.device.isConnected().catch(() => false);
|
|
415
|
+
if (
|
|
416
|
+
isCachedDeviceConnected &&
|
|
417
|
+
cachedProtocol &&
|
|
418
|
+
(!expectedProtocol || cachedProtocol === expectedProtocol)
|
|
419
|
+
) {
|
|
420
|
+
Log?.debug(
|
|
421
|
+
'[ReactNativeBleTransport] reuse cached BLE transport:',
|
|
422
|
+
uuid,
|
|
423
|
+
cachedProtocol
|
|
424
|
+
);
|
|
425
|
+
return { uuid, protocolType: cachedProtocol };
|
|
426
|
+
}
|
|
412
427
|
|
|
413
|
-
if (transportCache[uuid]) {
|
|
414
428
|
/**
|
|
415
|
-
* If the transport is not
|
|
416
|
-
* it
|
|
429
|
+
* If the transport is not reusable due to a protocol mismatch or stale
|
|
430
|
+
* connection, clean it up before creating a new transport instance.
|
|
417
431
|
*/
|
|
418
|
-
Log?.debug('transport not
|
|
419
|
-
await this.release(uuid);
|
|
432
|
+
Log?.debug('transport not reusable, will release: ', uuid);
|
|
433
|
+
await this.release(uuid, true);
|
|
420
434
|
}
|
|
421
435
|
|
|
436
|
+
let device: Device | null = null;
|
|
437
|
+
|
|
422
438
|
if (forceCleanRunPromise && this.runPromise) {
|
|
423
439
|
const error = ERRORS.TypedError(HardwareErrorCode.BleForceCleanRunPromise);
|
|
424
440
|
this.runPromise.reject(error);
|
|
@@ -611,7 +627,7 @@ export default class ReactNativeBleTransport {
|
|
|
611
627
|
inferProtocolHintFromDeviceName(getDeviceDisplayName(device));
|
|
612
628
|
|
|
613
629
|
// release transport before new transport instance
|
|
614
|
-
await this.release(uuid);
|
|
630
|
+
await this.release(uuid, true);
|
|
615
631
|
if (protocolHint) {
|
|
616
632
|
this.deviceProtocolHints.set(uuid, protocolHint);
|
|
617
633
|
}
|
|
@@ -673,7 +689,7 @@ export default class ReactNativeBleTransport {
|
|
|
673
689
|
} catch (e) {
|
|
674
690
|
Log?.debug('device disconnect error: ', e);
|
|
675
691
|
} finally {
|
|
676
|
-
this.release(uuid);
|
|
692
|
+
this.release(uuid, true);
|
|
677
693
|
}
|
|
678
694
|
});
|
|
679
695
|
|
|
@@ -789,7 +805,7 @@ export default class ReactNativeBleTransport {
|
|
|
789
805
|
return subscription;
|
|
790
806
|
}
|
|
791
807
|
|
|
792
|
-
async release(uuid: string) {
|
|
808
|
+
async release(uuid: string, onclose = false) {
|
|
793
809
|
const transport = transportCache[uuid];
|
|
794
810
|
if (this.runPromise) {
|
|
795
811
|
const error = ERRORS.TypedError(HardwareErrorCode.BleForceCleanRunPromise);
|
|
@@ -801,6 +817,15 @@ export default class ReactNativeBleTransport {
|
|
|
801
817
|
this.resetProtocolV2Frames(uuid);
|
|
802
818
|
}
|
|
803
819
|
|
|
820
|
+
if (Platform.OS === 'android' && !onclose && transport) {
|
|
821
|
+
this.protocolV2Assemblers.get(uuid)?.reset();
|
|
822
|
+
this.resetProtocolV2Frames(uuid);
|
|
823
|
+
if (this.activeProtocolV2Call?.uuid === uuid) {
|
|
824
|
+
this.activeProtocolV2Call = null;
|
|
825
|
+
}
|
|
826
|
+
return Promise.resolve(true);
|
|
827
|
+
}
|
|
828
|
+
|
|
804
829
|
if (transport) {
|
|
805
830
|
if (this.monitorTokens.get(uuid) === transport.monitorToken) {
|
|
806
831
|
this.monitorTokens.delete(uuid);
|