Matthias Nott
2026-04-01 1f5e5967edb4146b10f077dd7d38e73385b2ebfd
lib/services/mqtt_service.dart
....@@ -60,6 +60,8 @@
6060 // Callbacks
6161 void Function(ConnectionStatus status)? onStatusChanged;
6262 void Function(String detail)? onStatusDetail; // "Probing local...", "Scanning network..."
63
+ String? connectedHost; // The host we're currently connected to
64
+ String? connectedVia; // "Local", "VPN", "Remote", "Bonjour", "Scan"
6365 void Function(Map<String, dynamic> message)? onMessage;
6466 void Function()? onOpen;
6567 void Function()? onClose;
....@@ -158,12 +160,27 @@
158160 }
159161
160162 if (winner != null && !_intentionalClose) {
161
- _mqttLog('MQTT: winner: $winner, connecting...');
162
- onStatusDetail?.call('Connecting to $winner...');
163
+ // Determine connection method label
164
+ if (winner == config.localHost) {
165
+ connectedVia = 'Local';
166
+ } else if (winner == config.vpnHost) {
167
+ connectedVia = 'VPN';
168
+ } else if (winner == config.host) {
169
+ connectedVia = 'Remote';
170
+ } else if (winner == _lastDiscoveredHost) {
171
+ connectedVia = 'Discovered';
172
+ } else {
173
+ connectedVia = winner;
174
+ }
175
+ connectedHost = winner;
176
+ _mqttLog('MQTT: winner: $winner ($connectedVia), connecting...');
177
+ onStatusDetail?.call('Connecting via $connectedVia...');
163178 try {
164179 if (await _tryConnect(winner, clientId, timeout: 5000)) return;
165180 } catch (e) {
166181 _mqttLog('MQTT: connect to $winner failed: $e');
182
+ connectedHost = null;
183
+ connectedVia = null;
167184 }
168185 }
169186