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

Need callback for error in connection #33

Closed
bubooon opened this issue May 10, 2017 · 12 comments
Closed

Need callback for error in connection #33

bubooon opened this issue May 10, 2017 · 12 comments

Comments

@bubooon
Copy link

bubooon commented May 10, 2017

I want detect, if JS client can't connect to centrifugo, but i can't do this. I have just error in console
WebSocket connection to 'ws://domain.loc:8000/connection/websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
Can you add some event for it?

@FZambia
Copy link
Member

FZambia commented May 10, 2017

@bubooon hello! Yeah, I think it's reasonable to have, could you describe why do you specifically need this btw?

@bubooon
Copy link
Author

bubooon commented May 11, 2017

For example, I have an important functional in my application which depend on centrifuge . If suddenly the server of the centrifuge down, I want to show an adequate message for the user and not let him use this functionality. Now it is impossible to do it, because i can't handle this error.

@FZambia
Copy link
Member

FZambia commented May 12, 2017

Got it, thanks, will try to add during this weekend.

@FZambia
Copy link
Member

FZambia commented May 13, 2017

@bubooon just found a time to play with your request and I wonder why not using existing disconnect event for your case:

centrifuge.on('disconnect', function(ctx){
    console.log('Disconnected: ' + ctx.reason);
});

@bubooon
Copy link
Author

bubooon commented May 15, 2017

@FZambia Because i connect and disconnect to centrifuge in app and i will get this event when i disconnect manually. Better have special event when you trying connect but get error, because server is not responsing.

@FZambia
Copy link
Member

FZambia commented May 15, 2017

Hmm, it's not as easy as I initially thought. If using raw Websockets we can add callback to onerror event and it will be called every time client tries to reconnect to Centrifugo and server unavailable. But the hard part here is SockJS which does not use onerror event - it tries to create connection using possible transports - I need a time to investigate more.

@bubooon
Copy link
Author

bubooon commented May 15, 2017

And one more thing, i have disconnect event only one time, if i will disconnect manually and try to connect again i have not this event more, because client trying reconnect.

@bubooon
Copy link
Author

bubooon commented Jun 20, 2017

Any news?

@FZambia
Copy link
Member

FZambia commented Jun 20, 2017

@bubooon I am sorry for a delay - the reason why I have not just added this yet is SockJS which has no onerror event. But I have not found time to investigate this case more - will try to look at this ASAP.

@FZambia
Copy link
Member

FZambia commented Jun 23, 2017

@bubooon please look in on_transport_close branch and this comparison - I added onTransportClose callback which will be executed every time there is problem with connection (both raw Websocket and SockJS). There is also build with these changes in that branch so you can test it in your development environment. Does this help to solve your case?

Example:

var centrifuge = new Centrifuge({
        ...
        onTransportClose: function(ctx) {
            console.log(ctx);
        }
});

@FZambia
Copy link
Member

FZambia commented Jul 18, 2017

@bubooon hi, I merged changes above into master, please reopen if it does not work for you and you still need a solution.

@FZambia FZambia closed this as completed Jul 18, 2017
@bubooon
Copy link
Author

bubooon commented Apr 4, 2018

@FZambia, hi, sorry for a long response, but this is not solve my issue. I need catch event, for example, when i set bad port or Centrifuge server is down. Now in this case i have error:
WebSocket connection to 'ws://127.0.0.1:8001/connection/websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
And i have this message every 5-10 seconds.

I need just handle this case.

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