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

Handle connection errors #56

Closed
LamaMen opened this issue Nov 11, 2021 · 8 comments
Closed

Handle connection errors #56

LamaMen opened this issue Nov 11, 2021 · 8 comments

Comments

@LamaMen
Copy link

LamaMen commented Nov 11, 2021

Hello. I'm trying to use a centrifuge to create a simple chat and can't think of a better way to handle connection errors (for example, the user has no internet or the server is not available). Is there any way to do this?

@FZambia
Copy link
Member

FZambia commented Nov 11, 2021

@LamaMen hi, all other Centrifugo clients expose Disconnect event if the initial connect failed, but centrifuge-dart does not - it just tries to reconnect in the background. I think we should mimic this behaviour here too.

Do I understand right that your question is about handling errors on initial connect to the server?

@LamaMen
Copy link
Author

LamaMen commented Nov 11, 2021

Yes!))

@FZambia
Copy link
Member

FZambia commented Nov 14, 2021

@LamaMen hi, trying to address this and some other things in #57 – try to play with console/example.dart from that branch - does it makes sense or you still need sth else?

@LamaMen
Copy link
Author

LamaMen commented Nov 15, 2021

Hi, I looked at what you changed and I have a couple of questions:

  • It is not entirely clear why this method cannot be added to the client interface: bool get connected => _state == _ClientState.connected;
  • As I understand it, we can set a callback (config.retry()) that will be called on every reconnection and use it to handle these cases. But the question is, how can we figure out what was the reason for the reconnection? Or is it better to use streams disconnectStream and errorStream for the reasons of reconnection?

And one more question, is it possible to transfer these changes to the version of the library without support null safty (for example v0.5.1)? We use an old version of flutter sdk on our project (v1.22.6).

@FZambia
Copy link
Member

FZambia commented Nov 15, 2021

It is not entirely clear why this method cannot be added to the client interface: bool get connected => _state == _ClientState.connected;

The reason it's not exposed is that nobody asked about it and I had no use case for it personally. If you need it to be exposed describe your use case. In most cases you better listen to state changes using connect/disconnect events and update application state instead of checking for connected status before operations. But I may miss sth here since it's hard to have all possible apps/use cases in mind.

As I understand it, we can set a callback (config.retry()) that will be called on every reconnection and use it to handle these cases. But the question is, how can we figure out what was the reason for the reconnection? Or is it better to use streams disconnectStream and errorStream for the reasons of reconnection?

config.retry is mostly for changing reconnect time strategy, disconnect reason can be found from disconnect event, and you can log errors from errorStream to investigate the exact error happening. Disconnect reason does not have exact detailed error description, it acts more like enum with some predefined values why the connection state changed. There are some plans to standartize disconnects a bit throughout Centrifugo(e) ecosystem: tracked in centrifugal/centrifuge#149 - but cant give any ETAs for it.

Maybe you will have better ideas on the more handy error/disconnect handling strategy – we can discuss this!

is it possible to transfer these changes to the version of the library without support null safty

I won't backport this myself, but if you are interested in migrating some of the later added features into 0.5.x then I can help creating a 0.5.x branch, merge pr with backwards compatible changes into it and release.

@FZambia
Copy link
Member

FZambia commented Nov 19, 2021

Addressed by v0.8.0. Disconnect now fired on initial connect error and Client.errorStream added to log connection errors.

Closing, @LamaMen feel free to comment though – if you have ideas, suggestions on how we can improve API further we can continue discussion here.

@FZambia FZambia closed this as completed Nov 19, 2021
@LamaMen
Copy link
Author

LamaMen commented Nov 26, 2021

Hi, I'm sorry I didn't answer for so long. I would still ask for your help to make a backport. I just haven't done this yet))

@morfair
Copy link

morfair commented Feb 3, 2022

Why is Centrifuge's websocket used for mobile app instead of PUSH?

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