Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:mcollina/mosca
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed May 30, 2016
2 parents b68767e + 518bfea commit c55c444
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function Server(opts, callback) {
}
], function(err, results){
if(err) {
callback(err)
callback(err);
}
});

Expand Down Expand Up @@ -308,6 +308,18 @@ Server.prototype.toString = function() {
return 'mosca.Server';
};

/**
* Subscribes to a topic on the MQTT broker.
*
* @api public
* @param {String} topic The MQTT topic
* @param {Function} callback The callback with (topic, payload) arguments
* @param {Function} done The subscription result
*/
Server.prototype.subscribe = function subscribe(topic, callback, done) {
this.ascoltatore.subscribe(topic, callback, done);
};

/**
* Publishes a packet on the MQTT broker.
*
Expand Down
20 changes: 20 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ describe("mosca.Server", function() {
});
});

it("should support subscribing via server.subscribe", function(done) {
var that = this;
buildAndConnect(done, this.instance, buildOpts(), function(client) {

that.instance.subscribe('a/+', function(topic, payload){
expect(topic).to.be.equal('a/b');
expect(payload.toString()).to.be.equal('some data');
client.disconnect();
}, function(){
var messageId = Math.floor(65535 * Math.random());
client.publish({
topic: "a/b",
payload: "some data",
messageId: messageId,
qos: 1
});
});
});
});

describe("timers", function() {
var clock;

Expand Down

0 comments on commit c55c444

Please sign in to comment.