Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #174 from eiabea/master
Browse files Browse the repository at this point in the history
Added retain option to mqtt
  • Loading branch information
mcollina authored Apr 4, 2017
2 parents 4a91a36 + 5bf923e commit f64dfb8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/mqtt_ascoltatore.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ MQTTAscoltatore.prototype.publish = function publish(topic, message, options, do
this._raiseIfClosed();

this._client.publish(this._pubTopic(topic), message, {
qos: (options && (options.qos !== undefined)) ? options.qos : 1
qos: (options && (options.qos !== undefined)) ? options.qos : 1,
retain: (options && (options.retain !== undefined)) ? options.retain : false
}, function() {
debug("new message published to " + topic);
wrap(done)();
Expand Down
2 changes: 1 addition & 1 deletion lib/zeromq_ascoltatore.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ ZeromqAscoltatore.prototype._startControl = function() {
}, 250);

that._control_conn.on("message", function(data) {
var dest = String(data)
var dest = String(data);
debug("received connect response from " + dest);
if (that._sub_conns.findIndex(function (conn) {
return conn.port === dest;
Expand Down
3 changes: 2 additions & 1 deletion test/mqtt_ascoltatore_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ describeAscoltatore("MQTT", function() {
var that = this;
mqttServer.once('published', function(packet) {
expect(packet.qos).to.eql(0);
expect(packet.retain).to.eql(true);
done();
});
that.instance.publish("hello/123", "42", { qos: 0 });
that.instance.publish("hello/123", "42", { qos: 0, retain: true });
});

});
Expand Down
8 changes: 4 additions & 4 deletions test/zeromq_ascoltatore_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ describeAscoltatore("zeromq", function() {
if (--count === 0) {
instance._control_conn.removeListener("message", donner);

var subs = {}
var subs = {};
instance._sub_conns.forEach(function(c) {
subs[c.port] = true;
});
expect(instance._sub_conns.length).to.equal(3);
expect(Object.keys(subs).length).to.equal(3);

subs = {}
subs = {};
other._sub_conns.forEach(function(c) {
subs[c.port] = true;
});
expect(other._sub_conns.length).to.equal(3);
expect(Object.keys(subs).length).to.equal(3);

subs = {}
subs = {};
other2._sub_conns.forEach(function(c) {
subs[c.port] = true;
});
Expand Down Expand Up @@ -135,7 +135,7 @@ describeAscoltatore("zeromq", function() {
instance.connect(other._opts.controlPort);
instance.connect(other2._opts.controlPort);
instance._control_conn.on("message", donner);
cb()
cb();
}
]);
});
Expand Down

0 comments on commit f64dfb8

Please sign in to comment.