Skip to content

Commit

Permalink
feat: add suback packet to subscribe callback (#1923)
Browse files Browse the repository at this point in the history
* Subscribe callback to also include the suback

* Lint

* Update existing subscribe completion test with a suback check

---------

Co-authored-by: Daniel Lando <daniel.sorridi@gmail.com>
Co-authored-by: Bret Ambrose <bambrose@amazon.com>
  • Loading branch information
3 people committed Aug 7, 2024
1 parent 8bcf304 commit 93f4482
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ export type OnDisconnectCallback = (packet: IDisconnectPacket) => void
export type ClientSubscribeCallback = (
err: Error | null,
granted?: ISubscriptionGrant[],
packet?: ISubackPacket,
) => void
export type OnMessageCallback = (
topic: string,
Expand Down Expand Up @@ -1248,7 +1249,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
}
}

callback(err, subs)
callback(err, subs, packet2)
},
}
this.log('subscribe :: call _sendPacket')
Expand Down
4 changes: 3 additions & 1 deletion test/abstract_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2501,7 +2501,7 @@ export default function abstractTest(server, config, ports) {
const topic = 'test'

client.once('connect', () => {
client.subscribe(topic, { qos: 2 }, (err, granted) => {
client.subscribe(topic, { qos: 2 }, (err, granted, suback) => {
if (err) {
done(err)
} else {
Expand All @@ -2517,6 +2517,8 @@ export default function abstractTest(server, config, ports) {
expectedResult.properties = undefined
}
assert.include(granted[0], expectedResult)
assert.exists(suback, 'suback not given')
assert.deepStrictEqual(suback.granted, [2])
client.end((err2) => done(err2))
}
})
Expand Down

0 comments on commit 93f4482

Please sign in to comment.