Skip to content

Commit

Permalink
Merge pull request #35 from pkinney/master
Browse files Browse the repository at this point in the history
Add client to published callback for QoS 2
  • Loading branch information
mcollina committed Feb 26, 2016
2 parents 117a07d + cd4211b commit 1741b51
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/handlers/pubrel.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function pubrelGet (arg, done) {
}

function pubrelPublish (arg, done) {
this.client.broker.publish(arg.packet, done)
this.client.broker.publish(arg.packet, this.client, done)
}

function pubrelWrite (arg, done) {
Expand Down
30 changes: 30 additions & 0 deletions test/qos2.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,36 @@ test('subscribe QoS 2', function (t) {
})
})

test('call published method with client with QoS 2', function (t) {
t.plan(10)

var broker = aedes()
var publisher = connect(setup(broker))
var subscriber = connect(setup(broker))
var toPublish = {
cmd: 'publish',
topic: 'hello',
payload: new Buffer('world'),
qos: 2,
messageId: 42,
dup: false,
length: 14,
retain: false
}

broker.published = function (packet, client, cb) {
t.ok(client, 'client must be passed to published method')

cb()
}

subscribe(t, subscriber, 'hello', 2, function () {
publish(t, publisher, toPublish)

receive(t, subscriber, toPublish, t.pass.bind(t))
})
})

test('subscribe QoS 0, but publish QoS 2', function (t) {
var broker = aedes()
var publisher = connect(setup(broker))
Expand Down

0 comments on commit 1741b51

Please sign in to comment.