@onekeyfe/hd-transport-react-native 1.1.27-alpha.41 → 1.1.27-alpha.6

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/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { ProtocolType } from '@onekeyfe/hd-transport';
2
1
  export type { BleManager as BlePlxManager } from 'react-native-ble-plx';
3
2
  export type TransportOptions = {
4
3
  scanTimeout?: number;
@@ -6,6 +5,5 @@ export type TransportOptions = {
6
5
  export type BleAcquireInput = {
7
6
  uuid: string;
8
7
  forceCleanRunPromise?: boolean;
9
- expectedProtocol?: ProtocolType;
10
8
  };
11
9
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,YAAY,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAExE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,YAAY,CAAC;CACjC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAExE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.1.27-alpha.41",
3
+ "version": "1.1.27-alpha.6",
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.41",
23
- "@onekeyfe/hd-shared": "1.1.27-alpha.41",
24
- "@onekeyfe/hd-transport": "1.1.27-alpha.41",
22
+ "@onekeyfe/hd-core": "1.1.27-alpha.6",
23
+ "@onekeyfe/hd-shared": "1.1.27-alpha.6",
24
+ "@onekeyfe/hd-transport": "1.1.27-alpha.6",
25
25
  "@onekeyfe/react-native-ble-utils": "^0.1.4",
26
26
  "react-native-ble-plx": "3.5.1"
27
27
  },
28
- "gitHead": "09cece9f0c9d85f55ae2f7f0458ed7d8833483d2"
28
+ "gitHead": "a1fb7786313ccee4b1e570c53ae2c05a96f785df"
29
29
  }
package/src/BleManager.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import BleUtils from '@onekeyfe/react-native-ble-utils';
2
2
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
+ import { LoggerNames, getLogger } from '@onekeyfe/hd-core';
3
4
 
4
5
  import type { Peripheral } from '@onekeyfe/react-native-ble-utils';
5
6
 
6
- import { bleLogger } from './logger';
7
-
8
- const Logger = bleLogger;
7
+ const Logger = getLogger(LoggerNames.HdBleTransport);
9
8
 
