@onekeyfe/hd-transport-react-native 1.2.0-alpha.58 → 1.2.0-alpha.59

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.
@@ -1 +1 @@
1
- {"version":3,"file":"BleTransport.d.ts","sourceRoot":"","sources":["../src/BleTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEjF,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,IAAI,SAA6B;IAEjC,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,SAAM;IAEb,mBAAmB,EAAE,cAAc,CAAC;IAEpC,oBAAoB,EAAE,cAAc,CAAC;IAErC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAElC,sBAAsB,CAAC,EAAE,YAAY,CAAC;IAEtC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,YAAY,CAAC,EAAE,MAAM,CAAC;gBAGpB,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,cAAc,EACnC,oBAAoB,EAAE,cAAc;IAQhC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlD"}
1
+ {"version":3,"file":"BleTransport.d.ts","sourceRoot":"","sources":["../src/BleTransport.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEjF,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,IAAI,SAA6B;IAEjC,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,SAAM;IAEb,mBAAmB,EAAE,cAAc,CAAC;IAEpC,oBAAoB,EAAE,cAAc,CAAC;IAErC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAElC,sBAAsB,CAAC,EAAE,YAAY,CAAC;IAEtC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,YAAY,CAAC,EAAE,MAAM,CAAC;gBAGpB,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,cAAc,EACnC,oBAAoB,EAAE,cAAc;IAQhC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOlD"}
package/dist/index.js CHANGED
@@ -210,7 +210,11 @@ class BleTransport {
210
210
  }
211
211
  writeWithRetry(data) {
212
212
  return __awaiter(this, void 0, void 0, function* () {
213
- yield this.writeCharacteristic.writeWithResponse(data);
213
+ if (reactNative.Platform.OS === 'ios' && this.writeCharacteristic.isWritableWithResponse) {
214
+ yield this.writeCharacteristic.writeWithResponse(data);
215
+ return;
216
+ }
217
+ yield this.writeCharacteristic.writeWithoutResponse(data);
214
218
  });
215
219
  }
216
220
  }
@@ -1120,7 +1124,7 @@ class ReactNativeBleTransport {
1120
1124
  let attempt = 0;
1121
1125
  while (true) {
1122
1126
  try {
1123
- yield transport.writeCharacteristic.writeWithResponse(data);
1127
+ yield transport.writeWithRetry(data);
1124
1128
  return;
1125
1129
  }
1126
1130
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.0-alpha.58",
3
+ "version": "1.2.0-alpha.59",
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.0-alpha.58",
24
- "@onekeyfe/hd-shared": "1.2.0-alpha.58",
25
- "@onekeyfe/hd-transport": "1.2.0-alpha.58",
23
+ "@onekeyfe/hd-core": "1.2.0-alpha.59",
24
+ "@onekeyfe/hd-shared": "1.2.0-alpha.59",
25
+ "@onekeyfe/hd-transport": "1.2.0-alpha.59",
26
26
  "@onekeyfe/react-native-ble-utils": "^0.1.6",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "43c11efeb7001741d4258c855b287993bc0a798e"
29
+ "gitHead": "98794c3032aab55e13fb2afedc645d8281141d5f"
30
30
  }
@@ -1,3 +1,5 @@
1
+ import { Platform } from 'react-native';
2
+
1
3
  import type { Characteristic, Device, Subscription } from 'react-native-ble-plx';
2
4
 
3
5
  export default class BleTransport {
@@ -33,6 +35,10 @@ export default class BleTransport {
33
35
  }
34
36
 
35
37
  async writeWithRetry(data: string): Promise<void> {
36
- await this.writeCharacteristic.writeWithResponse(data);
38
+ if (Platform.OS === 'ios' && this.writeCharacteristic.isWritableWithResponse) {
39
+ await this.writeCharacteristic.writeWithResponse(data);
40
+ return;
41
+ }
42
+ await this.writeCharacteristic.writeWithoutResponse(data);
37
43
  }
38
44
  }
@@ -1,7 +1,16 @@
1
1
  import { BleErrorCode } from 'react-native-ble-plx';
2
+ import { Platform } from 'react-native';
2
3
 
3
4
  import BleTransport from '../BleTransport';
4
5
 
6
+ jest.mock(
7
+ 'react-native',
8
+ () => ({
9
+ Platform: { OS: 'ios' },
10
+ }),
11
+ { virtual: true }
12
+ );
13
+
5
14
  jest.mock(
6
15
  'react-native-ble-plx',
7
16
  () => ({
@@ -19,12 +28,18 @@ jest.mock('@onekeyfe/hd-shared', () => ({
19
28
  }));
20
29
 
21
30
  describe('BleTransport side-effecting writes', () => {
31
+ beforeEach(() => {
32
+ Platform.OS = 'ios';
33
+ });
34
+
22
35
  test('does not reconnect or replay after the device disconnects', async () => {
23
36
  const error = Object.assign(new Error('device disconnected'), {
24
37
  errorCode: BleErrorCode.DeviceDisconnected,
25
38
  });
26
39
  const writeCharacteristic = {
40
+ isWritableWithResponse: true,
27
41
  writeWithResponse: jest.fn(() => Promise.reject(error)),
42
+ writeWithoutResponse: jest.fn(() => Promise.resolve()),
28
43
  };
29
44
  const device = {
30
45
  id: 'classic-id',
@@ -38,4 +53,41 @@ describe('BleTransport side-effecting writes', () => {
38
53
  expect(writeCharacteristic.writeWithResponse).toHaveBeenCalledTimes(1);
39
54
  expect(device.connect).not.toHaveBeenCalled();
40
55
  });
56
+
57
+ test('keeps Android Protocol V1 writes on writeWithoutResponse', async () => {
58
+ Platform.OS = 'android';
59
+ const writeCharacteristic = {
60
+ isWritableWithResponse: true,
61
+ writeWithResponse: jest.fn(() => Promise.resolve()),
62
+ writeWithoutResponse: jest.fn(() => Promise.resolve()),
63
+ };
64
+ const transport = new BleTransport(
65
+ { id: 'classic-id' } as any,
66
+ writeCharacteristic as any,
67
+ {} as any
68
+ );
69
+
70
+ await transport.writeWithRetry('payload');
71
+
72
+ expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
73
+ expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledWith('payload');
74
+ });
75
+
76
+ test('uses writeWithoutResponse on iOS when the characteristic lacks response support', async () => {
77
+ const writeCharacteristic = {
78
+ isWritableWithResponse: false,
79
+ writeWithResponse: jest.fn(() => Promise.resolve()),
80
+ writeWithoutResponse: jest.fn(() => Promise.resolve()),
81
+ };
82
+ const transport = new BleTransport(
83
+ { id: 'classic-id' } as any,
84
+ writeCharacteristic as any,
85
+ {} as any
86
+ );
87
+
88
+ await transport.writeWithRetry('payload');
89
+
90
+ expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
91
+ expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledWith('payload');
92
+ });
41
93
  });
package/src/index.ts CHANGED
@@ -1223,7 +1223,7 @@ export default class ReactNativeBleTransport {
1223
1223
  // eslint-disable-next-line no-constant-condition
1224
1224
  while (true) {
1225
1225
  try {
1226
- await transport.writeCharacteristic.writeWithResponse(data);
1226
+ await transport.writeWithRetry(data);
1227
1227
  return;
1228
1228
  } catch (error) {
1229
1229
  const retryType = getFirmwareUploadWriteRetryType(error);