AngularStompDK icon indicating copy to clipboard operation
AngularStompDK copied to clipboard

Stop reconnection and throw error

Open ioana-m opened this issue 8 years ago • 3 comments

Hi,

At the moment if the websocket cannot connect it retries indefinite. I would like to make it stop after a number of retries and throw an error so that in my project I can show a specific page. I tried using ngstomp.connectionState.then(function () {}, function () {}); after calling the ngstomp subscribeTo but it works only for a new connection not for the current lost one, and it still tries to reconnect even if I call disconnect. So it tries to make new connections. I also tried setting the timeout -1 so that is does not reconnect at all and tried the reconnection from my project by using ngstomp.connect() but it did not work, the error function of the connectionState promise did not get called.

Could you please give me some ideas?

Thank you.

ioana-m avatar Apr 21 '17 14:04 ioana-m

Hi,

I will try to find a solution to your problem, but can you provide me some code example to be sure I understand what you've tried.

If you need to have an env with a WS backend, I use https://github.com/davinkevin/spring-websocket-backend for my experimentation... witch is very simple.

I mainly understand you want to limit the number of retry if the connection stop. I will try to do it, but if you want, you can do a PR ;)

davinkevin avatar Apr 29 '17 10:04 davinkevin

Hi,

Here is how I changed locally the library, by adding settings.reconnectWebSocketOnError and settings.errorCallback:

in the $connect method:

let errorCallback = () => { 
this.deferred.reject();
    this.$initConnectionState();
    this.settings.timeOut >= 0 && this.settings.reconnectWebSocketOnError && this.$timeout(() => {
        this.$connect();
    this.$reconnectAll();
}, this.settings.timeOut);
    if (!this.settings.reconnectWebSocketOnError && this.settings.errorCallback) {
        this.settings.errorCallback.call();
    }
};

in the send method before this.connectionState.then I added:

if (!this.stompClient || !this.stompClient.connected) { 
if (this.settings.errorCallback) {
		this.settings.errorCallback.call();
	}
}

ioana-m avatar May 02 '17 08:05 ioana-m

I would like to treat your request, but I don't have enough time right now, could you propose a PR for analysis ?

davinkevin avatar May 11 '17 17:05 davinkevin