| .. | .. |
|---|
| 56 | 56 | |
|---|
| 57 | 57 | // Callbacks |
|---|
| 58 | 58 | void Function(ConnectionStatus status)? onStatusChanged; |
|---|
| 59 | + void Function(String detail)? onStatusDetail; // "Probing local...", "Scanning network..." |
|---|
| 59 | 60 | void Function(Map<String, dynamic> message)? onMessage; |
|---|
| 60 | 61 | void Function()? onOpen; |
|---|
| 61 | 62 | void Function()? onClose; |
|---|
| .. | .. |
|---|
| 117 | 118 | if (config.vpnHost != null && config.vpnHost!.isNotEmpty) hosts.add(config.vpnHost!); |
|---|
| 118 | 119 | if (config.host.isNotEmpty) hosts.add(config.host); |
|---|
| 119 | 120 | _mqttLog('MQTT: probing ${hosts.length} hosts in parallel: ${hosts.join(", ")}'); |
|---|
| 121 | + onStatusDetail?.call('Probing ${hosts.length} hosts...'); |
|---|
| 120 | 122 | |
|---|
| 121 | 123 | // Probe all configured hosts in parallel — first to respond wins |
|---|
| 122 | 124 | String? winner; |
|---|
| .. | .. |
|---|
| 143 | 145 | |
|---|
| 144 | 146 | if (winner != null && !_intentionalClose) { |
|---|
| 145 | 147 | _mqttLog('MQTT: probe winner: $winner, connecting...'); |
|---|
| 148 | + onStatusDetail?.call('Connecting to $winner...'); |
|---|
| 146 | 149 | try { |
|---|
| 147 | 150 | if (await _tryConnect(winner, clientId, timeout: 5000)) return; |
|---|
| 148 | 151 | } catch (e) { |
|---|
| .. | .. |
|---|
| 152 | 155 | |
|---|
| 153 | 156 | // All hosts failed — retry after delay |
|---|
| 154 | 157 | _mqttLog('MQTT: all attempts failed, retrying in 5s'); |
|---|
| 158 | + onStatusDetail?.call('No server found, retrying...'); |
|---|
| 155 | 159 | _setStatus(ConnectionStatus.reconnecting); |
|---|
| 156 | 160 | Future.delayed(const Duration(seconds: 5), () { |
|---|
| 157 | 161 | if (!_intentionalClose && _status != ConnectionStatus.connected) { |
|---|
| .. | .. |
|---|
| 201 | 205 | |
|---|
| 202 | 206 | // Fallback: scan local subnet for MQTT port (handles Personal Hotspot) |
|---|
| 203 | 207 | _mqttLog('MQTT: Bonjour failed, trying subnet scan...'); |
|---|
| 208 | + onStatusDetail?.call('Scanning local network...'); |
|---|
| 204 | 209 | return _scanSubnetForMqtt(); |
|---|
| 205 | 210 | } |
|---|
| 206 | 211 | |
|---|