10
9
  /**
11
10
  * get the device basic info of connected devices
@@ -21,35 +20,36 @@ export const pairDevice = (macAddress: string) => BleUtils.pairDevice(macAddress
21
20
 
22
21
  export const onDeviceBondState = (bleMacAddress: string): Promise<Peripheral | undefined> =>
23
22
  new Promise((resolve, reject) => {
24
- let timeout: ReturnType<typeof setTimeout> | undefined;
25
- let cleanupListener: (() => void) | undefined;
23
+ let timeout: any | undefined;
26
24
 
27
- const cleanup = () => {
25
+ const cleanup = (cleanupListener: (() => void) | undefined) => {
28
26
  if (timeout) {
29
27
  clearTimeout(timeout);
30
28
  }
31
29
  if (cleanupListener) cleanupListener();
32
30
  };
33
31
 
34
- timeout = setTimeout(() => {
35
- cleanup();
36
- reject(ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded'));
37
- }, 60 * 1000);
38
-
39
- cleanupListener = BleUtils.onDeviceBondState(peripheral => {
32
+ const cleanupListener = BleUtils.onDeviceBondState(peripheral => {
40
33
  if (peripheral.id?.toLowerCase() !== bleMacAddress.toLowerCase()) {
41
34
  return;
42
35
  }
43
36
  const { bondState } = peripheral;
44
37
 
38
+ if (bondState.preState === 'BOND_NONE' && bondState.state === 'BOND_BONDING') {
39
+ timeout = setTimeout(() => {
40
+ cleanup(cleanupListener);
41
+ reject(ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded'));
42
+ }, 60 * 1000);
43
+ }
44
+
45
45
  const hasBonded = bondState.preState === 'BOND_BONDING' && bondState.state === 'BOND_BONDED';
46
46
  const hasCanceled = bondState.preState === 'BOND_BONDING' && bondState.state === 'BOND_NONE';
47
47
  Logger.debug('onDeviceBondState bondState:', bondState);
48
48
  if (hasBonded) {
49
- cleanup();
49
+ cleanup(cleanupListener);
50
50
  resolve(peripheral);
51
51
  } else if (hasCanceled) {
52
- cleanup();
52
+ cleanup(cleanupListener);
53
53
  reject(ERRORS.TypedError(HardwareErrorCode.BleDeviceBondedCanceled, 'bonding canceled'));
54
54
  }
55
55
  });
@@ -1,11 +1,10 @@
1
1
  import { BleErrorCode } from 'react-native-ble-plx';
2
- import { wait } from '@onekeyfe/hd-shared';
2
+ import { LoggerNames, getLogger, wait } from '@onekeyfe/hd-core';
3
3
 
4
4
  import type { Characteristic, Device, Subscription } from 'react-native-ble-plx';
5
+ // import { wait } from '@onekeyfe/hd-core/src/utils';
5
6
 
6
- import { bleLogger } from './logger';
7
-
8
- const Log = bleLogger;
7
+ const Log = getLogger(LoggerNames.HdBleTransport);
9
8
 
10
9
  export default class BleTransport {
11
10
  id: string;
@@ -14,7 +13,7 @@ export default class BleTransport {
14
13
 
15
14
  device: Device;
16
15
 
17
- mtuSize = 23;
16
+ mtuSize = 20;
18
17
 
19
18
  writeCharacteristic: Characteristic;
20
19
 
@@ -24,10 +23,6 @@ export default class BleTransport {
24
23
 
25
24
  disconnectSubscription?: Subscription;
26
25
 
27
- notifyTransactionId?: string;
28
-
29
- monitorToken?: number;
30
-
31
26
  static MAX_RETRIES = 5;
32
27
 
33
28
  static RETRY_DELAY = 2000;
@@ -41,6 +36,7 @@ export default class BleTransport {
41
36
  this.device = device;
42
37
  this.writeCharacteristic = writeCharacteristic;
43
38
  this.notifyCharacteristic = notifyCharacteristic;
39
+ console.log(`BleTransport(${String(this.id)}) new instance`);
44
40
  }
45
41
 
46
42
  /**
package/src/constants.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export const IOS_PACKET_LENGTH = 128;
2
2
  export const ANDROID_PACKET_LENGTH = 192;
3
- export const ANDROID_DEFAULT_MTU = 23;
4
3
 
5
4
  type BluetoothServices = Record<
6
5
  string,
@@ -36,32 +35,9 @@ export const getInfosForServiceUuid = (serviceUuid: string, deviceType: 'classic
36
35
  if (!services) {
37
36
  return null;
38
37
  }
39
- const normalizedServiceUuid = normalizeBleUuid(serviceUuid);
40
- const service =
41
- services[serviceUuid] ??
42
- Object.values(services).find(
43
- item => normalizeBleUuid(item.serviceUuid) === normalizedServiceUuid
44
- );
38
+ const service = services[serviceUuid];
45
39
  if (!service) {
46
40
  return null;
47
41
  }
48
42
  return service;
49
43
  };
50
-
51
- export const normalizeBleUuid = (uuid?: string | null) =>
52
- (uuid ?? '').replace(/-/g, '').toLowerCase();
53
-
54
- export const getBleUuidKey = (uuid?: string | null) => {
55
- const normalized = normalizeBleUuid(uuid);
56
- return normalized.length >= 8 ? normalized.substring(4, 8) : normalized;
57
- };
58
-
59
- export const isSameBleUuid = (left?: string | null, right?: string | null) => {
60
- const normalizedLeft = normalizeBleUuid(left);
61
- const normalizedRight = normalizeBleUuid(right);
62
-
63
- return (
64
- normalizedLeft === normalizedRight ||
65
- (getBleUuidKey(left) !== '' && getBleUuidKey(left) === getBleUuidKey(right))
66
- );
67
- };