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

View file

@ -738,7 +738,7 @@ class MeshCoreConnector extends ChangeNotifier {
});
await FlutterBluePlus.startScan(
withKeywords: ["MeshCore-", "Whisper-"],
withKeywords: ["MeshCore-", "Whisper-", "Wismesh-", "WisCore-"],
webOptionalServices: [Guid(MeshCoreUuids.service)],
timeout: timeout,
androidScanMode: AndroidScanMode.lowLatency,
@ -836,18 +836,30 @@ class MeshCoreConnector extends ChangeNotifier {
throw Exception("MeshCore characteristics not found");
}
// Retry setNotifyValue with increasing delays
bool notifySet = false;
for (int attempt = 0; attempt < 3 && !notifySet; attempt++) {
try {
if (attempt > 0) {
await Future.delayed(Duration(milliseconds: 500 * attempt));
if (PlatformInfo.isWeb) {
debugPrint('Starting setNotifyValue(true)');
debugPrint('Web: Calling setNotifyValue(true) without awaiting');
unawaited(() async {
try {
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(