@onekeyfe/hd-transport-react-native 1.2.0-alpha.6 → 1.2.0-alpha.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BleTransport.d.ts +1 -3
- package/dist/BleTransport.d.ts.map +1 -1
- package/dist/bleStrategy.d.ts +0 -2
- package/dist/bleStrategy.d.ts.map +1 -1
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +21 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +401 -367
- package/dist/subscribeBleOn.d.ts.map +1 -1
- package/dist/transportLog.d.ts +2 -0
- package/dist/transportLog.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/jest.config.js +5 -0
- package/package.json +7 -6
- package/src/BleTransport.ts +6 -41
- package/src/__tests__/BleTransport.test.ts +93 -0
- package/src/__tests__/bleStrategy.test.ts +1 -6
- package/src/__tests__/constants.test.ts +20 -0
- package/src/__tests__/enumerate.test.ts +132 -0
- package/src/__tests__/protocolV2Link.test.ts +747 -0
- package/src/bleStrategy.ts +0 -25
- package/src/constants.ts +7 -13
- package/src/index.ts +472 -386
- package/src/subscribeBleOn.ts +0 -2
- package/src/transportLog.ts +1 -0
- package/src/types.ts +1 -0
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/constants.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createKnownBleUuidAliases, matchesKnownBleUuid } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
1
3
|
export const IOS_PACKET_LENGTH = 128;
|
|
2
4
|
export const ANDROID_PACKET_LENGTH = 192;
|
|
3
5
|
export const ANDROID_DEFAULT_MTU = 23;
|
|
@@ -40,7 +42,9 @@ export const getInfosForServiceUuid = (serviceUuid: string, deviceType: 'classic
|
|
|
40
42
|
const service =
|
|
41
43
|
services[serviceUuid] ??
|
|
42
44
|
Object.values(services).find(
|
|
43
|
-
item =>
|
|
45
|
+
item =>
|
|
46
|
+
normalizeBleUuid(item.serviceUuid) === normalizedServiceUuid ||
|
|
47
|
+
matchesKnownBleUuid(serviceUuid, createKnownBleUuidAliases(item.serviceUuid))
|
|
44
48
|
);
|
|
45
49
|
if (!service) {
|
|
46
50
|
return null;
|
|
@@ -51,17 +55,7 @@ export const getInfosForServiceUuid = (serviceUuid: string, deviceType: 'classic
|
|
|
51
55
|
export const normalizeBleUuid = (uuid?: string | null) =>
|
|
52
56
|
(uuid ?? '').replace(/-/g, '').toLowerCase();
|
|
53
57
|
|
|
54
|
-
export const getBleUuidKey = (uuid?: string | null) => {
|
|
55
|
-
const normalized = normalizeBleUuid(uuid);
|
|
56
|
-
return normalized.length >= 8 ? normalized.substring(4, 8) : normalized;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
58
|
export const isSameBleUuid = (left?: string | null, right?: string | null) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
normalizedLeft === normalizedRight ||
|
|
65
|
-
(getBleUuidKey(left) !== '' && getBleUuidKey(left) === getBleUuidKey(right))
|
|
66
|
-
);
|
|
59
|
+
if (!left || !right) return false;
|
|
60
|
+
return matchesKnownBleUuid(left, createKnownBleUuidAliases(right));
|
|
67
61
|
};
|