Skip to content

Commit c3f4455

Browse files
committed
fix remove events, add more chaining
1 parent 5f0611b commit c3f4455

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

angular-websocket.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ module.provider('WebSocket', function() {
4141

4242
var wrappedWebSocket = {
4343
states: ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'],
44-
on: function(event) {
45-
return addListener(event);
44+
on: function(event, callback) {
45+
return addListener(event)(callback);
4646
},
4747
onmessage: addListener('message'),
4848
onclose: addListener('close'),
@@ -71,7 +71,8 @@ module.provider('WebSocket', function() {
7171

7272
removeListener: function(args) {
7373
args = Array.prototype.slice.call(arguments);
74-
return ws.removeListener.apply(ws, args);
74+
ws.removeEventListener.apply(ws, args);
75+
return this;
7576
},
7677

7778
// when ws.on('someEvent', fn (data) { ... }),
@@ -87,15 +88,17 @@ module.provider('WebSocket', function() {
8788
}
8889

8990
events.forEach(function(eventName) {
90-
var prefixed = _prefix + eventName;
91-
var forwardEvent = asyncAngularify(function (data) {
92-
scope.$broadcast(prefixed, data);
91+
var prefixedEvent = _prefix + eventName;
92+
var forwardEvent = asyncAngularify(function(data) {
93+
scope.$broadcast(prefixedEvent, data);
9394
});
9495
scope.$on('$destroy', function () {
95-
ws.removeListener(eventName, forwardEvent);
96+
ws.removeEventListener(eventName, forwardEvent);
9697
});
9798
ws.onmessage(eventName, forwardEvent);
9899
});
100+
return this;
101+
99102
}
100103
};
101104

0 commit comments

Comments
 (0)