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

How do I auto reconnect? #100

Open
ghost opened this issue Sep 20, 2016 · 3 comments
Open

How do I auto reconnect? #100

ghost opened this issue Sep 20, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Sep 20, 2016

I came from ng-websocket (https://github.com/wilk/ng-websocket) in which you can simply do:

var ws = $websocket.$new('ws://localhost:12345', true);

The true makes it auto-reconnect when there's a failure. How can I create the same in this project?

@lmmfranco
Copy link

lmmfranco commented Apr 11, 2017

It is not documented, but reading the source code we can see this bit:

    this.scope                       = options && options.scope                      || $rootScope;
    this.rootScopeFailover           = options && options.rootScopeFailover          && true;
    this.useApplyAsync               = options && options.useApplyAsync              || false;
    this.initialTimeout              = options && options.initialTimeout             || 500; // 500ms
    this.maxTimeout                  = options && options.maxTimeout                 || 5 * 60 * 1000; // 5 minutes
    this.reconnectIfNotNormalClose   = options && options.reconnectIfNotNormalClose  || false;
    this.binaryType                  = options && options.binaryType                 || 'blob';

So yeah, just call it like this:

$websocket("ws://localhost:8337", null, { reconnectIfNotNormalClose: true });

@TomaszWaszczyk
Copy link

Thanks!!

@VAluvila
Copy link

It is not documented, but reading the source code we can see this bit:

    this.scope                       = options && options.scope                      || $rootScope;
    this.rootScopeFailover           = options && options.rootScopeFailover          && true;
    this.useApplyAsync               = options && options.useApplyAsync              || false;
    this.initialTimeout              = options && options.initialTimeout             || 500; // 500ms
    this.maxTimeout                  = options && options.maxTimeout                 || 5 * 60 * 1000; // 5 minutes
    this.reconnectIfNotNormalClose   = options && options.reconnectIfNotNormalClose  || false;
    this.binaryType                  = options && options.binaryType                 || 'blob';

So yeah, just call it like this:

$websocket("ws://localhost:8337", null, { reconnectIfNotNormalClose: true });

Great! You saved my day dear ;-)

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

3 participants