Skip to content

Commit

Permalink
unsubscribe should not remove other topic's listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
gyeates committed Oct 1, 2014
1 parent 19558dd commit c896c17
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/core/Topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ function Topic(options) {
this.emit('warning', this.throttle_rate + ' is not allowed. Set to 0');
this.throttle_rate = 0;
}
}

var that = this;
this._messageCallback = function(data) {
that.emit('message', new Message(data));
};
}
Topic.prototype.__proto__ = EventEmitter2.prototype;

/**
Expand All @@ -55,14 +59,10 @@ Topic.prototype.__proto__ = EventEmitter2.prototype;
* * message - the published message
*/
Topic.prototype.subscribe = function(callback) {
var that = this;
this.on('message', callback);

if (this.subscribeId) { return; }
this.ros.on(this.name, function(data) {
var message = new Message(data);
that.emit('message', message);
});
this.ros.on(this.name, this._messageCallback);
this.subscribeId = 'subscribe:' + this.name + ':' + (++this.ros.idCounter);
this.ros.callOnConnection({
op: 'subscribe',
Expand All @@ -80,7 +80,7 @@ Topic.prototype.subscribe = function(callback) {
*/
Topic.prototype.unsubscribe = function() {
if (!this.subscribeId) { return; }
this.ros.removeAllListeners([this.name]);
this.ros.off(this.name, this._messageCallback);
this.ros.callOnConnection({
op: 'unsubscribe',
id: this.subscribeId,
Expand Down

0 comments on commit c896c17

Please sign in to comment.