From d553a3bf0d51323dd1a54c3826951748a9947068 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 9 Oct 2018 12:38:23 +0300 Subject: [PATCH] fix properties mqtt 5 in subscribe --- README.md | 2 +- lib/client.js | 4 ++++ test/client.js | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2032e33f..4b4dd60d4 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ Subscribe to a topic or topics * `topic` is a `String` topic to subscribe to or an `Array` of topics to subscribe to. It can also be an object, it has as object - keys the topic name and as value the QoS, like `{'test1': 0, 'test2': 1}`. + keys the topic name and as value the QoS, like `{'test1': {qos: 0}, 'test2': {qos: 1}}`. MQTT `topic` wildcard characters are supported (`+` - for single level and `#` - for multi level) * `options` is the options to subscribe with, including: * `qos` qos subscription level, default 0 diff --git a/lib/client.js b/lib/client.js index c4b8dd475..d42473a3a 100644 --- a/lib/client.js +++ b/lib/client.js @@ -552,6 +552,10 @@ MqttClient.prototype.subscribe = function () { messageId: this._nextId() } + if (opts.properties) { + packet.properties = opts.properties + } + if (!subs.length) { callback(null, []) return diff --git a/test/client.js b/test/client.js index ebbc7a437..187c56c2c 100644 --- a/test/client.js +++ b/test/client.js @@ -737,6 +737,33 @@ describe('MqttClient', function () { client.pubcomp(packet) }) }) + it('Subscribe properties', function (done) { + this.timeout(15000) + var opts = { + host: 'localhost', + port: port + 119, + protocolVersion: 5 + } + var subOptions = { properties: { subscriptionIdentifier: 1234 } } + var server119 = new Server(function (client) { + client.on('connect', function (packet) { + client.connack({ + reasonCode: 0 + }) + }) + client.on('subscribe', function (packet) { + should(packet.properties.subscriptionIdentifier).be.equal(subOptions.properties.subscriptionIdentifier) + server119.close() + done() + }) + }).listen(port + 119) + + var client = mqtt.connect(opts) + client.on('connect', function () { + client.subscribe('a/b', subOptions) + }) + }) + it('puback handling errors check', function (done) { this.timeout(15000) serverErr.listen(port + 117)