| .. | .. |
|---|
| 60 | 60 | // Callbacks |
|---|
| 61 | 61 | void Function(ConnectionStatus status)? onStatusChanged; |
|---|
| 62 | 62 | 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" |
|---|
| 63 | 65 | void Function(Map<String, dynamic> message)? onMessage; |
|---|
| 64 | 66 | void Function()? onOpen; |
|---|
| 65 | 67 | void Function()? onClose; |
|---|
| .. | .. |
|---|
| 158 | 160 | } |
|---|
| 159 | 161 | |
|---|
| 160 | 162 | 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...'); |
|---|
| 163 | 178 | try { |
|---|
| 164 | 179 | if (await _tryConnect(winner, clientId, timeout: 5000)) return; |
|---|
| 165 | 180 | } catch (e) { |
|---|
| 166 | 181 | _mqttLog('MQTT: connect to $winner failed: $e'); |
|---|
| 182 | + connectedHost = null; |
|---|
| 183 | + connectedVia = null; |
|---|
| 167 | 184 | } |
|---|
| 168 | 185 | } |
|---|
| 169 | 186 | |
|---|