summaryrefslogtreecommitdiff
path: root/lib/data.dart
diff options
context:
space:
mode:
Diffstat (limited to 'lib/data.dart')
-rw-r--r--lib/data.dart12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/data.dart b/lib/data.dart
index 08f8881..f5a24e8 100644
--- a/lib/data.dart
+++ b/lib/data.dart
@@ -10,8 +10,9 @@ const String topicPrefix = 'sia';
class AppState with ChangeNotifier {
Map<String, bool> contacts = <String, bool>{};
-
late final MqttServerClient _client;
+ bool _brokerConnected = false;
+ bool get brokerConnected => _brokerConnected;
AppState() {
_initMqtt();
@@ -31,9 +32,11 @@ class AppState with ChangeNotifier {
_client.port = brokerPort;
_client.keepAlivePeriod = 2;
+ _client.disconnectOnNoResponsePeriod = 1;
_client.logging(on: false);
_client.onConnected = _onConnected;
+ _client.onDisconnected = _onDisconnected;
try {
await _client.connect();
@@ -47,6 +50,13 @@ class AppState with ChangeNotifier {
void _onConnected() {
_client.subscribe('$topicPrefix/contact/+/state', MqttQos.exactlyOnce);
+ _brokerConnected = true;
+ notifyListeners();
+ }
+
+ void _onDisconnected() {
+ _brokerConnected = false;
+ notifyListeners();
}
void _onMessage(List<MqttReceivedMessage<MqttMessage>> messages) {