Skip to content

Commit

Permalink
Merge pull request #881 from mqttjs/mqtt-5-subscribe-fix
Browse files Browse the repository at this point in the history
fix properties mqtt 5 in subscribe
  • Loading branch information
mcollina committed Oct 11, 2018
2 parents f94cb75 + d553a3b commit 983c71d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/client.js
Expand Up @@ -552,6 +552,10 @@ MqttClient.prototype.subscribe = function () {
messageId: this._nextId()
}

if (opts.properties) {
packet.properties = opts.properties
}

if (!subs.length) {
callback(null, [])
return
Expand Down
27 changes: 27 additions & 0 deletions test/client.js
Expand Up @@ -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)
Expand Down

0 comments on commit 983c71d

Please sign in to comment.