dotnet / dotnet/MQTTnet

Question/Feat: Expose MQTT Client connection status

Open
#2,219 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
C#
Stars
5.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

### Which project is your feature request related to?
- Client

### Describe your question

`IMqttClient` exposes `bool IsConnected` property. In default implementation it calculates as `(MqttClientConnectionStatus)_connectionStatus == MqttClientConnectionStatus.Connected`.

So question is **why not expose ConnectionStatus directly**?

#### WHY?
> Disconnection happened or keepalive failed - need to reconnect.
Even if I `IsConnected` prop have been checked there can be case that reconnect shouldn't/mustn't be called (eg in case of client is connecting already)

It would be nice to have `public MqttClientConnectionStatus ConnectionStatus { get; }` in `IMqttClient` ([there](https://github.com/dotnet/MQTTnet/blob/d74d83453f18aa6e366314c7c71b21628733e151/Source/MQTTnet/IMqttClient.cs#L18)) and it's impl in `MqttClient`.

Or at least documentation for MQTT-client functional. It's very unclear of what happening inside package:
- What happen if Keep Alive task can't ping server - is there disconnect, disconnect+reconnect, some exception raised?
- Should I reconnect manually if client had been disconnected? Inside of `DisconnectedEvent` handler [mentioned here](https://github.com/dotnet/MQTTnet/issues/2060)?
- How can I know there is already a connection establishing (`_connectionStatus == Connecting`) without accessing to `_connectionStatus`? How can I avoid situations where a client is connecting but for some reason I will do `ConnectAsync`/`ReconnectAsync`?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.