@onekeyfe/hd-transport-react-native 1.2.0-alpha.67 → 1.2.0-alpha.69
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/BleTransport.d.ts +1 -1
- package/dist/BleTransport.d.ts.map +1 -1
- package/dist/bleStrategy.d.ts +6 -0
- package/dist/bleStrategy.d.ts.map +1 -1
- package/dist/constants.d.ts +2 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +9 -80
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +271 -343
- package/jest.config.js +0 -5
- package/package.json +5 -5
- package/src/BleTransport.ts +7 -1
- package/src/__tests__/BleTransport.test.ts +54 -2
- package/src/__tests__/bleStrategy.test.ts +77 -7
- package/src/__tests__/enumerate.test.ts +132 -0
- package/src/__tests__/protocolV2Link.test.ts +384 -49
- package/src/bleStrategy.ts +23 -10
- package/src/constants.ts +2 -1
- package/src/index.ts +290 -476
- package/src/__tests__/connectTimeout.test.ts +0 -281
- package/src/__tests__/protocolReprobe.test.ts +0 -132
- package/src/__tests__/protocolV1SchemaFixture.ts +0 -39
- package/src/__tests__/staleCallTimeout.test.ts +0 -210
- package/src/__tests__/writePacketTimeout.test.ts +0 -305
package/src/bleStrategy.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ANDROID_PROTOCOL_V2_PACKET_LENGTH, IOS_PROTOCOL_V2_PACKET_LENGTH } from './constants';
|
|
2
2
|
|
|
3
3
|
export type BlePlatform = 'ios' | 'android' | string;
|
|
4
4
|
|
|
@@ -13,8 +13,8 @@ export function hasWritableCapability(characteristic: BleWriteCapability) {
|
|
|
13
13
|
|
|
14
14
|
export function resolveProtocolV2PacketCapacity({
|
|
15
15
|
platform,
|
|
16
|
-
iosPacketLength =
|
|
17
|
-
androidPacketLength =
|
|
16
|
+
iosPacketLength = IOS_PROTOCOL_V2_PACKET_LENGTH,
|
|
17
|
+
androidPacketLength = ANDROID_PROTOCOL_V2_PACKET_LENGTH,
|
|
18
18
|
mtu,
|
|
19
19
|
}: {
|
|
20
20
|
platform: BlePlatform;
|
|
@@ -22,14 +22,27 @@ export function resolveProtocolV2PacketCapacity({
|
|
|
22
22
|
androidPacketLength?: number;
|
|
23
23
|
mtu?: number | null;
|
|
24
24
|
}) {
|
|
25
|
-
if (
|
|
26
|
-
|
|
25
|
+
if (typeof mtu !== 'number' || !Number.isFinite(mtu) || mtu <= 3) {
|
|
26
|
+
throw new Error(`Protocol V2 BLE requires a negotiated MTU, received: ${String(mtu)}`);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const payloadLength = Math.floor(mtu) - 3;
|
|
30
|
+
const configuredPacketLength = platform === 'ios' ? iosPacketLength : androidPacketLength;
|
|
31
|
+
return Math.min(configuredPacketLength, payloadLength);
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
export function shouldWriteProtocolV2WithResponse({
|
|
35
|
+
platform,
|
|
36
|
+
highVolume,
|
|
37
|
+
requestedWithResponse,
|
|
38
|
+
characteristic,
|
|
39
|
+
}: {
|
|
40
|
+
platform: BlePlatform;
|
|
41
|
+
highVolume: boolean;
|
|
42
|
+
requestedWithResponse?: boolean;
|
|
43
|
+
characteristic: BleWriteCapability;
|
|
44
|
+
}) {
|
|
45
|
+
if (!characteristic.isWritableWithResponse) return false;
|
|
46
|
+
if (!characteristic.isWritableWithoutResponse) return true;
|
|
47
|
+
return requestedWithResponse === true || (platform === 'ios' && !highVolume);
|
|
35
48
|
}
|
package/src/constants.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { createKnownBleUuidAliases, matchesKnownBleUuid } from '@onekeyfe/hd-sha
|
|
|
2
2
|
|
|
3
3
|
export const IOS_PACKET_LENGTH = 128;
|
|
4
4
|
export const ANDROID_PACKET_LENGTH = 192;
|
|
5
|
-
export const
|
|
5
|
+
export const IOS_PROTOCOL_V2_PACKET_LENGTH = 244;
|
|
6
|
+
export const ANDROID_PROTOCOL_V2_PACKET_LENGTH = 514;
|
|
6
7
|
|
|
7
8
|
type BluetoothServices = Record<
|
|
8
9
|
string,
|