Erweiterungen
This commit is contained in:
1 parent
25a2455ce1
commit
1732a634be
10 files changed
+268
-116
No files matched your search
@@ -5,14 +5,12 @@ import 'dart:math';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:mqtt_client/mqtt_client.dart';
|
||||
import 'package:mqtt_client/mqtt_server_client.dart';
|
||||
import 'package:stadtbote/model/job_tour.dart';
|
||||
import 'package:stadtbote/model/status.dart';
|
||||
import 'package:stadtbote/protocoll_messages/bootstrap_request.dart';
|
||||
import 'package:stadtbote/protocoll_messages/bootstrap_response_payload.dart';
|
||||
import 'package:stadtbote/protocoll_messages/device_object.dart';
|
||||
import 'package:stadtbote/model/job.dart';
|
||||
import 'package:stadtbote/model/message.dart';
|
||||
import 'package:stadtbote/protocoll_messages/fin_task_message.dart';
|
||||
import 'package:stadtbote/protocoll_messages/job_del_message.dart';
|
||||
import 'package:stadtbote/protocoll_messages/payload_container.dart';
|
||||
import 'package:stadtbote/protocoll_messages/start_session_message.dart';
|
||||
@@ -45,6 +43,8 @@ class MqttCore {
|
||||
|
||||
late ConnectionStateEnum connectionState = ConnectionStateEnum.notConnected;
|
||||
|
||||
late bool _disconnectInProgress = false;
|
||||
|
||||
late String _brokerUri;
|
||||
late int _brokerPort;
|
||||
late String _fromServerTopic;
|
||||
@@ -54,9 +54,13 @@ class MqttCore {
|
||||
|
||||
late int _reconnectDelay = 0;
|
||||
|
||||
late Timer? _trackTimer;
|
||||
late Timer? _reconnectTimer = null;
|
||||
|
||||
late Timer? _trackTimer = null;
|
||||
|
||||
MqttCore() {
|
||||
_disconnectInProgress = false;
|
||||
|
||||
_processBootstrap();
|
||||
}
|
||||
|
||||
@@ -64,6 +68,18 @@ class MqttCore {
|
||||
instance = MqttCore();
|
||||
}
|
||||
|
||||
diconnect() {
|
||||
_disconnectInProgress = true;
|
||||
|
||||
_cancelReconnectTimer();
|
||||
|
||||
_cancelTrackTimer();
|
||||
|
||||
_mqttClient.disconnect();
|
||||
|
||||
connectionState = ConnectionStateEnum.notConnected;
|
||||
}
|
||||
|
||||
_connectToBroker() async {
|
||||
try {
|
||||
String clientId = await Util.getAppUuid();
|
||||
@@ -303,13 +319,21 @@ class MqttCore {
|
||||
void _startReconnectTimer() {
|
||||
connectionState = ConnectionStateEnum.notConnected;
|
||||
|
||||
Util.logInfo("_startReconnectTimer called");
|
||||
if (!_disconnectInProgress) {
|
||||
Util.logInfo("_startReconnectTimer called");
|
||||
|
||||
_reconnectDelay = min(_reconnectDelay + 1, 30);
|
||||
_reconnectDelay = min(_reconnectDelay + 1, 30);
|
||||
|
||||
Timer(Duration(seconds: _reconnectDelay), () {
|
||||
_processBootstrap();
|
||||
});
|
||||
_reconnectTimer = Timer(Duration(seconds: _reconnectDelay), () {
|
||||
_processBootstrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _cancelReconnectTimer() {
|
||||
if (_reconnectTimer != null && _reconnectTimer!.isActive) {
|
||||
_reconnectTimer!.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void _clientDisconnected() {
|
||||
@@ -321,7 +345,9 @@ class MqttCore {
|
||||
|
||||
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));
|
||||
|
||||
_startReconnectTimer();
|
||||
if (!_disconnectInProgress) {
|
||||
_startReconnectTimer();
|
||||
}
|
||||
}
|
||||
|
||||
void _processBootstrap() async {
|
||||
|
||||
Reference in new issue
Block a user