From 7e85eb297d9ea8ad46af812e53cf737b93812b14 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 10 May 2014 23:33:02 +0100 Subject: [PATCH] Make status display toggleable and add to MQTT nodes --- nodes/core/io/10-mqtt.js | 19 ++++++++++++++++++- public/index.html | 2 ++ public/red/main.js | 15 +++++++++++++-- public/red/ui/view.js | 18 ++++++++++++++---- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/nodes/core/io/10-mqtt.js b/nodes/core/io/10-mqtt.js index fb37d448f..3b9c9befa 100644 --- a/nodes/core/io/10-mqtt.js +++ b/nodes/core/io/10-mqtt.js @@ -77,7 +77,9 @@ module.exports = function(RED) { this.topic = n.topic; this.broker = n.broker; this.brokerConfig = RED.nodes.getNode(this.broker); + var node = this; if (this.brokerConfig) { + this.status({fill:"red",shape:"ring",text:"disconnected"},true); this.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port,this.brokerConfig.clientid,this.brokerConfig.username,this.brokerConfig.password); var node = this; this.client.subscribe(this.topic,2,function(topic,payload,qos,retain) { @@ -87,6 +89,12 @@ module.exports = function(RED) { } node.send(msg); }); + this.client.on("connectionlost",function() { + node.status({fill:"red",shape:"ring",text:"disconnected"},true); + }); + this.client.on("connect",function() { + node.status({fill:"green",shape:"dot",text:"connected"},true); + }); this.client.connect(); } else { this.error("missing broker configuration"); @@ -109,8 +117,10 @@ module.exports = function(RED) { this.broker = n.broker; this.brokerConfig = RED.nodes.getNode(this.broker); - + var node = this; + if (this.brokerConfig) { + this.status({fill:"red",shape:"ring",text:"disconnected"},true); this.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port,this.brokerConfig.clientid,this.brokerConfig.username,this.brokerConfig.password); this.on("input",function(msg) { if (msg != null) { @@ -120,6 +130,13 @@ module.exports = function(RED) { this.client.publish(msg); } }); + this.client.on("connectionlost",function() { + node.status({fill:"red",shape:"ring",text:"disconnected"},true); + }); + this.client.on("connect",function() { + node.status({fill:"green",shape:"dot",text:"connected"},true); + }); + this.client.connect(); } else { this.error("missing broker configuration"); diff --git a/public/index.html b/public/index.html index d79ead7bd..8173b6fd1 100644 --- a/public/index.html +++ b/public/index.html @@ -34,6 +34,8 @@