Skip to content
This repository was archived by the owner on Aug 13, 2021. It is now read-only.
This repository was archived by the owner on Aug 13, 2021. It is now read-only.

Adjusment for unsubscribing #70

@synergycns

Description

@synergycns

Just FYI, I've seen some issues here and on various other sites about removing event subscriptions with ngSails ($sailsSocket). I'm pretty sure that this has to do with Socket.IO changing some of their method names. For me, at least, making the simple change below gets this functionality working for me using socket.io-client 1.3.7, sails.io.js 0.11.5, and angularSails 0.12.1.

The following block (starting at line 1278 in ngsails.io.js):

    //TODO normalize http paths to event names
    connection.subscribe = function(event,handler){
        var callback = tick($window.io.socket,handler);
        $window.io.socket.on(event,callback);
        return angular.bind($window.io.socket, $window.io.socket.removeListener, event, callback);
    }

Should be updated to:

    //TODO normalize http paths to event names
    connection.subscribe = function(event,handler){
        var callback = tick($window.io.socket,handler);
        $window.io.socket.on(event,callback);
        return angular.bind($window.io.socket, $window.io.socket.off, event, callback);
    }

Then, unsubscribing will work correctly, i.e.:

// Subscribe
var fnUnsubscribe = $sailsSocket.subscribe('event', function(oEvent) { /* Function body */ });

// Unsubscribe
fnUnsubscribe();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions