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

add message to publish callback #527

Merged
merged 3 commits into from
Jul 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Server.prototype.publish = function publish(packet, client, callback) {
logger.debug({ packet: newPacket }, "published packet");
}
that.emit("published", newPacket, client);
callback();
callback(undefined, newPacket);
});
}
);
Expand Down
18 changes: 18 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@ describe("mosca.Server", function() {
});
});

it("should provide packet in publish callback", function(done) {
var messageId;

this.instance.once("published", function(packet) {
messageId = packet.messageId;
});

this.instance.publish({
topic: "hello",
payload: "some data"
}, function(error, packet) {
expect(packet.topic).to.be.equal("hello");
expect(packet.payload.toString().toString()).to.be.equal("some data");
expect(packet.messageId.toString()).to.equal(messageId);
done();
});
});

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

Expand Down