Refactoring
This commit is contained in:
1 parent
66321f710b
commit
007aa8dd1a
3 files changed
+51
-48
No files matched your search
@@ -1,8 +1,7 @@
|
|||||||
|
import 'package:stadtbote/model/status.dart';
|
||||||
|
|
||||||
import 'package:stadtbote/model/session_status.dart';
|
class StatusInfoUpdate {
|
||||||
|
StatusInfoUpdate({required this.status});
|
||||||
|
|
||||||
class SessionStatusInfoUpdate {
|
final Status status;
|
||||||
SessionStatusInfoUpdate({required this.status});
|
|
||||||
|
|
||||||
final SessionStatus status;
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ class Constants {
|
|||||||
static const String messageTopicConnectionStatusChanged = "connection_status_changed";
|
static const String messageTopicConnectionStatusChanged = "connection_status_changed";
|
||||||
static const String messageTopicSessionInfoUpdate = "status_info_updated";
|
static const String messageTopicSessionInfoUpdate = "status_info_updated";
|
||||||
static const String messageTopicSessionStatusInfoUpdate = "session_status_info_updated";
|
static const String messageTopicSessionStatusInfoUpdate = "session_status_info_updated";
|
||||||
|
static const String messageTopicStatusInfoUpdated = "status_info_updated";
|
||||||
static const String messageTopicLocationStatusUpdated = "location_status_updated";
|
static const String messageTopicLocationStatusUpdated = "location_status_updated";
|
||||||
static const String messageTopicRankingUpdated = "ranking_updated";
|
static const String messageTopicRankingUpdated = "ranking_updated";
|
||||||
static const String messageTopicJobReceived = "job_received";
|
static const String messageTopicJobReceived = "job_received";
|
||||||
|
|||||||
+46
-43
@@ -23,6 +23,7 @@ import 'package:stadtbote/protocoll_messages/device_log_response.dart';
|
|||||||
import 'package:stadtbote/protocoll_messages/device_object.dart';
|
import 'package:stadtbote/protocoll_messages/device_object.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/payload_container.dart';
|
import 'package:stadtbote/protocoll_messages/payload_container.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/start_session_message.dart';
|
import 'package:stadtbote/protocoll_messages/start_session_message.dart';
|
||||||
|
import 'package:stadtbote/protocoll_messages/status_info_update.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/sync_jobs_message.dart';
|
import 'package:stadtbote/protocoll_messages/sync_jobs_message.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/track_message.dart';
|
import 'package:stadtbote/protocoll_messages/track_message.dart';
|
||||||
import 'package:stadtbote/tools/connection_status.dart';
|
import 'package:stadtbote/tools/connection_status.dart';
|
||||||
@@ -180,61 +181,63 @@ class MqttCore {
|
|||||||
void _setupMqtt() async {
|
void _setupMqtt() async {
|
||||||
Util.logInfo('_setupMqtt called');
|
Util.logInfo('_setupMqtt called');
|
||||||
|
|
||||||
_mqttClient!.updates?.listen((List<MqttReceivedMessage<MqttMessage>> c) {
|
_mqttClient!.updates?.listen((List<MqttReceivedMessage<MqttMessage>> messages) {
|
||||||
for (var message in c) {
|
for (var mqttMessage in messages) {
|
||||||
try {
|
try {
|
||||||
if (message.topic.endsWith(_clientId)) {
|
final MqttPublishMessage message = mqttMessage.payload as MqttPublishMessage;
|
||||||
var messageBytes = message.payload.;
|
|
||||||
String payload = utf8.decode(GZipDecoder().decodeBytes(messageBytes));
|
|
||||||
|
|
||||||
var topicArray = message.variableHeader?.topicName;
|
if (message.variableHeader!.topicName.endsWith(_clientId)) {
|
||||||
var topicArraySplited = topicArray!.split("/");
|
var messageBytes = message.payload.message;
|
||||||
var topic = topicArraySplited[3];
|
String payload = utf8.decode(GZipDecoder().decodeBytes(messageBytes));
|
||||||
|
|
||||||
Util.logInfo('message received\ntopic: $topic\nmessage: $payload');
|
var topicArray = message.variableHeader?.topicName;
|
||||||
|
var topicArraySplited = topicArray!.split("/");
|
||||||
|
var topic = topicArraySplited[3];
|
||||||
|
|
||||||
switch(topic) {
|
Util.logInfo('message received\ntopic: $topic\nmessage: $payload');
|
||||||
case 'session':
|
|
||||||
_sessionMessageReceived(jsonDecode(payload));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'status':
|
switch (topic) {
|
||||||
_statusMessageReceived(jsonDecode(payload));
|
case 'session':
|
||||||
break;
|
_sessionMessageReceived(jsonDecode(payload));
|
||||||
|
break;
|
||||||
|
|
||||||
case 'ranks':
|
case 'status':
|
||||||
_rankingMessageReceived(jsonDecode(payload));
|
_statusMessageReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'job':
|
case 'ranks':
|
||||||
_jobMessageReceived(jsonDecode(payload));
|
_rankingMessageReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'job_del':
|
case 'job':
|
||||||
_jobDeleteReceived(jsonDecode(payload));
|
_jobMessageReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'sync_request':
|
case 'job_del':
|
||||||
_syncRequestReceived(jsonDecode(payload));
|
_jobDeleteReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "mssg":
|
case 'sync_request':
|
||||||
_messageMessageReceived(jsonDecode(payload));
|
_syncRequestReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "upload_device_log":
|
case "mssg":
|
||||||
_messageUploadDeviceLogReceived(jsonDecode(payload));
|
_messageMessageReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case "upload_device_log":
|
||||||
Util.logInfo('Unknown topic: $topic');
|
_messageUploadDeviceLogReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
default:
|
||||||
|
Util.logInfo('Unknown topic: $topic');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch(ex) {
|
}
|
||||||
Util.logException(ex.toString());
|
} catch(ex) {
|
||||||
}
|
Util.logException(ex.toString());
|
||||||
});
|
}
|
||||||
|
}});
|
||||||
|
|
||||||
if (await Util.preferencesContainsKey(Constants.prefsPreviousMqttSubscription)) {
|
if (await Util.preferencesContainsKey(Constants.prefsPreviousMqttSubscription)) {
|
||||||
String previousMqttSubscription = await Util.preferencesGetString(Constants.prefsPreviousMqttSubscription, "") as String;
|
String previousMqttSubscription = await Util.preferencesGetString(Constants.prefsPreviousMqttSubscription, "") as String;
|
||||||
@@ -284,7 +287,7 @@ class MqttCore {
|
|||||||
MessageService().publish<StatusInfoUpdate>(Constants.messageTopicStatusInfoUpdated, arguments: StatusInfoUpdate(status: statusMessage));
|
MessageService().publish<StatusInfoUpdate>(Constants.messageTopicStatusInfoUpdated, arguments: StatusInfoUpdate(status: statusMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _locationSatusMessageReceived(payloadData) async {
|
void _locationStatusMessageReceived(payloadData) async {
|
||||||
var locationStatus = LocationStatus.fromJson(payloadData);
|
var locationStatus = LocationStatus.fromJson(payloadData);
|
||||||
|
|
||||||
await MyApp.isarInstance.writeTxn(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
|
|||||||
Reference in new issue
Block a user