mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat(mqtt): adopt mqttastic-client-kmp 0.2.0 — disconnect reasons + Test Connection (#5181)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
ef0e159abb
commit
14e86b90f1
12 changed files with 425 additions and 55 deletions
|
|
@ -16,20 +16,41 @@
|
|||
*/
|
||||
package org.meshtastic.core.model
|
||||
|
||||
/** App-level MQTT proxy connection state, decoupled from the MQTT library's internal type. */
|
||||
enum class MqttConnectionState {
|
||||
/**
|
||||
* App-level MQTT proxy connection state, decoupled from the MQTT library's internal type.
|
||||
*
|
||||
* Modeled as a sealed class so disconnect / reconnect events can carry diagnostic context — the user-facing reason for
|
||||
* an unexpected disconnect, or the most recent reconnect attempt failure — without requiring downstream consumers to
|
||||
* depend on the MQTT library's exception types.
|
||||
*/
|
||||
sealed class MqttConnectionState {
|
||||
/** The MQTT proxy has not been started (disabled or not yet initialized). */
|
||||
INACTIVE,
|
||||
|
||||
/** The MQTT client is not connected to the broker. */
|
||||
DISCONNECTED,
|
||||
data object Inactive : MqttConnectionState()
|
||||
|
||||
/** The MQTT client is actively connecting to the broker. */
|
||||
CONNECTING,
|
||||
data object Connecting : MqttConnectionState()
|
||||
|
||||
/** The MQTT client is connected and subscribed to topics. */
|
||||
CONNECTED,
|
||||
data object Connected : MqttConnectionState()
|
||||
|
||||
/** The MQTT client lost connection and is attempting to reconnect. */
|
||||
RECONNECTING,
|
||||
/**
|
||||
* The MQTT client lost connection and is attempting to reconnect.
|
||||
*
|
||||
* @property attempt 1-based attempt counter for the current reconnect loop.
|
||||
* @property lastError Localized message from the most recent reconnect failure, if any.
|
||||
*/
|
||||
data class Reconnecting(val attempt: Int = 0, val lastError: String? = null) : MqttConnectionState()
|
||||
|
||||
/**
|
||||
* The MQTT client is not connected to the broker.
|
||||
*
|
||||
* @property reason Localized failure message for an unexpected disconnect, or `null` for the idle / initial /
|
||||
* intentional-close case (use [Idle]).
|
||||
*/
|
||||
data class Disconnected(val reason: String? = null) : MqttConnectionState() {
|
||||
companion object {
|
||||
/** Singleton for the idle / no-reason disconnected state. */
|
||||
val Idle: Disconnected = Disconnected(reason = null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.model
|
||||
|
||||
/**
|
||||
* UI-friendly outcome of a one-shot MQTT broker reachability probe.
|
||||
*
|
||||
* Mirrors the failure shapes of `org.meshtastic.mqtt.ProbeResult` but stays in the model module so feature/UI code can
|
||||
* consume the result without depending on the MQTT library.
|
||||
*/
|
||||
sealed class MqttProbeStatus {
|
||||
/** Probe is currently in flight. */
|
||||
data object Probing : MqttProbeStatus()
|
||||
|
||||
/**
|
||||
* Broker accepted the connection. [serverInfo] is a short human-readable summary of any CONNACK properties that are
|
||||
* useful to surface to the user.
|
||||
*/
|
||||
data class Success(val serverInfo: String?) : MqttProbeStatus()
|
||||
|
||||
/** Broker rejected the connection (CONNACK with non-zero reason code). */
|
||||
data class Rejected(val reasonCode: Int, val reason: String?, val serverReference: String?) : MqttProbeStatus()
|
||||
|
||||
/** DNS lookup failed. */
|
||||
data class DnsFailure(val message: String?) : MqttProbeStatus()
|
||||
|
||||
/** TCP socket could not be opened. */
|
||||
data class TcpFailure(val message: String?) : MqttProbeStatus()
|
||||
|
||||
/** TLS handshake failed. */
|
||||
data class TlsFailure(val message: String?) : MqttProbeStatus()
|
||||
|
||||
/** Probe exceeded its timeout. */
|
||||
data class Timeout(val timeoutMs: Long) : MqttProbeStatus()
|
||||
|
||||
/** Any other / unclassified failure. */
|
||||
data class Other(val message: String?) : MqttProbeStatus()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue