1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Slight tidy to MQTT - move to fa icons - use built in close method.

This commit is contained in:
Dave C-J 2014-07-21 20:29:10 +01:00
parent d1300c0632
commit 0b308deb79
2 changed files with 25 additions and 33 deletions

View File

@ -1,5 +1,5 @@
<!-- <!--
Copyright 2013 IBM Corp. Copyright 2013,2014 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -16,15 +16,15 @@
<script type="text/x-red" data-template-name="mqtt in"> <script type="text/x-red" data-template-name="mqtt in">
<div class="form-row"> <div class="form-row">
<label for="node-input-broker"><i class="icon-tag"></i> Broker</label> <label for="node-input-broker"><i class="fa fa-globe"></i> Broker</label>
<input type="text" id="node-input-broker"> <input type="text" id="node-input-broker">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label> <label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Topic"> <input type="text" id="node-input-topic" placeholder="Topic">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name"> <input type="text" id="node-input-name" placeholder="Name">
</div> </div>
</script> </script>
@ -58,15 +58,15 @@
<script type="text/x-red" data-template-name="mqtt out"> <script type="text/x-red" data-template-name="mqtt out">
<div class="form-row"> <div class="form-row">
<label for="node-input-broker"><i class="icon-tag"></i> Broker</label> <label for="node-input-broker"><i class="fa fa-globe"></i> Broker</label>
<input type="text" id="node-input-broker"> <input type="text" id="node-input-broker">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label> <label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Topic"> <input type="text" id="node-input-topic" placeholder="Topic">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name"> <input type="text" id="node-input-name" placeholder="Name">
</div> </div>
</script> </script>
@ -101,21 +101,21 @@
<script type="text/x-red" data-template-name="mqtt-broker"> <script type="text/x-red" data-template-name="mqtt-broker">
<div class="form-row node-input-broker"> <div class="form-row node-input-broker">
<label for="node-config-input-broker"><i class="icon-bookmark"></i> Broker</label> <label for="node-config-input-broker"><i class="fa fa-globe"></i> Broker</label>
<input class="input-append-left" type="text" id="node-config-input-broker" placeholder="localhost" style="width: 40%;" > <input class="input-append-left" type="text" id="node-config-input-broker" placeholder="localhost" style="width: 40%;" >
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label> <label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
<input type="text" id="node-config-input-port" placeholder="Port" style="width:45px"> <input type="text" id="node-config-input-port" placeholder="Port" style="width:45px">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-config-input-clientid"><i class="icon-tag"></i> Client ID</label> <label for="node-config-input-clientid"><i class="fa fa-tag"></i> Client ID</label>
<input type="text" id="node-config-input-clientid" placeholder="Leave blank for auto generated"> <input type="text" id="node-config-input-clientid" placeholder="Leave blank for auto generated">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-config-input-user"><i class="icon-user"></i> Username</label> <label for="node-config-input-user"><i class="fa fa-user"></i> Username</label>
<input type="text" id="node-config-input-user"> <input type="text" id="node-config-input-user">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-config-input-password"><i class="icon-lock"></i> Password</label> <label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
<input type="password" id="node-config-input-password"> <input type="password" id="node-config-input-password">
</div> </div>
</script> </script>

View File

@ -1,5 +1,5 @@
/** /**
* Copyright 2013 IBM Corp. * Copyright 2013,2014 IBM Corp.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,7 +17,6 @@
module.exports = function(RED) { module.exports = function(RED) {
"use strict"; "use strict";
var connectionPool = require("./lib/mqttConnectionPool"); var connectionPool = require("./lib/mqttConnectionPool");
var util = require("util");
function MQTTBrokerNode(n) { function MQTTBrokerNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
@ -62,55 +61,48 @@ module.exports = function(RED) {
} else { } else {
this.error("missing broker configuration"); this.error("missing broker configuration");
} }
this.on('close', function() {
if (this.client) {
this.client.disconnect();
}
});
} }
RED.nodes.registerType("mqtt in",MQTTInNode); RED.nodes.registerType("mqtt in",MQTTInNode);
MQTTInNode.prototype.close = function() {
if (this.client) {
this.client.disconnect();
}
}
function MQTTOutNode(n) { function MQTTOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.topic = n.topic; this.topic = n.topic;
this.broker = n.broker; this.broker = n.broker;
this.brokerConfig = RED.nodes.getNode(this.broker); this.brokerConfig = RED.nodes.getNode(this.broker);
if (this.brokerConfig) { if (this.brokerConfig) {
this.status({fill:"red",shape:"ring",text:"disconnected"},true); 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.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port,this.brokerConfig.clientid,this.brokerConfig.username,this.brokerConfig.password);
var node = this;
this.on("input",function(msg) { this.on("input",function(msg) {
if (msg != null) { if (msg != null) {
if (this.topic) { if (node.topic) {
msg.topic = this.topic; msg.topic = node.topic;
} }
this.client.publish(msg); this.client.publish(msg);
} }
}); });
var node = this;
this.client.on("connectionlost",function() { this.client.on("connectionlost",function() {
node.status({fill:"red",shape:"ring",text:"disconnected"}); node.status({fill:"red",shape:"ring",text:"disconnected"});
}); });
this.client.on("connect",function() { this.client.on("connect",function() {
node.status({fill:"green",shape:"dot",text:"connected"}); node.status({fill:"green",shape:"dot",text:"connected"});
}); });
this.client.connect(); this.client.connect();
} else { } else {
this.error("missing broker configuration"); this.error("missing broker configuration");
} }
this.on('close', function() {
if (this.client) {
this.client.disconnect();
}
});
} }
RED.nodes.registerType("mqtt out",MQTTOutNode); RED.nodes.registerType("mqtt out",MQTTOutNode);
MQTTOutNode.prototype.close = function() {
if (this.client) {
this.client.disconnect();
}
}
} }