From ae9b342d482d93c42cab8dfe0f8c87d8281fc1c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20L=C3=A9caud=C3=A9?= Date: Tue, 28 Nov 2017 10:49:51 -0500 Subject: [PATCH] node-red-node-discovery: Add stop method and show status --- io/mdns/mdns.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/io/mdns/mdns.js b/io/mdns/mdns.js index b9853878..b74a064f 100644 --- a/io/mdns/mdns.js +++ b/io/mdns/mdns.js @@ -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); }