connectionStateStream property
Implementation
@override
Stream<MeshConnectionStateEvent> get connectionStateStream {
_connectionStreamController?.close();
_connectionStreamController =
StreamController<MeshConnectionStateEvent>.broadcast();
_connectionEventChannel.receiveBroadcastStream().listen(
(dynamic event) {
if (event is Map) {
try {
final stateEvent = MeshConnectionStateEvent.fromMap(
Map<String, dynamic>.from(event),
);
_connectionStreamController?.add(stateEvent);
} catch (e) {
debugPrint('Error parsing connection state: $e');
}
}
},
onError: (dynamic error) {
debugPrint('Connection stream error: $error');
_connectionStreamController?.addError(error);
},
onDone: () {
_connectionStreamController?.close();
},
);
return _connectionStreamController!.stream;
}