@onekeyfe/hd-transport-web-device 1.1.34-alpha.2 → 1.1.34-alpha.4
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.
|
@@ -37,7 +37,6 @@ export default class ElectronBleTransport {
|
|
|
37
37
|
path: string;
|
|
38
38
|
}>;
|
|
39
39
|
release(id: string): Promise<void>;
|
|
40
|
-
disconnect(id: string): Promise<void>;
|
|
41
40
|
private handleNotificationData;
|
|
42
41
|
call(uuid: string, name: string, data: Record<string, unknown>): Promise<import("@onekeyfe/hd-transport").MessageFromOneKey>;
|
|
43
42
|
private processNotificationPacket;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AAAA,OAAO,SAAkD,MAAM,wBAAwB,CAAC;AASxF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAKlE,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,EAAE,OAAO,CAAC;CAChC,CAAC;AASF,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC,SAAS,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,IAAI,SAA0B;IAE9B,UAAU,UAAS;IAEnB,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAExC,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;IAGvB,OAAO,CAAC,gBAAgB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AAC,gBAAgB,CAA0B;IAGlD,OAAO,CAAC,WAAW,CAAsE;IAGzF,OAAO,CAAC,oBAAoB,CAAsC;IAGlE,OAAO,CAAC,kBAAkB,CAAsC;IAGhE,OAAO,CAAC,oBAAoB;IAmC5B,OAAO,CAAC,kBAAkB;IAmB1B,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY;IAexC,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAEA,SAAS,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAcpD,OAAO,CAAC,KAAK,EAAE,eAAe;;;;IA8E9B,OAAO,CAAC,EAAE,EAAE,MAAM;IAwBxB,OAAO,CAAC,sBAAsB;IA2BxB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IA2EpE,OAAO,CAAC,yBAAyB;CAyDlC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -75,7 +75,6 @@ declare class ElectronBleTransport {
|
|
|
75
75
|
path: string;
|
|
76
76
|
}>;
|
|
77
77
|
release(id: string): Promise<void>;
|
|
78
|
-
disconnect(id: string): Promise<void>;
|
|
79
78
|
private handleNotificationData;
|
|
80
79
|
call(uuid: string, name: string, data: Record<string, unknown>): Promise<transport.MessageFromOneKey>;
|
|
81
80
|
private processNotificationPacket;
|
package/dist/index.js
CHANGED
|
@@ -461,7 +461,6 @@ class ElectronBleTransport {
|
|
|
461
461
|
if (forceCleanRunPromise && this.runPromise) {
|
|
462
462
|
this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleForceCleanRunPromise));
|
|
463
463
|
}
|
|
464
|
-
let step = 'getDevice';
|
|
465
464
|
try {
|
|
466
465
|
if (!((_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle)) {
|
|
467
466
|
throw new Error('Noble BLE API not available');
|
|
@@ -470,7 +469,6 @@ class ElectronBleTransport {
|
|
|
470
469
|
if (!device) {
|
|
471
470
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Device ${uuid} not found`);
|
|
472
471
|
}
|
|
473
|
-
step = 'connect';
|
|
474
472
|
try {
|
|
475
473
|
yield window.desktopApi.nobleBle.connect(uuid);
|
|
476
474
|
this.connectedDevices.add(uuid);
|
|
@@ -479,7 +477,6 @@ class ElectronBleTransport {
|
|
|
479
477
|
this.handleBluetoothError(error);
|
|
480
478
|
}
|
|
481
479
|
this.dataBuffers.set(uuid, { buffer: [], bufferLength: 0 });
|
|
482
|
-
step = 'subscribe';
|
|
483
480
|
yield window.desktopApi.nobleBle.subscribe(uuid);
|
|
484
481
|
const cleanup = window.desktopApi.nobleBle.onNotification((deviceId, data) => {
|
|
485
482
|
if (deviceId === uuid) {
|
|
@@ -490,9 +487,6 @@ class ElectronBleTransport {
|
|
|
490
487
|
const disconnectCleanup = window.desktopApi.nobleBle.onDeviceDisconnected((disconnectedDevice) => {
|
|
491
488
|
var _a;
|
|
492
489
|
if (disconnectedDevice.id === uuid) {
|
|
493
|
-
if (this.runPromise) {
|
|
494
|
-
this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected));
|
|
495
|
-
}
|
|
496
490
|
this.cleanupDeviceState(uuid);
|
|
497
491
|
(_a = this.emitter) === null || _a === void 0 ? void 0 : _a.emit('device-disconnect', {
|
|
498
492
|
name: disconnectedDevice.name,
|
|
@@ -511,9 +505,6 @@ class ElectronBleTransport {
|
|
|
511
505
|
}
|
|
512
506
|
catch (error) {
|
|
513
507
|
(_c = this.Log) === null || _c === void 0 ? void 0 : _c.error('[Transport] Noble BLE acquire failed:', error);
|
|
514
|
-
if (step === 'subscribe') {
|
|
515
|
-
yield this.disconnect(uuid);
|
|
516
|
-
}
|
|
517
508
|
throw error;
|
|
518
509
|
}
|
|
519
510
|
});
|
|
@@ -521,33 +512,23 @@ class ElectronBleTransport {
|
|
|
521
512
|
release(id) {
|
|
522
513
|
var _a, _b, _c;
|
|
523
514
|
return __awaiter(this, void 0, void 0, function* () {
|
|
524
|
-
this.cleanupDeviceState(id);
|
|
525
515
|
try {
|
|
526
|
-
|
|
516
|
+
if (this.connectedDevices.has(id)) {
|
|
517
|
+
if ((_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle) {
|
|
518
|
+
yield window.desktopApi.nobleBle.unsubscribe(id);
|
|
519
|
+
}
|
|
520
|
+
if ((_b = window.desktopApi) === null || _b === void 0 ? void 0 : _b.nobleBle) {
|
|
521
|
+
yield window.desktopApi.nobleBle.disconnect(id);
|
|
522
|
+
}
|
|
523
|
+
this.cleanupDeviceState(id);
|
|
524
|
+
}
|
|
527
525
|
}
|
|
528
|
-
catch (
|
|
526
|
+
catch (error) {
|
|
527
|
+
(_c = this.Log) === null || _c === void 0 ? void 0 : _c.error('[Transport] Noble BLE release failed:', error);
|
|
528
|
+
this.cleanupDeviceState(id);
|
|
529
529
|
}
|
|
530
530
|
});
|
|
531
531
|
}
|
|
532
|
-
disconnect(id) {
|
|
533
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
534
|
-
const bounded = (ms, run) => __awaiter(this, void 0, void 0, function* () {
|
|
535
|
-
try {
|
|
536
|
-
yield Promise.race([
|
|
537
|
-
Promise.resolve(run()),
|
|
538
|
-
new Promise(resolve => {
|
|
539
|
-
setTimeout(resolve, ms);
|
|
540
|
-
}),
|
|
541
|
-
]);
|
|
542
|
-
}
|
|
543
|
-
catch (_a) {
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
|
-
yield bounded(2000, () => { var _a, _b; return (_b = (_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle) === null || _b === void 0 ? void 0 : _b.unsubscribe(id); });
|
|
547
|
-
yield bounded(3000, () => { var _a, _b; return (_b = (_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle) === null || _b === void 0 ? void 0 : _b.disconnect(id); });
|
|
548
|
-
this.cleanupDeviceState(id);
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
532
|
handleNotificationData(deviceId, hexData) {
|
|
552
533
|
var _a, _b;
|
|
553
534
|
if (hexData === 'PAIRING_REJECTED') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-web-device",
|
|
3
|
-
"version": "1.1.34-alpha.
|
|
3
|
+
"version": "1.1.34-alpha.4",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"lint:fix": "eslint . --fix"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-shared": "1.1.34-alpha.
|
|
24
|
-
"@onekeyfe/hd-transport": "1.1.34-alpha.
|
|
23
|
+
"@onekeyfe/hd-shared": "1.1.34-alpha.4",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.1.34-alpha.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@onekeyfe/hd-transport-electron": "1.1.34-alpha.
|
|
27
|
+
"@onekeyfe/hd-transport-electron": "1.1.34-alpha.4",
|
|
28
28
|
"@types/w3c-web-usb": "^1.0.6",
|
|
29
29
|
"@types/web-bluetooth": "^0.0.17"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "d546bc55410990351d34009230aefea77725d0d6"
|
|
32
32
|
}
|
|
@@ -162,9 +162,6 @@ export default class ElectronBleTransport {
|
|
|
162
162
|
this.runPromise.reject(ERRORS.TypedError(HardwareErrorCode.BleForceCleanRunPromise));
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
// `step` pins down where a failed acquire died (subscribe = the
|
|
166
|
-
// encryption-gated characteristic, the broken-OS-bond signature).
|
|
167
|
-
let step = 'getDevice';
|
|
168
165
|
try {
|
|
169
166
|
if (!window.desktopApi?.nobleBle) {
|
|
170
167
|
throw new Error('Noble BLE API not available');
|
|
@@ -177,7 +174,6 @@ export default class ElectronBleTransport {
|
|
|
177
174
|
}
|
|
178
175
|
|
|
179
176
|
// Connect to device
|
|
180
|
-
step = 'connect';
|
|
181
177
|
try {
|
|
182
178
|
await window.desktopApi.nobleBle.connect(uuid);
|
|
183
179
|
this.connectedDevices.add(uuid);
|
|
@@ -189,7 +185,6 @@ export default class ElectronBleTransport {
|
|
|
189
185
|
this.dataBuffers.set(uuid, { buffer: [], bufferLength: 0 });
|
|
190
186
|
|
|
191
187
|
// Subscribe to notifications
|
|
192
|
-
step = 'subscribe';
|
|
193
188
|
await window.desktopApi.nobleBle.subscribe(uuid);
|
|
194
189
|
|
|
195
190
|
// Set up notification listener
|
|
@@ -206,10 +201,6 @@ export default class ElectronBleTransport {
|
|
|
206
201
|
const disconnectCleanup = window.desktopApi.nobleBle.onDeviceDisconnected(
|
|
207
202
|
(disconnectedDevice: any) => {
|
|
208
203
|
if (disconnectedDevice.id === uuid) {
|
|
209
|
-
// Fail a call blocked on a dead link instead of hanging.
|
|
210
|
-
if (this.runPromise) {
|
|
211
|
-
this.runPromise.reject(ERRORS.TypedError(HardwareErrorCode.BleDeviceDisconnected));
|
|
212
|
-
}
|
|
213
204
|
this.cleanupDeviceState(uuid);
|
|
214
205
|
|
|
215
206
|
// Trigger disconnect event
|
|
@@ -233,54 +224,31 @@ export default class ElectronBleTransport {
|
|
|
233
224
|
return { uuid, path: uuid };
|
|
234
225
|
} catch (error) {
|
|
235
226
|
this.Log?.error('[Transport] Noble BLE acquire failed:', error);
|
|
236
|
-
if (step === 'subscribe') {
|
|
237
|
-
// Broken-bond signature: tear the link down so the next attempt
|
|
238
|
-
// cold-connects and macOS can re-negotiate the bond.
|
|
239
|
-
await this.disconnect(uuid);
|
|
240
|
-
}
|
|
241
227
|
throw error;
|
|
242
228
|
}
|
|
243
229
|
}
|
|
244
230
|
|
|
245
231
|
async release(id: string) {
|
|
246
|
-
// Logical release only — the link and subscription stay up for reuse; the
|
|
247
|
-
// main process idle timer does the physical disconnect. Hard teardown is
|
|
248
|
-
// `disconnect()`. Renderer listeners must still go, or the next acquire's
|
|
249
|
-
// fresh listeners would double-process every packet.
|
|
250
|
-
this.cleanupDeviceState(id);
|
|
251
|
-
// Signal logical end-of-operation so the main process starts its 60s idle
|
|
252
|
-
// countdown (during a run it holds the long busy backstop instead). Best-
|
|
253
|
-
// effort: the idle/backstop timer still bounds the link if this never lands.
|
|
254
232
|
try {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
233
|
+
if (this.connectedDevices.has(id)) {
|
|
234
|
+
// Unsubscribe from notifications
|
|
235
|
+
if (window.desktopApi?.nobleBle) {
|
|
236
|
+
await window.desktopApi.nobleBle.unsubscribe(id);
|
|
237
|
+
}
|
|
260
238
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
// error-RECOVERY path — it must never hang the retry ladder.
|
|
269
|
-
const bounded = async (ms: number, run: () => Promise<unknown> | undefined) => {
|
|
270
|
-
try {
|
|
271
|
-
await Promise.race([
|
|
272
|
-
Promise.resolve(run()),
|
|
273
|
-
new Promise<void>(resolve => {
|
|
274
|
-
setTimeout(resolve, ms);
|
|
275
|
-
}),
|
|
276
|
-
]);
|
|
277
|
-
} catch {
|
|
278
|
-
// ignore — recovery path, best effort
|
|
239
|
+
// Disconnect device
|
|
240
|
+
if (window.desktopApi?.nobleBle) {
|
|
241
|
+
await window.desktopApi.nobleBle.disconnect(id);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Clean up all device state
|
|
245
|
+
this.cleanupDeviceState(id);
|
|
279
246
|
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
247
|
+
} catch (error) {
|
|
248
|
+
this.Log?.error('[Transport] Noble BLE release failed:', error);
|
|
249
|
+
// Clean up local state even if release fails
|
|
250
|
+
this.cleanupDeviceState(id);
|
|
251
|
+
}
|
|
284
252
|
}
|
|
285
253
|
|
|
286
254
|
// Handle notification data from Noble BLE
|