TheThingsArchive / ttn

The Things Network Stack V2
https://www.thethingsnetwork.org
MIT License
461 stars 279 forks source link

Add IsConnectionOpen() to mqtt client #781

Closed normie7 closed 3 years ago

normie7 commented 4 years ago

This is a enhancement for mqtt client.

What's wrong?

Current documentation for Client.IsConnected() does not represent underlying implementation and there is no way to actually know if the client is connected. https://github.com/TheThingsNetwork/ttn/blob/develop/mqtt/client.go#L264

It returns true not only when the client is connected, but also when it tries to reconnect. Once the client lost connection to mqtt server, it will always show IsConnected() -> true since autoreconnection is enabled.

// IsConnected returns a bool signifying whether // the client is connected or not. // connected means that the connection is up now OR it will // be established/reestablished automatically when possible https://github.com/eclipse/paho.mqtt.golang/blob/master/client.go#L168

What do you want to do?

I want to change the docs for IsConnected() function and add IsConnectionOpen() function similar to https://github.com/eclipse/paho.mqtt.golang/blob/master/client.go#L186

Can you fix this yourself and submit a pull request?

Yes