From 22888cd8bd596123de39743e39c04c96c66a643c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20L=C3=A9caud=C3=A9?= Date: Thu, 30 Nov 2017 18:34:49 -0500 Subject: [PATCH] node-red-node-discovery: Add status information (#383) --- io/mdns/mdns.js | 14 +++++++++++--- io/mdns/package.json | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/io/mdns/mdns.js b/io/mdns/mdns.js index b9853878..c448cb66 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"}); } }); @@ -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: "ring"}); + } + } + } RED.nodes.registerType("announce", MdnsAnnNode); } diff --git a/io/mdns/package.json b/io/mdns/package.json index cad9775a..0aba2e3e 100644 --- a/io/mdns/package.json +++ b/io/mdns/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-discovery", - "version" : "0.0.19", + "version" : "0.0.20", "description" : "A Node-RED node that uses Bonjour / Avahi to discover nearby services.", "dependencies" : { "mdns" : "~2.3.3"