Skip to content

How do I auto reconnect?Β #100

Open
Open

Description

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?

Activity

  1. lmmfranco commented on Apr 11, 2017

    @lmmfranco

    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 });
  2. TomaszWaszczyk commented on Mar 1, 2018

    @TomaszWaszczyk

    Thanks!!

  3. VAluvila commented on Jan 24, 2019

    @VAluvila

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions