PatrickJS / angular-websocket

:arrow_upper_left: The missing Angular WebSocket module for connecting client applications to servers by @AngularClass
https://angularclass.github.io/angular-websocket
MIT License
1.22k stars 195 forks source link

How do I auto reconnect? #100

Open ghost opened 8 years ago

ghost commented 8 years ago

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 commented 7 years ago

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 commented 6 years ago

Thanks!!

VAluvila commented 5 years ago

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