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

Stop reconnection and throw error #52

Open
ioana-m opened this issue Apr 21, 2017 · 3 comments
Open

Stop reconnection and throw error #52

ioana-m opened this issue Apr 21, 2017 · 3 comments

Comments

@ioana-m
Copy link

ioana-m commented Apr 21, 2017

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.

@davinkevin
Copy link
Owner

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 ;)

@ioana-m
Copy link
Author

ioana-m commented May 2, 2017

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();
	}
}

@davinkevin
Copy link
Owner

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

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