davinkevin / AngularStompDK

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

Is there a callback for reconnect ? #41

Closed sakthig closed 8 years ago

sakthig commented 8 years ago

I am using ngStompProvider to start the websocket connection, but it is not returning any promise. Is there a callback or a promise which can be used in the event on websocket reconnection.

davinkevin commented 8 years ago

Right now, the connection is launched automatically after the service is created (in constructor). This could be a problem for what you are asking. But, you can access the promise used during the connection process https://github.com/davinkevin/AngularStompDK/blob/master/core/service.js#L39

But, Stomp can fire the connection callback and the disconnect callback, so I don't think this will work well with the reject / resolve on the same promise.

Could you show in this issue what you would like to see in term of API in AngularStompDK to achieve this ? I would like to understand what is your need.

Thanks

sakthig commented 8 years ago

Below are the issues i am facing, not sure if it has to do with AngularStompDK.

  1. First my app connects to the web socket using ngstompProvider .. after this i subscribe to a channel using ngstomp.subscribeTo. Suppose there is re-connection happening, only the web socket connects again.. it is not subscribing to the channel during re-connection. Hence i was looking for a callback that can i can use to subscribe again. May be there can be an additional 'callback function' input for ngstompProvider which will be invoked whenever connection or reconnection happens.
  2. I tried to use that promiseResult.. but looks like during re-connection that promise is being overwritten. Pls Check this code Since it is overwritten i guess the old promise will not work and is not helping me to reconnect to the channel.
davinkevin commented 8 years ago

Which version do you use ?

Normaly, all the subscription shoud be 'replayed' after 5 seconds by defaut. Discussion about this in the issue #13 and present in https://github.com/davinkevin/AngularStompDK/blob/master/core/service.js#L34

Maybe you encounter an issue with the auto-reconnect method...

davinkevin commented 8 years ago

You can see an example of app doing reconnection automatically, because connection fail or because server cut the connection.

https://github.com/davinkevin/spring-websocket-backend

image

If you click "Loose connection from server", the system will automatically relaunch all subscription registered in AngularStompDK.

sakthig commented 8 years ago

Thanks for the replies. This issue does not seem to be present in latest version.

Sorry for not checking the latest version in first place and troubling you :smile:

Thanks

davinkevin commented 8 years ago

😄