Skip to content

event not fired on reconnect #100

@dandanknight

Description

@dandanknight

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.

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