@onekeyfe/hd-transport-web-device 1.2.0-alpha.69 → 1.2.0-alpha.70

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.
@@ -105,7 +105,6 @@ const createNobleBle = (device = { id: 'flaky-pro2-id', name: 'Unknown BLE Devic
105
105
  unsubscribe: jest.fn(() => Promise.resolve()),
106
106
  write: jest.fn(() => Promise.resolve()),
107
107
  onNotification: jest.fn(() => jest.fn()),
108
- onMtuChanged: jest.fn(() => jest.fn()),
109
108
  onDeviceDisconnected: jest.fn(() => jest.fn()),
110
109
  checkAvailability: jest.fn(() =>
111
110
  Promise.resolve({
@@ -177,9 +176,6 @@ describe('ElectronBleTransport protocol detection', () => {
177
176
  const bleTransport = configureTransport(nobleBle, emitter);
178
177
 
179
178
  await bleTransport.acquire({ uuid: device.id, expectedProtocol: 'V2' });
180
- expect(nobleBle.subscribe.mock.invocationCallOrder[0]).toBeLessThan(
181
- nobleBle.getDevice.mock.invocationCallOrder[1]
182
- );
183
179
  disconnectHandler?.(device);
184
180
 
185
181
  expect(publicConnect).not.toHaveBeenCalled();
@@ -209,56 +205,6 @@ describe('ElectronBleTransport protocol detection', () => {
209
205
  expect(nobleBle.write.mock.calls.map(([, hex]) => hex.length / 2)).toEqual([192, 1]);
210
206
  });
211
207
 
212
- test('uses the negotiated Noble MTU for Protocol V2 BLE writes', async () => {
213
- const device = { id: 'mtu-pro2-id', name: 'OneKey Pro 2', mtu: 247 };
214
- const nobleBle = createNobleBle(device);
215
- const bleTransport = configureTransport(nobleBle) as any;
216
- const context = {
217
- messageName: 'FilesystemFileWrite',
218
- timeoutMs: 1000,
219
- highVolume: true,
220
- generation: 1,
221
- signal: new AbortController().signal,
222
- };
223
-
224
- const setTimeoutSpy = jest.spyOn(global, 'setTimeout');
225
- try {
226
- await bleTransport.refreshBlePacketCapacity(device.id);
227
- await bleTransport.writeProtocolV2Frame(device.id, new Uint8Array(245), context, jest.fn());
228
-
229
- expect(setTimeoutSpy).not.toHaveBeenCalled();
230
- } finally {
231
- setTimeoutSpy.mockRestore();
232
- }
233
-
234
- expect(nobleBle.write).toHaveBeenCalledTimes(2);
235
- expect(nobleBle.write.mock.calls.map(([, hex]) => hex.length / 2)).toEqual([244, 1]);
236
- });
237
-
238
- test('updates Protocol V2 packet capacity when Noble reports a new MTU', async () => {
239
- const device = { id: 'mtu-event-pro2-id', name: 'OneKey Pro 2' };
240
- const nobleBle = createNobleBle(device);
241
- let mtuHandler: ((changedDevice: { id: string; mtu: number }) => void) | undefined;
242
- nobleBle.onMtuChanged.mockImplementation(handler => {
243
- mtuHandler = handler;
244
- return jest.fn();
245
- });
246
- const bleTransport = configureTransport(nobleBle) as any;
247
- const context = {
248
- messageName: 'FilesystemFileWrite',
249
- timeoutMs: 1000,
250
- highVolume: true,
251
- generation: 1,
252
- signal: new AbortController().signal,
253
- };
254
-
255
- bleTransport.createMtuSubscription(device.id);
256
- mtuHandler?.({ id: device.id, mtu: 247 });
257
- await bleTransport.writeProtocolV2Frame(device.id, new Uint8Array(245), context, jest.fn());
258
-
259
- expect(nobleBle.write.mock.calls.map(([, hex]) => hex.length / 2)).toEqual([244, 1]);
260
- });
261
-
262
208
  test('detects Protocol V2 after Protocol V1 probe timeout', async () => {
263
209
  const device = { id: 'unknown-pro2-id', name: 'Unknown BLE Device' };
264
210
  const nobleBle = createNobleBle(device);
@@ -27,15 +27,12 @@ export default class ElectronBleTransport {
27
27
  private connectedDevices;
28
28
  private deviceProtocol;
29
29
  private deviceProtocolHints;
30
- private deviceMtus;
31
- private devicePacketCapacities;
32
30
  private v1Buffers;
33
31
  private v2Assemblers;
34
32
  private v2FrameQueues;
35
33
  private v2FramePromises;
36
34
  private protocolV2Links;
37
35
  private notificationCleanups;
38
- private mtuCleanups;
39
36
  private disconnectCleanups;
40
37
  private notificationTokens;
41
38
  private nextNotificationToken;
@@ -68,9 +65,6 @@ export default class ElectronBleTransport {
68
65
  private probeProtocolV1;
69
66
  private probeProtocolV2;
70
67
  private writeOnce;
71
- private refreshBlePacketCapacity;
72
- private updateBlePacketCapacity;
73
- private createMtuSubscription;
74
68
  private writeProtocolV2Frame;
75
69
  private handleNotification;
76
70
  private handleProtocolV2Notification;
@@ -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,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,YAAY,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAqCF,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC,OAAO,CAAC,SAAS,CAA0D;IAE3E,OAAO,CAAC,WAAW,CAA0D;IAE7E,OAAO,CAAC,6BAA6B,CAAqB;IAE1D,IAAI,SAA0B;IAE9B,UAAU,UAAS;IAEnB,UAAU,EAAE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,GAAG,IAAI,CAAQ;IAExD,OAAO,CAAC,kBAAkB,CAAuB;IAEjD,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;IAEvB,OAAO,CAAC,gBAAgB,CAA0B;IAElD,OAAO,CAAC,cAAc,CAAwC;IAE9D,OAAO,CAAC,mBAAmB,CAAwC;IA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,OAAO,CAAC,4BAA4B;IAqB9B,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;YA2BlB,cAAc;YAqFd,cAAc;IA0B5B,OAAO,CAAC,uBAAuB;IAyC/B,OAAO,CAAC,6BAA6B;IAsCrC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.d.ts CHANGED
@@ -176,15 +176,12 @@ declare class ElectronBleTransport {
176
176
  private connectedDevices;
177
177
  private deviceProtocol;
178
178
  private deviceProtocolHints;
179
- private deviceMtus;
180
- private devicePacketCapacities;
181
179
  private v1Buffers;
182
180
  private v2Assemblers;
183
181
  private v2FrameQueues;
184
182
  private v2FramePromises;
185
183
  private protocolV2Links;
186
184
  private notificationCleanups;
187
- private mtuCleanups;
188
185
  private disconnectCleanups;
189
186
  private notificationTokens;
190
187
  private nextNotificationToken;
@@ -217,9 +214,6 @@ declare class ElectronBleTransport {
217
214
  private probeProtocolV1;
218
215
  private probeProtocolV2;
219
216
  private writeOnce;
220
- private refreshBlePacketCapacity;
221
- private updateBlePacketCapacity;
222
- private createMtuSubscription;
223
217
  private writeProtocolV2Frame;
224
218
  private handleNotification;
225
219
  private handleProtocolV2Notification;
package/dist/index.js CHANGED
@@ -725,21 +725,12 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
725
725
  }
726
726
  }
727
727
 
728
- const BLE_ATT_HEADER_BYTES = 3;
729
- function resolveBlePacketCapacity(mtu, maximumPacketCapacity, fallbackPacketCapacity) {
730
- if (typeof mtu !== 'number' || !Number.isFinite(mtu) || mtu <= BLE_ATT_HEADER_BYTES) {
731
- return fallbackPacketCapacity;
732
- }
733
- return Math.min(maximumPacketCapacity, Math.floor(mtu) - BLE_ATT_HEADER_BYTES);
734
- }
735
-
736
728
  const { parseConfigure, ProtocolV1, check } = transport__default["default"];
737
729
  function inferProtocolHintFromDeviceName(name) {
738
730
  return /\bpro\s*2\b/i.test(name !== null && name !== void 0 ? name : '') ? 'V2' : undefined;
739
731
  }
740
732
  const toBleDescriptor = (device, protocolType) => (Object.assign({ id: device.id, name: device.name, path: device.id, debug: false, commType: 'electron-ble' }, (protocolType ? { protocolType } : {})));
741
- const BLE_PACKET_SIZE_FALLBACK = 192;
742
- const BLE_PACKET_SIZE_MAXIMUM = 244;
733
+ const BLE_PACKET_SIZE = 192;
743
734
  const BLE_WRITE_DELAY_MS = 5;
744
735
  const PROTOCOL_PROBE_TIMEOUT_MS = 1000;
745
736
  const PROTOCOL_V2_PROBE_TIMEOUT_MS = 5000;
@@ -752,8 +743,6 @@ class ElectronBleTransport {
752
743
  this.connectedDevices = new Set();
753
744
  this.deviceProtocol = new Map();
754
745
  this.deviceProtocolHints = new Map();
755
- this.deviceMtus = new Map();
756
- this.devicePacketCapacities = new Map();
757
746
  this.v1Buffers = new Map();
758
747
  this.v2Assemblers = new Map();
759
748
  this.v2FrameQueues = new Map();
@@ -780,7 +769,6 @@ class ElectronBleTransport {
780
769
  }),
781
770
  });
782
771
  this.notificationCleanups = new Map();
783
- this.mtuCleanups = new Map();
784
772
  this.disconnectCleanups = new Map();
785
773
  this.notificationTokens = new Map();
786
774
  this.nextNotificationToken = 1;
@@ -820,8 +808,6 @@ class ElectronBleTransport {
820
808
  .catch(error => { var _a; return (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] link cleanup failed:', error); });
821
809
  this.connectedDevices.delete(deviceId);
822
810
  this.deviceProtocol.delete(deviceId);
823
- this.deviceMtus.delete(deviceId);
824
- this.devicePacketCapacities.delete(deviceId);
825
811
  this.v1Buffers.delete(deviceId);
826
812
  this.v2Assemblers.delete(deviceId);
827
813
  this.resetProtocolV2Frames(deviceId);
@@ -836,11 +822,6 @@ class ElectronBleTransport {
836
822
  notifyCleanup();
837
823
  this.notificationCleanups.delete(deviceId);
838
824
  }
839
- const mtuCleanup = this.mtuCleanups.get(deviceId);
840
- if (mtuCleanup) {
841
- mtuCleanup();
842
- this.mtuCleanups.delete(deviceId);
843
- }
844
825
  const disconnectCleanup = this.disconnectCleanups.get(deviceId);
845
826
  if (disconnectCleanup) {
846
827
  disconnectCleanup();
@@ -904,7 +885,7 @@ class ElectronBleTransport {
904
885
  });
905
886
  }
906
887
  acquire(input) {
907
- var _a, _b, _c, _d, _e, _f, _g, _h;
888
+ var _a, _b, _c, _d, _e, _f;
908
889
  return __awaiter(this, void 0, void 0, function* () {
909
890
  const { uuid, forceCleanRunPromise, expectedProtocol } = input;
910
891
  if (!uuid) {
@@ -940,25 +921,13 @@ class ElectronBleTransport {
940
921
  catch (error) {
941
922
  this.handleBluetoothError(error);
942
923
  }
943
- const mtuCleanup = this.createMtuSubscription(uuid);
944
- if (mtuCleanup) {
945
- this.mtuCleanups.set(uuid, mtuCleanup);
946
- }
947
924
  this.v1Buffers.set(uuid, { buffer: [], bufferLength: 0 });
948
925
  this.v2Assemblers.set(uuid, new transport.ProtocolV2FrameAssembler(transport.PROTOCOL_V2_BLE_FRAME_MAX_BYTES));
949
926
  yield window.desktopApi.nobleBle.subscribe(uuid);
950
- yield this.refreshBlePacketCapacity(uuid);
951
927
  const cleanup = this.createNotificationSubscription(uuid);
952
928
  this.notificationCleanups.set(uuid, cleanup);
953
929
  const connectionToken = this.notificationTokens.get(uuid);
954
930
  const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint);
955
- if (protocolType === 'V2') {
956
- (_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug('[Electron BLE] Protocol V2 write configured', {
957
- writeMode: 'withoutResponse',
958
- negotiatedMtu: this.deviceMtus.get(uuid),
959
- packetCapacity: (_e = this.devicePacketCapacities.get(uuid)) !== null && _e !== void 0 ? _e : BLE_PACKET_SIZE_FALLBACK,
960
- });
961
- }
962
931
  const disconnectCleanup = window.desktopApi.nobleBle.onDeviceDisconnected((disconnectedDevice) => {
963
932
  var _a;
964
933
  if (disconnectedDevice.id === uuid &&
@@ -975,15 +944,15 @@ class ElectronBleTransport {
975
944
  return Object.assign(Object.assign({}, toBleDescriptor({ id: device.id, name: device.name }, protocolType)), { uuid });
976
945
  }
977
946
  catch (error) {
978
- (_f = this.Log) === null || _f === void 0 ? void 0 : _f.error('[Electron BLE] acquire failed:', error);
947
+ (_d = this.Log) === null || _d === void 0 ? void 0 : _d.error('[Electron BLE] acquire failed:', error);
979
948
  try {
980
- if (((_g = window.desktopApi) === null || _g === void 0 ? void 0 : _g.nobleBle) && this.connectedDevices.has(uuid)) {
949
+ if (((_e = window.desktopApi) === null || _e === void 0 ? void 0 : _e.nobleBle) && this.connectedDevices.has(uuid)) {
981
950
  yield window.desktopApi.nobleBle.unsubscribe(uuid);
982
951
  yield window.desktopApi.nobleBle.disconnect(uuid);
983
952
  }
984
953
  }
985
954
  catch (cleanupError) {
986
- (_h = this.Log) === null || _h === void 0 ? void 0 : _h.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
955
+ (_f = this.Log) === null || _f === void 0 ? void 0 : _f.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
987
956
  }
988
957
  this.cleanupDeviceState(uuid);
989
958
  throw error;
@@ -1118,7 +1087,6 @@ class ElectronBleTransport {
1118
1087
  yield ((_j = (_h = window.desktopApi) === null || _h === void 0 ? void 0 : _h.nobleBle) === null || _j === void 0 ? void 0 : _j.connect(uuid));
1119
1088
  this.connectedDevices.add(uuid);
1120
1089
  yield ((_l = (_k = window.desktopApi) === null || _k === void 0 ? void 0 : _k.nobleBle) === null || _l === void 0 ? void 0 : _l.subscribe(uuid));
1121
- yield this.refreshBlePacketCapacity(uuid);
1122
1090
  }
1123
1091
  catch (error) {
1124
1092
  (_m = this.Log) === null || _m === void 0 ? void 0 : _m.debug(`[Electron BLE] reconnect after Protocol ${protocol} probe failed:`, error);
@@ -1181,47 +1149,16 @@ class ElectronBleTransport {
1181
1149
  yield nobleBle.write(uuid, hexData);
1182
1150
  });
1183
1151
  }
1184
- refreshBlePacketCapacity(uuid) {
1185
- var _a, _b;
1186
- return __awaiter(this, void 0, void 0, function* () {
1187
- const device = yield ((_b = (_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle) === null || _b === void 0 ? void 0 : _b.getDevice(uuid));
1188
- this.updateBlePacketCapacity(uuid, device === null || device === void 0 ? void 0 : device.mtu);
1189
- });
1190
- }
1191
- updateBlePacketCapacity(uuid, mtu) {
1192
- const packetCapacity = resolveBlePacketCapacity(mtu, BLE_PACKET_SIZE_MAXIMUM, BLE_PACKET_SIZE_FALLBACK);
1193
- if (typeof mtu === 'number') {
1194
- this.deviceMtus.set(uuid, mtu);
1195
- }
1196
- else {
1197
- this.deviceMtus.delete(uuid);
1198
- }
1199
- this.devicePacketCapacities.set(uuid, packetCapacity);
1200
- }
1201
- createMtuSubscription(uuid) {
1202
- var _a, _b;
1203
- const onMtuChanged = (_b = (_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle) === null || _b === void 0 ? void 0 : _b.onMtuChanged;
1204
- if (!onMtuChanged)
1205
- return undefined;
1206
- return onMtuChanged(device => {
1207
- if (device.id === uuid) {
1208
- this.updateBlePacketCapacity(uuid, device.mtu);
1209
- }
1210
- });
1211
- }
1212
1152
  writeProtocolV2Frame(uuid, frame, context, assertCurrentGeneration) {
1213
- var _a;
1214
- const packetCapacity = (_a = this.devicePacketCapacities.get(uuid)) !== null && _a !== void 0 ? _a : BLE_PACKET_SIZE_FALLBACK;
1215
- const shouldPace = !context.highVolume;
1216
1153
  return transport.writeProtocolV2BleFrame({
1217
1154
  frame,
1218
- packetCapacity,
1155
+ packetCapacity: BLE_PACKET_SIZE,
1219
1156
  assertActive: assertCurrentGeneration,
1220
1157
  signal: context.signal,
1221
1158
  abortMessage: `Protocol V2 BLE write aborted for ${context.messageName}`,
1222
- initialDelayMs: shouldPace && frame.length <= packetCapacity ? BLE_WRITE_DELAY_MS : 0,
1223
- burstSize: shouldPace ? 1 : undefined,
1224
- burstPauseMs: shouldPace ? BLE_WRITE_DELAY_MS : 0,
1159
+ initialDelayMs: frame.length <= BLE_PACKET_SIZE ? BLE_WRITE_DELAY_MS : 0,
1160
+ burstSize: 1,
1161
+ burstPauseMs: BLE_WRITE_DELAY_MS,
1225
1162
  writePacket: packet => this.writeOnce(uuid, transport.bytesToHex(packet)),
1226
1163
  });
1227
1164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-web-device",
3
- "version": "1.2.0-alpha.69",
3
+ "version": "1.2.0-alpha.70",
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.69",
25
- "@onekeyfe/hd-transport": "1.2.0-alpha.69"
24
+ "@onekeyfe/hd-shared": "1.2.0-alpha.70",
25
+ "@onekeyfe/hd-transport": "1.2.0-alpha.70"
26
26
  },
27
27
  "devDependencies": {
28
- "@onekeyfe/hd-transport-electron": "1.2.0-alpha.69",
28
+ "@onekeyfe/hd-transport-electron": "1.2.0-alpha.70",
29
29
  "@types/w3c-web-usb": "^1.0.6",
30
30
  "@types/web-bluetooth": "^0.0.17"
31
31
  },
32
- "gitHead": "c6baed25917e3c3f027f83dfc23cde85400de558"
32
+ "gitHead": "d86b033cf970f97e060c49fe4cf618f38b9ce666"
33
33
  }
@@ -19,7 +19,6 @@ import {
19
19
  } from '@onekeyfe/hd-shared';
20
20
 
21
21
  import { createTransportCallLog, shouldSuppressHighVolumeCallLog } from './transportLog';
22
- import { resolveBlePacketCapacity } from './ble-packet-capacity';
23
22
 
24
23
  import type { Deferred } from '@onekeyfe/hd-shared';
25
24
  import type { DesktopAPI } from '@onekeyfe/hd-transport-electron';
@@ -69,8 +68,7 @@ const toBleDescriptor = (
69
68
  ...(protocolType ? { protocolType } : {}),
70
69
  } as OneKeyDeviceInfo);
71
70
 
72
- const BLE_PACKET_SIZE_FALLBACK = 192;
73
- const BLE_PACKET_SIZE_MAXIMUM = 244;
71
+ const BLE_PACKET_SIZE = 192;
74
72
  const BLE_WRITE_DELAY_MS = 5;
75
73
  const PROTOCOL_PROBE_TIMEOUT_MS = 1000;
76
74
  const PROTOCOL_V2_PROBE_TIMEOUT_MS = 5000;
@@ -106,10 +104,6 @@ export default class ElectronBleTransport {
106
104
 
107
105
  private deviceProtocolHints: Map<string, ProtocolType> = new Map();
108
106
 
109
- private deviceMtus: Map<string, number> = new Map();
110
-
111
- private devicePacketCapacities: Map<string, number> = new Map();
112
-
113
107
  private v1Buffers: Map<string, { buffer: number[]; bufferLength: number }> = new Map();
114
108
 
115
109
  private v2Assemblers: Map<string, ProtocolV2FrameAssembler> = new Map();
@@ -141,8 +135,6 @@ export default class ElectronBleTransport {
141
135
 
142
136
  private notificationCleanups: Map<string, () => void> = new Map();
143
137
 
144
- private mtuCleanups: Map<string, () => void> = new Map();
145
-
146
138
  private disconnectCleanups: Map<string, () => void> = new Map();
147
139
 
148
140
  private notificationTokens: Map<string, number> = new Map();
@@ -186,8 +178,6 @@ export default class ElectronBleTransport {
186
178
  .catch(error => this.Log?.debug('[Electron BLE] link cleanup failed:', error));
187
179
  this.connectedDevices.delete(deviceId);
188
180
  this.deviceProtocol.delete(deviceId);
189
- this.deviceMtus.delete(deviceId);
190
- this.devicePacketCapacities.delete(deviceId);
191
181
  // Keep deviceProtocolHints — it's inferred from device name (e.g. "Pro 2" → V2)
192
182
  // and doesn't depend on connection state. Preserving it avoids redundant V1 probe on reconnect.
193
183
  this.v1Buffers.delete(deviceId);
@@ -206,12 +196,6 @@ export default class ElectronBleTransport {
206
196
  this.notificationCleanups.delete(deviceId);
207
197
  }
208
198
 
209
- const mtuCleanup = this.mtuCleanups.get(deviceId);
210
- if (mtuCleanup) {
211
- mtuCleanup();
212
- this.mtuCleanups.delete(deviceId);
213
- }
214
-
215
199
  const disconnectCleanup = this.disconnectCleanups.get(deviceId);
216
200
  if (disconnectCleanup) {
217
201
  disconnectCleanup();
@@ -322,29 +306,16 @@ export default class ElectronBleTransport {
322
306
  this.handleBluetoothError(error);
323
307
  }
324
308
 
325
- const mtuCleanup = this.createMtuSubscription(uuid);
326
- if (mtuCleanup) {
327
- this.mtuCleanups.set(uuid, mtuCleanup);
328
- }
329
-
330
309
  this.v1Buffers.set(uuid, { buffer: [], bufferLength: 0 });
331
310
  this.v2Assemblers.set(uuid, new ProtocolV2FrameAssembler(PROTOCOL_V2_BLE_FRAME_MAX_BYTES));
332
311
 
333
312
  await window.desktopApi.nobleBle.subscribe(uuid);
334
- await this.refreshBlePacketCapacity(uuid);
335
313
 
336
314
  const cleanup = this.createNotificationSubscription(uuid);
337
315
  this.notificationCleanups.set(uuid, cleanup);
338
316
  const connectionToken = this.notificationTokens.get(uuid);
339
317
 
340
318
  const protocolType = await this.detectProtocol(uuid, expectedProtocol, protocolHint);
341
- if (protocolType === 'V2') {
342
- this.Log?.debug('[Electron BLE] Protocol V2 write configured', {
343
- writeMode: 'withoutResponse',
344
- negotiatedMtu: this.deviceMtus.get(uuid),
345
- packetCapacity: this.devicePacketCapacities.get(uuid) ?? BLE_PACKET_SIZE_FALLBACK,
346
- });
347
- }
348
319
 
349
320
  const disconnectCleanup = window.desktopApi.nobleBle.onDeviceDisconnected(
350
321
  (disconnectedDevice: any) => {
@@ -527,7 +498,6 @@ export default class ElectronBleTransport {
527
498
  await window.desktopApi?.nobleBle?.connect(uuid);
528
499
  this.connectedDevices.add(uuid);
529
500
  await window.desktopApi?.nobleBle?.subscribe(uuid);
530
- await this.refreshBlePacketCapacity(uuid);
531
501
  } catch (error) {
532
502
  this.Log?.debug(`[Electron BLE] reconnect after Protocol ${protocol} probe failed:`, error);
533
503
  throw error;
@@ -587,52 +557,21 @@ export default class ElectronBleTransport {
587
557
  await nobleBle.write(uuid, hexData);
588
558
  }
589
559
 
590
- private async refreshBlePacketCapacity(uuid: string): Promise<void> {
591
- const device = await window.desktopApi?.nobleBle?.getDevice(uuid);
592
- this.updateBlePacketCapacity(uuid, device?.mtu);
593
- }
594
-
595
- private updateBlePacketCapacity(uuid: string, mtu?: number): void {
596
- const packetCapacity = resolveBlePacketCapacity(
597
- mtu,
598
- BLE_PACKET_SIZE_MAXIMUM,
599
- BLE_PACKET_SIZE_FALLBACK
600
- );
601
- if (typeof mtu === 'number') {
602
- this.deviceMtus.set(uuid, mtu);
603
- } else {
604
- this.deviceMtus.delete(uuid);
605
- }
606
- this.devicePacketCapacities.set(uuid, packetCapacity);
607
- }
608
-
609
- private createMtuSubscription(uuid: string): (() => void) | undefined {
610
- const onMtuChanged = window.desktopApi?.nobleBle?.onMtuChanged;
611
- if (!onMtuChanged) return undefined;
612
- return onMtuChanged(device => {
613
- if (device.id === uuid) {
614
- this.updateBlePacketCapacity(uuid, device.mtu);
615
- }
616
- });
617
- }
618
-
619
560
  private writeProtocolV2Frame(
620
561
  uuid: string,
621
562
  frame: Uint8Array,
622
563
  context: ProtocolV2CallContext,
623
564
  assertCurrentGeneration: () => void
624
565
  ) {
625
- const packetCapacity = this.devicePacketCapacities.get(uuid) ?? BLE_PACKET_SIZE_FALLBACK;
626
- const shouldPace = !context.highVolume;
627
566
  return writeProtocolV2BleFrame({
628
567
  frame,
629
- packetCapacity,
568
+ packetCapacity: BLE_PACKET_SIZE,
630
569
  assertActive: assertCurrentGeneration,
631
570
  signal: context.signal,
632
571
  abortMessage: `Protocol V2 BLE write aborted for ${context.messageName}`,
633
- initialDelayMs: shouldPace && frame.length <= packetCapacity ? BLE_WRITE_DELAY_MS : 0,
634
- burstSize: shouldPace ? 1 : undefined,
635
- burstPauseMs: shouldPace ? BLE_WRITE_DELAY_MS : 0,
572
+ initialDelayMs: frame.length <= BLE_PACKET_SIZE ? BLE_WRITE_DELAY_MS : 0,
573
+ burstSize: 1,
574
+ burstPauseMs: BLE_WRITE_DELAY_MS,
636
575
  writePacket: packet => this.writeOnce(uuid, bytesToHex(packet)),
637
576
  });
638
577
  }
@@ -1,2 +0,0 @@
1
- export declare function resolveBlePacketCapacity(mtu: number | null | undefined, maximumPacketCapacity: number, fallbackPacketCapacity: number): number;
2
- //# sourceMappingURL=ble-packet-capacity.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ble-packet-capacity.d.ts","sourceRoot":"","sources":["../src/ble-packet-capacity.ts"],"names":[],"mappings":"AAEA,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC9B,qBAAqB,EAAE,MAAM,EAC7B,sBAAsB,EAAE,MAAM,GAC7B,MAAM,CAMR"}
@@ -1,13 +0,0 @@
1
- const BLE_ATT_HEADER_BYTES = 3;
2
-
3
- export function resolveBlePacketCapacity(
4
- mtu: number | null | undefined,
5
- maximumPacketCapacity: number,
6
- fallbackPacketCapacity: number
7
- ): number {
8
- if (typeof mtu !== 'number' || !Number.isFinite(mtu) || mtu <= BLE_ATT_HEADER_BYTES) {
9
- return fallbackPacketCapacity;
10
- }
11
-
12
- return Math.min(maximumPacketCapacity, Math.floor(mtu) - BLE_ATT_HEADER_BYTES);
13
- }