davinkevin / AngularStompDK

Angular service to communicate to Stomp-Websocket
http://davinkevin.github.io/AngularStompDK/
Apache License 2.0
36 stars 12 forks source link

auto reconnect #13

Closed genuinefafa closed 8 years ago

genuinefafa commented 8 years ago

I'm reading this article and the are proposing a nice way to reconnect stomp on timeout. But I'm unable to do it using ngstomp.

Whats the correct way to do it?

davinkevin commented 8 years ago

This article propose to reconnect with the onclose function on the stompClient.

But, I don't find any information about this element in the official Stomp-Websocket-JS documentation (http://jmesnil.net/stomp-websocket/doc/).

The best implementation in AngularStompDK seems to add an attribute on configuration to define if we want to reconnect on close.

For other behaviour (for example, modify a controller value on close), we will need an other callback function define on the service invocation.

I will do some investigation as soon as possible (maybe this week-end), and I will let you know. Don't forge, you can do a PR if you want to help.

Thanks

genuinefafa commented 8 years ago

Interesting. I was pretty sure that reconnect behavior was part of the specification. You are right, it is not. However, the source code for the stomp-websocket does have that method.

I'm not a expert user of this tecnologies. That's why I am at the read article and do comments stage. :expressionless:

Do you think I can help? I'm more than ready to do that. Just point me in the right direction and I'll do my best. :metal:

davinkevin commented 8 years ago

You can help, you just have to test and check if a behavior can be associated with the onclose of Stomp. I'm building a little backend app to ease the testing of the lib (https://github.com/davinkevin/spring-websocket-disconnect) and I'm trying to add a custom behavior...

For the API modification, let me now what you prefer (just an element on config to auto-reconnect) or a special behavior for each call to ngStompProvider ?

davinkevin commented 8 years ago

I've modified the onclose callback of the StompClient (https://github.com/davinkevin/spring-websocket-disconnect/blob/master/src/main/resources/static/angularStompDK.js#L198), it's never called... I've tried with a connection closed from the server and from the browser...

All the code is here : https://github.com/davinkevin/spring-websocket-disconnect

I don't have much time today, I will try to work on it... because the auto-reconnect is something I would like to add.

genuinefafa commented 8 years ago

@davinkevin i'm watching this but some other matters are taking my full attention... i'll catch up with this soon and get back to you! thanks for your quick reply ;)

davinkevin commented 8 years ago

I don't find any solution for this use case. Do you find something to enable the auto-reconnection ?

genuinefafa commented 8 years ago

It is strange. Have the same issue here (at least with Chrome). Then I do some googleing, check this out.

Apparently the alternative is to add some logic here to throw disconnection event.

Is it right?

davinkevin commented 8 years ago

Handle some logic in the 'error callback' of connection promise seems strange for me.

A promise is evaluated only once, so if the promise succeed once, it will never reach the error callback. That's why I've searched in the StompClient disconnect callback, but without any success.

The solution should be to remove promise wrapping around stomClient connection, because both success an error should be called...

Keep working on it.

davinkevin commented 8 years ago

I've implemented it very simply (example here : https://github.com/davinkevin/spring-websocket-backend)

If the error callback of the stomp client is called, I reconnect by using all the parameters gave to the service before (I store it now...)

This behavior is not triggered if disconnection made manually.

Say me if it's alright for your need

davinkevin commented 8 years ago

Add in 0.6.1 a timeOut parameter to configure the waiting time between two try of reconnection. Without it, the system reach StackOverflow...

By default, the system is waiting 5 Seconds between each try, this value could be changed by the provider.

genuinefafa commented 8 years ago

Excellent! :+1: