Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onConnect callback required for renewing subscriptions #52

Closed
elementzonline opened this issue Nov 22, 2018 · 5 comments
Closed

onConnect callback required for renewing subscriptions #52

elementzonline opened this issue Nov 22, 2018 · 5 comments

Comments

@elementzonline
Copy link

onConnect callback feature is required when the client gets disconnected when there is network loss. This callback can be used to renew subscriptions.

@shamblett
Copy link
Owner

Yes OK I'll update the client to add one.

As a thought, the client maintains a list of subscriptions, would an option to automatically re-subscribe to these on re-connection be useful?

@drost
Copy link

drost commented Nov 23, 2018

On that note, how is reconnection supposed to work? If there is an error during the initial connect, I can't see that a reconnection attempt will be made.

@shamblett
Copy link
Owner

The client automatically tries to reconnect if the initial connection attempt fails, at the moment this is hard wired to 3 attempts in total, you can see this if you edit the mqtt_client.dart in the examples folder to connect to a non-existent broker and turn logging on

@elementzonline
Copy link
Author

elementzonline commented Nov 24, 2018

I solved this issue for now by using a 5 second one shot timer to call _connect when the timer expires in the _onDisconnect

void _onDisconnected() {
client.disconnect();
Timer(Duration(seconds: 5), _reconnect);
}

void _reconnect() {
print('MQTT client reconnecting');
_connect();
}

@shamblett
Copy link
Owner

OnConnect callback added, client re-published at 5.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants