Matthias Nott
2026-07-05 f28cf788428c8ab4465e51c62b63fc038b8d2971
lib/services/mqtt_service.dart
....@@ -81,6 +81,9 @@
8181 String? connectedHost; // The host we're currently connected to
8282 String? connectedVia; // "Local", "VPN", "Remote", "Bonjour", "Scan"
8383 void Function(Map<String, dynamic> message)? onMessage;
84
+ /// Called when the server sends a debug_state_request on pailot/control/out.
85
+ /// The handler should read current session state and call [publishDebugStateResponse].
86
+ void Function(String requestId)? onDebugStateRequest;
8487 void Function()? onOpen;
8588 void Function()? onClose;
8689 void Function()? onReconnecting;
....@@ -625,6 +628,15 @@
625628
626629 // pailot/control/out — command responses
627630 if (topic == 'pailot/control/out') {
631
+ // Intercept debug_state_request — handle locally, do not forward to UI.
632
+ if (json['type'] == 'debug_state_request') {
633
+ final requestId = json['requestId'] as String?;
634
+ if (requestId != null) {
635
+ _mqttLog('debug_state_request received (requestId=$requestId)');
636
+ onDebugStateRequest?.call(requestId);
637
+ }
638
+ return;
639
+ }
628640 onMessage?.call(json);
629641 return;
630642 }
....@@ -686,6 +698,29 @@
686698 }
687699 }
688700
701
+ /// Publish a debug_state_response back to the broker on pailot/control/in.
702
+ /// Call this from the [onDebugStateRequest] handler once session state is collected.
703
+ void publishDebugStateResponse({
704
+ required String requestId,
705
+ required String? activeSessionId,
706
+ required List<Map<String, dynamic>> sessions,
707
+ String? appVersion,
708
+ String? platform,
709
+ }) {
710
+ _publish('pailot/control/in', {
711
+ 'msgId': const Uuid().v4(),
712
+ 'type': 'command',
713
+ 'command': 'debug_state_response',
714
+ 'requestId': requestId,
715
+ 'activeSessionId': activeSessionId,
716
+ 'sessions': sessions,
717
+ if (appVersion != null) 'appVersion': appVersion,
718
+ if (platform != null) 'platform': platform,
719
+ 'ts': DateTime.now().millisecondsSinceEpoch,
720
+ }, MqttQos.atLeastOnce);
721
+ _mqttLog('debug_state_response sent for requestId=$requestId sessions=${sessions.length}');
722
+ }
723
+
689724 /// Send a message — routes to the appropriate MQTT topic based on content.
690725 void send(Map<String, dynamic> message) {
691726 final type = message['type'] as String?;