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

event not fired on reconnect #100

Open
dandanknight opened this issue Mar 21, 2018 · 0 comments
Open

event not fired on reconnect #100

dandanknight opened this issue Mar 21, 2018 · 0 comments

Comments

@dandanknight
Copy link

Hi, I am subscribing to the 'connect' and 'disconnect' events in my app controller, which stays in scope always. In the event of a socket disconnect, I'm displaying a 'reconnect' button (or I may do it on a timer), which reconnects successfully using $sails.connect(). Thing is, the 'connect' or 'reconnect' events are not fired this time. Any ideas why? Or how I can improve on this? I've tried accessing the _raw events also, but seems the same.

He's some simplified code...

    vm.sailsState = 'disconnected';

    vm.reconnect = function(){
      $sails.connect();
    };

    $sails.on('connect', function (a, b) {
      $log.log("Sails socket connected", a, b);
      vm.sailsState = 'connected';
      // This fires on initial connect, then never again
    });

    $sails.on('reconnect', function (a, b) {
      $log.log("Sails socket reconnected", a, b);
      vm.sailsState = 'connected';
      // This never fires, not sure it should though
    });

    $sails.on('disconnect', function (a, b) {
      $log.warn("Sails socket disconnected", $sails);
      vm.sailsState = 'disconnected';
      // This fires once first disconnect, then never again
    });

Also, am I right in thinking that auto-reconnect is forcibly disabled ? I guess so it doesn't keep trying to connect after scope is destroyed.

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

1 participant