| .. | .. |
|---|
| 95 | 95 | |
|---|
| 96 | 96 | final clientId = await _getClientId(); |
|---|
| 97 | 97 | final hosts = _getHosts(); |
|---|
| 98 | + _mqttLog('MQTT: hosts=${hosts.join(", ")} port=${config.port}'); |
|---|
| 98 | 99 | |
|---|
| 99 | 100 | for (final host in hosts) { |
|---|
| 100 | 101 | if (_intentionalClose) return; |
|---|
| .. | .. |
|---|
| 162 | 163 | // Set _client BEFORE connect() so _onConnected can subscribe |
|---|
| 163 | 164 | _client = client; |
|---|
| 164 | 165 | |
|---|
| 165 | | - _mqttLog('MQTT: connecting to $host:${config.port} as $clientId'); |
|---|
| 166 | | - final result = await client.connect(); |
|---|
| 166 | + _mqttLog('MQTT: connecting to $host:${config.port} as $clientId (timeout=${timeout}ms)'); |
|---|
| 167 | + final result = await client.connect().timeout( |
|---|
| 168 | + Duration(milliseconds: timeout + 1000), |
|---|
| 169 | + onTimeout: () { |
|---|
| 170 | + _mqttLog('MQTT: connect timed out for $host'); |
|---|
| 171 | + return null; |
|---|
| 172 | + }, |
|---|
| 173 | + ); |
|---|
| 167 | 174 | _mqttLog('MQTT: connect result=${result?.state}'); |
|---|
| 168 | 175 | if (result?.state == MqttConnectionState.connected) { |
|---|
| 169 | 176 | client.autoReconnect = true; // Now enable auto-reconnect for the live connection |
|---|