@onekeyfe/hd-transport-react-native 1.2.2-alpha.6 → 1.2.2-alpha.7

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.
@@ -11,7 +11,7 @@ export declare function resolveProtocolV2PacketCapacity({ platform, iosPacketLen
11
11
  mtu?: number | null;
12
12
  }): number;
13
13
  export declare function shouldRefreshNegotiatedMtu(mtu?: number | null): boolean;
14
- export declare function shouldWriteProtocolV2WithResponse({ platform, highThroughput, requestedWithResponse, characteristic, }: {
14
+ export declare function shouldWriteProtocolV2WithResponse({ requestedWithResponse, characteristic, }: {
15
15
  platform: BlePlatform;
16
16
  highThroughput: boolean;
17
17
  requestedWithResponse?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"bleStrategy.d.ts","sourceRoot":"","sources":["../src/bleStrategy.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,sBAAsB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,yBAAyB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,kBAAkB,WAEvE;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,QAAQ,EACR,eAA+C,EAC/C,mBAAuD,EACvD,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,UAMA;AAED,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,WAE7D;AAED,wBAAgB,iCAAiC,CAAC,EAChD,QAAQ,EACR,cAAc,EACd,qBAAqB,EACrB,cAAc,GACf,EAAE;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,cAAc,EAAE,kBAAkB,CAAC;CACpC,WAIA"}
1
+ {"version":3,"file":"bleStrategy.d.ts","sourceRoot":"","sources":["../src/bleStrategy.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,sBAAsB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,yBAAyB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,kBAAkB,WAEvE;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,QAAQ,EACR,eAA+C,EAC/C,mBAAuD,EACvD,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,UAMA;AAED,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,WAE7D;AAED,wBAAgB,iCAAiC,CAAC,EAChD,qBAAqB,EACrB,cAAc,GACf,EAAE;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,cAAc,EAAE,kBAAkB,CAAC;CACpC,WAIA"}
package/dist/index.js CHANGED
@@ -144,12 +144,12 @@ function resolveProtocolV2PacketCapacity({ platform, iosPacketLength = IOS_PROTO
144
144
  function shouldRefreshNegotiatedMtu(mtu) {
145
145
  return typeof mtu !== 'number' || !Number.isFinite(mtu) || mtu <= 23;
146
146
  }
147
- function shouldWriteProtocolV2WithResponse({ platform, highThroughput, requestedWithResponse, characteristic, }) {
147
+ function shouldWriteProtocolV2WithResponse({ requestedWithResponse, characteristic, }) {
148
148
  if (!characteristic.isWritableWithResponse)
149
149
  return false;
150
150
  if (!characteristic.isWritableWithoutResponse)
151
151
  return true;
152
- return requestedWithResponse === true || (platform === 'ios' && !highThroughput);
152
+ return requestedWithResponse === true;
153
153
  }
154
154
 
155
155
  const timer = process.env.NODE_ENV === 'development'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.2-alpha.6",
3
+ "version": "1.2.2-alpha.7",
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.6",
24
- "@onekeyfe/hd-shared": "1.2.2-alpha.6",
25
- "@onekeyfe/hd-transport": "1.2.2-alpha.6",
23
+ "@onekeyfe/hd-core": "1.2.2-alpha.7",
24
+ "@onekeyfe/hd-shared": "1.2.2-alpha.7",
25
+ "@onekeyfe/hd-transport": "1.2.2-alpha.7",
26
26
  "@onekeyfe/react-native-ble-utils": "^0.1.6",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "538d5371d9369747beabf68c5dc7a617531bace2"
29
+ "gitHead": "29b87f1c04fea60459d900ef1f61cb9f17eaa4d3"
30
30
  }
@@ -90,7 +90,7 @@ describe('React Native BLE strategy', () => {
90
90
  ).toBe(182);
91
91
  });
92
92
 
93
- test('uses withoutResponse for a high-volume write unless explicitly overridden', () => {
93
+ test('uses withoutResponse by default unless explicitly overridden', () => {
94
94
  const characteristic = {
95
95
  isWritableWithResponse: true,
96
96
  isWritableWithoutResponse: true,
@@ -99,8 +99,7 @@ describe('React Native BLE strategy', () => {
99
99
  expect(
100
100
  shouldWriteProtocolV2WithResponse({
101
101
  platform: 'ios',
102
- highThroughput: true,
103
- requestedWithResponse: false,
102
+ highThroughput: false,
104
103
  characteristic,
105
104
  })
106
105
  ).toBe(false);
@@ -436,7 +436,8 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
436
436
  protocolType: 'V2',
437
437
  });
438
438
  expect(device.requestMTU).toHaveBeenCalledWith(247);
439
- expect(writeCharacteristic.writeWithResponse.mock.calls.length).toBeGreaterThan(1);
439
+ expect(writeCharacteristic.writeWithResponse).toHaveBeenCalledTimes(1);
440
+ expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalled();
440
441
 
441
442
  await expect(
442
443
  transport.call(uuid, 'Ping', { message: 'first-core-command' })
@@ -795,7 +796,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
795
796
  });
796
797
  expect(device.requestMTU).toHaveBeenCalledTimes(3);
797
798
  expect((transport as any).getCachedTransport(uuid).mtuSize).toBeUndefined();
798
- expect(writeCharacteristic.writeWithResponse).toHaveBeenCalled();
799
+ expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalled();
799
800
  await transport.release(uuid, true);
800
801
  });
801
802
 
@@ -804,6 +805,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
804
805
  device.mtu = undefined;
805
806
 
806
807
  await transport.acquire({ uuid, expectedProtocol: 'V2' });
808
+ const writesBeforeFileWrite = writeCharacteristic.writeWithoutResponse.mock.calls.length;
807
809
  device.requestMTU.mockImplementationOnce(() => {
808
810
  device.mtu = 247;
809
811
  return Promise.resolve(device);
@@ -811,7 +813,9 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
811
813
 
812
814
  await expect(transport.call(uuid, 'FileWrite', {})).resolves.toBeDefined();
813
815
  expect(device.requestMTU).toHaveBeenCalledTimes(4);
814
- expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(1);
816
+ expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(
817
+ writesBeforeFileWrite + 1
818
+ );
815
819
  await transport.release(uuid, true);
816
820
  });
817
821
 
@@ -820,12 +824,13 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
820
824
  device.mtu = undefined;
821
825
 
822
826
  await transport.acquire({ uuid, expectedProtocol: 'V2' });
827
+ const writesBeforeFileWrite = writeCharacteristic.writeWithoutResponse.mock.calls.length;
823
828
 
824
829
  await expect(transport.call(uuid, 'FileWrite', {})).rejects.toMatchObject({
825
830
  errorCode: HardwareErrorCode.BleConnectedError,
826
831
  });
827
832
  expect(device.requestMTU).toHaveBeenCalledTimes(4);
828
- expect(writeCharacteristic.writeWithoutResponse).not.toHaveBeenCalled();
833
+ expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(writesBeforeFileWrite);
829
834
  await transport.release(uuid, true);
830
835
  });
831
836
 
@@ -945,19 +950,19 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
945
950
  await transport.release(uuid, true);
946
951
  });
947
952
 
948
- test('uses withResponse for consecutive iOS Protocol V2 control calls without releasing', async () => {
953
+ test('uses withoutResponse for consecutive iOS Protocol V2 control calls without releasing', async () => {
949
954
  const { transport, uuid, writeCharacteristic } = createHarness();
950
955
 
951
956
  await transport.acquire({ uuid, expectedProtocol: 'V2' });
952
957
  const releaseNative = jest.spyOn(transport as any, 'releaseNative');
953
- expect(writeCharacteristic.writeWithoutResponse).not.toHaveBeenCalled();
954
- expect(writeCharacteristic.writeWithResponse).toHaveBeenCalledTimes(1);
958
+ expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(1);
959
+ expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
955
960
 
956
961
  await transport.call(uuid, 'DeviceInfoGet', {});
957
962
  await transport.call(uuid, 'ProtocolInfoRequest', {});
958
963
 
959
- expect(writeCharacteristic.writeWithResponse).toHaveBeenCalledTimes(3);
960
- expect(writeCharacteristic.writeWithoutResponse).not.toHaveBeenCalled();
964
+ expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(3);
965
+ expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
961
966
  expect(releaseNative).not.toHaveBeenCalled();
962
967
 
963
968
  await transport.release(uuid, true);
@@ -970,8 +975,8 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
970
975
 
971
976
  await transport.call(uuid, 'FileWrite', {});
972
977
  await transport.call(uuid, 'FileWrite', {});
973
- expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(2);
974
- expect(writeCharacteristic.writeWithResponse).toHaveBeenCalledTimes(1);
978
+ expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(3);
979
+ expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
975
980
  expect(
976
981
  logger.debug.mock.calls.filter(
977
982
  ([message]) =>
@@ -1004,8 +1009,8 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
1004
1009
  await transport.acquire({ uuid, expectedProtocol: 'V2' });
1005
1010
 
1006
1011
  await transport.call(uuid, 'FileWrite', {}, { writeWithResponse: true });
1007
- expect(writeCharacteristic.writeWithResponse).toHaveBeenCalledTimes(2);
1008
- expect(writeCharacteristic.writeWithoutResponse).not.toHaveBeenCalled();
1012
+ expect(writeCharacteristic.writeWithResponse).toHaveBeenCalledTimes(1);
1013
+ expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(1);
1009
1014
  await transport.release(uuid, true);
1010
1015
  });
1011
1016
 
@@ -34,8 +34,6 @@ export function shouldRefreshNegotiatedMtu(mtu?: number | null) {
34
34
  }
35
35
 
36
36
  export function shouldWriteProtocolV2WithResponse({
37
- platform,
38
- highThroughput,
39
37
  requestedWithResponse,
40
38
  characteristic,
41
39
  }: {
@@ -46,5 +44,5 @@ export function shouldWriteProtocolV2WithResponse({
46
44
  }) {
47
45
  if (!characteristic.isWritableWithResponse) return false;
48
46
  if (!characteristic.isWritableWithoutResponse) return true;
49
- return requestedWithResponse === true || (platform === 'ios' && !highThroughput);
47
+ return requestedWithResponse === true;
50
48
  }