@onekeyfe/hd-transport-react-native 1.2.8-alpha.12 → 1.2.8-alpha.120
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/index.d.ts +37 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +344 -21
- package/package.json +5 -5
- package/src/__tests__/enumerate.test.ts +139 -0
- package/src/__tests__/nativeFrameWrite.test.ts +910 -0
- package/src/__tests__/protocolV2Link.test.ts +107 -7
- package/src/index.ts +494 -40
|
@@ -12,6 +12,7 @@ import ReactNativeBleTransport, {
|
|
|
12
12
|
BLE_WRITE_PACKET_TIMEOUT_MS,
|
|
13
13
|
configureProtocolV2BleTuning,
|
|
14
14
|
getFirmwareUploadWriteRetryType,
|
|
15
|
+
getProtocolV2BleTuning,
|
|
15
16
|
resetProtocolV2BleTuning,
|
|
16
17
|
} from '../index';
|
|
17
18
|
|
|
@@ -821,7 +822,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
821
822
|
|
|
822
823
|
const acquiring = transport.acquire({ uuid });
|
|
823
824
|
const failure = expect(acquiring).rejects.toMatchObject({
|
|
824
|
-
errorCode: HardwareErrorCode.
|
|
825
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
825
826
|
});
|
|
826
827
|
const reconnecting = transport.acquire({ uuid, expectedProtocol: 'V2' });
|
|
827
828
|
|
|
@@ -860,7 +861,8 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
860
861
|
jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
|
|
861
862
|
|
|
862
863
|
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
863
|
-
errorCode: HardwareErrorCode.
|
|
864
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
865
|
+
params: { expectedProtocol: 'V2' },
|
|
864
866
|
});
|
|
865
867
|
|
|
866
868
|
expect(device.cancelConnection).toHaveBeenCalledTimes(1);
|
|
@@ -876,10 +878,12 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
876
878
|
jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
|
|
877
879
|
|
|
878
880
|
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
879
|
-
errorCode: HardwareErrorCode.
|
|
881
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
882
|
+
params: { expectedProtocol: 'V2' },
|
|
880
883
|
});
|
|
881
884
|
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
882
|
-
errorCode: HardwareErrorCode.
|
|
885
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
886
|
+
params: { expectedProtocol: 'V2' },
|
|
883
887
|
});
|
|
884
888
|
|
|
885
889
|
expect(device.cancelConnection).toHaveBeenCalledTimes(2);
|
|
@@ -897,7 +901,8 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
897
901
|
jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
|
|
898
902
|
|
|
899
903
|
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
900
|
-
errorCode: HardwareErrorCode.
|
|
904
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
905
|
+
params: { expectedProtocol: 'V2' },
|
|
901
906
|
});
|
|
902
907
|
|
|
903
908
|
expect(device.cancelConnection).toHaveBeenCalledTimes(1);
|
|
@@ -1732,7 +1737,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
1732
1737
|
|
|
1733
1738
|
await expect(transport.acquire({ uuid })).rejects.toBeDefined();
|
|
1734
1739
|
await expect(transport.acquire({ uuid })).rejects.toMatchObject({
|
|
1735
|
-
errorCode: HardwareErrorCode.
|
|
1740
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
1736
1741
|
});
|
|
1737
1742
|
await transport.disconnect(uuid);
|
|
1738
1743
|
await transport.stop();
|
|
@@ -1840,7 +1845,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
1840
1845
|
jest.spyOn(transport as any, 'probeProtocolV1').mockResolvedValue(false);
|
|
1841
1846
|
|
|
1842
1847
|
await expect(transport.acquire({ uuid, protocolHint: 'V2' })).rejects.toMatchObject({
|
|
1843
|
-
errorCode: HardwareErrorCode.
|
|
1848
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
1844
1849
|
});
|
|
1845
1850
|
|
|
1846
1851
|
expect(device.onDisconnected).not.toHaveBeenCalled();
|
|
@@ -2086,6 +2091,101 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
2086
2091
|
expect(device.requestConnectionPriority).toHaveBeenLastCalledWith(0);
|
|
2087
2092
|
});
|
|
2088
2093
|
|
|
2094
|
+
describe('Android connection priority by API level', () => {
|
|
2095
|
+
const setPlatformVersion = (version: number | undefined) => {
|
|
2096
|
+
const reactNative: { Platform: { Version?: number } } = jest.requireMock('react-native');
|
|
2097
|
+
reactNative.Platform.Version = version;
|
|
2098
|
+
};
|
|
2099
|
+
|
|
2100
|
+
afterEach(() => {
|
|
2101
|
+
setPlatformVersion(undefined);
|
|
2102
|
+
});
|
|
2103
|
+
|
|
2104
|
+
const runHighVolumeCalls = async (harness: ReturnType<typeof createHarness>) => {
|
|
2105
|
+
await harness.transport.acquire({ uuid: harness.uuid, expectedProtocol: 'V2' });
|
|
2106
|
+
await harness.transport.call(harness.uuid, 'FileWrite', {});
|
|
2107
|
+
await harness.transport.call(harness.uuid, 'FileWrite', {});
|
|
2108
|
+
};
|
|
2109
|
+
|
|
2110
|
+
const createAndroidHarness = (apiLevel: number) => {
|
|
2111
|
+
setPlatformOS('android');
|
|
2112
|
+
setPlatformVersion(apiLevel);
|
|
2113
|
+
const harness = createHarness();
|
|
2114
|
+
harness.device.mtu = 517;
|
|
2115
|
+
return harness;
|
|
2116
|
+
};
|
|
2117
|
+
|
|
2118
|
+
test('leaves the priority to the peripheral on Android 17 by default', async () => {
|
|
2119
|
+
const harness = createAndroidHarness(37);
|
|
2120
|
+
|
|
2121
|
+
await runHighVolumeCalls(harness);
|
|
2122
|
+
await harness.transport.release(harness.uuid, true);
|
|
2123
|
+
|
|
2124
|
+
expect(harness.device.requestConnectionPriority).not.toHaveBeenCalled();
|
|
2125
|
+
expect(
|
|
2126
|
+
harness.logger.debug.mock.calls.filter(
|
|
2127
|
+
([message]) =>
|
|
2128
|
+
message ===
|
|
2129
|
+
'[ReactNativeBleTransport] Android BLE connection priority left to peripheral'
|
|
2130
|
+
)
|
|
2131
|
+
).toHaveLength(1);
|
|
2132
|
+
});
|
|
2133
|
+
|
|
2134
|
+
test('keeps requesting HIGH below Android 17 by default', async () => {
|
|
2135
|
+
const harness = createAndroidHarness(36);
|
|
2136
|
+
|
|
2137
|
+
await runHighVolumeCalls(harness);
|
|
2138
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledTimes(1);
|
|
2139
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledWith(1);
|
|
2140
|
+
|
|
2141
|
+
await harness.transport.release(harness.uuid, true);
|
|
2142
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenLastCalledWith(0);
|
|
2143
|
+
});
|
|
2144
|
+
|
|
2145
|
+
test.each([
|
|
2146
|
+
[37, true],
|
|
2147
|
+
[36, false],
|
|
2148
|
+
] as const)('applies the tuning switch on API %s when set to %s', async (apiLevel, setting) => {
|
|
2149
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: setting });
|
|
2150
|
+
const harness = createAndroidHarness(apiLevel);
|
|
2151
|
+
|
|
2152
|
+
await runHighVolumeCalls(harness);
|
|
2153
|
+
|
|
2154
|
+
if (setting) {
|
|
2155
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledWith(1);
|
|
2156
|
+
} else {
|
|
2157
|
+
expect(harness.device.requestConnectionPriority).not.toHaveBeenCalled();
|
|
2158
|
+
}
|
|
2159
|
+
await harness.transport.release(harness.uuid, true);
|
|
2160
|
+
});
|
|
2161
|
+
|
|
2162
|
+
test('keeps the switch across unrelated tuning and ignores invalid values', () => {
|
|
2163
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe('auto');
|
|
2164
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: false });
|
|
2165
|
+
configureProtocolV2BleTuning({ androidPacketLength: 200 });
|
|
2166
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe(false);
|
|
2167
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: 'on' as never });
|
|
2168
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe(false);
|
|
2169
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: 'auto' });
|
|
2170
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe('auto');
|
|
2171
|
+
});
|
|
2172
|
+
|
|
2173
|
+
test('requests HIGH again on the next link after a manual disconnect', async () => {
|
|
2174
|
+
const harness = createAndroidHarness(36);
|
|
2175
|
+
|
|
2176
|
+
await runHighVolumeCalls(harness);
|
|
2177
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledTimes(1);
|
|
2178
|
+
|
|
2179
|
+
await harness.transport.disconnect(harness.uuid);
|
|
2180
|
+
await runHighVolumeCalls(harness);
|
|
2181
|
+
|
|
2182
|
+
expect(
|
|
2183
|
+
harness.device.requestConnectionPriority.mock.calls.filter(([priority]) => priority === 1)
|
|
2184
|
+
).toHaveLength(2);
|
|
2185
|
+
await harness.transport.release(harness.uuid, true);
|
|
2186
|
+
});
|
|
2187
|
+
});
|
|
2188
|
+
|
|
2089
2189
|
test('uses withResponse for an iOS Protocol V2 firmware file write when requested', async () => {
|
|
2090
2190
|
const { transport, uuid, writeCharacteristic } = createHarness();
|
|
2091
2191
|
|