node-red-node-discovery: Add stop method and show status

This commit is contained in:
Nathanaël Lécaudé 2017-11-28 10:49:51 -05:00
parent b49f1d17ac
commit ae9b342d48

View File

@ -66,7 +66,7 @@ module.exports = function(RED) {
this.on("input", function(msg) {
if (msg.payload == false) {
if (node.ad) { node.ad.stop(); }
this.stop();
}
else {
var service = node.service || msg.service;
@ -76,9 +76,10 @@ module.exports = function(RED) {
options.name = (node.name || msg.name).replace(/\%h/g, os.hostname());
}
if (node.txt || msg.txtRecord) { options.txtRecord = node.txt || msg.txtRecord }
if (node.ad) { node.ad.stop(); }
this.stop();
node.ad = mdns.createAdvertisement(service, port, options);
node.ad.start();
node.status({fill: "green", shape: "dot", text: "started"});
}
});
@ -87,9 +88,16 @@ module.exports = function(RED) {
});
this.on("close", function() {
if (node.ad) { node.ad.stop(); }
this.stop();
});
this.stop = function() {
if (node.ad) {
node.ad.stop();
node.status({fill: "red", shape: "dot", text: "stopped"});
}
}
}
RED.nodes.registerType("announce", MdnsAnnNode);
}