@onekeyfe/hd-transport-react-native 1.1.21 → 1.1.22-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 +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -3
- package/package.json +4 -4
- package/src/index.ts +67 -3
package/dist/index.d.ts
CHANGED
|
@@ -32,11 +32,12 @@ declare class ReactNativeBleTransport {
|
|
|
32
32
|
acquire(input: BleAcquireInput): Promise<{
|
|
33
33
|
uuid: string;
|
|
34
34
|
}>;
|
|
35
|
-
_monitorCharacteristic(characteristic: Characteristic): () => void;
|
|
35
|
+
_monitorCharacteristic(characteristic: Characteristic, uuid: string): () => void;
|
|
36
36
|
release(uuid: string): Promise<boolean>;
|
|
37
37
|
post(session: string, name: string, data: Record<string, unknown>): Promise<void>;
|
|
38
38
|
call(uuid: string, name: string, data: Record<string, unknown>): Promise<transport.MessageFromOneKey>;
|
|
39
39
|
stop(): void;
|
|
40
|
+
disconnect(session: string): Promise<void>;
|
|
40
41
|
cancel(): void;
|
|
41
42
|
}
|
|
42
43
|
|
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,EAGhB,KAAK,oBAAoB,EAC1B,MAAM,wBAAwB,CAAC;AAehC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAYjE,MAAM,MAAM,aAAa,GAAG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;IAEzC,SAAS,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,IAAI,SAA6B;IAEjC,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;IAWjC,SAAS;IA6FT,OAAO,CAAC,KAAK,EAAE,eAAe;;;IAqNpC,sBAAsB,CAAC,cAAc,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM;IAkF7D,OAAO,CAAC,IAAI,EAAE,MAAM;IAepB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIjE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IA2HpE,IAAI;IAIE,UAAU,CAAC,OAAO,EAAE,MAAM;IA6DhC,MAAM;CAOP"}
|
package/dist/index.js
CHANGED
|
@@ -497,7 +497,7 @@ class ReactNativeBleTransport {
|
|
|
497
497
|
}
|
|
498
498
|
yield this.release(uuid);
|
|
499
499
|
const transport = new BleTransport(device, writeCharacteristic, notifyCharacteristic);
|
|
500
|
-
transport.nofitySubscription = this._monitorCharacteristic(transport.notifyCharacteristic);
|
|
500
|
+
transport.nofitySubscription = this._monitorCharacteristic(transport.notifyCharacteristic, uuid);
|
|
501
501
|
transportCache[uuid] = transport;
|
|
502
502
|
(_a = this.emitter) === null || _a === void 0 ? void 0 : _a.emit('device-connect', {
|
|
503
503
|
name: device.name,
|
|
@@ -528,7 +528,7 @@ class ReactNativeBleTransport {
|
|
|
528
528
|
return { uuid };
|
|
529
529
|
});
|
|
530
530
|
}
|
|
531
|
-
_monitorCharacteristic(characteristic) {
|
|
531
|
+
_monitorCharacteristic(characteristic, uuid) {
|
|
532
532
|
let bufferLength = 0;
|
|
533
533
|
let buffer$1 = [];
|
|
534
534
|
const subscription = characteristic.monitor((error, c) => {
|
|
@@ -580,7 +580,7 @@ class ReactNativeBleTransport {
|
|
|
580
580
|
this.Log.debug('monitor data error: ', error);
|
|
581
581
|
(_j = this.runPromise) === null || _j === void 0 ? void 0 : _j.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError));
|
|
582
582
|
}
|
|
583
|
-
});
|
|
583
|
+
}, uuid);
|
|
584
584
|
return () => {
|
|
585
585
|
this.Log.debug('remove characteristic monitor: ', characteristic.uuid);
|
|
586
586
|
subscription.remove();
|
|
@@ -714,6 +714,58 @@ class ReactNativeBleTransport {
|
|
|
714
714
|
stop() {
|
|
715
715
|
this.stopped = true;
|
|
716
716
|
}
|
|
717
|
+
disconnect(session) {
|
|
718
|
+
var _a, _b, _c, _d;
|
|
719
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
720
|
+
this.Log.debug('transport-react-native transport resetSession: ', session);
|
|
721
|
+
const transport = transportCache[session];
|
|
722
|
+
if (transport === null || transport === void 0 ? void 0 : transport.nofitySubscription) {
|
|
723
|
+
try {
|
|
724
|
+
transport.nofitySubscription();
|
|
725
|
+
transport.nofitySubscription = undefined;
|
|
726
|
+
}
|
|
727
|
+
catch (e) {
|
|
728
|
+
this.Log.error('resetSession: remove notify subscription error: ', e);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if (session) {
|
|
732
|
+
try {
|
|
733
|
+
yield ((_a = this.blePlxManager) === null || _a === void 0 ? void 0 : _a.cancelTransaction(session));
|
|
734
|
+
}
|
|
735
|
+
catch (e) {
|
|
736
|
+
this.Log.debug('resetSession: cancel transaction error (ignored): ', (e === null || e === void 0 ? void 0 : e.message) || e);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if (transport === null || transport === void 0 ? void 0 : transport.device) {
|
|
740
|
+
try {
|
|
741
|
+
yield transport.device.cancelConnection();
|
|
742
|
+
}
|
|
743
|
+
catch (e) {
|
|
744
|
+
this.Log.debug('resetSession: device.cancelConnection error (ignored): ', (e === null || e === void 0 ? void 0 : e.message) || e);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
try {
|
|
748
|
+
yield ((_b = this.blePlxManager) === null || _b === void 0 ? void 0 : _b.cancelDeviceConnection(session));
|
|
749
|
+
}
|
|
750
|
+
catch (e) {
|
|
751
|
+
this.Log.debug('resetSession: manager.cancelDeviceConnection error (ignored): ', (e === null || e === void 0 ? void 0 : e.message) || e);
|
|
752
|
+
}
|
|
753
|
+
if (transportCache[session]) {
|
|
754
|
+
delete transportCache[session];
|
|
755
|
+
}
|
|
756
|
+
try {
|
|
757
|
+
(_c = this.emitter) === null || _c === void 0 ? void 0 : _c.emit('device-disconnect', {
|
|
758
|
+
name: (_d = transport === null || transport === void 0 ? void 0 : transport.device) === null || _d === void 0 ? void 0 : _d.name,
|
|
759
|
+
id: session,
|
|
760
|
+
connectId: session,
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
catch (e) {
|
|
764
|
+
this.Log.error('resetSession: emit disconnect event error: ', e);
|
|
765
|
+
}
|
|
766
|
+
yield new Promise(resolve => setTimeout(() => resolve(), 100));
|
|
767
|
+
});
|
|
768
|
+
}
|
|
717
769
|
cancel() {
|
|
718
770
|
this.Log.debug('transport-react-native transport cancel');
|
|
719
771
|
if (this.runPromise) ;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.22-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.1.
|
|
23
|
-
"@onekeyfe/hd-transport": "1.1.
|
|
22
|
+
"@onekeyfe/hd-shared": "1.1.22-alpha.2",
|
|
23
|
+
"@onekeyfe/hd-transport": "1.1.22-alpha.2",
|
|
24
24
|
"@onekeyfe/react-native-ble-utils": "^0.1.4",
|
|
25
25
|
"react-native-ble-plx": "3.5.0"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "a619ea24331a5c59b2d9b4b251c95a56a420739a"
|
|
28
28
|
}
|
package/src/index.ts
CHANGED
|
@@ -405,7 +405,10 @@ export default class ReactNativeBleTransport {
|
|
|
405
405
|
await this.release(uuid);
|
|
406
406
|
|
|
407
407
|
const transport = new BleTransport(device, writeCharacteristic, notifyCharacteristic);
|
|
408
|
-
transport.nofitySubscription = this._monitorCharacteristic(
|
|
408
|
+
transport.nofitySubscription = this._monitorCharacteristic(
|
|
409
|
+
transport.notifyCharacteristic,
|
|
410
|
+
uuid
|
|
411
|
+
);
|
|
409
412
|
transportCache[uuid] = transport;
|
|
410
413
|
|
|
411
414
|
this.emitter?.emit('device-connect', {
|
|
@@ -436,7 +439,7 @@ export default class ReactNativeBleTransport {
|
|
|
436
439
|
return { uuid };
|
|
437
440
|
}
|
|
438
441
|
|
|
439
|
-
_monitorCharacteristic(characteristic: Characteristic) {
|
|
442
|
+
_monitorCharacteristic(characteristic: Characteristic, uuid: string) {
|
|
440
443
|
let bufferLength = 0;
|
|
441
444
|
let buffer: any[] = [];
|
|
442
445
|
const subscription = characteristic.monitor((error, c) => {
|
|
@@ -510,7 +513,7 @@ export default class ReactNativeBleTransport {
|
|
|
510
513
|
this.Log.debug('monitor data error: ', error);
|
|
511
514
|
this.runPromise?.reject(ERRORS.TypedError(HardwareErrorCode.BleWriteCharacteristicError));
|
|
512
515
|
}
|
|
513
|
-
});
|
|
516
|
+
}, uuid);
|
|
514
517
|
|
|
515
518
|
return () => {
|
|
516
519
|
this.Log.debug('remove characteristic monitor: ', characteristic.uuid);
|
|
@@ -664,6 +667,67 @@ export default class ReactNativeBleTransport {
|
|
|
664
667
|
this.stopped = true;
|
|
665
668
|
}
|
|
666
669
|
|
|
670
|
+
async disconnect(session: string) {
|
|
671
|
+
this.Log.debug('transport-react-native transport resetSession: ', session);
|
|
672
|
+
const transport = transportCache[session] as BleTransport;
|
|
673
|
+
|
|
674
|
+
// cancel the notify subscription
|
|
675
|
+
if (transport?.nofitySubscription) {
|
|
676
|
+
try {
|
|
677
|
+
transport.nofitySubscription();
|
|
678
|
+
transport.nofitySubscription = undefined;
|
|
679
|
+
} catch (e) {
|
|
680
|
+
this.Log.error('resetSession: remove notify subscription error: ', e);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// cancel the ble transaction
|
|
685
|
+
if (session) {
|
|
686
|
+
try {
|
|
687
|
+
await this.blePlxManager?.cancelTransaction(session);
|
|
688
|
+
} catch (e) {
|
|
689
|
+
this.Log.debug('resetSession: cancel transaction error (ignored): ', e?.message || e);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// disconnect the device via the device object
|
|
694
|
+
if (transport?.device) {
|
|
695
|
+
try {
|
|
696
|
+
await transport.device.cancelConnection();
|
|
697
|
+
} catch (e) {
|
|
698
|
+
this.Log.debug('resetSession: device.cancelConnection error (ignored): ', e?.message || e);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// disconnect the device via the ble manager
|
|
703
|
+
try {
|
|
704
|
+
await this.blePlxManager?.cancelDeviceConnection(session);
|
|
705
|
+
} catch (e) {
|
|
706
|
+
this.Log.debug(
|
|
707
|
+
'resetSession: manager.cancelDeviceConnection error (ignored): ',
|
|
708
|
+
e?.message || e
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// clear the transport cache
|
|
713
|
+
if (transportCache[session]) {
|
|
714
|
+
delete transportCache[session];
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// emit the disconnect event
|
|
718
|
+
try {
|
|
719
|
+
this.emitter?.emit('device-disconnect', {
|
|
720
|
+
name: transport?.device?.name,
|
|
721
|
+
id: session,
|
|
722
|
+
connectId: session,
|
|
723
|
+
});
|
|
724
|
+
} catch (e) {
|
|
725
|
+
this.Log.error('resetSession: emit disconnect event error: ', e);
|
|
726
|
+
}
|
|
727
|
+
// eslint-disable-next-line no-promise-executor-return
|
|
728
|
+
await new Promise<void>(resolve => setTimeout(() => resolve(), 100));
|
|
729
|
+
}
|
|
730
|
+
|
|
667
731
|
cancel() {
|
|
668
732
|
this.Log.debug('transport-react-native transport cancel');
|
|
669
733
|
if (this.runPromise) {
|