@onekeyfe/hd-transport-react-native 1.2.2-alpha.108 → 1.2.2-alpha.109

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.
@@ -5,5 +5,5 @@ export declare const pairDevice: (macAddress: string) => Promise<{
5
5
  bonded: boolean;
6
6
  bonding: boolean;
7
7
  }>;
8
- export declare const onDeviceBondState: (bleMacAddress: string) => Promise<Peripheral | undefined>;
8
+ export declare const onDeviceBondState: (bleMacAddress: string, signal?: AbortSignal) => Promise<Peripheral | undefined>;
9
9
  //# sourceMappingURL=BleManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BleManager.d.ts","sourceRoot":"","sources":["../src/BleManager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAsBnE,eAAO,MAAM,qBAAqB,iBAAkB,MAAM,EAAE,0BACZ,CAAC;AAEjD,eAAO,MAAM,gBAAgB,6BAAwC,CAAC;AAEtE,eAAO,MAAM,UAAU,eAAgB,MAAM;;;EAAoC,CAAC;AAElF,eAAO,MAAM,iBAAiB,kBAAmB,MAAM,KAAG,QAAQ,UAAU,GAAG,SAAS,CAwEpF,CAAC"}
1
+ {"version":3,"file":"BleManager.d.ts","sourceRoot":"","sources":["../src/BleManager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAsBnE,eAAO,MAAM,qBAAqB,iBAAkB,MAAM,EAAE,0BACZ,CAAC;AAEjD,eAAO,MAAM,gBAAgB,6BAAwC,CAAC;AAEtE,eAAO,MAAM,UAAU,eAAgB,MAAM;;;EAAoC,CAAC;AAElF,eAAO,MAAM,iBAAiB,kBACb,MAAM,WACZ,WAAW,KACnB,QAAQ,UAAU,GAAG,SAAS,CAmF7B,CAAC"}
package/dist/index.d.ts CHANGED
@@ -109,6 +109,7 @@ declare class ReactNativeBleTransport {
109
109
  name: string;
110
110
  configured: boolean;
111
111
  stopped: boolean;
112
+ private readonly bondAbortController;
112
113
  scanTimeout: number;
113
114
  runPromise: Deferred<any> | null;
114
115
  private runPromiseDeviceId;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAGL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AAgChC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,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;AAEjE,KAAK,8BAA8B,GAAG,eAAe,GAAG;IAMtD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAkBF,KAAK,4BAA4B,GAAG,WAAW,CAAC;AAChD,KAAK,0BAA0B,GAAG;IAChC,mBAAmB,EAAE,cAAc,CAAC;IACpC,oBAAoB,EAAE,cAAc,CAAC;CACtC,CAAC;AAkCF,eAAO,MAAM,+BAA+B,UACnC,OAAO,KACb,4BAA4B,GAAG,IAsBjC,CAAC;AAcF,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAClD,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AAwBpD,eAAO,MAAM,yCAAyC,IAAI,CAAC;AAI3D,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAiBF,wBAAgB,4BA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leUtils__default["default"].getConnectedPeripherals(serviceUuids);
72
72
  const pairDevice = (macAddress) => BleUtils__default["default"].pairDevice(macAddress);
73
- const onDeviceBondState = (bleMacAddress) => new Promise((resolve, reject) => {
73
+ const onDeviceBondState = (bleMacAddress, signal) => new Promise((resolve, reject) => {
74
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
75
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected));
76
+ return;
77
+ }
74
78
  const cleanup = () => {
75
79
  if (timeout) {
76
80
  clearTimeout(timeout);
77
81
  }
78
82
  if (cleanupListener)
79
83
  cleanupListener();
84
+ signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
85
+ };
86
+ const onAbort = () => {
87
+ cleanup();
88
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected));
80
89
  };
90
+ signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', onAbort, { once: true });
81
91
  const timeout = setTimeout(() => {
82
92
  cleanup();
83
93
  reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'Bluetooth pairing timed out', {
@@ -489,6 +499,7 @@ class ReactNativeBleTransport {
489
499
  this.name = 'ReactNativeBleTransport';
490
500
  this.configured = false;
491
501
  this.stopped = false;
502
+ this.bondAbortController = new AbortController();
492
503
  this.scanTimeout = DEVICE_SCAN_TIMEOUT_MS;
493
504
  this.runPromise = null;
494
505
  this.runPromiseDeviceId = null;
@@ -1025,7 +1036,7 @@ class ReactNativeBleTransport {
1025
1036
  try {
1026
1037
  const bondState = yield pairDevice(uuid);
1027
1038
  if (bondState.bonding) {
1028
- yield onDeviceBondState(uuid);
1039
+ yield onDeviceBondState(uuid, this.bondAbortController.signal);
1029
1040
  }
1030
1041
  else if (!bondState.bonded) {
1031
1042
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
@@ -1601,6 +1612,7 @@ class ReactNativeBleTransport {
1601
1612
  if (this.stopPromise)
1602
1613
  return this.stopPromise;
1603
1614
  this.stopped = true;
1615
+ this.bondAbortController.abort();
1604
1616
  const deviceIds = new Set([
1605
1617
  ...this.monitorTokens.keys(),
1606
1618
  ...this.sessionProtocols.keys(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.2-alpha.108",
3
+ "version": "1.2.2-alpha.109",
4
4
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -20,11 +20,11 @@
20
20
  "lint:fix": "eslint . --fix"
21
21
  },
22
22
  "dependencies": {
23
- "@onekeyfe/hd-core": "1.2.2-alpha.108",
24
- "@onekeyfe/hd-shared": "1.2.2-alpha.108",
25
- "@onekeyfe/hd-transport": "1.2.2-alpha.108",
23
+ "@onekeyfe/hd-core": "1.2.2-alpha.109",
24
+ "@onekeyfe/hd-shared": "1.2.2-alpha.109",
25
+ "@onekeyfe/hd-transport": "1.2.2-alpha.109",
26
26
  "@onekeyfe/react-native-ble-utils": "0.1.6",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "962db9ecea348976a93de3c3039ac171ca0086d8"
29
+ "gitHead": "4ee0588f08abdde1c72b8044091a76106e4770c4"
30
30
  }
package/src/BleManager.ts CHANGED
@@ -32,14 +32,28 @@ export const getBondedDevices = () => BleUtils.getBondedPeripherals();
32
32
 
33
33
  export const pairDevice = (macAddress: string) => BleUtils.pairDevice(macAddress);
34
34
 
35
- export const onDeviceBondState = (bleMacAddress: string): Promise<Peripheral | undefined> =>
35
+ export const onDeviceBondState = (
36
+ bleMacAddress: string,
37
+ signal?: AbortSignal
38
+ ): Promise<Peripheral | undefined> =>
36
39
  new Promise((resolve, reject) => {
40
+ if (signal?.aborted) {
41
+ reject(ERRORS.TypedError(HardwareErrorCode.BleDeviceDisconnected));
42
+ return;
43
+ }
37
44
  const cleanup = () => {
38
45
  if (timeout) {
39
46
  clearTimeout(timeout);
40
47
  }
41
48
  if (cleanupListener) cleanupListener();
49
+ signal?.removeEventListener('abort', onAbort);
42
50
  };
51
+ const onAbort = () => {
52
+ cleanup();
53
+ reject(ERRORS.TypedError(HardwareErrorCode.BleDeviceDisconnected));
54
+ };
55
+
56
+ signal?.addEventListener('abort', onAbort, { once: true });
43
57
 
44
58
  const timeout = setTimeout(() => {
45
59
  cleanup();
@@ -127,6 +127,32 @@ describe('Android bond failure reasons', () => {
127
127
  expect(cleanup).toHaveBeenCalledTimes(1);
128
128
  });
129
129
 
130
+ test('aborts the bond wait and removes its listener and deadline', async () => {
131
+ const controller = new AbortController();
132
+ const result = onDeviceBondState(UUID, controller.signal);
133
+ const rejection = expect(result).rejects.toMatchObject({
134
+ errorCode: HardwareErrorCode.BleDeviceDisconnected,
135
+ });
136
+
137
+ controller.abort();
138
+
139
+ await rejection;
140
+ expect(cleanup).toHaveBeenCalledTimes(1);
141
+ expect(jest.getTimerCount()).toBe(0);
142
+ });
143
+
144
+ test('does not subscribe when the transport stopped before the bond wait starts', async () => {
145
+ const controller = new AbortController();
146
+ controller.abort();
147
+ const subscribe = jest.spyOn(BleUtils, 'onDeviceBondState').mockClear();
148
+
149
+ await expect(onDeviceBondState(UUID, controller.signal)).rejects.toMatchObject({
150
+ errorCode: HardwareErrorCode.BleDeviceDisconnected,
151
+ });
152
+ expect(subscribe).not.toHaveBeenCalled();
153
+ expect(jest.getTimerCount()).toBe(0);
154
+ });
155
+
130
156
  test('ignores other devices and clears the deadline after bonding succeeds', async () => {
131
157
  const result = onDeviceBondState(UUID);
132
158
  const otherPeripheral = {
@@ -336,6 +362,41 @@ describe('BLE connect timeout', () => {
336
362
  });
337
363
  });
338
364
 
365
+ test.each(['V1', 'V2'] as const)(
366
+ 'stop completes while Android %s bonding remains pending',
367
+ async expectedProtocol => {
368
+ Object.assign(Platform, { OS: 'android' });
369
+ const { transport, bleManager, connect } = createHarness(() => Promise.resolve());
370
+ jest.spyOn(BleUtils, 'pairDevice').mockResolvedValueOnce({ bonded: false, bonding: true });
371
+ const listening = createDeferred<void>();
372
+ const cleanup = jest.fn();
373
+ jest.spyOn(BleUtils, 'onDeviceBondState').mockImplementationOnce(() => {
374
+ listening.resolve();
375
+ return cleanup;
376
+ });
377
+ const acquiring = transport.acquire({ uuid: UUID, expectedProtocol });
378
+ const rejection = expect(acquiring).rejects.toMatchObject({
379
+ errorCode: HardwareErrorCode.BleDeviceDisconnected,
380
+ });
381
+ await listening.promise;
382
+
383
+ // Advance only the existing 100ms disconnect drain, not the bond deadline.
384
+ let stopped = false;
385
+ const stopping = transport.stop().then(() => {
386
+ stopped = true;
387
+ });
388
+ await advanceUntil(() => stopped, 1000);
389
+ expect(stopped).toBe(true);
390
+ await stopping;
391
+
392
+ await rejection;
393
+ expect(cleanup).toHaveBeenCalledTimes(1);
394
+ expect(jest.getTimerCount()).toBe(0);
395
+ expect(bleManager.devices).not.toHaveBeenCalled();
396
+ expect(connect).not.toHaveBeenCalled();
397
+ }
398
+ );
399
+
339
400
  test('stop rejects a pending read and waits for native disconnection without destroying the shared manager', async () => {
340
401
  const { transport, bleManager } = createHarness(() => Promise.resolve());
341
402
  const nativeDisconnect = createDeferred<void>();
package/src/index.ts CHANGED
@@ -380,6 +380,8 @@ export default class ReactNativeBleTransport {
380
380
 
381
381
  stopped = false;
382
382
 
383
+ private readonly bondAbortController = new AbortController();
384
+
383
385
  scanTimeout = DEVICE_SCAN_TIMEOUT_MS;
384
386
 
385
387
  runPromise: Deferred<any> | null = null;
@@ -1061,7 +1063,7 @@ export default class ReactNativeBleTransport {
1061
1063
  try {
1062
1064
  const bondState = await pairDevice(uuid);
1063
1065
  if (bondState.bonding) {
1064
- await onDeviceBondState(uuid);
1066
+ await onDeviceBondState(uuid, this.bondAbortController.signal);
1065
1067
  } else if (!bondState.bonded) {
1066
1068
  throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
1067
1069
  }
@@ -1788,6 +1790,8 @@ export default class ReactNativeBleTransport {
1788
1790
  stop() {
1789
1791
  if (this.stopPromise) return this.stopPromise;
1790
1792
  this.stopped = true;
1793
+ // Bonding precedes GATT, so cancelDeviceConnection cannot end this wait.
1794
+ this.bondAbortController.abort();
1791
1795
  const deviceIds = new Set([
1792
1796
  ...this.monitorTokens.keys(),
1793
1797
  ...this.sessionProtocols.keys(),