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

Execute function on reconnect #41

Closed
zuboje opened this issue Feb 15, 2021 · 2 comments
Closed

Execute function on reconnect #41

zuboje opened this issue Feb 15, 2021 · 2 comments

Comments

@zuboje
Copy link

zuboje commented Feb 15, 2021

This is not an issue but more like enhancement. When I use a function "withAutomaticReconnect()", it is a great feature and I get automatically reconnected to the hub. But when the device joins the hub, I send a set of commands to "group" devices. With automatic reconnect, I have to write a logic to keep track of my connection state and re-join a group on a signalR hub. It would be nice if I could provide to "withAutomaticReconnect()" a function to execute upon successful reconnect, that way I can write in a code "when you reconnect, send this to the hub to join your group to start receiving data". Hopefully, it would be on your road map down the road :)

@dees91
Copy link

dees91 commented Feb 15, 2021

@zuboje HubConnection already have such callbacks:

void onclose(ClosedCallback callback) {
  if (callback != null) {
    _closedCallbacks.add(callback);
  }
}

/// Registers a handler that will be invoked when the connection starts reconnecting.
void onreconnecting(ReconnectingCallback callback) {
  if (callback != null) {
    _reconnectingCallbacks.add(callback);
  }
}

/// Registers a handler that will be invoked when the connection successfully reconnects.
void onreconnected(ReconnectedCallback callback) {
  if (callback != null) {
    _reconnectedCallbacks.add(callback);
  }
}

https://github.com/jamiewest/signalr_core/blob/main/lib/src/hub_connection.dart#L959

So I think you can use one of those in described scenario.

@zuboje
Copy link
Author

zuboje commented Feb 15, 2021

@dees91 Thank you, I missed that!

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

2 participants