@onekeyfe/hd-transport-web-device 1.2.2-alpha.119 → 1.2.2-alpha.120
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/__tests__/electron-ble-transport.test.ts +2 -42
- package/__tests__/webusb-protocol-cache.test.ts +0 -33
- package/dist/electron-ble-transport.d.ts +0 -1
- package/dist/electron-ble-transport.d.ts.map +1 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.js +9 -18
- package/dist/webusb.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/electron-ble-transport.ts +4 -29
- package/src/webusb.ts +4 -8
|
@@ -205,52 +205,12 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
205
205
|
expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
|
|
206
206
|
});
|
|
207
207
|
|
|
208
|
-
test('
|
|
208
|
+
test('sends a native disconnect even before acquire marks the device connected', async () => {
|
|
209
209
|
const device = { id: 'pending-connect-id', name: 'OneKey Pro 2' };
|
|
210
210
|
const nobleBle = createNobleBle(device);
|
|
211
|
-
// Never calls back: the field case the Core acquire deadline has to break.
|
|
212
|
-
nobleBle.connect.mockImplementation(
|
|
213
|
-
() =>
|
|
214
|
-
new Promise<void>(() => {
|
|
215
|
-
// intentionally never settles
|
|
216
|
-
})
|
|
217
|
-
);
|
|
218
|
-
const bleTransport = configureTransport(nobleBle) as any;
|
|
219
|
-
|
|
220
|
-
const pendingAcquire = bleTransport.acquire({ uuid: device.id, expectedProtocol: 'V2' });
|
|
221
|
-
pendingAcquire.catch(() => undefined);
|
|
222
|
-
await new Promise(resolve => {
|
|
223
|
-
setTimeout(resolve, 10);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
// What the deadline / user abort calls. connectedDevices is still empty
|
|
227
|
-
// here, so this only works because the acquire is tracked as in flight.
|
|
228
|
-
await bleTransport.disconnect(device.id);
|
|
229
|
-
|
|
230
|
-
expect(nobleBle.unsubscribe).not.toHaveBeenCalled();
|
|
231
|
-
expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
test('leaves a kept-alive link up when a released device is disconnected', async () => {
|
|
235
|
-
const device = { id: 'kept-alive-id', name: 'OneKey Pro 2' };
|
|
236
|
-
const nobleBle = createNobleBle(device);
|
|
237
|
-
const bleTransport = configureTransport(nobleBle) as any;
|
|
238
|
-
|
|
239
|
-
// No acquire in flight and nothing in connectedDevices: the link was
|
|
240
|
-
// released logically and belongs to the main-process keep-alive timer.
|
|
241
|
-
// The routine post-call cancel must not cost the next call a cold connect.
|
|
242
|
-
await bleTransport.disconnect(device.id);
|
|
243
|
-
|
|
244
|
-
expect(nobleBle.disconnect).not.toHaveBeenCalled();
|
|
245
|
-
expect(nobleBle.unsubscribe).not.toHaveBeenCalled();
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
test('forceNative disconnects a device the renderer no longer tracks', async () => {
|
|
249
|
-
const device = { id: 'presumed-dead-id', name: 'OneKey Pro 2' };
|
|
250
|
-
const nobleBle = createNobleBle(device);
|
|
251
211
|
const bleTransport = configureTransport(nobleBle) as any;
|
|
252
212
|
|
|
253
|
-
await bleTransport.releaseNative(device.id
|
|
213
|
+
await bleTransport.releaseNative(device.id);
|
|
254
214
|
|
|
255
215
|
expect(nobleBle.unsubscribe).not.toHaveBeenCalled();
|
|
256
216
|
expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
|
|
@@ -31,39 +31,6 @@ function buildAcquirableTransport(path = 'pro-webusb') {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
describe('WebUsbTransport protocol probe cache', () => {
|
|
34
|
-
test.each([
|
|
35
|
-
['V1', false, 0],
|
|
36
|
-
['V1', true, 1],
|
|
37
|
-
['V2', false, 1],
|
|
38
|
-
[undefined, false, 1],
|
|
39
|
-
] as const)(
|
|
40
|
-
'reconnect protocol=%s first=%s resets USB %s times',
|
|
41
|
-
async (protocol, first, resets) => {
|
|
42
|
-
const webusb = new WebUsbTransport();
|
|
43
|
-
const path = 'connected-usb-device';
|
|
44
|
-
const device = {
|
|
45
|
-
opened: true,
|
|
46
|
-
configuration: { configurationValue: 1 },
|
|
47
|
-
configurations: [],
|
|
48
|
-
reset: jest.fn().mockResolvedValue(undefined),
|
|
49
|
-
selectConfiguration: jest.fn().mockResolvedValue(undefined),
|
|
50
|
-
claimInterface: jest.fn().mockResolvedValue(undefined),
|
|
51
|
-
clearHalt: jest.fn().mockResolvedValue(undefined),
|
|
52
|
-
};
|
|
53
|
-
jest.spyOn(webusb, 'findDevice').mockResolvedValue(device as unknown as USBDevice);
|
|
54
|
-
jest.spyOn(webusb, 'getConnectedDevices').mockResolvedValue([]);
|
|
55
|
-
if (protocol) {
|
|
56
|
-
const state = webusb as unknown as { deviceProtocol: Map<string, 'V1' | 'V2'> };
|
|
57
|
-
state.deviceProtocol.set(path, protocol);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
await webusb.connectToDevice(path, first);
|
|
61
|
-
|
|
62
|
-
expect(device.reset).toHaveBeenCalledTimes(resets);
|
|
63
|
-
expect(device.claimInterface).toHaveBeenCalledWith(0);
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
|
|
67
34
|
test('acquire skips the wire probe when the protocol is already cached', async () => {
|
|
68
35
|
const webusb = buildAcquirableTransport();
|
|
69
36
|
const path = 'pro-webusb';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AA0BA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAA4B,MAAM,iCAAiC,CAAC;AAC5F,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EAEZ,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAI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-216,14 +216,6 @@ declare class ElectronBleTransport {
|
|
|
216
216
|
Log?: any;
|
|
217
217
|
emitter?: EventEmitter;
|
|
218
218
|
private connectedDevices;
|
|
219
|
-
/**
|
|
220
|
-
* Devices whose acquire() is still in flight.
|
|
221
|
-
*
|
|
222
|
-
* A native connect that never calls back has not reached `connectedDevices`
|
|
223
|
-
* yet, so this is the only record that the renderer is still trying to own
|
|
224
|
-
* the link; `releaseNative()` needs it to cancel that pending connect.
|
|
225
|
-
*/
|
|
226
|
-
private acquiringDevices;
|
|
227
219
|
private deviceProtocol;
|
|
228
220
|
private deviceProtocolHints;
|
|
229
221
|
private deviceMtus;
|
package/dist/index.js
CHANGED
|
@@ -375,13 +375,11 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
375
375
|
if (!device.opened) {
|
|
376
376
|
yield device.open();
|
|
377
377
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[WebUsbTransport] reset before claim failed, continuing:', error);
|
|
384
|
-
}
|
|
378
|
+
try {
|
|
379
|
+
yield device.reset();
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[WebUsbTransport] reset before claim failed, continuing:', error);
|
|
385
383
|
}
|
|
386
384
|
yield this.getConnectedDevices();
|
|
387
385
|
device = yield this.findDevice(path);
|
|
@@ -850,7 +848,6 @@ class ElectronBleTransport {
|
|
|
850
848
|
this.runPromise = null;
|
|
851
849
|
this.runPromiseDeviceId = null;
|
|
852
850
|
this.connectedDevices = new Set();
|
|
853
|
-
this.acquiringDevices = new Set();
|
|
854
851
|
this.deviceProtocol = new Map();
|
|
855
852
|
this.deviceProtocolHints = new Map();
|
|
856
853
|
this.deviceMtus = new Map();
|
|
@@ -876,7 +873,7 @@ class ElectronBleTransport {
|
|
|
876
873
|
this.rejectProtocolV2Frames(uuid, new Error(reason));
|
|
877
874
|
(_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug('[Electron BLE] Protocol V2 link invalidated:', uuid, reason);
|
|
878
875
|
if (reason.startsWith('Protocol V2 link-fatal error:')) {
|
|
879
|
-
yield this.releaseNative(uuid
|
|
876
|
+
yield this.releaseNative(uuid);
|
|
880
877
|
}
|
|
881
878
|
}),
|
|
882
879
|
});
|
|
@@ -1035,7 +1032,6 @@ class ElectronBleTransport {
|
|
|
1035
1032
|
this.runPromise = null;
|
|
1036
1033
|
this.runPromiseDeviceId = null;
|
|
1037
1034
|
}
|
|
1038
|
-
this.acquiringDevices.add(uuid);
|
|
1039
1035
|
try {
|
|
1040
1036
|
if (!((_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle)) {
|
|
1041
1037
|
throw new Error('Noble BLE API not available');
|
|
@@ -1102,9 +1098,6 @@ class ElectronBleTransport {
|
|
|
1102
1098
|
this.cleanupDeviceState(uuid);
|
|
1103
1099
|
this.handleBluetoothError(error);
|
|
1104
1100
|
}
|
|
1105
|
-
finally {
|
|
1106
|
-
this.acquiringDevices.delete(uuid);
|
|
1107
|
-
}
|
|
1108
1101
|
});
|
|
1109
1102
|
}
|
|
1110
1103
|
release(id, _onclose, keepSession) {
|
|
@@ -1125,14 +1118,12 @@ class ElectronBleTransport {
|
|
|
1125
1118
|
return this.releaseNative(id);
|
|
1126
1119
|
});
|
|
1127
1120
|
}
|
|
1128
|
-
releaseNative(id
|
|
1121
|
+
releaseNative(id) {
|
|
1129
1122
|
var _a, _b;
|
|
1130
1123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1131
|
-
const rendererOwnsLink = this.connectedDevices.has(id) || this.acquiringDevices.has(id);
|
|
1132
|
-
const shouldDisconnect = (options === null || options === void 0 ? void 0 : options.forceNative) === true || rendererOwnsLink;
|
|
1133
1124
|
try {
|
|
1134
1125
|
const nobleBle = (_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle;
|
|
1135
|
-
if (nobleBle
|
|
1126
|
+
if (nobleBle) {
|
|
1136
1127
|
if (this.connectedDevices.has(id)) {
|
|
1137
1128
|
yield invokeNobleBle(nobleBle.unsubscribe(id)).catch(error => {
|
|
1138
1129
|
var _a;
|
|
@@ -1571,7 +1562,7 @@ class ElectronBleTransport {
|
|
|
1571
1562
|
this.notificationCleanups.delete(uuid);
|
|
1572
1563
|
this.notificationTokens.delete(uuid);
|
|
1573
1564
|
if (!isProbeTimeout) {
|
|
1574
|
-
yield this.releaseNative(uuid
|
|
1565
|
+
yield this.releaseNative(uuid);
|
|
1575
1566
|
}
|
|
1576
1567
|
}
|
|
1577
1568
|
throw this.normalizeBluetoothError(e);
|
package/dist/webusb.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webusb.d.ts","sourceRoot":"","sources":["../src/webusb.ts"],"names":[],"mappings":";;AACA,OAAO,SAAS,EAAE,EAQhB,0BAA0B,EAG3B,MAAM,wBAAwB,CAAC;AAYhC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAuBhC,MAAM,WAAW,UAAW,SAAQ,oBAAoB;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,CAAC;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAuCD,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,0BAA0B,CAAC,MAAM,CAAC;IAC7E,QAAQ,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAGlE,UAAU,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEpE,OAAO,CAAC,sBAAsB,CAAqB;IAGnD,OAAO,C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,MAAM;IAY1B,SAAS,CAAC,uBAAuB,IAAI,iBAAiB;IAUtD,SAAS,CAAC,sBAAsB;cAIhB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,IAAI,CAAC;cAIA,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,UAAU,CAAC;cASN,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1F,SAAS,CAAC,8BAA8B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAKrE,SAAS,CAAC,+BAA+B,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK;IAWjF,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-web-device",
|
|
3
|
-
"version": "1.2.2-alpha.
|
|
3
|
+
"version": "1.2.2-alpha.120",
|
|
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.2-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.2-alpha.
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.2-alpha.120",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.2-alpha.120"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@onekeyfe/hd-transport-electron": "1.2.2-alpha.
|
|
28
|
+
"@onekeyfe/hd-transport-electron": "1.2.2-alpha.120",
|
|
29
29
|
"@types/w3c-web-usb": "^1.0.6",
|
|
30
30
|
"@types/web-bluetooth": "^0.0.17"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "26958fa2be6aa34a07f42403fb7022d2785e70b9"
|
|
33
33
|
}
|
|
@@ -117,15 +117,6 @@ export default class ElectronBleTransport {
|
|
|
117
117
|
|
|
118
118
|
private connectedDevices: Set<string> = new Set();
|
|
119
119
|
|
|
120
|
-
/**
|
|
121
|
-
* Devices whose acquire() is still in flight.
|
|
122
|
-
*
|
|
123
|
-
* A native connect that never calls back has not reached `connectedDevices`
|
|
124
|
-
* yet, so this is the only record that the renderer is still trying to own
|
|
125
|
-
* the link; `releaseNative()` needs it to cancel that pending connect.
|
|
126
|
-
*/
|
|
127
|
-
private acquiringDevices: Set<string> = new Set();
|
|
128
|
-
|
|
129
120
|
private deviceProtocol: Map<string, ProtocolType> = new Map();
|
|
130
121
|
|
|
131
122
|
private deviceProtocolHints: Map<string, ProtocolType> = new Map();
|
|
@@ -158,7 +149,7 @@ export default class ElectronBleTransport {
|
|
|
158
149
|
this.rejectProtocolV2Frames(uuid, new Error(reason));
|
|
159
150
|
this.Log?.debug('[Electron BLE] Protocol V2 link invalidated:', uuid, reason);
|
|
160
151
|
if (reason.startsWith('Protocol V2 link-fatal error:')) {
|
|
161
|
-
await this.releaseNative(uuid
|
|
152
|
+
await this.releaseNative(uuid);
|
|
162
153
|
}
|
|
163
154
|
},
|
|
164
155
|
});
|
|
@@ -372,7 +363,6 @@ export default class ElectronBleTransport {
|
|
|
372
363
|
this.runPromiseDeviceId = null;
|
|
373
364
|
}
|
|
374
365
|
|
|
375
|
-
this.acquiringDevices.add(uuid);
|
|
376
366
|
try {
|
|
377
367
|
if (!window.desktopApi?.nobleBle) {
|
|
378
368
|
throw new Error('Noble BLE API not available');
|
|
@@ -444,8 +434,6 @@ export default class ElectronBleTransport {
|
|
|
444
434
|
}
|
|
445
435
|
this.cleanupDeviceState(uuid);
|
|
446
436
|
this.handleBluetoothError(error);
|
|
447
|
-
} finally {
|
|
448
|
-
this.acquiringDevices.delete(uuid);
|
|
449
437
|
}
|
|
450
438
|
}
|
|
451
439
|
|
|
@@ -466,23 +454,10 @@ export default class ElectronBleTransport {
|
|
|
466
454
|
}
|
|
467
455
|
|
|
468
456
|
// Hard teardown, error paths only: a link presumed dead must not be reused.
|
|
469
|
-
|
|
470
|
-
// The native disconnect is sent while the renderer still owns the link, or is
|
|
471
|
-
// still trying to get it: a stuck acquire has not reached `connectedDevices`
|
|
472
|
-
// yet, and its pending native connect can only be cancelled from here, so the
|
|
473
|
-
// Core acquire deadline would otherwise be unable to terminate it.
|
|
474
|
-
//
|
|
475
|
-
// It is NOT sent for a device the renderer has already released logically.
|
|
476
|
-
// That link belongs to the main-process keep-alive timer, and dropping it on
|
|
477
|
-
// the routine post-call `cancel()` (Device.interruptionFromUser, no acquire
|
|
478
|
-
// held, empty request queue) costs a full cold reconnect on the very next
|
|
479
|
-
// operation — measured 2.93s on Pro and 17-26s on Pro 2.
|
|
480
|
-
private async releaseNative(id: string, options?: { forceNative?: boolean }) {
|
|
481
|
-
const rendererOwnsLink = this.connectedDevices.has(id) || this.acquiringDevices.has(id);
|
|
482
|
-
const shouldDisconnect = options?.forceNative === true || rendererOwnsLink;
|
|
457
|
+
private async releaseNative(id: string) {
|
|
483
458
|
try {
|
|
484
459
|
const nobleBle = window.desktopApi?.nobleBle;
|
|
485
|
-
if (nobleBle
|
|
460
|
+
if (nobleBle) {
|
|
486
461
|
if (this.connectedDevices.has(id)) {
|
|
487
462
|
await invokeNobleBle(nobleBle.unsubscribe(id)).catch(error => {
|
|
488
463
|
this.Log?.debug('[Electron BLE] release unsubscribe failed:', error);
|
|
@@ -995,7 +970,7 @@ export default class ElectronBleTransport {
|
|
|
995
970
|
this.notificationCleanups.delete(uuid);
|
|
996
971
|
this.notificationTokens.delete(uuid);
|
|
997
972
|
if (!isProbeTimeout) {
|
|
998
|
-
await this.releaseNative(uuid
|
|
973
|
+
await this.releaseNative(uuid);
|
|
999
974
|
}
|
|
1000
975
|
}
|
|
1001
976
|
throw this.normalizeBluetoothError(e);
|
package/src/webusb.ts
CHANGED
|
@@ -566,14 +566,10 @@ export default class WebUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
566
566
|
if (!device.opened) {
|
|
567
567
|
await device.open();
|
|
568
568
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
await device.reset();
|
|
574
|
-
} catch (error) {
|
|
575
|
-
this.Log?.debug('[WebUsbTransport] reset before claim failed, continuing:', error);
|
|
576
|
-
}
|
|
569
|
+
try {
|
|
570
|
+
await device.reset();
|
|
571
|
+
} catch (error) {
|
|
572
|
+
this.Log?.debug('[WebUsbTransport] reset before claim failed, continuing:', error);
|
|
577
573
|
}
|
|
578
574
|
await this.getConnectedDevices();
|
|
579
575
|
device = await this.findDevice(path);
|