@onekeyfe/hd-transport-web-device 1.2.0-alpha.74 → 1.2.0-alpha.75
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.
|
@@ -34,6 +34,7 @@ export default class ElectronBleTransport {
|
|
|
34
34
|
private v2FrameQueues;
|
|
35
35
|
private v2FramePromises;
|
|
36
36
|
private protocolV2Links;
|
|
37
|
+
private warnedMissingRelease;
|
|
37
38
|
private notificationCleanups;
|
|
38
39
|
private mtuCleanups;
|
|
39
40
|
private disconnectCleanups;
|
|
@@ -57,8 +58,10 @@ export default class ElectronBleTransport {
|
|
|
57
58
|
name: string | null;
|
|
58
59
|
protocolType?: ProtocolType | undefined;
|
|
59
60
|
}>;
|
|
60
|
-
release(id: string): Promise<void>;
|
|
61
|
+
release(id: string, _onclose?: boolean, keepSession?: boolean): Promise<void>;
|
|
62
|
+
disconnect(id: string): Promise<void>;
|
|
61
63
|
private releaseNative;
|
|
64
|
+
private releaseLogical;
|
|
62
65
|
private createProtocolMismatchError;
|
|
63
66
|
private createProtocolDetectionError;
|
|
64
67
|
private clearProbeProtocol;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AAuBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EAEZ,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAIvC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,UAAU,CAAC;KACzB;CACF;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC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romises;
|
|
185
185
|
private protocolV2Links;
|
|
186
|
+
/** One-shot guard so a missing preload `release` bridge is reported once. */
|
|
187
|
+
private warnedMissingRelease;
|
|
186
188
|
private notificationCleanups;
|
|
187
189
|
private mtuCleanups;
|
|
188
190
|
private disconnectCleanups;
|
|
@@ -206,8 +208,10 @@ declare class ElectronBleTransport {
|
|
|
206
208
|
name: string | null;
|
|
207
209
|
protocolType?: ProtocolType | undefined;
|
|
208
210
|
}>;
|
|
209
|
-
release(id: string): Promise<void>;
|
|
211
|
+
release(id: string, _onclose?: boolean, keepSession?: boolean): Promise<void>;
|
|
212
|
+
disconnect(id: string): Promise<void>;
|
|
210
213
|
private releaseNative;
|
|
214
|
+
private releaseLogical;
|
|
211
215
|
private createProtocolMismatchError;
|
|
212
216
|
private createProtocolDetectionError;
|
|
213
217
|
private clearProbeProtocol;
|
package/dist/index.js
CHANGED
|
@@ -779,6 +779,7 @@ class ElectronBleTransport {
|
|
|
779
779
|
}
|
|
780
780
|
}),
|
|
781
781
|
});
|
|
782
|
+
this.warnedMissingRelease = false;
|
|
782
783
|
this.notificationCleanups = new Map();
|
|
783
784
|
this.mtuCleanups = new Map();
|
|
784
785
|
this.disconnectCleanups = new Map();
|
|
@@ -990,12 +991,12 @@ class ElectronBleTransport {
|
|
|
990
991
|
}
|
|
991
992
|
});
|
|
992
993
|
}
|
|
993
|
-
release(id) {
|
|
994
|
+
release(id, _onclose, keepSession) {
|
|
994
995
|
var _a;
|
|
995
996
|
return __awaiter(this, void 0, void 0, function* () {
|
|
996
997
|
try {
|
|
997
998
|
yield this.protocolV2Links.invalidateLink(id, 'Electron BLE transport released');
|
|
998
|
-
yield this.
|
|
999
|
+
yield this.releaseLogical(id, keepSession);
|
|
999
1000
|
}
|
|
1000
1001
|
catch (error) {
|
|
1001
1002
|
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.error('[Electron BLE] release failed:', error);
|
|
@@ -1003,6 +1004,11 @@ class ElectronBleTransport {
|
|
|
1003
1004
|
}
|
|
1004
1005
|
});
|
|
1005
1006
|
}
|
|
1007
|
+
disconnect(id) {
|
|
1008
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1009
|
+
return this.releaseNative(id);
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1006
1012
|
releaseNative(id) {
|
|
1007
1013
|
var _a, _b;
|
|
1008
1014
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1021,6 +1027,30 @@ class ElectronBleTransport {
|
|
|
1021
1027
|
}
|
|
1022
1028
|
});
|
|
1023
1029
|
}
|
|
1030
|
+
releaseLogical(id, keepSession) {
|
|
1031
|
+
var _a, _b, _c, _d;
|
|
1032
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1033
|
+
try {
|
|
1034
|
+
if (!this.connectedDevices.has(id))
|
|
1035
|
+
return;
|
|
1036
|
+
this.cleanupDeviceState(id);
|
|
1037
|
+
const release = (_b = (_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle) === null || _b === void 0 ? void 0 : _b.release;
|
|
1038
|
+
if (!release) {
|
|
1039
|
+
if (!this.warnedMissingRelease) {
|
|
1040
|
+
this.warnedMissingRelease = true;
|
|
1041
|
+
(_c = this.Log) === null || _c === void 0 ? void 0 : _c.error('[Electron BLE] desktopApi.nobleBle.release is missing from the preload bridge; ' +
|
|
1042
|
+
'keep-alive idle countdown will never start — map NOBLE_BLE_RELEASE in the desktop preload');
|
|
1043
|
+
}
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
yield release(id, keepSession);
|
|
1047
|
+
}
|
|
1048
|
+
catch (error) {
|
|
1049
|
+
(_d = this.Log) === null || _d === void 0 ? void 0 : _d.error('[Electron BLE] logical release failed:', error);
|
|
1050
|
+
this.cleanupDeviceState(id);
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1024
1054
|
createProtocolMismatchError(expected) {
|
|
1025
1055
|
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
|
|
1026
1056
|
}
|
|
@@ -1482,6 +1512,7 @@ class ElectronBleTransport {
|
|
|
1482
1512
|
};
|
|
1483
1513
|
}
|
|
1484
1514
|
processProtocolV1Notification(deviceId, hexData) {
|
|
1515
|
+
var _a;
|
|
1485
1516
|
try {
|
|
1486
1517
|
if (typeof hexData !== 'string') {
|
|
1487
1518
|
return { isComplete: false, error: 'Invalid hexData type' };
|
|
@@ -1500,6 +1531,10 @@ class ElectronBleTransport {
|
|
|
1500
1531
|
bufferState.buffer = [...data.subarray(3)];
|
|
1501
1532
|
}
|
|
1502
1533
|
else {
|
|
1534
|
+
if (bufferState.buffer.length === 0) {
|
|
1535
|
+
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] Orphan continuation chunk discarded');
|
|
1536
|
+
return { isComplete: false };
|
|
1537
|
+
}
|
|
1503
1538
|
bufferState.buffer = bufferState.buffer.concat([...data]);
|
|
1504
1539
|
}
|
|
1505
1540
|
if (bufferState.buffer.length - transport.PROTOCOL_V1_MESSAGE_HEADER_SIZE >= bufferState.bufferLength) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-web-device",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.75",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"lint:fix": "eslint . --fix"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.75",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.75"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.75",
|
|
29
29
|
"@types/w3c-web-usb": "^1.0.6",
|
|
30
30
|
"@types/web-bluetooth": "^0.0.17"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "a9b3ab1cb53f87121ababb2b0ce45789be8fe5ad"
|
|
33
33
|
}
|
|
@@ -139,6 +139,9 @@ export default class ElectronBleTransport {
|
|
|
139
139
|
},
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
+
/** One-shot guard so a missing preload `release` bridge is reported once. */
|
|
143
|
+
private warnedMissingRelease = false;
|
|
144
|
+
|
|
142
145
|
private notificationCleanups: Map<string, () => void> = new Map();
|
|
143
146
|
|
|
144
147
|
private mtuCleanups: Map<string, () => void> = new Map();
|
|
@@ -382,16 +385,23 @@ export default class ElectronBleTransport {
|
|
|
382
385
|
}
|
|
383
386
|
}
|
|
384
387
|
|
|
385
|
-
async release(id: string) {
|
|
388
|
+
async release(id: string, _onclose?: boolean, keepSession?: boolean) {
|
|
386
389
|
try {
|
|
387
390
|
await this.protocolV2Links.invalidateLink(id, 'Electron BLE transport released');
|
|
388
|
-
await this.
|
|
391
|
+
await this.releaseLogical(id, keepSession);
|
|
389
392
|
} catch (error) {
|
|
390
393
|
this.Log?.error('[Electron BLE] release failed:', error);
|
|
391
394
|
this.cleanupDeviceState(id);
|
|
392
395
|
}
|
|
393
396
|
}
|
|
394
397
|
|
|
398
|
+
// DeviceConnector.disconnect feature-detects this; without it REQUIRE_DISCONNECT
|
|
399
|
+
// recovery is a no-op and keep-alive hands the wedged link to every retry.
|
|
400
|
+
async disconnect(id: string) {
|
|
401
|
+
return this.releaseNative(id);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Hard teardown, error paths only: a link presumed dead must not be reused.
|
|
395
405
|
private async releaseNative(id: string) {
|
|
396
406
|
try {
|
|
397
407
|
if (this.connectedDevices.has(id)) {
|
|
@@ -407,6 +417,32 @@ export default class ElectronBleTransport {
|
|
|
407
417
|
}
|
|
408
418
|
}
|
|
409
419
|
|
|
420
|
+
// Logical release: link and subscription stay up for the next call. Renderer
|
|
421
|
+
// listeners are still torn down, or fresh ones would double-process packets.
|
|
422
|
+
private async releaseLogical(id: string, keepSession?: boolean) {
|
|
423
|
+
try {
|
|
424
|
+
if (!this.connectedDevices.has(id)) return;
|
|
425
|
+
this.cleanupDeviceState(id);
|
|
426
|
+
|
|
427
|
+
const release = window.desktopApi?.nobleBle?.release;
|
|
428
|
+
if (!release) {
|
|
429
|
+
// Degraded, not broken: say it once, it just looks like a slow device.
|
|
430
|
+
if (!this.warnedMissingRelease) {
|
|
431
|
+
this.warnedMissingRelease = true;
|
|
432
|
+
this.Log?.error(
|
|
433
|
+
'[Electron BLE] desktopApi.nobleBle.release is missing from the preload bridge; ' +
|
|
434
|
+
'keep-alive idle countdown will never start — map NOBLE_BLE_RELEASE in the desktop preload'
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
await release(id, keepSession);
|
|
440
|
+
} catch (error) {
|
|
441
|
+
this.Log?.error('[Electron BLE] logical release failed:', error);
|
|
442
|
+
this.cleanupDeviceState(id);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
410
446
|
private createProtocolMismatchError(expected: ProtocolType) {
|
|
411
447
|
return ERRORS.TypedError(
|
|
412
448
|
HardwareErrorCode.RuntimeError,
|
|
@@ -953,6 +989,12 @@ export default class ElectronBleTransport {
|
|
|
953
989
|
bufferState.bufferLength = dataView.getInt32(5, false);
|
|
954
990
|
bufferState.buffer = [...data.subarray(3)];
|
|
955
991
|
} else {
|
|
992
|
+
if (bufferState.buffer.length === 0) {
|
|
993
|
+
// Tail of a cancelled call, arriving after the buffer was reset. Not an
|
|
994
|
+
// `error`: the caller rejects the in-flight call on that field.
|
|
995
|
+
this.Log?.debug('[Electron BLE] Orphan continuation chunk discarded');
|
|
996
|
+
return { isComplete: false };
|
|
997
|
+
}
|
|
956
998
|
bufferState.buffer = bufferState.buffer.concat([...data]);
|
|
957
999
|
}
|
|
958
1000
|
|