angular-sails icon indicating copy to clipboard operation
angular-sails copied to clipboard

event not fired on reconnect

Open dandanknight opened this issue 6 years ago • 0 comments

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.

dandanknight avatar Mar 21 '18 08:03 dandanknight