Skip to content

Commit 93f4482

Browse files
bretambroserobertsLandoBret Ambrose
authoredAug 7, 2024··
feat: add suback packet to subscribe callback (#1923)
* 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>
1 parent 8bcf304 commit 93f4482

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed
 

‎src/lib/client.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ export type OnDisconnectCallback = (packet: IDisconnectPacket) => void
383383
export type ClientSubscribeCallback = (
384384
err: Error | null,
385385
granted?: ISubscriptionGrant[],
386+
packet?: ISubackPacket,
386387
) => void
387388
export type OnMessageCallback = (
388389
topic: string,
@@ -1248,7 +1249,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
12481249
}
12491250
}
12501251

1251-
callback(err, subs)
1252+
callback(err, subs, packet2)
12521253
},
12531254
}
12541255
this.log('subscribe :: call _sendPacket')

‎test/abstract_client.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@ export default function abstractTest(server, config, ports) {
25012501
const topic = 'test'
25022502

25032503
client.once('connect', () => {
2504-
client.subscribe(topic, { qos: 2 }, (err, granted) => {
2504+
client.subscribe(topic, { qos: 2 }, (err, granted, suback) => {
25052505
if (err) {
25062506
done(err)
25072507
} else {
@@ -2517,6 +2517,8 @@ export default function abstractTest(server, config, ports) {
25172517
expectedResult.properties = undefined
25182518
}
25192519
assert.include(granted[0], expectedResult)
2520+
assert.exists(suback, 'suback not given')
2521+
assert.deepStrictEqual(suback.granted, [2])
25202522
client.end((err2) => done(err2))
25212523
}
25222524
})

0 commit comments

Comments
 (0)
Please sign in to comment.