PatrickJS/angular-websocket

How do I auto reconnect?

Fossil01 opened this issue · 3 comments

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?

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

Thanks!!

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