From f2d19d5b5d67ee2e7cd7979eb051f552f2a5bd6c Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 10 Oct 2014 15:05:46 +0100 Subject: [PATCH] Vary api call based on share --- mqlight/mqlight.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mqlight/mqlight.js b/mqlight/mqlight.js index b28f225..c091309 100644 --- a/mqlight/mqlight.js +++ b/mqlight/mqlight.js @@ -73,14 +73,19 @@ module.exports = function(RED) { node.send(msg); }); node.log("Subscribing to "+node.topic+(node.share?+" ["+node.share+"]":"")); - node.log("Node share: ["+node.share+"]"); - recvClient.subscribe(node.topic, node.share, function(err) { + var subscribeCallback = function(err) { if (err) { node.error("Failed to subscribe: " + err); } else { node.log("Subscribed to "+node.topic+(node.share?+" ["+node.share+"]":"")); } - }); + }; + + if (node.share) { + recvClient.subscribe(node.topic, node.share,subscribeCallback); + } else { + recvClient.subscribe(node.topic,subscribeCallback); + } } }); node.on("close", function (done) {