diff --git a/lib/server.js b/lib/server.js index 96afbbc..5b80e46 100755 --- a/lib/server.js +++ b/lib/server.js @@ -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); }); } ); diff --git a/test/server.js b/test/server.js index 365a458..d8b177c 100644 --- a/test/server.js +++ b/test/server.js @@ -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;