@onekeyfe/hd-transport-react-native 1.1.20-alpha.0 → 1.1.20-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 +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -4
- package/src/index.ts +22 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as transport from '@onekeyfe/hd-transport';
|
|
2
|
-
import transport__default from '@onekeyfe/hd-transport';
|
|
3
|
-
import {
|
|
2
|
+
import transport__default, { OneKeyDeviceInfoBase } from '@onekeyfe/hd-transport';
|
|
3
|
+
import { Device, BleManager, Characteristic } from 'react-native-ble-plx';
|
|
4
4
|
import { Deferred } from '@onekeyfe/hd-shared';
|
|
5
5
|
import EventEmitter from 'events';
|
|
6
6
|
|
|
@@ -12,6 +12,7 @@ type BleAcquireInput = {
|
|
|
12
12
|
forceCleanRunPromise?: boolean;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
|
|
15
16
|
declare class ReactNativeBleTransport {
|
|
16
17
|
blePlxManager: BleManager | undefined;
|
|
17
18
|
_messages: ReturnType<typeof transport__default.parseConfigure> | undefined;
|
|
@@ -27,7 +28,7 @@ declare class ReactNativeBleTransport {
|
|
|
27
28
|
configure(signedData: any): void;
|
|
28
29
|
listen(): void;
|
|
29
30
|
getPlxManager(): Promise<BleManager>;
|
|
30
|
-
enumerate(): Promise<
|
|
31
|
+
enumerate(): Promise<IOneKeyDevice[]>;
|
|
31
32
|
acquire(input: BleAcquireInput): Promise<{
|
|
32
33
|
uuid: string;
|
|
33
34
|
}>;
|
|
@@ -39,4 +40,4 @@ declare class ReactNativeBleTransport {
|
|
|
39
40
|
cancel(): void;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export { ReactNativeBleTransport as default };
|
|
43
|
+
export { IOneKeyDevice, ReactNativeBleTransport as default };
|
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,
|
|
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,GAAG,MAAM,CAAC;AA0C1D,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,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
|
@@ -338,7 +338,7 @@ class ReactNativeBleTransport {
|
|
|
338
338
|
});
|
|
339
339
|
const addDevice = (device) => {
|
|
340
340
|
if (deviceList.every(d => d.id !== device.id)) {
|
|
341
|
-
deviceList.push(device);
|
|
341
|
+
deviceList.push(Object.assign(Object.assign({}, device), { commType: 'ble' }));
|
|
342
342
|
}
|
|
343
343
|
};
|
|
344
344
|
timer.timeout(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.1.20-alpha.
|
|
3
|
+
"version": "1.1.20-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.20-alpha.
|
|
23
|
-
"@onekeyfe/hd-transport": "1.1.20-alpha.
|
|
22
|
+
"@onekeyfe/hd-shared": "1.1.20-alpha.2",
|
|
23
|
+
"@onekeyfe/hd-transport": "1.1.20-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": "dbf71f2cde0679e6f0bc84441ff0d0f905b054c0"
|
|
28
28
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PermissionsAndroid, Platform } from 'react-native';
|
|
2
2
|
import { Buffer } from 'buffer';
|
|
3
3
|
import {
|
|
4
|
-
BleManager as BlePlxManager,
|
|
5
|
-
Device,
|
|
6
|
-
BleErrorCode,
|
|
7
|
-
Characteristic,
|
|
8
|
-
ScanMode,
|
|
9
4
|
BleATTErrorCode,
|
|
10
5
|
BleError,
|
|
6
|
+
BleErrorCode,
|
|
7
|
+
BleManager as BlePlxManager,
|
|
8
|
+
ScanMode,
|
|
11
9
|
} from 'react-native-ble-plx';
|
|
12
10
|
import ByteBuffer from 'bytebuffer';
|
|
13
|
-
import transport, {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} from '@onekeyfe/hd-shared';
|
|
21
|
-
import type EventEmitter from 'events';
|
|
11
|
+
import transport, {
|
|
12
|
+
COMMON_HEADER_SIZE,
|
|
13
|
+
LogBlockCommand,
|
|
14
|
+
type OneKeyDeviceInfoBase,
|
|
15
|
+
} from '@onekeyfe/hd-transport';
|
|
16
|
+
import { ERRORS, HardwareErrorCode, createDeferred, isOnekeyDevice } from '@onekeyfe/hd-shared';
|
|
17
|
+
|
|
22
18
|
import { getConnectedDeviceIds, onDeviceBondState, pairDevice } from './BleManager';
|
|
23
19
|
import { subscribeBleOn } from './subscribeBleOn';
|
|
24
20
|
import {
|
|
21
|
+
ANDROID_PACKET_LENGTH,
|
|
22
|
+
IOS_PACKET_LENGTH,
|
|
25
23
|
getBluetoothServiceUuids,
|
|
26
24
|
getInfosForServiceUuid,
|
|
27
|
-
IOS_PACKET_LENGTH,
|
|
28
|
-
ANDROID_PACKET_LENGTH,
|
|
29
25
|
} from './constants';
|
|
30
26
|
import { isHeaderChunk } from './utils/validateNotify';
|
|
31
27
|
import BleTransport from './BleTransport';
|
|
32
28
|
import timer from './utils/timer';
|
|
29
|
+
|
|
30
|
+
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
31
|
+
import type { Characteristic, Device } from 'react-native-ble-plx';
|
|
32
|
+
import type EventEmitter from 'events';
|
|
33
33
|
import type { BleAcquireInput, TransportOptions } from './types';
|
|
34
34
|
|
|
35
35
|
const { check, buildBuffers, receiveOne, parseConfigure } = transport;
|
|
@@ -42,6 +42,8 @@ let connectOptions: Record<string, unknown> = {
|
|
|
42
42
|
refreshGatt: 'OnConnected',
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
export type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
|
|
46
|
+
|
|
45
47
|
const tryToGetConfiguration = (device: Device) => {
|
|
46
48
|
if (!device || !device.serviceUUIDs) return null;
|
|
47
49
|
const [serviceUUID] = device.serviceUUIDs;
|
|
@@ -133,8 +135,8 @@ export default class ReactNativeBleTransport {
|
|
|
133
135
|
*/
|
|
134
136
|
async enumerate() {
|
|
135
137
|
// eslint-disable-next-line no-async-promise-executor
|
|
136
|
-
return new Promise<
|
|
137
|
-
const deviceList:
|
|
138
|
+
return new Promise<IOneKeyDevice[]>(async (resolve, reject) => {
|
|
139
|
+
const deviceList: IOneKeyDevice[] = [];
|
|
138
140
|
const blePlxManager = await this.getPlxManager();
|
|
139
141
|
try {
|
|
140
142
|
await subscribeBleOn(blePlxManager);
|
|
@@ -213,7 +215,7 @@ export default class ReactNativeBleTransport {
|
|
|
213
215
|
|
|
214
216
|
const addDevice = (device: Device) => {
|
|
215
217
|
if (deviceList.every(d => d.id !== device.id)) {
|
|
216
|
-
deviceList.push(device);
|
|
218
|
+
deviceList.push({ ...device, commType: 'ble' } as IOneKeyDevice);
|
|
217
219
|
}
|
|
218
220
|
};
|
|
219
221
|
|