| .. | .. |
|---|
| 440 | 440 | ); |
|---|
| 441 | 441 | _mqttLog('MQTT: connect result=${result?.state}'); |
|---|
| 442 | 442 | if (result?.state == MqttConnectionState.connected) { |
|---|
| 443 | | - // Don't enable autoReconnect — we handle reconnection ourselves |
|---|
| 444 | | - // in didChangeAppLifecycleState(resumed). The library's autoReconnect |
|---|
| 445 | | - // competes with our force-reconnect and causes connection flickering. |
|---|
| 443 | + client.autoReconnect = true; |
|---|
| 446 | 444 | return true; |
|---|
| 447 | 445 | } |
|---|
| 448 | 446 | _client = null; |
|---|
| .. | .. |
|---|
| 800 | 798 | switch (state) { |
|---|
| 801 | 799 | case AppLifecycleState.resumed: |
|---|
| 802 | 800 | if (_intentionalClose) break; |
|---|
| 803 | | - _mqttLog('MQTT: app resumed — reconnecting to last host'); |
|---|
| 804 | | - // Kill old client completely (disable autoReconnect first to prevent |
|---|
| 805 | | - // the MQTT library from spawning its own reconnect attempt) |
|---|
| 806 | | - final oldClient = _client; |
|---|
| 807 | | - if (oldClient != null) { |
|---|
| 808 | | - oldClient.autoReconnect = false; |
|---|
| 809 | | - try { oldClient.disconnect(); } catch (_) {} |
|---|
| 810 | | - } |
|---|
| 811 | | - _updatesSub?.cancel(); |
|---|
| 812 | | - _updatesSub = null; |
|---|
| 813 | | - _client = null; |
|---|
| 814 | | - _setStatus(ConnectionStatus.reconnecting); |
|---|
| 815 | | - onReconnecting?.call(); |
|---|
| 816 | | - if (connectedHost != null) { |
|---|
| 817 | | - _fastReconnect(connectedHost!); |
|---|
| 818 | | - } else { |
|---|
| 819 | | - connect(); |
|---|
| 820 | | - } |
|---|
| 801 | + _mqttLog('MQTT: app resumed'); |
|---|
| 802 | + // Let autoReconnect handle dead connections (keepalive timeout). |
|---|
| 803 | + // Just trigger catch_up to fetch missed messages and rebuild UI. |
|---|
| 804 | + onResume?.call(); |
|---|
| 821 | 805 | case AppLifecycleState.paused: |
|---|
| 822 | 806 | break; |
|---|
| 823 | 807 | default: |
|---|