Enhance Bluetooth scanning and notification handling for web platform

This commit is contained in:
just_stuff_tm
2026-03-02 00:41:52 -05:00
committed by just-stuff-tm
parent c23a1da430
commit 5f4333398e
+24 -12
View File
@@ -738,7 +738,7 @@ class MeshCoreConnector extends ChangeNotifier {
}); });
await FlutterBluePlus.startScan( await FlutterBluePlus.startScan(
withKeywords: ["MeshCore-", "Whisper-"], withKeywords: ["MeshCore-", "Whisper-", "Wismesh-", "WisCore-"],
webOptionalServices: [Guid(MeshCoreUuids.service)], webOptionalServices: [Guid(MeshCoreUuids.service)],
timeout: timeout, timeout: timeout,
androidScanMode: AndroidScanMode.lowLatency, androidScanMode: AndroidScanMode.lowLatency,
@@ -836,18 +836,30 @@ class MeshCoreConnector extends ChangeNotifier {
throw Exception("MeshCore characteristics not found"); throw Exception("MeshCore characteristics not found");
} }
// Retry setNotifyValue with increasing delays if (PlatformInfo.isWeb) {
bool notifySet = false; debugPrint('Starting setNotifyValue(true)');
for (int attempt = 0; attempt < 3 && !notifySet; attempt++) { debugPrint('Web: Calling setNotifyValue(true) without awaiting');
try { unawaited(() async {
if (attempt > 0) { try {
await Future.delayed(Duration(milliseconds: 500 * attempt)); await _txCharacteristic!.setNotifyValue(true);
} catch (error) {
debugPrint('Web setNotifyValue error (ignoring): $error');
}
}());
debugPrint('setNotifyValue(true) configuration completed');
} else {
bool notifySet = false;
for (int attempt = 0; attempt < 3 && !notifySet; attempt++) {
try {
if (attempt > 0) {
await Future.delayed(Duration(milliseconds: 500 * attempt));
}
await _txCharacteristic!.setNotifyValue(true);
notifySet = true;
} catch (e) {
debugPrint('setNotifyValue attempt ${attempt + 1}/3 failed: $e');
if (attempt == 2) rethrow;
} }
await _txCharacteristic!.setNotifyValue(true);
notifySet = true;
} catch (e) {
debugPrint('setNotifyValue attempt ${attempt + 1}/3 failed: $e');
if (attempt == 2) rethrow;
} }
} }
_notifySubscription = _txCharacteristic!.onValueReceived.listen( _notifySubscription = _txCharacteristic!.onValueReceived.listen(