Corrections to node-red-node-discovery (#380)

1- Ensure we stop advertising before creating a new advertiser if the object exists
2- Allow bool false to stop advertising
3- Documentation correction (state is in msg.payload, not in msg)
This commit is contained in:
Nathanaël Lécaudé 2017-11-23 15:53:44 -05:00 committed by Dave Conway-Jones
parent ab99139ce3
commit c153024c91
4 changed files with 8 additions and 7 deletions

View File

@ -32,7 +32,7 @@ service discovery capability.
`msg.payload` contains the service object on both arrival and leaving. `msg.payload` contains the service object on both arrival and leaving.
`msg.state` contains boolean true or false depending if the service has arrived (true) or gone away (false).. `msg.payload.state` contains boolean true or false depending if the service has arrived (true) or gone away (false)..
Within the `msg.payload` object the most interesting things are: Within the `msg.payload` object the most interesting things are:
@ -48,7 +48,7 @@ For a full list of official service types see [this list](http://www.dns-sd.org/
Provides a Bonjour / Avahi / Zeroconf announcement node. Provides a Bonjour / Avahi / Zeroconf announcement node.
If `msg.payload` is 0 - the announcement is stopped. Any other value starts the announcement process. If `msg.payload` is `false` - the announcement is stopped. Any other value starts the announcement process.
The announcement can be customised by the msg if not configured in the edit panel. The announcement can be customised by the msg if not configured in the edit panel.

View File

@ -18,7 +18,7 @@
<script type="text/x-red" data-help-name="discovery"> <script type="text/x-red" data-help-name="discovery">
<p>Provides a Bonjour / Avahi / Zeroconf discovery node.</p> <p>Provides a Bonjour / Avahi / Zeroconf discovery node.</p>
<p><code>msg.payload</code> contains the service object on both arrival and leaving.</p> <p><code>msg.payload</code> contains the service object on both arrival and leaving.</p>
<p><code>msg.state</code> contains boolean <i>true</i> or <i>false</i> depending <p><code>msg.payload.state</code> contains boolean <i>true</i> or <i>false</i> depending
if the service has arrived (<i>true</i>) or gone away (<i>false</i>).</p> if the service has arrived (<i>true</i>) or gone away (<i>false</i>).</p>
<p>Within the msg.payload object the most interesting things are: <p>Within the msg.payload object the most interesting things are:
<ul><li>msg.payload.name</li> <ul><li>msg.payload.name</li>
@ -73,7 +73,7 @@
<script type="text/x-red" data-help-name="announce"> <script type="text/x-red" data-help-name="announce">
<p>Provides a Bonjour / Avahi / Zeroconf announcement node.</p> <p>Provides a Bonjour / Avahi / Zeroconf announcement node.</p>
<p>If <code>msg.payload</code> is 0 - the announcement is stopped. Any other value starts the announcement process.</p> <p>If <code>msg.payload</code> is <code>false</code> - the announcement is stopped. Any other value starts the announcement process.</p>
<p>The announcement can be customised by the msg if not configured in the edit panel.</p> <p>The announcement can be customised by the msg if not configured in the edit panel.</p>
<p><ul> <p><ul>
<li><code>msg.service</code> - For a full list of official service types see <i><a href="http://www.dns-sd.org/ServiceTypes.html" target="_new">this list</a></i>.</li> <li><code>msg.service</code> - For a full list of official service types see <i><a href="http://www.dns-sd.org/ServiceTypes.html" target="_new">this list</a></i>.</li>

View File

@ -65,8 +65,8 @@ module.exports = function(RED) {
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg) {
if ((msg.payload === 0) || (msg.payload === "0")) { if (msg.payload == false) {
node.ad.stop(); if (node.ad) { node.ad.stop(); }
} }
else { else {
var service = node.service || msg.service; var service = node.service || msg.service;
@ -76,6 +76,7 @@ module.exports = function(RED) {
options.name = (node.name || msg.name).replace(/\%h/g, os.hostname()); options.name = (node.name || msg.name).replace(/\%h/g, os.hostname());
} }
if (node.txt || msg.txtRecord) { options.txtRecord = node.txt || msg.txtRecord } if (node.txt || msg.txtRecord) { options.txtRecord = node.txt || msg.txtRecord }
if (node.ad) { node.ad.stop(); }
node.ad = mdns.createAdvertisement(service, port, options); node.ad = mdns.createAdvertisement(service, port, options);
node.ad.start(); node.ad.start();
} }

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-discovery", "name" : "node-red-node-discovery",
"version" : "0.0.18", "version" : "0.0.19",
"description" : "A Node-RED node that uses Bonjour / Avahi to discover nearby services.", "description" : "A Node-RED node that uses Bonjour / Avahi to discover nearby services.",
"dependencies" : { "dependencies" : {
"mdns" : "~2.3.3" "mdns" : "~2.3.3"