@onekeyfe/hd-transport-electron 1.2.0-alpha.166 → 1.2.0-alpha.167
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.
|
@@ -32,7 +32,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
32
32
|
|
|
33
33
|
function initNobleBleSupport(webContents) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-
|
|
35
|
+
const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-ed9148f1.js'); });
|
|
36
36
|
setupNobleBleHandlers(webContents);
|
|
37
37
|
});
|
|
38
38
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-d4b61656.js');
|
|
4
4
|
var hdShared = require('@onekeyfe/hd-shared');
|
|
5
5
|
var pRetry = require('p-retry');
|
|
6
6
|
|
|
@@ -396,10 +396,6 @@ function cleanupDevice(deviceId, webContents, options = {}) {
|
|
|
396
396
|
pairedDevices.delete(deviceId);
|
|
397
397
|
}
|
|
398
398
|
if (cleanupDiscoveredCache) {
|
|
399
|
-
const evicted = discoveredDevices.get(deviceId);
|
|
400
|
-
if (evicted) {
|
|
401
|
-
stalePeripherals.set(deviceId, evicted);
|
|
402
|
-
}
|
|
403
399
|
discoveredDevices.delete(deviceId);
|
|
404
400
|
}
|
|
405
401
|
if (sendDisconnectEvent) {
|
|
@@ -549,6 +545,7 @@ function attemptWindowsWriteUntilPaired(deviceId, doGetWriteCharacteristic, payl
|
|
|
549
545
|
});
|
|
550
546
|
}
|
|
551
547
|
function transmitHexDataToDevice(deviceId, hexData, options) {
|
|
548
|
+
var _a;
|
|
552
549
|
return index.__awaiter(this, void 0, void 0, function* () {
|
|
553
550
|
const characteristics = deviceCharacteristics.get(deviceId);
|
|
554
551
|
const peripheral = connectedDevices.get(deviceId);
|
|
@@ -560,6 +557,14 @@ function transmitHexDataToDevice(deviceId, hexData, options) {
|
|
|
560
557
|
const doGetWriteCharacteristic = () => { var _a; return (_a = deviceCharacteristics.get(deviceId)) === null || _a === void 0 ? void 0 : _a.write; };
|
|
561
558
|
const packetCapacity = resolveBlePacketCapacity(peripheral.mtu, BLE_PACKET_SIZE_MAXIMUM, BLE_PACKET_SIZE_FALLBACK);
|
|
562
559
|
const pacingDelayMs = resolveNobleBleWritePacingDelay(options);
|
|
560
|
+
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Write frame', {
|
|
561
|
+
deviceId,
|
|
562
|
+
bytes: toBuffer.length,
|
|
563
|
+
head: toBuffer.subarray(0, 8).toString('hex'),
|
|
564
|
+
packetCapacity,
|
|
565
|
+
mtu: (_a = peripheral.mtu) !== null && _a !== void 0 ? _a : null,
|
|
566
|
+
pacingDelayMs,
|
|
567
|
+
});
|
|
563
568
|
if (!IS_WINDOWS || pairedDevices.has(deviceId)) {
|
|
564
569
|
const writeCharacteristic = doGetWriteCharacteristic();
|
|
565
570
|
if (!writeCharacteristic) {
|
|
@@ -604,7 +609,6 @@ function transmitHexDataToDevice(deviceId, hexData, options) {
|
|
|
604
609
|
});
|
|
605
610
|
}
|
|
606
611
|
const BLE_COLD_CONNECT_SCAN_TIMEOUT_MS = 1500;
|
|
607
|
-
const stalePeripherals = new Map();
|
|
608
612
|
const bleNamesById = new Map();
|
|
609
613
|
function rememberBleName(deviceId, name) {
|
|
610
614
|
const trimmed = name === null || name === void 0 ? void 0 : name.trim();
|
|
@@ -914,12 +918,7 @@ function forceReconnectPeripheral(peripheral, deviceId) {
|
|
|
914
918
|
yield runBleCallbackOperation(callback => peripheral.disconnect(() => {
|
|
915
919
|
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Force disconnect completed');
|
|
916
920
|
callback();
|
|
917
|
-
}), { timeoutMs:
|
|
918
|
-
if (peripheral.state === 'connected') {
|
|
919
|
-
logger === null || logger === void 0 ? void 0 : logger.warn('[NobleBLE] Reset disconnect did not confirm, reconnecting anyway', {
|
|
920
|
-
deviceId,
|
|
921
|
-
});
|
|
922
|
-
}
|
|
921
|
+
}), { timeoutMs: BLE_CLEANUP_TIMEOUT, timeoutBehavior: 'resolve' });
|
|
923
922
|
}
|
|
924
923
|
yield runBleCallbackOperation(callback => peripheral.connect(callback), {
|
|
925
924
|
timeoutMs: NOBLE_BLE_CONNECTION_TIMEOUT_MS,
|
|
@@ -1122,16 +1121,6 @@ function connectDevice(deviceId, webContents) {
|
|
|
1122
1121
|
if (!peripheral) {
|
|
1123
1122
|
peripheral = byIdFirst ? yield scanForPeripheral() : yield connectById();
|
|
1124
1123
|
}
|
|
1125
|
-
if (!peripheral) {
|
|
1126
|
-
const stale = stalePeripherals.get(deviceId);
|
|
1127
|
-
if (stale) {
|
|
1128
|
-
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Falling back to the last known peripheral:', deviceId);
|
|
1129
|
-
peripheral = stale;
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
else {
|
|
1133
|
-
stalePeripherals.delete(deviceId);
|
|
1134
|
-
}
|
|
1135
1124
|
}
|
|
1136
1125
|
if (!peripheral) {
|
|
1137
1126
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Device ${deviceId} not found`);
|
|
@@ -1322,6 +1311,11 @@ function subscribeNotifications(deviceId, callback) {
|
|
|
1322
1311
|
timeoutBehavior: 'reject',
|
|
1323
1312
|
});
|
|
1324
1313
|
notifyCharacteristic.on('data', (data) => {
|
|
1314
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('[NobleBLE] Notify frame', {
|
|
1315
|
+
deviceId,
|
|
1316
|
+
bytes: data.length,
|
|
1317
|
+
head: data.subarray(0, 8).toString('hex'),
|
|
1318
|
+
});
|
|
1325
1319
|
if (!pairedDevices.has(deviceId)) {
|
|
1326
1320
|
pairedDevices.add(deviceId);
|
|
1327
1321
|
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Device paired successfully', { deviceId });
|
|
@@ -1330,9 +1324,14 @@ function subscribeNotifications(deviceId, callback) {
|
|
|
1330
1324
|
});
|
|
1331
1325
|
});
|
|
1332
1326
|
}
|
|
1327
|
+
const subscribeStartedAt = Date.now();
|
|
1333
1328
|
try {
|
|
1334
1329
|
yield rebuildAppSubscription(deviceId, notifyCharacteristic);
|
|
1335
1330
|
subscribedDevices.set(deviceId, true);
|
|
1331
|
+
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Notification subscription active', {
|
|
1332
|
+
deviceId,
|
|
1333
|
+
ms: Date.now() - subscribeStartedAt,
|
|
1334
|
+
});
|
|
1336
1335
|
}
|
|
1337
1336
|
finally {
|
|
1338
1337
|
subscriptionOperations.set(deviceId, 'idle');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAoFhE,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,oBAAoB,UAI7E;
|
|
1
|
+
{"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAoFhE,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,oBAAoB,UAI7E;AAutDD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAkMpE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-electron",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.167",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"electron-log": ">=4.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-core": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
30
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.167",
|
|
29
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.167",
|
|
30
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.167",
|
|
31
31
|
"@stoprocent/noble": "2.3.16",
|
|
32
32
|
"p-retry": "^4.6.2"
|
|
33
33
|
},
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"electron": "^25.0.0",
|
|
37
37
|
"typescript": "^5.3.3"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "aa450044aaef7519d647a1857a38ac3d4e306475"
|
|
40
40
|
}
|
package/src/noble-ble-handler.ts
CHANGED
|
@@ -503,16 +503,8 @@ function cleanupDevice(
|
|
|
503
503
|
pairedDevices.delete(deviceId);
|
|
504
504
|
}
|
|
505
505
|
|
|
506
|
-
// 2. Clean up discovered cache (optional)
|
|
507
|
-
// through a disconnect is never preferred again — reconnecting it is what
|
|
508
|
-
// produces stale-session links — but it is kept aside as the last resort for
|
|
509
|
-
// a bonded device that stays silent, so eviction cannot turn a working
|
|
510
|
-
// reconnect into DeviceNotFound.
|
|
506
|
+
// 2. Clean up discovered cache (optional)
|
|
511
507
|
if (cleanupDiscoveredCache) {
|
|
512
|
-
const evicted = discoveredDevices.get(deviceId);
|
|
513
|
-
if (evicted) {
|
|
514
|
-
stalePeripherals.set(deviceId, evicted);
|
|
515
|
-
}
|
|
516
508
|
discoveredDevices.delete(deviceId);
|
|
517
509
|
}
|
|
518
510
|
|
|
@@ -741,6 +733,17 @@ async function transmitHexDataToDevice(
|
|
|
741
733
|
);
|
|
742
734
|
const pacingDelayMs = resolveNobleBleWritePacingDelay(options);
|
|
743
735
|
|
|
736
|
+
// Diagnostics: the frame header alone (report id + magic + message type +
|
|
737
|
+
// length) identifies which protocol frame went out, without logging payload.
|
|
738
|
+
logger?.info('[NobleBLE] Write frame', {
|
|
739
|
+
deviceId,
|
|
740
|
+
bytes: toBuffer.length,
|
|
741
|
+
head: toBuffer.subarray(0, 8).toString('hex'),
|
|
742
|
+
packetCapacity,
|
|
743
|
+
mtu: peripheral.mtu ?? null,
|
|
744
|
+
pacingDelayMs,
|
|
745
|
+
});
|
|
746
|
+
|
|
744
747
|
if (!IS_WINDOWS || pairedDevices.has(deviceId)) {
|
|
745
748
|
// macOS / Linux or already paired on Windows: direct write
|
|
746
749
|
const writeCharacteristic = doGetWriteCharacteristic();
|
|
@@ -804,10 +807,6 @@ async function transmitHexDataToDevice(
|
|
|
804
807
|
// 631ms, so this leaves ~2x headroom while keeping a miss cheap.
|
|
805
808
|
const BLE_COLD_CONNECT_SCAN_TIMEOUT_MS = 1500;
|
|
806
809
|
|
|
807
|
-
// Peripherals evicted by a disconnect, kept only as the fallback of last
|
|
808
|
-
// resort in connectDevice (see cleanupDevice).
|
|
809
|
-
const stalePeripherals = new Map<string, Peripheral>();
|
|
810
|
-
|
|
811
810
|
// Advertised names, kept for the life of the process: device caches are purged
|
|
812
811
|
// on every disconnect, but the family a device belongs to never changes and
|
|
813
812
|
// decides which connection strategy is safe for it.
|
|
@@ -1237,10 +1236,7 @@ async function forceReconnectPeripheral(peripheral: Peripheral, deviceId: string
|
|
|
1237
1236
|
reason: 'force-reconnect',
|
|
1238
1237
|
});
|
|
1239
1238
|
|
|
1240
|
-
// Step 2: Force disconnect if connected
|
|
1241
|
-
// confirmed: reconnecting while CoreBluetooth is still closing the old link
|
|
1242
|
-
// rebuilds the very stale-session state this reset exists to clear, and
|
|
1243
|
-
// 250ms is not enough to prove a physical teardown on macOS.
|
|
1239
|
+
// Step 2: Force disconnect if connected
|
|
1244
1240
|
if (peripheral.state === 'connected') {
|
|
1245
1241
|
await runBleCallbackOperation(
|
|
1246
1242
|
callback =>
|
|
@@ -1248,13 +1244,8 @@ async function forceReconnectPeripheral(peripheral: Peripheral, deviceId: string
|
|
|
1248
1244
|
logger?.info('[NobleBLE] Force disconnect completed');
|
|
1249
1245
|
callback();
|
|
1250
1246
|
}),
|
|
1251
|
-
{ timeoutMs:
|
|
1247
|
+
{ timeoutMs: BLE_CLEANUP_TIMEOUT, timeoutBehavior: 'resolve' }
|
|
1252
1248
|
);
|
|
1253
|
-
if (peripheral.state === 'connected') {
|
|
1254
|
-
logger?.warn('[NobleBLE] Reset disconnect did not confirm, reconnecting anyway', {
|
|
1255
|
-
deviceId,
|
|
1256
|
-
});
|
|
1257
|
-
}
|
|
1258
1249
|
}
|
|
1259
1250
|
|
|
1260
1251
|
// Step 3: Re-establish connection
|
|
@@ -1555,18 +1546,6 @@ async function connectDevice(deviceId: string, webContents: WebContents): Promis
|
|
|
1555
1546
|
// silent), or not reachable by id. Try the other one before giving up.
|
|
1556
1547
|
peripheral = byIdFirst ? await scanForPeripheral() : await connectById();
|
|
1557
1548
|
}
|
|
1558
|
-
if (!peripheral) {
|
|
1559
|
-
// Neither route resolved a peripheral: a bonded device that has gone
|
|
1560
|
-
// silent, or connect-by-id sitting in its cooldown. The evicted object is
|
|
1561
|
-
// worse than a fresh one, but it beats failing the call outright.
|
|
1562
|
-
const stale = stalePeripherals.get(deviceId);
|
|
1563
|
-
if (stale) {
|
|
1564
|
-
logger?.info('[NobleBLE] Falling back to the last known peripheral:', deviceId);
|
|
1565
|
-
peripheral = stale;
|
|
1566
|
-
}
|
|
1567
|
-
} else {
|
|
1568
|
-
stalePeripherals.delete(deviceId);
|
|
1569
|
-
}
|
|
1570
1549
|
}
|
|
1571
1550
|
|
|
1572
1551
|
// At this point, peripheral is guaranteed to be defined
|
|
@@ -1862,6 +1841,11 @@ async function subscribeNotifications(
|
|
|
1862
1841
|
});
|
|
1863
1842
|
|
|
1864
1843
|
notifyCharacteristic.on('data', (data: Buffer) => {
|
|
1844
|
+
logger?.debug('[NobleBLE] Notify frame', {
|
|
1845
|
+
deviceId,
|
|
1846
|
+
bytes: data.length,
|
|
1847
|
+
head: data.subarray(0, 8).toString('hex'),
|
|
1848
|
+
});
|
|
1865
1849
|
// Windows BLE pairing detection: receiving any data means device is paired
|
|
1866
1850
|
if (!pairedDevices.has(deviceId)) {
|
|
1867
1851
|
pairedDevices.add(deviceId);
|
|
@@ -1872,9 +1856,14 @@ async function subscribeNotifications(
|
|
|
1872
1856
|
});
|
|
1873
1857
|
}
|
|
1874
1858
|
|
|
1859
|
+
const subscribeStartedAt = Date.now();
|
|
1875
1860
|
try {
|
|
1876
1861
|
await rebuildAppSubscription(deviceId, notifyCharacteristic);
|
|
1877
1862
|
subscribedDevices.set(deviceId, true);
|
|
1863
|
+
logger?.info('[NobleBLE] Notification subscription active', {
|
|
1864
|
+
deviceId,
|
|
1865
|
+
ms: Date.now() - subscribeStartedAt,
|
|
1866
|
+
});
|
|
1878
1867
|
} finally {
|
|
1879
1868
|
// 🔒 CRITICAL: Always clear operation state (even on error)
|
|
1880
1869
|
subscriptionOperations.set(deviceId, 'idle');
|