@onekeyfe/hd-transport-react-native 1.2.8-alpha.2 → 1.2.8-alpha.20
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/BleManager.d.ts +3 -1
- package/dist/BleManager.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -5
- package/package.json +5 -5
- package/src/BleManager.ts +18 -1
- package/src/__tests__/connectTimeout.test.ts +96 -0
- package/src/__tests__/enumerate.test.ts +2 -2
- package/src/__tests__/protocolV2Link.test.ts +53 -4
- package/src/__tests__/subscribeBleOn.test.ts +1 -1
- package/src/index.ts +6 -3
- package/src/subscribeBleOn.ts +1 -1
package/dist/BleManager.d.ts
CHANGED
|
@@ -2,5 +2,7 @@ import type { Peripheral } from '@onekeyfe/react-native-ble-utils';
|
|
|
2
2
|
export declare const getConnectedDeviceIds: (serviceUuids: string[]) => Promise<Peripheral[]>;
|
|
3
3
|
export declare const getBondedDevices: () => Promise<Peripheral[]>;
|
|
4
4
|
export declare const pairDevice: (macAddress: string) => Promise<import("@onekeyfe/react-native-ble-utils").PairDeviceResult>;
|
|
5
|
-
export declare const onDeviceBondState: (bleMacAddress: string, signal?: AbortSignal
|
|
5
|
+
export declare const onDeviceBondState: (bleMacAddress: string, signal?: AbortSignal, options?: {
|
|
6
|
+
systemInitiated?: boolean;
|
|
7
|
+
}) => Promise<Peripheral | undefined>;
|
|
6
8
|
//# sourceMappingURL=BleManager.d.ts.map
|
package/dist/BleManager.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BleManager.d.ts","sourceRoot":"","sources":["../src/BleManager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAsBnE,eAAO,MAAM,qBAAqB,iBAAkB,MAAM,EAAE,0BACZ,CAAC;AAEjD,eAAO,MAAM,gBAAgB,6BAAwC,CAAC;AAEtE,eAAO,MAAM,UAAU,eAAgB,MAAM,yEAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"BleManager.d.ts","sourceRoot":"","sources":["../src/BleManager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAsBnE,eAAO,MAAM,qBAAqB,iBAAkB,MAAM,EAAE,0BACZ,CAAC;AAEjD,eAAO,MAAM,gBAAgB,6BAAwC,CAAC;AAEtE,eAAO,MAAM,UAAU,eAAgB,MAAM,yEAAoC,CAAC;AAoClF,eAAO,MAAM,iBAAiB,kBACb,MAAM,WACZ,WAAW,YACV;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,KACtC,QAAQ,UAAU,GAAG,SAAS,CA6D7B,CAAC"}
|
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,EAGL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AA2BhC,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,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEjE,KAAK,8BAA8B,GAAG,eAAe,GAAG;IAMtD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAkBF,KAAK,4BAA4B,GAAG,WAAW,CAAC;AAChD,KAAK,0BAA0B,GAAG;I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;YAShB,mBAAmB;YAiBnB,qBAAqB;YA8DrB,oBAAoB;YAgCpB,cAAc;YAmFd,iCAAiC;IAsB/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
|
@@ -70,6 +70,7 @@ const bondFailureReasons = {
|
|
|
70
70
|
};
|
|
71
71
|
const getConnectedDeviceIds = (serviceUuids) => BleUtils__default["default"].getConnectedPeripherals(serviceUuids);
|
|
72
72
|
const pairDevice = (macAddress) => BleUtils__default["default"].pairDevice(macAddress);
|
|
73
|
+
const SYSTEM_BONDING_RESTART_WINDOW_MS = 1500;
|
|
73
74
|
const createBondFailureError = (bondState) => {
|
|
74
75
|
var _a;
|
|
75
76
|
const nativeReason = 'reason' in bondState && typeof bondState.reason === 'number' ? bondState.reason : undefined;
|
|
@@ -83,15 +84,18 @@ const createBondFailureError = (bondState) => {
|
|
|
83
84
|
}
|
|
84
85
|
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'Bluetooth pairing failed', params);
|
|
85
86
|
};
|
|
86
|
-
const onDeviceBondState = (bleMacAddress, signal) => new Promise((resolve, reject) => {
|
|
87
|
+
const onDeviceBondState = (bleMacAddress, signal, options) => new Promise((resolve, reject) => {
|
|
87
88
|
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
88
89
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected));
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
92
|
+
let pendingFailure;
|
|
91
93
|
const cleanup = () => {
|
|
92
94
|
if (timeout) {
|
|
93
95
|
clearTimeout(timeout);
|
|
94
96
|
}
|
|
97
|
+
if (pendingFailure)
|
|
98
|
+
clearTimeout(pendingFailure);
|
|
95
99
|
if (cleanupListener)
|
|
96
100
|
cleanupListener();
|
|
97
101
|
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
|
|
@@ -116,11 +120,24 @@ const onDeviceBondState = (bleMacAddress, signal) => new Promise((resolve, rejec
|
|
|
116
120
|
const { bondState } = peripheral;
|
|
117
121
|
const hasBonded = bondState.preState === 'BOND_BONDING' && bondState.state === 'BOND_BONDED';
|
|
118
122
|
const hasFailed = bondState.preState === 'BOND_BONDING' && bondState.state === 'BOND_NONE';
|
|
123
|
+
const hasRestarted = bondState.preState === 'BOND_NONE' && bondState.state === 'BOND_BONDING';
|
|
119
124
|
Logger.debug('onDeviceBondState bondState:', bondState);
|
|
120
125
|
if (hasBonded) {
|
|
121
126
|
cleanup();
|
|
122
127
|
resolve(peripheral);
|
|
123
128
|
}
|
|
129
|
+
else if (hasRestarted && pendingFailure) {
|
|
130
|
+
clearTimeout(pendingFailure);
|
|
131
|
+
pendingFailure = undefined;
|
|
132
|
+
}
|
|
133
|
+
else if (hasFailed && (options === null || options === void 0 ? void 0 : options.systemInitiated)) {
|
|
134
|
+
if (pendingFailure)
|
|
135
|
+
clearTimeout(pendingFailure);
|
|
136
|
+
pendingFailure = setTimeout(() => {
|
|
137
|
+
cleanup();
|
|
138
|
+
reject(createBondFailureError(bondState));
|
|
139
|
+
}, SYSTEM_BONDING_RESTART_WINDOW_MS);
|
|
140
|
+
}
|
|
124
141
|
else if (hasFailed) {
|
|
125
142
|
cleanup();
|
|
126
143
|
reject(createBondFailureError(bondState));
|
|
@@ -238,7 +255,7 @@ const subscribeBleOn = (bleManager, ms = 2000) => new Promise((resolve, reject)
|
|
|
238
255
|
pendingError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnsupported);
|
|
239
256
|
}
|
|
240
257
|
else if (state === 'Unauthorized') {
|
|
241
|
-
pendingError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
258
|
+
pendingError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleLocationError);
|
|
242
259
|
}
|
|
243
260
|
else {
|
|
244
261
|
pendingError = undefined;
|
|
@@ -842,7 +859,7 @@ class ReactNativeBleTransport {
|
|
|
842
859
|
Log === null || Log === void 0 ? void 0 : Log.debug('requesting permissions, result: ', resultConnect);
|
|
843
860
|
if (resultConnect[reactNative.PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT] !== 'granted' ||
|
|
844
861
|
resultConnect[reactNative.PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN] !== 'granted') {
|
|
845
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
862
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleLocationError);
|
|
846
863
|
}
|
|
847
864
|
}
|
|
848
865
|
yield subscribeBleOn(blePlxManager);
|
|
@@ -893,7 +910,7 @@ class ReactNativeBleTransport {
|
|
|
893
910
|
finishScan(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnsupported));
|
|
894
911
|
}
|
|
895
912
|
else if (error.errorCode === reactNativeBlePlx.BleErrorCode.BluetoothUnauthorized) {
|
|
896
|
-
finishScan(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
913
|
+
finishScan(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleLocationError));
|
|
897
914
|
}
|
|
898
915
|
else if (error.errorCode === reactNativeBlePlx.BleErrorCode.LocationServicesDisabled) {
|
|
899
916
|
finishScan(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleLocationServicesDisabled));
|
|
@@ -987,6 +1004,7 @@ class ReactNativeBleTransport {
|
|
|
987
1004
|
if (this.stopped)
|
|
988
1005
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
989
1006
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE MTU ready', {
|
|
1007
|
+
connectionId: monitorToken,
|
|
990
1008
|
platform: reactNative.Platform.OS,
|
|
991
1009
|
requested: getRequestedBleMtu(),
|
|
992
1010
|
actual: transport$1.mtuSize,
|
|
@@ -1082,7 +1100,9 @@ class ReactNativeBleTransport {
|
|
|
1082
1100
|
try {
|
|
1083
1101
|
const bondState = yield pairDevice(uuid);
|
|
1084
1102
|
if (bondState.bonding) {
|
|
1085
|
-
yield onDeviceBondState(uuid, this.bondAbortController.signal
|
|
1103
|
+
yield onDeviceBondState(uuid, this.bondAbortController.signal, {
|
|
1104
|
+
systemInitiated: bondState.initiated === false,
|
|
1105
|
+
});
|
|
1086
1106
|
}
|
|
1087
1107
|
else if (!bondState.bonded) {
|
|
1088
1108
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.8-alpha.
|
|
3
|
+
"version": "1.2.8-alpha.20",
|
|
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.8-alpha.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.8-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.8-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.8-alpha.20",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.8-alpha.20",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.8-alpha.20",
|
|
26
26
|
"@onekeyfe/react-native-ble-utils": "0.1.9",
|
|
27
27
|
"react-native-ble-plx": "3.5.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "973f059fe93a58fdcf098ddb32ba63f621a2c78e"
|
|
30
30
|
}
|
package/src/BleManager.ts
CHANGED
|
@@ -32,6 +32,8 @@ export const getBondedDevices = () => BleUtils.getBondedPeripherals();
|
|
|
32
32
|
|
|
33
33
|
export const pairDevice = (macAddress: string) => BleUtils.pairDevice(macAddress);
|
|
34
34
|
|
|
35
|
+
const SYSTEM_BONDING_RESTART_WINDOW_MS = 1500;
|
|
36
|
+
|
|
35
37
|
const createBondFailureError = (bondState: Peripheral['bondState']) => {
|
|
36
38
|
const nativeReason =
|
|
37
39
|
'reason' in bondState && typeof bondState.reason === 'number' ? bondState.reason : undefined;
|
|
@@ -66,17 +68,20 @@ const createBondFailureError = (bondState: Peripheral['bondState']) => {
|
|
|
66
68
|
|
|
67
69
|
export const onDeviceBondState = (
|
|
68
70
|
bleMacAddress: string,
|
|
69
|
-
signal?: AbortSignal
|
|
71
|
+
signal?: AbortSignal,
|
|
72
|
+
options?: { systemInitiated?: boolean }
|
|
70
73
|
): Promise<Peripheral | undefined> =>
|
|
71
74
|
new Promise((resolve, reject) => {
|
|
72
75
|
if (signal?.aborted) {
|
|
73
76
|
reject(ERRORS.TypedError(HardwareErrorCode.BleDeviceDisconnected));
|
|
74
77
|
return;
|
|
75
78
|
}
|
|
79
|
+
let pendingFailure: ReturnType<typeof setTimeout> | undefined;
|
|
76
80
|
const cleanup = () => {
|
|
77
81
|
if (timeout) {
|
|
78
82
|
clearTimeout(timeout);
|
|
79
83
|
}
|
|
84
|
+
if (pendingFailure) clearTimeout(pendingFailure);
|
|
80
85
|
if (cleanupListener) cleanupListener();
|
|
81
86
|
signal?.removeEventListener('abort', onAbort);
|
|
82
87
|
};
|
|
@@ -105,10 +110,22 @@ export const onDeviceBondState = (
|
|
|
105
110
|
|
|
106
111
|
const hasBonded = bondState.preState === 'BOND_BONDING' && bondState.state === 'BOND_BONDED';
|
|
107
112
|
const hasFailed = bondState.preState === 'BOND_BONDING' && bondState.state === 'BOND_NONE';
|
|
113
|
+
const hasRestarted = bondState.preState === 'BOND_NONE' && bondState.state === 'BOND_BONDING';
|
|
108
114
|
Logger.debug('onDeviceBondState bondState:', bondState);
|
|
109
115
|
if (hasBonded) {
|
|
110
116
|
cleanup();
|
|
111
117
|
resolve(peripheral);
|
|
118
|
+
} else if (hasRestarted && pendingFailure) {
|
|
119
|
+
clearTimeout(pendingFailure);
|
|
120
|
+
pendingFailure = undefined;
|
|
121
|
+
} else if (hasFailed && options?.systemInitiated) {
|
|
122
|
+
// Android can briefly remove the old bond before continuing an
|
|
123
|
+
// already-running system pairing. The original overall deadline stays.
|
|
124
|
+
if (pendingFailure) clearTimeout(pendingFailure);
|
|
125
|
+
pendingFailure = setTimeout(() => {
|
|
126
|
+
cleanup();
|
|
127
|
+
reject(createBondFailureError(bondState));
|
|
128
|
+
}, SYSTEM_BONDING_RESTART_WINDOW_MS);
|
|
112
129
|
} else if (hasFailed) {
|
|
113
130
|
cleanup();
|
|
114
131
|
reject(createBondFailureError(bondState));
|
|
@@ -129,6 +129,102 @@ describe('Android bond failure reasons', () => {
|
|
|
129
129
|
expect(cleanup).toHaveBeenCalledTimes(1);
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
+
test('lets system-initiated bonding restart before accepting the replacement bond', async () => {
|
|
133
|
+
const result = onDeviceBondState(UUID, undefined, { systemInitiated: true });
|
|
134
|
+
const outcome = result.catch(error => error);
|
|
135
|
+
emitBondState({
|
|
136
|
+
id: UUID,
|
|
137
|
+
advertising: {},
|
|
138
|
+
bondState: { preState: 'BOND_BONDING', state: 'BOND_NONE', reason: 9 },
|
|
139
|
+
});
|
|
140
|
+
jest.advanceTimersByTime(1499);
|
|
141
|
+
expect(cleanup).not.toHaveBeenCalled();
|
|
142
|
+
|
|
143
|
+
emitBondState({
|
|
144
|
+
id: UUID,
|
|
145
|
+
advertising: {},
|
|
146
|
+
bondState: { preState: 'BOND_NONE', state: 'BOND_BONDING' },
|
|
147
|
+
});
|
|
148
|
+
jest.advanceTimersByTime(1500);
|
|
149
|
+
expect(cleanup).not.toHaveBeenCalled();
|
|
150
|
+
const bonded: Peripheral = {
|
|
151
|
+
id: UUID,
|
|
152
|
+
advertising: {},
|
|
153
|
+
bondState: { preState: 'BOND_BONDING', state: 'BOND_BONDED' },
|
|
154
|
+
};
|
|
155
|
+
emitBondState(bonded);
|
|
156
|
+
|
|
157
|
+
await expect(outcome).resolves.toBe(bonded);
|
|
158
|
+
expect(cleanup).toHaveBeenCalledTimes(1);
|
|
159
|
+
expect(jest.getTimerCount()).toBe(0);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('rejects a genuine system bond failure when the restart window expires', async () => {
|
|
163
|
+
const result = onDeviceBondState(UUID, undefined, { systemInitiated: true });
|
|
164
|
+
const rejection = expect(result).rejects.toMatchObject({
|
|
165
|
+
errorCode: HardwareErrorCode.BleDeviceNotBonded,
|
|
166
|
+
params: { phase: 'bond', reason: 'authentication_failed', nativeReason: 1 },
|
|
167
|
+
});
|
|
168
|
+
emitBondState({
|
|
169
|
+
id: UUID,
|
|
170
|
+
advertising: {},
|
|
171
|
+
bondState: { preState: 'BOND_BONDING', state: 'BOND_NONE', reason: 1 },
|
|
172
|
+
});
|
|
173
|
+
jest.advanceTimersByTime(1499);
|
|
174
|
+
expect(cleanup).not.toHaveBeenCalled();
|
|
175
|
+
jest.advanceTimersByTime(1);
|
|
176
|
+
|
|
177
|
+
await rejection;
|
|
178
|
+
expect(cleanup).toHaveBeenCalledTimes(1);
|
|
179
|
+
expect(jest.getTimerCount()).toBe(0);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('aborts a pending system restart without leaving either timer or listener', async () => {
|
|
183
|
+
const controller = new AbortController();
|
|
184
|
+
const result = onDeviceBondState(UUID, controller.signal, { systemInitiated: true });
|
|
185
|
+
const outcome = result.catch(error => error);
|
|
186
|
+
emitBondState({
|
|
187
|
+
id: UUID,
|
|
188
|
+
advertising: {},
|
|
189
|
+
bondState: { preState: 'BOND_BONDING', state: 'BOND_NONE', reason: 9 },
|
|
190
|
+
});
|
|
191
|
+
expect(cleanup).not.toHaveBeenCalled();
|
|
192
|
+
|
|
193
|
+
controller.abort();
|
|
194
|
+
await expect(outcome).resolves.toMatchObject({
|
|
195
|
+
errorCode: HardwareErrorCode.BleDeviceDisconnected,
|
|
196
|
+
});
|
|
197
|
+
expect(cleanup).toHaveBeenCalledTimes(1);
|
|
198
|
+
expect(jest.getTimerCount()).toBe(0);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('keeps the overall deadline when system bonding repeatedly restarts', async () => {
|
|
202
|
+
const result = onDeviceBondState(UUID, undefined, { systemInitiated: true });
|
|
203
|
+
const outcome = result.catch(error => error);
|
|
204
|
+
for (let index = 0; index < 40; index += 1) {
|
|
205
|
+
emitBondState({
|
|
206
|
+
id: UUID,
|
|
207
|
+
advertising: {},
|
|
208
|
+
bondState: { preState: 'BOND_BONDING', state: 'BOND_NONE', reason: 9 },
|
|
209
|
+
});
|
|
210
|
+
emitBondState({
|
|
211
|
+
id: UUID,
|
|
212
|
+
advertising: {},
|
|
213
|
+
bondState: { preState: 'BOND_NONE', state: 'BOND_BONDING' },
|
|
214
|
+
});
|
|
215
|
+
jest.advanceTimersByTime(1000);
|
|
216
|
+
}
|
|
217
|
+
expect(cleanup).not.toHaveBeenCalled();
|
|
218
|
+
jest.advanceTimersByTime(20_000);
|
|
219
|
+
|
|
220
|
+
await expect(outcome).resolves.toMatchObject({
|
|
221
|
+
errorCode: HardwareErrorCode.BleDeviceNotBonded,
|
|
222
|
+
params: { phase: 'bond', reason: 'timeout' },
|
|
223
|
+
});
|
|
224
|
+
expect(cleanup).toHaveBeenCalledTimes(1);
|
|
225
|
+
expect(jest.getTimerCount()).toBe(0);
|
|
226
|
+
});
|
|
227
|
+
|
|
132
228
|
test('aborts the bond wait and removes its listener and deadline', async () => {
|
|
133
229
|
const controller = new AbortController();
|
|
134
230
|
const result = onDeviceBondState(UUID, controller.signal);
|
|
@@ -68,7 +68,7 @@ describe('ReactNativeBleTransport scan error mapping', () => {
|
|
|
68
68
|
transport.init({ debug: jest.fn(), error: jest.fn() }, new EventEmitter());
|
|
69
69
|
|
|
70
70
|
await expect(transport.enumerate()).rejects.toMatchObject({
|
|
71
|
-
errorCode: HardwareErrorCode.
|
|
71
|
+
errorCode: HardwareErrorCode.BleLocationError,
|
|
72
72
|
});
|
|
73
73
|
expect(subscribeBleOn).not.toHaveBeenCalled();
|
|
74
74
|
});
|
|
@@ -77,7 +77,7 @@ describe('ReactNativeBleTransport scan error mapping', () => {
|
|
|
77
77
|
[BleErrorCode.BluetoothPoweredOff, HardwareErrorCode.BlePoweredOff],
|
|
78
78
|
[BleErrorCode.BluetoothUnsupported, HardwareErrorCode.BleUnsupported],
|
|
79
79
|
[BleErrorCode.BluetoothInUnknownState, HardwareErrorCode.BleScanError],
|
|
80
|
-
[BleErrorCode.BluetoothUnauthorized, HardwareErrorCode.
|
|
80
|
+
[BleErrorCode.BluetoothUnauthorized, HardwareErrorCode.BleLocationError],
|
|
81
81
|
])('maps native BLE error %s to hardware error %s', async (nativeCode, errorCode) => {
|
|
82
82
|
jest.mocked(getConnectedDeviceIds).mockResolvedValueOnce([]);
|
|
83
83
|
const blePlxManager = {
|
|
@@ -303,6 +303,45 @@ const createV1Harness = ({
|
|
|
303
303
|
};
|
|
304
304
|
|
|
305
305
|
describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
306
|
+
test.each(['ios', 'android'] as const)(
|
|
307
|
+
'identifies MTU logs for concurrent devices and reconnects on %s',
|
|
308
|
+
async platform => {
|
|
309
|
+
setPlatformOS(platform);
|
|
310
|
+
const { transport, uuid, device, bleManager, logger } = createHarness();
|
|
311
|
+
const otherUuid = 'rn-pro2-other-id';
|
|
312
|
+
const otherDevice = { ...device, id: otherUuid };
|
|
313
|
+
|
|
314
|
+
try {
|
|
315
|
+
await transport.acquire({ uuid, expectedProtocol: 'V2' });
|
|
316
|
+
await transport.acquire({ uuid, expectedProtocol: 'V2' });
|
|
317
|
+
bleManager.devices.mockResolvedValue([otherDevice]);
|
|
318
|
+
await transport.acquire({ uuid: otherUuid, expectedProtocol: 'V2' });
|
|
319
|
+
await transport.release(uuid, true);
|
|
320
|
+
bleManager.devices.mockResolvedValue([device]);
|
|
321
|
+
await transport.acquire({ uuid, expectedProtocol: 'V2' });
|
|
322
|
+
|
|
323
|
+
const mtuLogs = logger.debug.mock.calls
|
|
324
|
+
.filter(([message]) => message === '[ReactNativeBleTransport] BLE MTU ready')
|
|
325
|
+
.map(([, params]) => params as { connectionId: number; actual: number });
|
|
326
|
+
expect(mtuLogs).toHaveLength(3);
|
|
327
|
+
expect(new Set(mtuLogs.map(({ connectionId }) => connectionId)).size).toBe(3);
|
|
328
|
+
for (const params of mtuLogs) {
|
|
329
|
+
expect(params).toEqual({
|
|
330
|
+
platform,
|
|
331
|
+
requested: expect.any(Number),
|
|
332
|
+
actual: device.mtu,
|
|
333
|
+
connectionId: expect.any(Number),
|
|
334
|
+
});
|
|
335
|
+
expect(Number.isSafeInteger(params.connectionId)).toBe(true);
|
|
336
|
+
expect(params.connectionId).toBeGreaterThan(0);
|
|
337
|
+
}
|
|
338
|
+
} finally {
|
|
339
|
+
await transport.release(uuid, true);
|
|
340
|
+
await transport.release(otherUuid, true);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
);
|
|
344
|
+
|
|
306
345
|
test('does not classify disconnects as retryable firmware writes', () => {
|
|
307
346
|
expect(
|
|
308
347
|
getFirmwareUploadWriteRetryType({
|
|
@@ -363,9 +402,16 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
363
402
|
expect(new ReactNativeBleTransport({}).scanTimeout).toBe(3000);
|
|
364
403
|
});
|
|
365
404
|
|
|
366
|
-
test.each([
|
|
367
|
-
|
|
368
|
-
|
|
405
|
+
test.each([
|
|
406
|
+
{ protocol: 'V1', initiated: true },
|
|
407
|
+
{ protocol: 'V1', initiated: false },
|
|
408
|
+
{ protocol: 'V1', initiated: undefined },
|
|
409
|
+
{ protocol: 'V2', initiated: true },
|
|
410
|
+
{ protocol: 'V2', initiated: false },
|
|
411
|
+
{ protocol: 'V2', initiated: undefined },
|
|
412
|
+
] as const)(
|
|
413
|
+
'waits for Android bonding before connecting $protocol GATT, initiated=$initiated',
|
|
414
|
+
async ({ protocol, initiated }) => {
|
|
369
415
|
setPlatformOS('android');
|
|
370
416
|
const { transport, uuid, device } = protocol === 'V1' ? createV1Harness() : createHarness();
|
|
371
417
|
const operationOrder: string[] = [];
|
|
@@ -380,7 +426,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
380
426
|
});
|
|
381
427
|
pairDeviceMock.mockImplementationOnce(() => {
|
|
382
428
|
operationOrder.push('bond');
|
|
383
|
-
return Promise.resolve({ bonded: false, bonding: true });
|
|
429
|
+
return Promise.resolve({ bonded: false, bonding: true, initiated });
|
|
384
430
|
});
|
|
385
431
|
bondStateMock.mockImplementationOnce(() => bonding.promise);
|
|
386
432
|
|
|
@@ -390,6 +436,9 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
390
436
|
});
|
|
391
437
|
expect(operationOrder).toEqual(['bond']);
|
|
392
438
|
expect(device.connect).not.toHaveBeenCalled();
|
|
439
|
+
expect(bondStateMock).toHaveBeenLastCalledWith(uuid, expect.any(AbortSignal), {
|
|
440
|
+
systemInitiated: initiated === false,
|
|
441
|
+
});
|
|
393
442
|
|
|
394
443
|
bonding.resolve();
|
|
395
444
|
await expect(acquiring).resolves.toEqual({
|
|
@@ -64,7 +64,7 @@ describe('subscribeBleOn', () => {
|
|
|
64
64
|
test.each([
|
|
65
65
|
['PoweredOff', HardwareErrorCode.BlePoweredOff],
|
|
66
66
|
['Unsupported', HardwareErrorCode.BleUnsupported],
|
|
67
|
-
['Unauthorized', HardwareErrorCode.
|
|
67
|
+
['Unauthorized', HardwareErrorCode.BleLocationError],
|
|
68
68
|
] as const)('maps %s to hardware error %s', async (state, errorCode) => {
|
|
69
69
|
const { bleManager, emitState, remove } = createBleManager();
|
|
70
70
|
const result = subscribeBleOn(bleManager, 2000);
|
package/src/index.ts
CHANGED
|
@@ -836,7 +836,7 @@ export default class ReactNativeBleTransport {
|
|
|
836
836
|
resultConnect[PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT] !== 'granted' ||
|
|
837
837
|
resultConnect[PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN] !== 'granted'
|
|
838
838
|
) {
|
|
839
|
-
throw ERRORS.TypedError(HardwareErrorCode.
|
|
839
|
+
throw ERRORS.TypedError(HardwareErrorCode.BleLocationError);
|
|
840
840
|
}
|
|
841
841
|
}
|
|
842
842
|
await subscribeBleOn(blePlxManager);
|
|
@@ -887,7 +887,7 @@ export default class ReactNativeBleTransport {
|
|
|
887
887
|
} else if (error.errorCode === BleErrorCode.BluetoothUnsupported) {
|
|
888
888
|
finishScan(ERRORS.TypedError(HardwareErrorCode.BleUnsupported));
|
|
889
889
|
} else if (error.errorCode === BleErrorCode.BluetoothUnauthorized) {
|
|
890
|
-
finishScan(ERRORS.TypedError(HardwareErrorCode.
|
|
890
|
+
finishScan(ERRORS.TypedError(HardwareErrorCode.BleLocationError));
|
|
891
891
|
} else if (error.errorCode === BleErrorCode.LocationServicesDisabled) {
|
|
892
892
|
finishScan(ERRORS.TypedError(HardwareErrorCode.BleLocationServicesDisabled));
|
|
893
893
|
} else if (error.errorCode === BleErrorCode.ScanStartFailed) {
|
|
@@ -1010,6 +1010,7 @@ export default class ReactNativeBleTransport {
|
|
|
1010
1010
|
if (this.stopped) throw ERRORS.TypedError(HardwareErrorCode.BleDeviceDisconnected);
|
|
1011
1011
|
|
|
1012
1012
|
Log?.debug('[ReactNativeBleTransport] BLE MTU ready', {
|
|
1013
|
+
connectionId: monitorToken,
|
|
1013
1014
|
platform: Platform.OS,
|
|
1014
1015
|
requested: getRequestedBleMtu(),
|
|
1015
1016
|
actual: transport.mtuSize,
|
|
@@ -1136,7 +1137,9 @@ export default class ReactNativeBleTransport {
|
|
|
1136
1137
|
try {
|
|
1137
1138
|
const bondState = await pairDevice(uuid);
|
|
1138
1139
|
if (bondState.bonding) {
|
|
1139
|
-
await onDeviceBondState(uuid, this.bondAbortController.signal
|
|
1140
|
+
await onDeviceBondState(uuid, this.bondAbortController.signal, {
|
|
1141
|
+
systemInitiated: bondState.initiated === false,
|
|
1142
|
+
});
|
|
1140
1143
|
} else if (!bondState.bonded) {
|
|
1141
1144
|
throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
|
1142
1145
|
}
|
package/src/subscribeBleOn.ts
CHANGED
|
@@ -28,7 +28,7 @@ export const subscribeBleOn = (bleManager: BlePlxManager, ms = 2000): Promise<vo
|
|
|
28
28
|
} else if (state === 'Unsupported') {
|
|
29
29
|
pendingError = ERRORS.TypedError(HardwareErrorCode.BleUnsupported);
|
|
30
30
|
} else if (state === 'Unauthorized') {
|
|
31
|
-
pendingError = ERRORS.TypedError(HardwareErrorCode.
|
|
31
|
+
pendingError = ERRORS.TypedError(HardwareErrorCode.BleLocationError);
|
|
32
32
|
} else {
|
|
33
33
|
pendingError = undefined;
|
|
34
34
|
}
|