mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-08-04 15:03:00 +10:00
chrome connect
This commit is contained in:
@@ -837,12 +837,18 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
);
|
||||
|
||||
// Request larger MTU for sending larger frames
|
||||
if (!PlatformInfo.isWeb) {
|
||||
try {
|
||||
final mtu = await device.requestMtu(185);
|
||||
debugPrint('MTU set to: $mtu');
|
||||
} catch (e) {
|
||||
debugPrint('MTU request failed: $e, using default');
|
||||
}
|
||||
} else {
|
||||
// On Chrome Web Bluetooth, give the GATT connection a moment to settle
|
||||
// before discovering services, which is a common quirk to avoid timeouts.
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
}
|
||||
|
||||
List<BluetoothService> services = await device.discoverServices();
|
||||
|
||||
@@ -871,13 +877,34 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
throw Exception("MeshCore characteristics not found");
|
||||
}
|
||||
|
||||
// Retry setNotifyValue with increasing delays
|
||||
// Setup listener BEFORE enabling notifications so we don't miss anything
|
||||
_notifySubscription = _txCharacteristic!.onValueReceived.listen(
|
||||
_handleFrame,
|
||||
onError: (Object e) {
|
||||
debugPrint("onValueReceived stream error: $e");
|
||||
},
|
||||
);
|
||||
|
||||
debugPrint('Starting setNotifyValue(true)');
|
||||
if (PlatformInfo.isWeb) {
|
||||
// On Web, setNotifyValue often hangs indefinitely on the Promise resolution.
|
||||
// We trigger it but don't await its completion to avoid blocking the connection flow.
|
||||
debugPrint('Web: Calling setNotifyValue(true) without awaiting');
|
||||
// ignore: unawaited_futures
|
||||
_txCharacteristic!.setNotifyValue(true).catchError((e) {
|
||||
debugPrint('Web setNotifyValue error (ignoring): $e');
|
||||
});
|
||||
// Give the browser a moment to process the underlying startNotifications call
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
} else {
|
||||
// Native platforms handle setNotifyValue blockingly with CCCD descriptors
|
||||
bool notifySet = false;
|
||||
for (int attempt = 0; attempt < 3 && !notifySet; attempt++) {
|
||||
try {
|
||||
if (attempt > 0) {
|
||||
await Future.delayed(Duration(milliseconds: 500 * attempt));
|
||||
}
|
||||
debugPrint('Calling setNotifyValue(true), attempt ${attempt + 1}');
|
||||
await _txCharacteristic!.setNotifyValue(true);
|
||||
notifySet = true;
|
||||
} catch (e) {
|
||||
@@ -885,12 +912,8 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
if (attempt == 2) rethrow;
|
||||
}
|
||||
}
|
||||
_notifySubscription = _txCharacteristic!.onValueReceived.listen(
|
||||
_handleFrame,
|
||||
onError: (Object e) {
|
||||
debugPrint("onValueReceived stream error: $e");
|
||||
},
|
||||
);
|
||||
}
|
||||
debugPrint('setNotifyValue(true) configuration completed');
|
||||
|
||||
_setState(MeshCoreConnectionState.connected);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user