@onekeyfe/hd-transport-react-native 1.2.0-alpha.11 → 1.2.0-alpha.13
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/bleStrategy.d.ts +0 -2
- package/dist/bleStrategy.d.ts.map +1 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -100
- package/dist/subscribeBleOn.d.ts.map +1 -1
- package/dist/transportLog.d.ts +13 -0
- package/dist/transportLog.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/__tests__/bleStrategy.test.ts +1 -6
- package/src/__tests__/protocolV2Link.test.ts +28 -22
- package/src/bleStrategy.ts +0 -25
- package/src/index.ts +51 -140
- package/src/subscribeBleOn.ts +0 -2
- package/src/transportLog.ts +18 -0
package/dist/bleStrategy.d.ts
CHANGED
|
@@ -3,9 +3,7 @@ export type BleWriteCapability = {
|
|
|
3
3
|
isWritableWithResponse?: boolean | null;
|
|
4
4
|
isWritableWithoutResponse?: boolean | null;
|
|
5
5
|
};
|
|
6
|
-
export type BleWriteMode = 'withResponse' | 'withoutResponse';
|
|
7
6
|
export declare function hasWritableCapability(characteristic: BleWriteCapability): boolean;
|
|
8
|
-
export declare function resolveBleWriteMode(characteristic: BleWriteCapability, preferredMode?: BleWriteMode): BleWriteMode;
|
|
9
7
|
export declare function resolveProtocolV2PacketCapacity({ platform, iosPacketLength, androidPacketLength, mtu, }: {
|
|
10
8
|
platform: BlePlatform;
|
|
11
9
|
iosPacketLength?: number;
|
|
@@ -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,
|
|
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,eAAmC,EACnC,mBAA2C,EAC3C,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,UAWA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -37,20 +37,12 @@ type ResolvedBleCharacteristics = {
|
|
|
37
37
|
type ProtocolV2BleTuning = {
|
|
38
38
|
iosPacketLength?: number;
|
|
39
39
|
androidPacketLength?: number;
|
|
40
|
-
highVolumeWriteBurstSize?: number;
|
|
41
|
-
highVolumeWritePauseMs?: number;
|
|
42
|
-
highVolumeWriteFlushDelayMs?: number;
|
|
43
|
-
highVolumeWriteWithResponse?: boolean;
|
|
44
40
|
};
|
|
45
41
|
declare function configureProtocolV2BleTuning(tuning?: ProtocolV2BleTuning): void;
|
|
46
42
|
declare function resetProtocolV2BleTuning(): void;
|
|
47
43
|
declare function getProtocolV2BleTuning(): {
|
|
48
44
|
iosPacketLength: number;
|
|
49
45
|
androidPacketLength: number;
|
|
50
|
-
highVolumeWriteBurstSize: number;
|
|
51
|
-
highVolumeWritePauseMs: number;
|
|
52
|
-
highVolumeWriteFlushDelayMs: number;
|
|
53
|
-
highVolumeWriteWithResponse: boolean;
|
|
54
46
|
};
|
|
55
47
|
type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
|
|
56
48
|
declare class ReactNativeBleTransport {
|
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,EAE5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAEhB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAGjB,KAAK,oBAAoB,EAE1B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -138,21 +138,6 @@ const isSameBleUuid = (left, right) => {
|
|
|
138
138
|
function hasWritableCapability(characteristic) {
|
|
139
139
|
return !!(characteristic.isWritableWithResponse || characteristic.isWritableWithoutResponse);
|
|
140
140
|
}
|
|
141
|
-
function resolveBleWriteMode(characteristic, preferredMode = 'withoutResponse') {
|
|
142
|
-
if (preferredMode === 'withoutResponse' && characteristic.isWritableWithoutResponse) {
|
|
143
|
-
return 'withoutResponse';
|
|
144
|
-
}
|
|
145
|
-
if (preferredMode === 'withResponse' && characteristic.isWritableWithResponse) {
|
|
146
|
-
return 'withResponse';
|
|
147
|
-
}
|
|
148
|
-
if (characteristic.isWritableWithoutResponse) {
|
|
149
|
-
return 'withoutResponse';
|
|
150
|
-
}
|
|
151
|
-
if (characteristic.isWritableWithResponse) {
|
|
152
|
-
return 'withResponse';
|
|
153
|
-
}
|
|
154
|
-
return preferredMode;
|
|
155
|
-
}
|
|
156
141
|
function resolveProtocolV2PacketCapacity({ platform, iosPacketLength = IOS_PACKET_LENGTH, androidPacketLength = ANDROID_PACKET_LENGTH, mtu, }) {
|
|
157
142
|
if (platform === 'ios') {
|
|
158
143
|
return iosPacketLength;
|
|
@@ -189,7 +174,6 @@ const timer = process.env.NODE_ENV === 'development'
|
|
|
189
174
|
const subscribeBleOn = (bleManager, ms = 1000) => new Promise((resolve, reject) => {
|
|
190
175
|
let done = false;
|
|
191
176
|
const subscription = bleManager.onStateChange(state => {
|
|
192
|
-
console.log('ble state -> ', state);
|
|
193
177
|
if (state === 'PoweredOn') {
|
|
194
178
|
if (done)
|
|
195
179
|
return;
|
|
@@ -261,6 +245,18 @@ class BleTransport {
|
|
|
261
245
|
BleTransport.MAX_RETRIES = 5;
|
|
262
246
|
BleTransport.RETRY_DELAY = 2000;
|
|
263
247
|
|
|
248
|
+
function createTransportCallLog(name, protocol, data) {
|
|
249
|
+
if (name === 'ResourceUpdate' || name === 'ResourceAck') {
|
|
250
|
+
return {
|
|
251
|
+
name,
|
|
252
|
+
protocol,
|
|
253
|
+
file_name: data.file_name,
|
|
254
|
+
hash: data.hash,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return { name, protocol };
|
|
258
|
+
}
|
|
259
|
+
|
|
264
260
|
const { check, ProtocolV1, parseConfigure } = transport__default["default"];
|
|
265
261
|
const Log = bleLogger;
|
|
266
262
|
const transportCache = {};
|
|
@@ -299,16 +295,9 @@ const PROTOCOL_V2_PROBE_TIMEOUT_MS = 10000;
|
|
|
299
295
|
const DEVICE_SCAN_TIMEOUT_MS = 8000;
|
|
300
296
|
const IOS_NOTIFY_READY_DELAY_MS = 150;
|
|
301
297
|
const ANDROID_NOTIFY_READY_DELAY_MS = 300;
|
|
302
|
-
const HIGH_VOLUME_WRITE_BURST_SIZE = reactNative.Platform.OS === 'ios' ? 4 : 6;
|
|
303
|
-
const HIGH_VOLUME_WRITE_PAUSE_MS = reactNative.Platform.OS === 'ios' ? 6 : 2;
|
|
304
|
-
const HIGH_VOLUME_WRITE_FLUSH_DELAY_MS = reactNative.Platform.OS === 'ios' ? 20 : 8;
|
|
305
298
|
const DEFAULT_PROTOCOL_V2_BLE_TUNING = {
|
|
306
299
|
iosPacketLength: IOS_PACKET_LENGTH,
|
|
307
300
|
androidPacketLength: ANDROID_PACKET_LENGTH,
|
|
308
|
-
highVolumeWriteBurstSize: HIGH_VOLUME_WRITE_BURST_SIZE,
|
|
309
|
-
highVolumeWritePauseMs: HIGH_VOLUME_WRITE_PAUSE_MS,
|
|
310
|
-
highVolumeWriteFlushDelayMs: HIGH_VOLUME_WRITE_FLUSH_DELAY_MS,
|
|
311
|
-
highVolumeWriteWithResponse: false,
|
|
312
301
|
};
|
|
313
302
|
let protocolV2BleTuning = Object.assign({}, DEFAULT_PROTOCOL_V2_BLE_TUNING);
|
|
314
303
|
const normalizePositiveInteger = (value, fallback) => {
|
|
@@ -318,20 +307,15 @@ const normalizePositiveInteger = (value, fallback) => {
|
|
|
318
307
|
return Math.floor(normalized);
|
|
319
308
|
};
|
|
320
309
|
function configureProtocolV2BleTuning(tuning = {}) {
|
|
321
|
-
var _a;
|
|
322
310
|
protocolV2BleTuning = {
|
|
323
311
|
iosPacketLength: normalizePositiveInteger(tuning.iosPacketLength, protocolV2BleTuning.iosPacketLength),
|
|
324
312
|
androidPacketLength: normalizePositiveInteger(tuning.androidPacketLength, protocolV2BleTuning.androidPacketLength),
|
|
325
|
-
highVolumeWriteBurstSize: normalizePositiveInteger(tuning.highVolumeWriteBurstSize, protocolV2BleTuning.highVolumeWriteBurstSize),
|
|
326
|
-
highVolumeWritePauseMs: normalizePositiveInteger(tuning.highVolumeWritePauseMs, protocolV2BleTuning.highVolumeWritePauseMs),
|
|
327
|
-
highVolumeWriteFlushDelayMs: normalizePositiveInteger(tuning.highVolumeWriteFlushDelayMs, protocolV2BleTuning.highVolumeWriteFlushDelayMs),
|
|
328
|
-
highVolumeWriteWithResponse: (_a = tuning.highVolumeWriteWithResponse) !== null && _a !== void 0 ? _a : protocolV2BleTuning.highVolumeWriteWithResponse,
|
|
329
313
|
};
|
|
330
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport]
|
|
314
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE tuning configured', protocolV2BleTuning);
|
|
331
315
|
}
|
|
332
316
|
function resetProtocolV2BleTuning() {
|
|
333
317
|
protocolV2BleTuning = Object.assign({}, DEFAULT_PROTOCOL_V2_BLE_TUNING);
|
|
334
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport]
|
|
318
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE tuning reset', protocolV2BleTuning);
|
|
335
319
|
}
|
|
336
320
|
function getProtocolV2BleTuning() {
|
|
337
321
|
return Object.assign({}, protocolV2BleTuning);
|
|
@@ -371,9 +355,10 @@ const requestAndroidMtu = (device) => __awaiter(void 0, void 0, void 0, function
|
|
|
371
355
|
return device;
|
|
372
356
|
try {
|
|
373
357
|
const mtuDevice = yield device.requestMTU(ANDROID_REQUEST_MTU);
|
|
374
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport]
|
|
358
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] MTU configured', {
|
|
359
|
+
deviceId: device.id,
|
|
375
360
|
requested: ANDROID_REQUEST_MTU,
|
|
376
|
-
|
|
361
|
+
actual: mtuDevice.mtu,
|
|
377
362
|
});
|
|
378
363
|
return mtuDevice;
|
|
379
364
|
}
|
|
@@ -453,7 +438,6 @@ class ReactNativeBleTransport {
|
|
|
453
438
|
this.protocolV2Links
|
|
454
439
|
.invalidateAllLinks('Protocol V2 schema reconfigured')
|
|
455
440
|
.catch(error => Log === null || Log === void 0 ? void 0 : Log.debug('Protocol V2 schema link cleanup failed:', error));
|
|
456
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 schema configured');
|
|
457
441
|
}
|
|
458
442
|
listen() {
|
|
459
443
|
}
|
|
@@ -646,13 +630,12 @@ class ReactNativeBleTransport {
|
|
|
646
630
|
return;
|
|
647
631
|
}
|
|
648
632
|
}
|
|
649
|
-
blePlxManager.startDeviceScan(
|
|
633
|
+
blePlxManager.startDeviceScan(getBluetoothServiceUuids(), {
|
|
650
634
|
allowDuplicates: true,
|
|
651
635
|
scanMode: reactNativeBlePlx.ScanMode.LowLatency,
|
|
652
636
|
}, (error, device) => {
|
|
653
637
|
var _a, _b, _c;
|
|
654
638
|
if (error) {
|
|
655
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('ble scan manager: ', blePlxManager);
|
|
656
639
|
Log === null || Log === void 0 ? void 0 : Log.debug('ble scan error: ', error);
|
|
657
640
|
if ([reactNativeBlePlx.BleErrorCode.BluetoothPoweredOff, reactNativeBlePlx.BleErrorCode.BluetoothInUnknownState].includes(error.errorCode)) {
|
|
658
641
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));
|
|
@@ -675,22 +658,8 @@ class ReactNativeBleTransport {
|
|
|
675
658
|
const isOneKey = hdShared.isOnekeyDevice((_b = device === null || device === void 0 ? void 0 : device.name) !== null && _b !== void 0 ? _b : null, device === null || device === void 0 ? void 0 : device.id) ||
|
|
676
659
|
hdShared.isOnekeyDevice((_c = device === null || device === void 0 ? void 0 : device.localName) !== null && _c !== void 0 ? _c : null, device === null || device === void 0 ? void 0 : device.id) ||
|
|
677
660
|
hasKnownOneKeyService(device);
|
|
678
|
-
const shouldTraceCandidate = !!displayName && /onekey|bixinkey|pro\s*2|pro\b|touch|^k\d|^t\d/i.test(displayName);
|
|
679
|
-
if (shouldTraceCandidate) {
|
|
680
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] scan candidate', {
|
|
681
|
-
name: device === null || device === void 0 ? void 0 : device.name,
|
|
682
|
-
localName: device === null || device === void 0 ? void 0 : device.localName,
|
|
683
|
-
id: device === null || device === void 0 ? void 0 : device.id,
|
|
684
|
-
serviceUUIDs: device === null || device === void 0 ? void 0 : device.serviceUUIDs,
|
|
685
|
-
accepted: isOneKey,
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
661
|
if (isOneKey) {
|
|
689
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('search device start ======================');
|
|
690
|
-
const { name, localName, id, serviceUUIDs } = device !== null && device !== void 0 ? device : {};
|
|
691
|
-
Log === null || Log === void 0 ? void 0 : Log.debug(`device name: ${name !== null && name !== void 0 ? name : ''}\nlocalName: ${localName !== null && localName !== void 0 ? localName : ''}\nid: ${id !== null && id !== void 0 ? id : ''}\nserviceUUIDs: ${(serviceUUIDs !== null && serviceUUIDs !== void 0 ? serviceUUIDs : []).join(',')}`);
|
|
692
662
|
addDevice(device);
|
|
693
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('search device end ======================\n');
|
|
694
663
|
}
|
|
695
664
|
else if (displayName && /\bpro\s*2\b/i.test(displayName)) {
|
|
696
665
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Pro2-like BLE device was not accepted:', {
|
|
@@ -701,10 +670,15 @@ class ReactNativeBleTransport {
|
|
|
701
670
|
});
|
|
702
671
|
}
|
|
703
672
|
});
|
|
704
|
-
getConnectedDeviceIds(getBluetoothServiceUuids()).then(devices => {
|
|
673
|
+
getConnectedDeviceIds(reactNative.Platform.OS === 'ios' ? getBluetoothServiceUuids() : []).then(devices => {
|
|
705
674
|
for (const device of devices) {
|
|
706
|
-
|
|
707
|
-
|
|
675
|
+
const { serviceUUIDs } = device;
|
|
676
|
+
const hasCachedServiceUuid = Boolean(serviceUUIDs === null || serviceUUIDs === void 0 ? void 0 : serviceUUIDs.length);
|
|
677
|
+
const keepDevice = reactNative.Platform.OS === 'ios' || hasCachedServiceUuid;
|
|
678
|
+
if (keepDevice) {
|
|
679
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('search connected peripheral: ', device.id);
|
|
680
|
+
addDevice(device);
|
|
681
|
+
}
|
|
708
682
|
}
|
|
709
683
|
});
|
|
710
684
|
const addDevice = (device) => {
|
|
@@ -716,6 +690,12 @@ class ReactNativeBleTransport {
|
|
|
716
690
|
this.deviceProtocolHints.set(device.id, protocolHint);
|
|
717
691
|
}
|
|
718
692
|
deviceList.push(Object.assign(Object.assign({}, device), { name: displayName, commType: 'ble' }));
|
|
693
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] OneKey BLE device discovered', {
|
|
694
|
+
deviceId: device.id,
|
|
695
|
+
name: displayName,
|
|
696
|
+
serviceUUIDs: device.serviceUUIDs,
|
|
697
|
+
protocolHint,
|
|
698
|
+
});
|
|
719
699
|
}
|
|
720
700
|
};
|
|
721
701
|
timer.timeout(() => {
|
|
@@ -1045,23 +1025,11 @@ class ReactNativeBleTransport {
|
|
|
1045
1025
|
if (!protocol) {
|
|
1046
1026
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol has not been detected for ${uuid}`);
|
|
1047
1027
|
}
|
|
1048
|
-
|
|
1049
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', {
|
|
1050
|
-
file_name: data === null || data === void 0 ? void 0 : data.file_name,
|
|
1051
|
-
hash: data === null || data === void 0 ? void 0 : data.hash,
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
else if (transport.LogBlockCommand.has(name)) {
|
|
1055
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native', 'call-', ' name: ', name, ' protocol: ', protocol);
|
|
1056
|
-
}
|
|
1057
|
-
else {
|
|
1058
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data, ' protocol: ', protocol);
|
|
1059
|
-
}
|
|
1028
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('transport call', createTransportCallLog(name, protocol, data));
|
|
1060
1029
|
if (protocol === 'V2') {
|
|
1061
1030
|
return this.callProtocolV2(uuid, name, data, options);
|
|
1062
1031
|
}
|
|
1063
1032
|
const forceRun = name === 'Initialize' || name === 'Cancel';
|
|
1064
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native call this.runPromise', this.runPromise);
|
|
1065
1033
|
if (this.runPromise && !forceRun) {
|
|
1066
1034
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportCallInProgress);
|
|
1067
1035
|
}
|
|
@@ -1140,7 +1108,7 @@ class ReactNativeBleTransport {
|
|
|
1140
1108
|
});
|
|
1141
1109
|
}
|
|
1142
1110
|
else if (name === 'FirmwareUpload') {
|
|
1143
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport]
|
|
1111
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Firmware upload transport configured', {
|
|
1144
1112
|
packetCapacity: FIRMWARE_UPLOAD_WRITE_PACKET_CAPACITY,
|
|
1145
1113
|
burstSize: FIRMWARE_UPLOAD_WRITE_BURST_SIZE,
|
|
1146
1114
|
pauseMs: FIRMWARE_UPLOAD_WRITE_PAUSE_MS,
|
|
@@ -1229,7 +1197,6 @@ class ReactNativeBleTransport {
|
|
|
1229
1197
|
if (typeof response !== 'string') {
|
|
1230
1198
|
throw new Error('Returning data is not string.');
|
|
1231
1199
|
}
|
|
1232
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('receive data: ', response);
|
|
1233
1200
|
const jsonData = ProtocolV1.decodeMessage(messages, response);
|
|
1234
1201
|
return check.call(jsonData);
|
|
1235
1202
|
}
|
|
@@ -1257,7 +1224,6 @@ class ReactNativeBleTransport {
|
|
|
1257
1224
|
disconnect(session) {
|
|
1258
1225
|
var _a, _b, _c, _d, _e;
|
|
1259
1226
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1260
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native transport resetSession: ', session);
|
|
1261
1227
|
yield this.protocolV2Links.invalidateLink(session, 'React Native BLE transport disconnected');
|
|
1262
1228
|
const transport = transportCache[session];
|
|
1263
1229
|
if (transport === null || transport === void 0 ? void 0 : transport.disconnectSubscription) {
|
|
@@ -1350,14 +1316,22 @@ class ReactNativeBleTransport {
|
|
|
1350
1316
|
if (expectedProtocol === 'V1') {
|
|
1351
1317
|
if (yield this.probeProtocolV1(uuid)) {
|
|
1352
1318
|
this.deviceProtocol.set(uuid, 'V1');
|
|
1353
|
-
Log === null || Log === void 0 ? void 0 : Log.debug(
|
|
1319
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1320
|
+
deviceId: uuid,
|
|
1321
|
+
protocol: 'V1',
|
|
1322
|
+
source: 'expected',
|
|
1323
|
+
});
|
|
1354
1324
|
return 'V1';
|
|
1355
1325
|
}
|
|
1356
1326
|
throw this.createProtocolMismatchError(expectedProtocol);
|
|
1357
1327
|
}
|
|
1358
1328
|
if (expectedProtocol === 'V2') {
|
|
1359
1329
|
this.deviceProtocol.set(uuid, 'V2');
|
|
1360
|
-
Log === null || Log === void 0 ? void 0 : Log.debug(
|
|
1330
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1331
|
+
deviceId: uuid,
|
|
1332
|
+
protocol: 'V2',
|
|
1333
|
+
source: 'expected',
|
|
1334
|
+
});
|
|
1361
1335
|
return 'V2';
|
|
1362
1336
|
}
|
|
1363
1337
|
const probeOrder = protocolHint === 'V2' || this.deviceProtocol.get(uuid) === 'V2' ? ['V2', 'V1'] : ['V1', 'V2'];
|
|
@@ -1369,7 +1343,11 @@ class ReactNativeBleTransport {
|
|
|
1369
1343
|
const detected = protocol === 'V1' ? yield this.probeProtocolV1(uuid) : yield this.probeProtocolV2(uuid);
|
|
1370
1344
|
if (detected) {
|
|
1371
1345
|
this.deviceProtocol.set(uuid, protocol);
|
|
1372
|
-
Log === null || Log === void 0 ? void 0 : Log.debug(
|
|
1346
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1347
|
+
deviceId: uuid,
|
|
1348
|
+
protocol,
|
|
1349
|
+
source: 'probe',
|
|
1350
|
+
});
|
|
1373
1351
|
return protocol;
|
|
1374
1352
|
}
|
|
1375
1353
|
}
|
|
@@ -1537,7 +1515,7 @@ class ReactNativeBleTransport {
|
|
|
1537
1515
|
}
|
|
1538
1516
|
});
|
|
1539
1517
|
}
|
|
1540
|
-
writeProtocolV2Frame(transport, frame
|
|
1518
|
+
writeProtocolV2Frame(transport, frame) {
|
|
1541
1519
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1542
1520
|
const tuning = getProtocolV2BleTuning();
|
|
1543
1521
|
const packetCapacity = resolveProtocolV2PacketCapacity({
|
|
@@ -1546,28 +1524,10 @@ class ReactNativeBleTransport {
|
|
|
1546
1524
|
androidPacketLength: tuning.androidPacketLength,
|
|
1547
1525
|
mtu: reactNative.Platform.OS === 'android' ? transport.mtuSize : undefined,
|
|
1548
1526
|
});
|
|
1549
|
-
const writeWithResponse = !!(options === null || options === void 0 ? void 0 : options.writeWithResponse) || (!!(options === null || options === void 0 ? void 0 : options.highVolume) && tuning.highVolumeWriteWithResponse);
|
|
1550
|
-
const writeMode = resolveBleWriteMode(transport.writeCharacteristic, writeWithResponse ? 'withResponse' : 'withoutResponse');
|
|
1551
|
-
const shouldThrottle = !!(options === null || options === void 0 ? void 0 : options.highVolume) && writeMode === 'withoutResponse';
|
|
1552
|
-
let packetsWritten = 0;
|
|
1553
1527
|
for (let offset = 0; offset < frame.length; offset += packetCapacity) {
|
|
1554
1528
|
const chunk = frame.slice(offset, offset + packetCapacity);
|
|
1555
1529
|
const base64 = buffer.Buffer.from(chunk).toString('base64');
|
|
1556
|
-
|
|
1557
|
-
yield transport.writeCharacteristic.writeWithResponse(base64);
|
|
1558
|
-
}
|
|
1559
|
-
else {
|
|
1560
|
-
yield transport.writeCharacteristic.writeWithoutResponse(base64);
|
|
1561
|
-
}
|
|
1562
|
-
packetsWritten += 1;
|
|
1563
|
-
if (shouldThrottle &&
|
|
1564
|
-
packetsWritten % tuning.highVolumeWriteBurstSize === 0 &&
|
|
1565
|
-
offset + packetCapacity < frame.length) {
|
|
1566
|
-
yield delay(tuning.highVolumeWritePauseMs);
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
if (shouldThrottle) {
|
|
1570
|
-
yield delay(tuning.highVolumeWriteFlushDelayMs);
|
|
1530
|
+
yield transport.writeCharacteristic.writeWithoutResponse(base64);
|
|
1571
1531
|
}
|
|
1572
1532
|
});
|
|
1573
1533
|
}
|
|
@@ -1581,12 +1541,10 @@ class ReactNativeBleTransport {
|
|
|
1581
1541
|
const highVolumeWrite = transport.LogBlockCommand.has(name);
|
|
1582
1542
|
if (highVolumeWrite) {
|
|
1583
1543
|
const tuning = getProtocolV2BleTuning();
|
|
1584
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 high-volume write
|
|
1544
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 high-volume write configured', {
|
|
1545
|
+
name,
|
|
1546
|
+
writeMode: 'withoutResponse',
|
|
1585
1547
|
packetCapacity: reactNative.Platform.OS === 'ios' ? tuning.iosPacketLength : tuning.androidPacketLength,
|
|
1586
|
-
burstSize: tuning.highVolumeWriteBurstSize,
|
|
1587
|
-
pauseMs: tuning.highVolumeWritePauseMs,
|
|
1588
|
-
flushDelayMs: tuning.highVolumeWriteFlushDelayMs,
|
|
1589
|
-
writeWithResponse: tuning.highVolumeWriteWithResponse,
|
|
1590
1548
|
});
|
|
1591
1549
|
}
|
|
1592
1550
|
try {
|
|
@@ -1616,12 +1574,10 @@ class ReactNativeBleTransport {
|
|
|
1616
1574
|
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
1617
1575
|
this.resetProtocolV2Frames(uuid);
|
|
1618
1576
|
},
|
|
1619
|
-
writeFrame: (frame
|
|
1577
|
+
writeFrame: (frame) => __awaiter(this, void 0, void 0, function* () {
|
|
1620
1578
|
assertCurrentGeneration();
|
|
1621
1579
|
const currentTransport = this.getCachedTransport(uuid);
|
|
1622
|
-
yield this.writeProtocolV2Frame(currentTransport, frame
|
|
1623
|
-
highVolume: context.highVolume,
|
|
1624
|
-
});
|
|
1580
|
+
yield this.writeProtocolV2Frame(currentTransport, frame);
|
|
1625
1581
|
}),
|
|
1626
1582
|
readFrame: () => __awaiter(this, void 0, void 0, function* () {
|
|
1627
1583
|
assertCurrentGeneration();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribeBleOn.d.ts","sourceRoot":"","sources":["../src/subscribeBleOn.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAO,MAAM,cAAc,eAAgB,aAAa,kBAAc,QAAQ,IAAI,
|
|
1
|
+
{"version":3,"file":"subscribeBleOn.d.ts","sourceRoot":"","sources":["../src/subscribeBleOn.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAO,MAAM,cAAc,eAAgB,aAAa,kBAAc,QAAQ,IAAI,CAmB9E,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProtocolType } from '@onekeyfe/hd-transport';
|
|
2
|
+
export declare function createTransportCallLog(name: string, protocol: ProtocolType, data: Record<string, unknown>): {
|
|
3
|
+
name: string;
|
|
4
|
+
protocol: ProtocolType;
|
|
5
|
+
file_name: unknown;
|
|
6
|
+
hash: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
name: string;
|
|
9
|
+
protocol: ProtocolType;
|
|
10
|
+
file_name?: undefined;
|
|
11
|
+
hash?: undefined;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=transportLog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transportLog.d.ts","sourceRoot":"","sources":["../src/transportLog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;EAY9B"}
|
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.13",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"lint:fix": "eslint . --fix"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@onekeyfe/hd-core": "1.2.0-alpha.
|
|
23
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
24
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
25
|
-
"@onekeyfe/react-native-ble-utils": "^0.1.
|
|
22
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.13",
|
|
23
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.13",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.13",
|
|
25
|
+
"@onekeyfe/react-native-ble-utils": "^0.1.6",
|
|
26
26
|
"react-native-ble-plx": "3.5.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "a907a7ec140123107f6188b37550a7143f1e0d91"
|
|
29
29
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hasWritableCapability,
|
|
3
|
-
resolveBleWriteMode,
|
|
4
|
-
resolveProtocolV2PacketCapacity,
|
|
5
|
-
} from '../bleStrategy';
|
|
1
|
+
import { hasWritableCapability, resolveProtocolV2PacketCapacity } from '../bleStrategy';
|
|
6
2
|
|
|
7
3
|
describe('React Native BLE strategy', () => {
|
|
8
4
|
test('accepts writeWithoutResponse-only characteristics', () => {
|
|
@@ -12,7 +8,6 @@ describe('React Native BLE strategy', () => {
|
|
|
12
8
|
};
|
|
13
9
|
|
|
14
10
|
expect(hasWritableCapability(characteristic)).toBe(true);
|
|
15
|
-
expect(resolveBleWriteMode(characteristic)).toBe('withoutResponse');
|
|
16
11
|
});
|
|
17
12
|
|
|
18
13
|
test('falls back to Android default ATT payload when MTU is unavailable', () => {
|
|
@@ -107,28 +107,27 @@ const createHarness = () => {
|
|
|
107
107
|
return { remove: jest.fn() };
|
|
108
108
|
}),
|
|
109
109
|
};
|
|
110
|
+
const handleWrite = (base64: string) => {
|
|
111
|
+
const frame = Buffer.from(base64, 'base64');
|
|
112
|
+
sentSeqs.push(frame[6]);
|
|
113
|
+
if (shouldRespond) {
|
|
114
|
+
const response = ProtocolV2.encodeFrame(
|
|
115
|
+
schemas,
|
|
116
|
+
'Success',
|
|
117
|
+
{ message: 'ok' },
|
|
118
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
119
|
+
);
|
|
120
|
+
notifyCallback?.(null, { value: Buffer.from(response).toString('base64') });
|
|
121
|
+
}
|
|
122
|
+
return Promise.resolve();
|
|
123
|
+
};
|
|
110
124
|
const writeCharacteristic = {
|
|
111
125
|
uuid: '0002',
|
|
112
126
|
deviceID: uuid,
|
|
113
127
|
isWritableWithResponse: true,
|
|
114
128
|
isWritableWithoutResponse: true,
|
|
115
|
-
writeWithResponse: jest.fn(
|
|
116
|
-
|
|
117
|
-
sentSeqs.push(frame[6]);
|
|
118
|
-
if (shouldRespond) {
|
|
119
|
-
const response = ProtocolV2.encodeFrame(
|
|
120
|
-
schemas,
|
|
121
|
-
'Success',
|
|
122
|
-
{ message: 'ok' },
|
|
123
|
-
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
124
|
-
);
|
|
125
|
-
notifyCallback?.(null, { value: Buffer.from(response).toString('base64') });
|
|
126
|
-
}
|
|
127
|
-
return Promise.resolve();
|
|
128
|
-
}),
|
|
129
|
-
writeWithoutResponse: jest.fn(async (base64: string) => {
|
|
130
|
-
await writeCharacteristic.writeWithResponse(base64);
|
|
131
|
-
}),
|
|
129
|
+
writeWithResponse: jest.fn(handleWrite),
|
|
130
|
+
writeWithoutResponse: jest.fn(handleWrite),
|
|
132
131
|
};
|
|
133
132
|
const device = {
|
|
134
133
|
id: uuid,
|
|
@@ -156,6 +155,7 @@ const createHarness = () => {
|
|
|
156
155
|
transport,
|
|
157
156
|
uuid,
|
|
158
157
|
sentSeqs,
|
|
158
|
+
writeCharacteristic,
|
|
159
159
|
setShouldRespond(value: boolean) {
|
|
160
160
|
shouldRespond = value;
|
|
161
161
|
},
|
|
@@ -208,14 +208,20 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
208
208
|
await transport.release(uuid, true);
|
|
209
209
|
});
|
|
210
210
|
|
|
211
|
-
test('
|
|
212
|
-
const { transport, uuid } = createHarness();
|
|
213
|
-
const writeSpy = jest.spyOn(transport as any, 'writeProtocolV2Frame');
|
|
211
|
+
test('uses withoutResponse for normal and high-volume calls', async () => {
|
|
212
|
+
const { transport, uuid, writeCharacteristic } = createHarness();
|
|
214
213
|
|
|
215
214
|
await transport.acquire({ uuid });
|
|
216
|
-
|
|
215
|
+
expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(1);
|
|
216
|
+
expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
|
|
217
|
+
|
|
218
|
+
await transport.call(uuid, 'Ping', { message: 'normal' });
|
|
219
|
+
expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(2);
|
|
220
|
+
expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
|
|
217
221
|
|
|
218
|
-
|
|
222
|
+
await transport.call(uuid, 'FileWrite', {});
|
|
223
|
+
expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(3);
|
|
224
|
+
expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
|
|
219
225
|
await transport.release(uuid, true);
|
|
220
226
|
});
|
|
221
227
|
|
package/src/bleStrategy.ts
CHANGED
|
@@ -7,35 +7,10 @@ export type BleWriteCapability = {
|
|
|
7
7
|
isWritableWithoutResponse?: boolean | null;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export type BleWriteMode = 'withResponse' | 'withoutResponse';
|
|
11
|
-
|
|
12
10
|
export function hasWritableCapability(characteristic: BleWriteCapability) {
|
|
13
11
|
return !!(characteristic.isWritableWithResponse || characteristic.isWritableWithoutResponse);
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
export function resolveBleWriteMode(
|
|
17
|
-
characteristic: BleWriteCapability,
|
|
18
|
-
preferredMode: BleWriteMode = 'withoutResponse'
|
|
19
|
-
): BleWriteMode {
|
|
20
|
-
if (preferredMode === 'withoutResponse' && characteristic.isWritableWithoutResponse) {
|
|
21
|
-
return 'withoutResponse';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (preferredMode === 'withResponse' && characteristic.isWritableWithResponse) {
|
|
25
|
-
return 'withResponse';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (characteristic.isWritableWithoutResponse) {
|
|
29
|
-
return 'withoutResponse';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (characteristic.isWritableWithResponse) {
|
|
33
|
-
return 'withResponse';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return preferredMode;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
14
|
export function resolveProtocolV2PacketCapacity({
|
|
40
15
|
platform,
|
|
41
16
|
iosPacketLength = IOS_PACKET_LENGTH,
|
package/src/index.ts
CHANGED
|
@@ -23,11 +23,7 @@ import transport, {
|
|
|
23
23
|
import { ERRORS, HardwareErrorCode, createDeferred, isOnekeyDevice } from '@onekeyfe/hd-shared';
|
|
24
24
|
|
|
25
25
|
import { getConnectedDeviceIds, onDeviceBondState, pairDevice } from './BleManager';
|
|
26
|
-
import {
|
|
27
|
-
hasWritableCapability,
|
|
28
|
-
resolveBleWriteMode,
|
|
29
|
-
resolveProtocolV2PacketCapacity,
|
|
30
|
-
} from './bleStrategy';
|
|
26
|
+
import { hasWritableCapability, resolveProtocolV2PacketCapacity } from './bleStrategy';
|
|
31
27
|
import { subscribeBleOn } from './subscribeBleOn';
|
|
32
28
|
import {
|
|
33
29
|
ANDROID_PACKET_LENGTH,
|
|
@@ -41,6 +37,7 @@ import { isHeaderChunk } from './utils/validateNotify';
|
|
|
41
37
|
import BleTransport from './BleTransport';
|
|
42
38
|
import timer from './utils/timer';
|
|
43
39
|
import { bleLogger, setBleLogger } from './logger';
|
|
40
|
+
import { createTransportCallLog } from './transportLog';
|
|
44
41
|
|
|
45
42
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
46
43
|
import type { Characteristic, Device, Subscription } from 'react-native-ble-plx';
|
|
@@ -112,17 +109,9 @@ const PROTOCOL_V2_PROBE_TIMEOUT_MS = 10_000;
|
|
|
112
109
|
const DEVICE_SCAN_TIMEOUT_MS = 8000;
|
|
113
110
|
const IOS_NOTIFY_READY_DELAY_MS = 150;
|
|
114
111
|
const ANDROID_NOTIFY_READY_DELAY_MS = 300;
|
|
115
|
-
const HIGH_VOLUME_WRITE_BURST_SIZE = Platform.OS === 'ios' ? 4 : 6;
|
|
116
|
-
const HIGH_VOLUME_WRITE_PAUSE_MS = Platform.OS === 'ios' ? 6 : 2;
|
|
117
|
-
const HIGH_VOLUME_WRITE_FLUSH_DELAY_MS = Platform.OS === 'ios' ? 20 : 8;
|
|
118
|
-
|
|
119
112
|
export type ProtocolV2BleTuning = {
|
|
120
113
|
iosPacketLength?: number;
|
|
121
114
|
androidPacketLength?: number;
|
|
122
|
-
highVolumeWriteBurstSize?: number;
|
|
123
|
-
highVolumeWritePauseMs?: number;
|
|
124
|
-
highVolumeWriteFlushDelayMs?: number;
|
|
125
|
-
highVolumeWriteWithResponse?: boolean;
|
|
126
115
|
};
|
|
127
116
|
|
|
128
117
|
type ResolvedProtocolV2BleTuning = Required<ProtocolV2BleTuning>;
|
|
@@ -130,10 +119,6 @@ type ResolvedProtocolV2BleTuning = Required<ProtocolV2BleTuning>;
|
|
|
130
119
|
const DEFAULT_PROTOCOL_V2_BLE_TUNING: ResolvedProtocolV2BleTuning = {
|
|
131
120
|
iosPacketLength: IOS_PACKET_LENGTH,
|
|
132
121
|
androidPacketLength: ANDROID_PACKET_LENGTH,
|
|
133
|
-
highVolumeWriteBurstSize: HIGH_VOLUME_WRITE_BURST_SIZE,
|
|
134
|
-
highVolumeWritePauseMs: HIGH_VOLUME_WRITE_PAUSE_MS,
|
|
135
|
-
highVolumeWriteFlushDelayMs: HIGH_VOLUME_WRITE_FLUSH_DELAY_MS,
|
|
136
|
-
highVolumeWriteWithResponse: false,
|
|
137
122
|
};
|
|
138
123
|
|
|
139
124
|
let protocolV2BleTuning: ResolvedProtocolV2BleTuning = { ...DEFAULT_PROTOCOL_V2_BLE_TUNING };
|
|
@@ -154,27 +139,13 @@ export function configureProtocolV2BleTuning(tuning: ProtocolV2BleTuning = {}) {
|
|
|
154
139
|
tuning.androidPacketLength,
|
|
155
140
|
protocolV2BleTuning.androidPacketLength
|
|
156
141
|
),
|
|
157
|
-
highVolumeWriteBurstSize: normalizePositiveInteger(
|
|
158
|
-
tuning.highVolumeWriteBurstSize,
|
|
159
|
-
protocolV2BleTuning.highVolumeWriteBurstSize
|
|
160
|
-
),
|
|
161
|
-
highVolumeWritePauseMs: normalizePositiveInteger(
|
|
162
|
-
tuning.highVolumeWritePauseMs,
|
|
163
|
-
protocolV2BleTuning.highVolumeWritePauseMs
|
|
164
|
-
),
|
|
165
|
-
highVolumeWriteFlushDelayMs: normalizePositiveInteger(
|
|
166
|
-
tuning.highVolumeWriteFlushDelayMs,
|
|
167
|
-
protocolV2BleTuning.highVolumeWriteFlushDelayMs
|
|
168
|
-
),
|
|
169
|
-
highVolumeWriteWithResponse:
|
|
170
|
-
tuning.highVolumeWriteWithResponse ?? protocolV2BleTuning.highVolumeWriteWithResponse,
|
|
171
142
|
};
|
|
172
|
-
Log?.debug('[ReactNativeBleTransport]
|
|
143
|
+
Log?.debug('[ReactNativeBleTransport] BLE tuning configured', protocolV2BleTuning);
|
|
173
144
|
}
|
|
174
145
|
|
|
175
146
|
export function resetProtocolV2BleTuning() {
|
|
176
147
|
protocolV2BleTuning = { ...DEFAULT_PROTOCOL_V2_BLE_TUNING };
|
|
177
|
-
Log?.debug('[ReactNativeBleTransport]
|
|
148
|
+
Log?.debug('[ReactNativeBleTransport] BLE tuning reset', protocolV2BleTuning);
|
|
178
149
|
}
|
|
179
150
|
|
|
180
151
|
export function getProtocolV2BleTuning() {
|
|
@@ -223,9 +194,10 @@ const requestAndroidMtu = async (device: Device) => {
|
|
|
223
194
|
|
|
224
195
|
try {
|
|
225
196
|
const mtuDevice = await device.requestMTU(ANDROID_REQUEST_MTU);
|
|
226
|
-
Log?.debug('[ReactNativeBleTransport]
|
|
197
|
+
Log?.debug('[ReactNativeBleTransport] MTU configured', {
|
|
198
|
+
deviceId: device.id,
|
|
227
199
|
requested: ANDROID_REQUEST_MTU,
|
|
228
|
-
|
|
200
|
+
actual: mtuDevice.mtu,
|
|
229
201
|
});
|
|
230
202
|
return mtuDevice;
|
|
231
203
|
} catch (error) {
|
|
@@ -343,7 +315,6 @@ export default class ReactNativeBleTransport {
|
|
|
343
315
|
this.protocolV2Links
|
|
344
316
|
.invalidateAllLinks('Protocol V2 schema reconfigured')
|
|
345
317
|
.catch(error => Log?.debug('Protocol V2 schema link cleanup failed:', error));
|
|
346
|
-
Log?.debug('[ReactNativeBleTransport] Protocol V2 schema configured');
|
|
347
318
|
}
|
|
348
319
|
|
|
349
320
|
listen() {
|
|
@@ -574,14 +545,13 @@ export default class ReactNativeBleTransport {
|
|
|
574
545
|
}
|
|
575
546
|
|
|
576
547
|
blePlxManager.startDeviceScan(
|
|
577
|
-
|
|
548
|
+
getBluetoothServiceUuids(),
|
|
578
549
|
{
|
|
579
550
|
allowDuplicates: true,
|
|
580
551
|
scanMode: ScanMode.LowLatency,
|
|
581
552
|
},
|
|
582
553
|
(error, device) => {
|
|
583
554
|
if (error) {
|
|
584
|
-
Log?.debug('ble scan manager: ', blePlxManager);
|
|
585
555
|
Log?.debug('ble scan error: ', error);
|
|
586
556
|
if (
|
|
587
557
|
[BleErrorCode.BluetoothPoweredOff, BleErrorCode.BluetoothInUnknownState].includes(
|
|
@@ -609,29 +579,8 @@ export default class ReactNativeBleTransport {
|
|
|
609
579
|
isOnekeyDevice(device?.name ?? null, device?.id) ||
|
|
610
580
|
isOnekeyDevice(device?.localName ?? null, device?.id) ||
|
|
611
581
|
hasKnownOneKeyService(device);
|
|
612
|
-
const shouldTraceCandidate =
|
|
613
|
-
!!displayName && /onekey|bixinkey|pro\s*2|pro\b|touch|^k\d|^t\d/i.test(displayName);
|
|
614
|
-
|
|
615
|
-
if (shouldTraceCandidate) {
|
|
616
|
-
Log?.debug('[ReactNativeBleTransport] scan candidate', {
|
|
617
|
-
name: device?.name,
|
|
618
|
-
localName: device?.localName,
|
|
619
|
-
id: device?.id,
|
|
620
|
-
serviceUUIDs: device?.serviceUUIDs,
|
|
621
|
-
accepted: isOneKey,
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
|
|
625
582
|
if (isOneKey) {
|
|
626
|
-
Log?.debug('search device start ======================');
|
|
627
|
-
const { name, localName, id, serviceUUIDs } = device ?? {};
|
|
628
|
-
Log?.debug(
|
|
629
|
-
`device name: ${name ?? ''}\nlocalName: ${localName ?? ''}\nid: ${
|
|
630
|
-
id ?? ''
|
|
631
|
-
}\nserviceUUIDs: ${(serviceUUIDs ?? []).join(',')}`
|
|
632
|
-
);
|
|
633
583
|
addDevice(device as unknown as Device);
|
|
634
|
-
Log?.debug('search device end ======================\n');
|
|
635
584
|
} else if (displayName && /\bpro\s*2\b/i.test(displayName)) {
|
|
636
585
|
Log?.debug('[ReactNativeBleTransport] Pro2-like BLE device was not accepted:', {
|
|
637
586
|
name: device?.name,
|
|
@@ -643,12 +592,19 @@ export default class ReactNativeBleTransport {
|
|
|
643
592
|
}
|
|
644
593
|
);
|
|
645
594
|
|
|
646
|
-
getConnectedDeviceIds(getBluetoothServiceUuids()).then(
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
595
|
+
getConnectedDeviceIds(Platform.OS === 'ios' ? getBluetoothServiceUuids() : []).then(
|
|
596
|
+
devices => {
|
|
597
|
+
for (const device of devices) {
|
|
598
|
+
const { serviceUUIDs } = device as { serviceUUIDs?: string[] };
|
|
599
|
+
const hasCachedServiceUuid = Boolean(serviceUUIDs?.length);
|
|
600
|
+
const keepDevice = Platform.OS === 'ios' || hasCachedServiceUuid;
|
|
601
|
+
if (keepDevice) {
|
|
602
|
+
Log?.debug('search connected peripheral: ', device.id);
|
|
603
|
+
addDevice(device as unknown as Device);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
650
606
|
}
|
|
651
|
-
|
|
607
|
+
);
|
|
652
608
|
|
|
653
609
|
const addDevice = (device: Device) => {
|
|
654
610
|
if (deviceList.every(d => d.id !== device.id)) {
|
|
@@ -662,6 +618,12 @@ export default class ReactNativeBleTransport {
|
|
|
662
618
|
name: displayName,
|
|
663
619
|
commType: 'ble',
|
|
664
620
|
} as IOneKeyDevice);
|
|
621
|
+
Log?.debug('[ReactNativeBleTransport] OneKey BLE device discovered', {
|
|
622
|
+
deviceId: device.id,
|
|
623
|
+
name: displayName,
|
|
624
|
+
serviceUUIDs: device.serviceUUIDs,
|
|
625
|
+
protocolHint,
|
|
626
|
+
});
|
|
665
627
|
}
|
|
666
628
|
};
|
|
667
629
|
|
|
@@ -1075,33 +1037,13 @@ export default class ReactNativeBleTransport {
|
|
|
1075
1037
|
`Device protocol has not been detected for ${uuid}`
|
|
1076
1038
|
);
|
|
1077
1039
|
}
|
|
1078
|
-
|
|
1079
|
-
if (name === 'ResourceUpdate' || name === 'ResourceAck') {
|
|
1080
|
-
Log?.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', {
|
|
1081
|
-
file_name: data?.file_name,
|
|
1082
|
-
hash: data?.hash,
|
|
1083
|
-
});
|
|
1084
|
-
} else if (LogBlockCommand.has(name)) {
|
|
1085
|
-
Log?.debug('transport-react-native', 'call-', ' name: ', name, ' protocol: ', protocol);
|
|
1086
|
-
} else {
|
|
1087
|
-
Log?.debug(
|
|
1088
|
-
'transport-react-native',
|
|
1089
|
-
'call-',
|
|
1090
|
-
' name: ',
|
|
1091
|
-
name,
|
|
1092
|
-
' data: ',
|
|
1093
|
-
data,
|
|
1094
|
-
' protocol: ',
|
|
1095
|
-
protocol
|
|
1096
|
-
);
|
|
1097
|
-
}
|
|
1040
|
+
Log?.debug('transport call', createTransportCallLog(name, protocol, data));
|
|
1098
1041
|
|
|
1099
1042
|
if (protocol === 'V2') {
|
|
1100
1043
|
return this.callProtocolV2(uuid, name, data, options);
|
|
1101
1044
|
}
|
|
1102
1045
|
|
|
1103
1046
|
const forceRun = name === 'Initialize' || name === 'Cancel';
|
|
1104
|
-
Log?.debug('transport-react-native call this.runPromise', this.runPromise);
|
|
1105
1047
|
if (this.runPromise && !forceRun) {
|
|
1106
1048
|
throw ERRORS.TypedError(HardwareErrorCode.TransportCallInProgress);
|
|
1107
1049
|
}
|
|
@@ -1199,14 +1141,13 @@ export default class ReactNativeBleTransport {
|
|
|
1199
1141
|
}
|
|
1200
1142
|
);
|
|
1201
1143
|
} else if (name === 'FirmwareUpload') {
|
|
1202
|
-
Log?.debug('[ReactNativeBleTransport]
|
|
1144
|
+
Log?.debug('[ReactNativeBleTransport] Firmware upload transport configured', {
|
|
1203
1145
|
packetCapacity: FIRMWARE_UPLOAD_WRITE_PACKET_CAPACITY,
|
|
1204
1146
|
burstSize: FIRMWARE_UPLOAD_WRITE_BURST_SIZE,
|
|
1205
1147
|
pauseMs: FIRMWARE_UPLOAD_WRITE_PAUSE_MS,
|
|
1206
1148
|
flushDelayMs: FIRMWARE_UPLOAD_WRITE_FLUSH_DELAY_MS,
|
|
1207
1149
|
maxRetries: FIRMWARE_UPLOAD_WRITE_MAX_RETRIES,
|
|
1208
1150
|
});
|
|
1209
|
-
|
|
1210
1151
|
await writeFirmwareUploadChunkedData(
|
|
1211
1152
|
buffers,
|
|
1212
1153
|
async data => {
|
|
@@ -1260,7 +1201,6 @@ export default class ReactNativeBleTransport {
|
|
|
1260
1201
|
for (const o of buffers) {
|
|
1261
1202
|
const outData = o.toString('base64');
|
|
1262
1203
|
// Upload resources on low-end phones may OOM
|
|
1263
|
-
// this.Log.debug('send hex strting: ', o.toString('hex'));
|
|
1264
1204
|
try {
|
|
1265
1205
|
await transport.writeCharacteristic.writeWithoutResponse(outData);
|
|
1266
1206
|
} catch (e) {
|
|
@@ -1298,7 +1238,6 @@ export default class ReactNativeBleTransport {
|
|
|
1298
1238
|
throw new Error('Returning data is not string.');
|
|
1299
1239
|
}
|
|
1300
1240
|
|
|
1301
|
-
Log?.debug('receive data: ', response);
|
|
1302
1241
|
const jsonData = ProtocolV1.decodeMessage(messages, response);
|
|
1303
1242
|
return check.call(jsonData);
|
|
1304
1243
|
} catch (e) {
|
|
@@ -1321,7 +1260,6 @@ export default class ReactNativeBleTransport {
|
|
|
1321
1260
|
}
|
|
1322
1261
|
|
|
1323
1262
|
async disconnect(session: string) {
|
|
1324
|
-
Log?.debug('transport-react-native transport resetSession: ', session);
|
|
1325
1263
|
await this.protocolV2Links.invalidateLink(session, 'React Native BLE transport disconnected');
|
|
1326
1264
|
const transport = transportCache[session];
|
|
1327
1265
|
|
|
@@ -1443,7 +1381,11 @@ export default class ReactNativeBleTransport {
|
|
|
1443
1381
|
if (expectedProtocol === 'V1') {
|
|
1444
1382
|
if (await this.probeProtocolV1(uuid)) {
|
|
1445
1383
|
this.deviceProtocol.set(uuid, 'V1');
|
|
1446
|
-
Log?.debug(
|
|
1384
|
+
Log?.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1385
|
+
deviceId: uuid,
|
|
1386
|
+
protocol: 'V1',
|
|
1387
|
+
source: 'expected',
|
|
1388
|
+
});
|
|
1447
1389
|
return 'V1';
|
|
1448
1390
|
}
|
|
1449
1391
|
throw this.createProtocolMismatchError(expectedProtocol);
|
|
@@ -1453,7 +1395,11 @@ export default class ReactNativeBleTransport {
|
|
|
1453
1395
|
// 免探测路径:调用方显式承诺该设备是 V2(例如固件升级重启后的重连场景,
|
|
1454
1396
|
// 上层已经探测过协议并通过 expectedProtocol 传回),这里不再重复探测。
|
|
1455
1397
|
this.deviceProtocol.set(uuid, 'V2');
|
|
1456
|
-
Log?.debug(
|
|
1398
|
+
Log?.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1399
|
+
deviceId: uuid,
|
|
1400
|
+
protocol: 'V2',
|
|
1401
|
+
source: 'expected',
|
|
1402
|
+
});
|
|
1457
1403
|
return 'V2';
|
|
1458
1404
|
}
|
|
1459
1405
|
|
|
@@ -1473,7 +1419,11 @@ export default class ReactNativeBleTransport {
|
|
|
1473
1419
|
protocol === 'V1' ? await this.probeProtocolV1(uuid) : await this.probeProtocolV2(uuid);
|
|
1474
1420
|
if (detected) {
|
|
1475
1421
|
this.deviceProtocol.set(uuid, protocol);
|
|
1476
|
-
Log?.debug(
|
|
1422
|
+
Log?.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1423
|
+
deviceId: uuid,
|
|
1424
|
+
protocol,
|
|
1425
|
+
source: 'probe',
|
|
1426
|
+
});
|
|
1477
1427
|
return protocol;
|
|
1478
1428
|
}
|
|
1479
1429
|
}
|
|
@@ -1659,11 +1609,7 @@ export default class ReactNativeBleTransport {
|
|
|
1659
1609
|
}
|
|
1660
1610
|
}
|
|
1661
1611
|
|
|
1662
|
-
private async writeProtocolV2Frame(
|
|
1663
|
-
transport: BleTransport,
|
|
1664
|
-
frame: Uint8Array,
|
|
1665
|
-
options?: { highVolume?: boolean; writeWithResponse?: boolean }
|
|
1666
|
-
) {
|
|
1612
|
+
private async writeProtocolV2Frame(transport: BleTransport, frame: Uint8Array) {
|
|
1667
1613
|
const tuning = getProtocolV2BleTuning();
|
|
1668
1614
|
const packetCapacity = resolveProtocolV2PacketCapacity({
|
|
1669
1615
|
platform: Platform.OS,
|
|
@@ -1671,36 +1617,10 @@ export default class ReactNativeBleTransport {
|
|
|
1671
1617
|
androidPacketLength: tuning.androidPacketLength,
|
|
1672
1618
|
mtu: Platform.OS === 'android' ? transport.mtuSize : undefined,
|
|
1673
1619
|
});
|
|
1674
|
-
const writeWithResponse =
|
|
1675
|
-
!!options?.writeWithResponse || (!!options?.highVolume && tuning.highVolumeWriteWithResponse);
|
|
1676
|
-
const writeMode = resolveBleWriteMode(
|
|
1677
|
-
transport.writeCharacteristic,
|
|
1678
|
-
writeWithResponse ? 'withResponse' : 'withoutResponse'
|
|
1679
|
-
);
|
|
1680
|
-
const shouldThrottle = !!options?.highVolume && writeMode === 'withoutResponse';
|
|
1681
|
-
let packetsWritten = 0;
|
|
1682
|
-
|
|
1683
1620
|
for (let offset = 0; offset < frame.length; offset += packetCapacity) {
|
|
1684
1621
|
const chunk = frame.slice(offset, offset + packetCapacity);
|
|
1685
1622
|
const base64 = Buffer.from(chunk).toString('base64');
|
|
1686
|
-
|
|
1687
|
-
await transport.writeCharacteristic.writeWithResponse(base64);
|
|
1688
|
-
} else {
|
|
1689
|
-
await transport.writeCharacteristic.writeWithoutResponse(base64);
|
|
1690
|
-
}
|
|
1691
|
-
packetsWritten += 1;
|
|
1692
|
-
|
|
1693
|
-
if (
|
|
1694
|
-
shouldThrottle &&
|
|
1695
|
-
packetsWritten % tuning.highVolumeWriteBurstSize === 0 &&
|
|
1696
|
-
offset + packetCapacity < frame.length
|
|
1697
|
-
) {
|
|
1698
|
-
await delay(tuning.highVolumeWritePauseMs);
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
|
|
1702
|
-
if (shouldThrottle) {
|
|
1703
|
-
await delay(tuning.highVolumeWriteFlushDelayMs);
|
|
1623
|
+
await transport.writeCharacteristic.writeWithoutResponse(base64);
|
|
1704
1624
|
}
|
|
1705
1625
|
}
|
|
1706
1626
|
|
|
@@ -1722,18 +1642,11 @@ export default class ReactNativeBleTransport {
|
|
|
1722
1642
|
|
|
1723
1643
|
if (highVolumeWrite) {
|
|
1724
1644
|
const tuning = getProtocolV2BleTuning();
|
|
1725
|
-
Log?.debug(
|
|
1726
|
-
'[ReactNativeBleTransport] Protocol V2 high-volume write uses throttled writeWithoutResponse:',
|
|
1645
|
+
Log?.debug('[ReactNativeBleTransport] Protocol V2 high-volume write configured', {
|
|
1727
1646
|
name,
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
burstSize: tuning.highVolumeWriteBurstSize,
|
|
1732
|
-
pauseMs: tuning.highVolumeWritePauseMs,
|
|
1733
|
-
flushDelayMs: tuning.highVolumeWriteFlushDelayMs,
|
|
1734
|
-
writeWithResponse: tuning.highVolumeWriteWithResponse,
|
|
1735
|
-
}
|
|
1736
|
-
);
|
|
1647
|
+
writeMode: 'withoutResponse',
|
|
1648
|
+
packetCapacity: Platform.OS === 'ios' ? tuning.iosPacketLength : tuning.androidPacketLength,
|
|
1649
|
+
});
|
|
1737
1650
|
}
|
|
1738
1651
|
|
|
1739
1652
|
try {
|
|
@@ -1767,12 +1680,10 @@ export default class ReactNativeBleTransport {
|
|
|
1767
1680
|
this.protocolV2Assemblers.get(uuid)?.reset();
|
|
1768
1681
|
this.resetProtocolV2Frames(uuid);
|
|
1769
1682
|
},
|
|
1770
|
-
writeFrame: async (frame: Uint8Array
|
|
1683
|
+
writeFrame: async (frame: Uint8Array) => {
|
|
1771
1684
|
assertCurrentGeneration();
|
|
1772
1685
|
const currentTransport = this.getCachedTransport(uuid);
|
|
1773
|
-
await this.writeProtocolV2Frame(currentTransport, frame
|
|
1774
|
-
highVolume: context.highVolume,
|
|
1775
|
-
});
|
|
1686
|
+
await this.writeProtocolV2Frame(currentTransport, frame);
|
|
1776
1687
|
},
|
|
1777
1688
|
readFrame: async () => {
|
|
1778
1689
|
assertCurrentGeneration();
|
package/src/subscribeBleOn.ts
CHANGED
|
@@ -9,8 +9,6 @@ export const subscribeBleOn = (bleManager: BlePlxManager, ms = 1000): Promise<vo
|
|
|
9
9
|
let done = false;
|
|
10
10
|
|
|
11
11
|
const subscription = bleManager.onStateChange(state => {
|
|
12
|
-
console.log('ble state -> ', state);
|
|
13
|
-
|
|
14
12
|
if (state === 'PoweredOn') {
|
|
15
13
|
if (done) return;
|
|
16
14
|
clearTimeout();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ProtocolType } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
3
|
+
export function createTransportCallLog(
|
|
4
|
+
name: string,
|
|
5
|
+
protocol: ProtocolType,
|
|
6
|
+
data: Record<string, unknown>
|
|
7
|
+
) {
|
|
8
|
+
if (name === 'ResourceUpdate' || name === 'ResourceAck') {
|
|
9
|
+
return {
|
|
10
|
+
name,
|
|
11
|
+
protocol,
|
|
12
|
+
file_name: data.file_name,
|
|
13
|
+
hash: data.hash,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return { name, protocol };
|
|
18
|
+
}
|