@onekeyfe/hd-transport-react-native 1.1.21-alpha.5 → 1.1.21
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 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -55
- package/package.json +4 -4
- package/src/index.ts +3 -67
package/dist/index.d.ts
CHANGED
|
@@ -32,12 +32,11 @@ declare class ReactNativeBleTransport {
|
|
|
32
32
|
acquire(input: BleAcquireInput): Promise<{
|
|
33
33
|
uuid: string;
|
|
34
34
|
}>;
|
|
35
|
-
_monitorCharacteristic(characteristic: Characteristic
|
|
35
|
+
_monitorCharacteristic(characteristic: Characteristic): () => 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>;
|
|
41
40
|
cancel(): void;
|
|
42
41
|
}
|
|
43
42
|
|
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,oBAAoB,GAA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,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;;;IAkNpC,sBAAsB,CAAC,cAAc,EAAE,cAAc;IAkF/C,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;IAIJ,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);
|
|
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) {
|
|
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
|
+
});
|
|
584
584
|
return () => {
|
|
585
585
|
this.Log.debug('remove characteristic monitor: ', characteristic.uuid);
|
|
586
586
|
subscription.remove();
|
|
@@ -714,58 +714,6 @@ 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
|
-
}
|
|
769
717
|
cancel() {
|
|
770
718
|
this.Log.debug('transport-react-native transport cancel');
|
|
771
719
|
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.21
|
|
3
|
+
"version": "1.1.21",
|
|
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.21
|
|
23
|
-
"@onekeyfe/hd-transport": "1.1.21
|
|
22
|
+
"@onekeyfe/hd-shared": "1.1.21",
|
|
23
|
+
"@onekeyfe/hd-transport": "1.1.21",
|
|
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": "2c691aee96693b102a0edeca7e7768448090b4d1"
|
|
28
28
|
}
|
package/src/index.ts
CHANGED
|
@@ -405,10 +405,7 @@ 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(
|
|
409
|
-
transport.notifyCharacteristic,
|
|
410
|
-
uuid
|
|
411
|
-
);
|
|
408
|
+
transport.nofitySubscription = this._monitorCharacteristic(transport.notifyCharacteristic);
|
|
412
409
|
transportCache[uuid] = transport;
|
|
413
410
|
|
|
414
411
|
this.emitter?.emit('device-connect', {
|
|
@@ -439,7 +436,7 @@ export default class ReactNativeBleTransport {
|
|
|
439
436
|
return { uuid };
|
|
440
437
|
}
|
|
441
438
|
|
|
442
|
-
_monitorCharacteristic(characteristic: Characteristic
|
|
439
|
+
_monitorCharacteristic(characteristic: Characteristic) {
|
|
443
440
|
let bufferLength = 0;
|
|
444
441
|
let buffer: any[] = [];
|
|
445
442
|
const subscription = characteristic.monitor((error, c) => {
|
|
@@ -513,7 +510,7 @@ export default class ReactNativeBleTransport {
|
|
|
513
510
|
this.Log.debug('monitor data error: ', error);
|
|
514
511
|
this.runPromise?.reject(ERRORS.TypedError(HardwareErrorCode.BleWriteCharacteristicError));
|
|
515
512
|
}
|
|
516
|
-
}
|
|
513
|
+
});
|
|
517
514
|
|
|
518
515
|
return () => {
|
|
519
516
|
this.Log.debug('remove characteristic monitor: ', characteristic.uuid);
|
|
@@ -667,67 +664,6 @@ export default class ReactNativeBleTransport {
|
|
|
667
664
|
this.stopped = true;
|
|
668
665
|
}
|
|
669
666
|
|
|
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
|
-
|
|
731
667
|
cancel() {
|
|
732
668
|
this.Log.debug('transport-react-native transport cancel');
|
|
733
669
|
if (this.runPromise) {
|