@onekeyfe/hd-transport-react-native 1.2.0-alpha.146 → 1.2.0-alpha.148
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 +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -4
- package/package.json +5 -5
- package/src/__tests__/connectTimeout.test.ts +19 -8
- package/src/index.ts +33 -5
package/dist/index.d.ts
CHANGED
|
@@ -91,6 +91,7 @@ declare const BLE_GATT_SETUP_TIMEOUT_MS = 10000;
|
|
|
91
91
|
declare const PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = 3;
|
|
92
92
|
/** BLE setup timeouts since the last successful setup before the manager is recreated. */
|
|
93
93
|
declare const BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
|
|
94
|
+
declare const BLE_SETUP_WEDGED_MESSAGE = "BLE setup wedged repeatedly";
|
|
94
95
|
type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
|
|
95
96
|
declare class ReactNativeBleTransport {
|
|
96
97
|
blePlxManager: BleManager | undefined;
|
|
@@ -181,8 +182,10 @@ declare class ReactNativeBleTransport {
|
|
|
181
182
|
* Give up on a BLE setup operation the native layer did not settle. The abandoned
|
|
182
183
|
* operation still owns native connection/GATT state that can poison the next attempt,
|
|
183
184
|
* so it is cleared here without awaiting the same queue that stopped responding.
|
|
185
|
+
* Returns true when the manager itself was reset so the caller can stop Core retries.
|
|
184
186
|
*/
|
|
185
187
|
private abandonStalledConnection;
|
|
188
|
+
private createWedgedBleSetupError;
|
|
186
189
|
private getCachedTransport;
|
|
187
190
|
/**
|
|
188
191
|
* Write one packet under a bounded budget. A write that never settles means the
|
|
@@ -226,4 +229,4 @@ declare class ReactNativeBleTransport {
|
|
|
226
229
|
getProtocolType(path: string): ProtocolType | undefined;
|
|
227
230
|
}
|
|
228
231
|
|
|
229
|
-
export { BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD, BLE_CONNECT_TIMEOUT_MS, BLE_GATT_SETUP_TIMEOUT_MS, BLE_NATIVE_TEARDOWN_TIMEOUT_MS, BLE_WRITE_PACKET_TIMEOUT_MS, BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD, IOneKeyDevice, PROTOCOL_REPROBE_FALLBACK_ATTEMPTS, ProtocolV2BleTuning, configureProtocolV2BleTuning, ReactNativeBleTransport as default, getFirmwareUploadWriteRetryType, getProtocolV2BleTuning, resetProtocolV2BleTuning };
|
|
232
|
+
export { BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD, BLE_CONNECT_TIMEOUT_MS, BLE_GATT_SETUP_TIMEOUT_MS, BLE_NATIVE_TEARDOWN_TIMEOUT_MS, BLE_SETUP_WEDGED_MESSAGE, BLE_WRITE_PACKET_TIMEOUT_MS, BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD, IOneKeyDevice, PROTOCOL_REPROBE_FALLBACK_ATTEMPTS, ProtocolV2BleTuning, configureProtocolV2BleTuning, ReactNativeBleTransport as default, getFirmwareUploadWriteRetryType, getProtocolV2BleTuning, resetProtocolV2BleTuning };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAIL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AA0BhC,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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AAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;YAiBnB,qBAAqB;YA2DrB,oBAAoB;YAgCpB,cAAc;YAqEd,iCAAiC;IAiB/C,OAAO,CAAC,8BAA8B;YAQxB,mCAAmC;IAsBjD,OAAO,CAAC,yCAAyC;YAanC,gCAAgC;IAoB9C,OAAO,CAAC,uBAAuB;IAmD/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
|
@@ -333,9 +333,14 @@ const BLE_GATT_SETUP_TIMEOUT_MS = 10000;
|
|
|
333
333
|
const PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = 3;
|
|
334
334
|
const BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
|
|
335
335
|
const CONNECT_TIMEOUT_MESSAGE = 'BLE connect timeout after';
|
|
336
|
+
const BLE_SETUP_WEDGED_MESSAGE = 'BLE setup wedged repeatedly';
|
|
336
337
|
const isConnectTimeoutError = (error) => (error === null || error === void 0 ? void 0 : error.errorCode) === hdShared.HardwareErrorCode.BleConnectedError &&
|
|
337
338
|
typeof (error === null || error === void 0 ? void 0 : error.message) === 'string' &&
|
|
338
339
|
error.message.startsWith(CONNECT_TIMEOUT_MESSAGE);
|
|
340
|
+
const isWedgedBleSetupError = (error) => (error === null || error === void 0 ? void 0 : error.errorCode) === hdShared.HardwareErrorCode.PollingTimeout &&
|
|
341
|
+
typeof (error === null || error === void 0 ? void 0 : error.message) === 'string' &&
|
|
342
|
+
error.message.startsWith(BLE_SETUP_WEDGED_MESSAGE);
|
|
343
|
+
const shouldRethrowBleSetupError = (error) => isConnectTimeoutError(error) || isWedgedBleSetupError(error);
|
|
339
344
|
const isNativeOperationTimeoutError = (error) => (error === null || error === void 0 ? void 0 : error.errorCode) === reactNativeBlePlx.BleErrorCode.OperationTimedOut;
|
|
340
345
|
const tryToGetConfiguration = (device) => {
|
|
341
346
|
if (!device || !device.serviceUUIDs)
|
|
@@ -853,7 +858,7 @@ class ReactNativeBleTransport {
|
|
|
853
858
|
}
|
|
854
859
|
catch (e) {
|
|
855
860
|
Log === null || Log === void 0 ? void 0 : Log.debug('try to connect to device has error: ', e);
|
|
856
|
-
if (
|
|
861
|
+
if (shouldRethrowBleSetupError(e)) {
|
|
857
862
|
throw e;
|
|
858
863
|
}
|
|
859
864
|
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
|
|
@@ -881,7 +886,7 @@ class ReactNativeBleTransport {
|
|
|
881
886
|
}
|
|
882
887
|
catch (e) {
|
|
883
888
|
Log === null || Log === void 0 ? void 0 : Log.debug('not connected, try to connect to device has error: ', e);
|
|
884
|
-
if (
|
|
889
|
+
if (shouldRethrowBleSetupError(e)) {
|
|
885
890
|
throw e;
|
|
886
891
|
}
|
|
887
892
|
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
|
|
@@ -1493,7 +1498,10 @@ class ReactNativeBleTransport {
|
|
|
1493
1498
|
}
|
|
1494
1499
|
catch (error) {
|
|
1495
1500
|
if (timedOut || isNativeOperationTimeoutError(error)) {
|
|
1496
|
-
this.abandonStalledConnection(uuid, timedOut ? 'connect-backstop' : 'connect-native');
|
|
1501
|
+
const resetManager = this.abandonStalledConnection(uuid, timedOut ? 'connect-backstop' : 'connect-native');
|
|
1502
|
+
if (resetManager) {
|
|
1503
|
+
throw this.createWedgedBleSetupError();
|
|
1504
|
+
}
|
|
1497
1505
|
}
|
|
1498
1506
|
throw error;
|
|
1499
1507
|
}
|
|
@@ -1524,7 +1532,10 @@ class ReactNativeBleTransport {
|
|
|
1524
1532
|
}
|
|
1525
1533
|
catch (error) {
|
|
1526
1534
|
if (timedOut || isNativeOperationTimeoutError(error)) {
|
|
1527
|
-
this.abandonStalledConnection(uuid, timedOut ? 'gatt-backstop' : 'gatt-native');
|
|
1535
|
+
const resetManager = this.abandonStalledConnection(uuid, timedOut ? 'gatt-backstop' : 'gatt-native');
|
|
1536
|
+
if (resetManager) {
|
|
1537
|
+
throw this.createWedgedBleSetupError();
|
|
1538
|
+
}
|
|
1528
1539
|
}
|
|
1529
1540
|
throw error;
|
|
1530
1541
|
}
|
|
@@ -1556,7 +1567,12 @@ class ReactNativeBleTransport {
|
|
|
1556
1567
|
Log === null || Log === void 0 ? void 0 : Log.error('[ReactNativeBleTransport] BLE setup wedged repeatedly, resetting BLE manager');
|
|
1557
1568
|
this.resetPlxManager();
|
|
1558
1569
|
this.connectionSetupTimeoutCounts.delete(uuid);
|
|
1570
|
+
return true;
|
|
1559
1571
|
}
|
|
1572
|
+
return false;
|
|
1573
|
+
}
|
|
1574
|
+
createWedgedBleSetupError() {
|
|
1575
|
+
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingTimeout, BLE_SETUP_WEDGED_MESSAGE);
|
|
1560
1576
|
}
|
|
1561
1577
|
getCachedTransport(uuid) {
|
|
1562
1578
|
const transport = transportCache[uuid];
|
|
@@ -2179,6 +2195,7 @@ exports.BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = BLE_CONNECT_TIMEOUT_MANAGE
|
|
|
2179
2195
|
exports.BLE_CONNECT_TIMEOUT_MS = BLE_CONNECT_TIMEOUT_MS;
|
|
2180
2196
|
exports.BLE_GATT_SETUP_TIMEOUT_MS = BLE_GATT_SETUP_TIMEOUT_MS;
|
|
2181
2197
|
exports.BLE_NATIVE_TEARDOWN_TIMEOUT_MS = BLE_NATIVE_TEARDOWN_TIMEOUT_MS;
|
|
2198
|
+
exports.BLE_SETUP_WEDGED_MESSAGE = BLE_SETUP_WEDGED_MESSAGE;
|
|
2182
2199
|
exports.BLE_WRITE_PACKET_TIMEOUT_MS = BLE_WRITE_PACKET_TIMEOUT_MS;
|
|
2183
2200
|
exports.BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD = BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD;
|
|
2184
2201
|
exports.PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = PROTOCOL_REPROBE_FALLBACK_ATTEMPTS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.148",
|
|
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.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.148",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.148",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.148",
|
|
26
26
|
"@onekeyfe/react-native-ble-utils": "^0.1.6",
|
|
27
27
|
"react-native-ble-plx": "3.5.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "0538b18c48292741d9b7c29a87851227bc3e229b"
|
|
30
30
|
}
|
|
@@ -6,6 +6,7 @@ import ReactNativeBleTransport, {
|
|
|
6
6
|
BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD,
|
|
7
7
|
BLE_CONNECT_TIMEOUT_MS,
|
|
8
8
|
BLE_GATT_SETUP_TIMEOUT_MS,
|
|
9
|
+
BLE_SETUP_WEDGED_MESSAGE,
|
|
9
10
|
} from '../index';
|
|
10
11
|
import protocolV1Schema from './protocolV1SchemaFixture';
|
|
11
12
|
|
|
@@ -179,7 +180,7 @@ describe('BLE connect timeout', () => {
|
|
|
179
180
|
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(UUID);
|
|
180
181
|
});
|
|
181
182
|
|
|
182
|
-
test('repeated stalled connects recreate the BLE manager', async () => {
|
|
183
|
+
test('repeated stalled connects recreate the BLE manager and stop with PollingTimeout', async () => {
|
|
183
184
|
const { transport, bleManager } = createHarness(
|
|
184
185
|
() =>
|
|
185
186
|
new Promise(() => {
|
|
@@ -188,10 +189,12 @@ describe('BLE connect timeout', () => {
|
|
|
188
189
|
);
|
|
189
190
|
const destroy = jest.fn();
|
|
190
191
|
(bleManager as unknown as { destroy: jest.Mock }).destroy = destroy;
|
|
192
|
+
const errors: Array<{ errorCode?: unknown; message?: unknown }> = [];
|
|
191
193
|
|
|
192
194
|
for (let attempt = 0; attempt < BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD; attempt += 1) {
|
|
193
195
|
let settled = false;
|
|
194
|
-
transport.acquire({ uuid: UUID }).catch(
|
|
196
|
+
transport.acquire({ uuid: UUID }).catch(error => {
|
|
197
|
+
errors.push(error);
|
|
195
198
|
settled = true;
|
|
196
199
|
});
|
|
197
200
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -202,6 +205,11 @@ describe('BLE connect timeout', () => {
|
|
|
202
205
|
|
|
203
206
|
expect(destroy).toHaveBeenCalledTimes(1);
|
|
204
207
|
expect((transport as unknown as { blePlxManager?: unknown }).blePlxManager).toBeUndefined();
|
|
208
|
+
expect(errors[0]?.errorCode).toBe(HardwareErrorCode.BleConnectedError);
|
|
209
|
+
expect(errors[1]).toMatchObject({
|
|
210
|
+
errorCode: HardwareErrorCode.PollingTimeout,
|
|
211
|
+
message: BLE_SETUP_WEDGED_MESSAGE,
|
|
212
|
+
});
|
|
205
213
|
});
|
|
206
214
|
|
|
207
215
|
test('a recreated BLE manager starts with fresh timeout budgets for every device', () => {
|
|
@@ -224,12 +232,15 @@ describe('BLE connect timeout', () => {
|
|
|
224
232
|
errorCode: BleErrorCode.OperationTimedOut,
|
|
225
233
|
});
|
|
226
234
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
).
|
|
232
|
-
|
|
235
|
+
await expect(
|
|
236
|
+
(transport as any).connectWithTimeout(UUID, () => Promise.reject(nativeTimeout))
|
|
237
|
+
).rejects.toBe(nativeTimeout);
|
|
238
|
+
await expect(
|
|
239
|
+
(transport as any).connectWithTimeout(UUID, () => Promise.reject(nativeTimeout))
|
|
240
|
+
).rejects.toMatchObject({
|
|
241
|
+
errorCode: HardwareErrorCode.PollingTimeout,
|
|
242
|
+
message: BLE_SETUP_WEDGED_MESSAGE,
|
|
243
|
+
});
|
|
233
244
|
|
|
234
245
|
expect(destroy).toHaveBeenCalledTimes(1);
|
|
235
246
|
});
|
package/src/index.ts
CHANGED
|
@@ -254,10 +254,17 @@ export const PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = 3;
|
|
|
254
254
|
/** BLE setup timeouts since the last successful setup before the manager is recreated. */
|
|
255
255
|
export const BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
|
|
256
256
|
const CONNECT_TIMEOUT_MESSAGE = 'BLE connect timeout after';
|
|
257
|
+
export const BLE_SETUP_WEDGED_MESSAGE = 'BLE setup wedged repeatedly';
|
|
257
258
|
const isConnectTimeoutError = (error: unknown): boolean =>
|
|
258
259
|
(error as { errorCode?: unknown })?.errorCode === HardwareErrorCode.BleConnectedError &&
|
|
259
260
|
typeof (error as { message?: unknown })?.message === 'string' &&
|
|
260
261
|
(error as { message: string }).message.startsWith(CONNECT_TIMEOUT_MESSAGE);
|
|
262
|
+
const isWedgedBleSetupError = (error: unknown): boolean =>
|
|
263
|
+
(error as { errorCode?: unknown })?.errorCode === HardwareErrorCode.PollingTimeout &&
|
|
264
|
+
typeof (error as { message?: unknown })?.message === 'string' &&
|
|
265
|
+
(error as { message: string }).message.startsWith(BLE_SETUP_WEDGED_MESSAGE);
|
|
266
|
+
const shouldRethrowBleSetupError = (error: unknown): boolean =>
|
|
267
|
+
isConnectTimeoutError(error) || isWedgedBleSetupError(error);
|
|
261
268
|
const isNativeOperationTimeoutError = (error: unknown): boolean =>
|
|
262
269
|
(error as { errorCode?: unknown })?.errorCode === BleErrorCode.OperationTimedOut;
|
|
263
270
|
|
|
@@ -939,7 +946,7 @@ export default class ReactNativeBleTransport {
|
|
|
939
946
|
);
|
|
940
947
|
} catch (e) {
|
|
941
948
|
Log?.debug('try to connect to device has error: ', e);
|
|
942
|
-
if (
|
|
949
|
+
if (shouldRethrowBleSetupError(e)) {
|
|
943
950
|
throw e;
|
|
944
951
|
}
|
|
945
952
|
if (
|
|
@@ -973,7 +980,7 @@ export default class ReactNativeBleTransport {
|
|
|
973
980
|
);
|
|
974
981
|
} catch (e) {
|
|
975
982
|
Log?.debug('not connected, try to connect to device has error: ', e);
|
|
976
|
-
if (
|
|
983
|
+
if (shouldRethrowBleSetupError(e)) {
|
|
977
984
|
throw e;
|
|
978
985
|
}
|
|
979
986
|
if (
|
|
@@ -1754,7 +1761,13 @@ export default class ReactNativeBleTransport {
|
|
|
1754
1761
|
return result;
|
|
1755
1762
|
} catch (error) {
|
|
1756
1763
|
if (timedOut || isNativeOperationTimeoutError(error)) {
|
|
1757
|
-
this.abandonStalledConnection(
|
|
1764
|
+
const resetManager = this.abandonStalledConnection(
|
|
1765
|
+
uuid,
|
|
1766
|
+
timedOut ? 'connect-backstop' : 'connect-native'
|
|
1767
|
+
);
|
|
1768
|
+
if (resetManager) {
|
|
1769
|
+
throw this.createWedgedBleSetupError();
|
|
1770
|
+
}
|
|
1758
1771
|
}
|
|
1759
1772
|
throw error;
|
|
1760
1773
|
} finally {
|
|
@@ -1790,7 +1803,13 @@ export default class ReactNativeBleTransport {
|
|
|
1790
1803
|
return result;
|
|
1791
1804
|
} catch (error) {
|
|
1792
1805
|
if (timedOut || isNativeOperationTimeoutError(error)) {
|
|
1793
|
-
this.abandonStalledConnection(
|
|
1806
|
+
const resetManager = this.abandonStalledConnection(
|
|
1807
|
+
uuid,
|
|
1808
|
+
timedOut ? 'gatt-backstop' : 'gatt-native'
|
|
1809
|
+
);
|
|
1810
|
+
if (resetManager) {
|
|
1811
|
+
throw this.createWedgedBleSetupError();
|
|
1812
|
+
}
|
|
1794
1813
|
}
|
|
1795
1814
|
throw error;
|
|
1796
1815
|
} finally {
|
|
@@ -1802,11 +1821,12 @@ export default class ReactNativeBleTransport {
|
|
|
1802
1821
|
* Give up on a BLE setup operation the native layer did not settle. The abandoned
|
|
1803
1822
|
* operation still owns native connection/GATT state that can poison the next attempt,
|
|
1804
1823
|
* so it is cleared here without awaiting the same queue that stopped responding.
|
|
1824
|
+
* Returns true when the manager itself was reset so the caller can stop Core retries.
|
|
1805
1825
|
*/
|
|
1806
1826
|
private abandonStalledConnection(
|
|
1807
1827
|
uuid: string,
|
|
1808
1828
|
stage: 'connect-backstop' | 'connect-native' | 'gatt-backstop' | 'gatt-native'
|
|
1809
|
-
) {
|
|
1829
|
+
): boolean {
|
|
1810
1830
|
const timeouts = (this.connectionSetupTimeoutCounts.get(uuid) ?? 0) + 1;
|
|
1811
1831
|
this.connectionSetupTimeoutCounts.set(uuid, timeouts);
|
|
1812
1832
|
Log?.error('[ReactNativeBleTransport] BLE setup timed out:', uuid, {
|
|
@@ -1832,7 +1852,15 @@ export default class ReactNativeBleTransport {
|
|
|
1832
1852
|
Log?.error('[ReactNativeBleTransport] BLE setup wedged repeatedly, resetting BLE manager');
|
|
1833
1853
|
this.resetPlxManager();
|
|
1834
1854
|
this.connectionSetupTimeoutCounts.delete(uuid);
|
|
1855
|
+
return true;
|
|
1835
1856
|
}
|
|
1857
|
+
return false;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
private createWedgedBleSetupError() {
|
|
1861
|
+
// PollingTimeout is not retried by connectDeviceForBle and already maps
|
|
1862
|
+
// to the App "connection failed" help text.
|
|
1863
|
+
return ERRORS.TypedError(HardwareErrorCode.PollingTimeout, BLE_SETUP_WEDGED_MESSAGE);
|
|
1836
1864
|
}
|
|
1837
1865
|
|
|
1838
1866
|
private getCachedTransport(uuid: string) {
|