fix(#718): stop the BLE MTU floor locking the composer on web

Web Bluetooth exposes no ATT MTU to page script; there is no API for it, so
`mtuNow` can only ever be the 23-byte default. `effectiveMaxFrameSize` applied
the BLE floor on every platform whenever the transport was bluetooth, so web
landed on 20 bytes permanently and the channel composer computed a 0-byte
limit. That is the #592 symptom on a third platform.

Unlike Windows (#686) and Linux (#717), this cannot be fixed by reporting an
MTU, because there is none to report. Patching flutter_blue_plus_web would
achieve nothing.

The floor exists because a raw single characteristic write larger than the PDU
is rejected and wedges the send path (#395). That failure mode is not reachable
on web: the browser owns fragmentation, and the Web Bluetooth spec caps one
write at 512 bytes, rejecting anything larger with InvalidModificationError.
maxFrameSize (172) is well inside that, so a write cannot be oversized whatever
the link negotiated. Cited rather than assumed, because "just remove the floor"
was considered and rejected as the fix for #592.

Not unit-testable: `kIsWeb` is a compile-time constant, so a VM test cannot
enter this branch and CI runs the suite on the VM only. The floor's behaviour
on the other platforms stays covered. Proving this one needs a max-length send
over web BLE in a browser, which is the acceptance criterion on #718.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
pull/741/head
diffwireauto 2 months ago committed by Benjamin Wiechel
parent 610cbcd3d4
commit 8d62dc7cc8

@ -507,6 +507,19 @@ class MeshCoreConnector extends ChangeNotifier {
if (_activeTransport != MeshCoreTransportType.bluetooth) {
return maxFrameSize;
}
// Web Bluetooth exposes no ATT MTU to page script: there is no API for it,
// so `mtuNow` can only ever be the 23-byte default and the floor below
// would cap every composer at 0-4 bytes forever (#718, the #592 symptom).
//
// The floor exists because a raw single characteristic write larger than
// the PDU is rejected and wedges the send path (#395). That failure mode is
// not reachable here: the browser owns fragmentation, and the Web Bluetooth
// spec caps one write at 512 bytes, rejecting anything larger with
// InvalidModificationError. maxFrameSize (172) is well inside that, so the
// write cannot be oversized no matter what the link negotiated.
if (PlatformInfo.isWeb) {
return maxFrameSize;
}
final mtu = _device?.mtuNow ?? 0;
// ATT_MTU 23 is the BLE minimum; a single write then carries 23 - 3 = 20
// bytes. An unknown MTU must fall back to that floor, never [maxFrameSize],

Loading…
Cancel
Save

Powered by TurnKey Linux.