mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	Merge 1808b43893 into 805287cad9
				
					
				
			This commit is contained in:
		@@ -128,6 +128,22 @@
 | 
				
			|||||||
        <label for="node-config-input-pass"><i class="fa fa-lock"></i> Password</label>
 | 
					        <label for="node-config-input-pass"><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>
 | 
				
			||||||
 | 
					    <div class="form-row">
 | 
				
			||||||
 | 
					        <label for="node-config-input-protocolversion"><i class="fa fa-tag"></i> Protocol Version</label>
 | 
				
			||||||
 | 
					        <input type="text" id="node-config-input-protocolversion" placeholder="Default is 1.0" />
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					    <div class="form-row">
 | 
				
			||||||
 | 
					        <label for="node-config-input-vhost"><i class="fa fa-tag"></i> vhost</label>
 | 
				
			||||||
 | 
					        <input type="text" id="node-config-input-vhost" placeholder="Default is null" />
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					    <div class="form-row">
 | 
				
			||||||
 | 
					        <label for="node-config-input-reconnectretries"><i class="fa fa-repeat"></i> Reconnect Retries</label>
 | 
				
			||||||
 | 
					        <input type="number" id="node-config-input-reconnectretries" />
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					    <div class="form-row">
 | 
				
			||||||
 | 
					        <label for="node-config-input-reconnectdelay"><i class="fa fa-clock-o"></i> Reconnect Delay</label>
 | 
				
			||||||
 | 
					        <input type="number" id="node-config-input-reconnectdelay" />
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
    <div class="form-row">
 | 
					    <div class="form-row">
 | 
				
			||||||
        <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
 | 
					        <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
 | 
				
			||||||
        <input type="text" id="node-config-input-name" placeholder="Name">
 | 
					        <input type="text" id="node-config-input-name" placeholder="Name">
 | 
				
			||||||
@@ -140,6 +156,10 @@
 | 
				
			|||||||
        defaults: {
 | 
					        defaults: {
 | 
				
			||||||
            server: {required:true},
 | 
					            server: {required:true},
 | 
				
			||||||
            port: {value:61618,required:true,validate:RED.validators.number()},
 | 
					            port: {value:61618,required:true,validate:RED.validators.number()},
 | 
				
			||||||
 | 
					            protocolversion: {value:"1.0",required:true},
 | 
				
			||||||
 | 
					            vhost: {},
 | 
				
			||||||
 | 
					            reconnectretries: {value:0,required:true,validate:RED.validators.number()},
 | 
				
			||||||
 | 
					            reconnectdelay: {value:100,required:true,validate:RED.validators.number()},
 | 
				
			||||||
            name: {}
 | 
					            name: {}
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        credentials: {
 | 
					        credentials: {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,10 @@ module.exports = function(RED) {
 | 
				
			|||||||
        RED.nodes.createNode(this,n);
 | 
					        RED.nodes.createNode(this,n);
 | 
				
			||||||
        this.server = n.server;
 | 
					        this.server = n.server;
 | 
				
			||||||
        this.port = n.port;
 | 
					        this.port = n.port;
 | 
				
			||||||
 | 
					        this.protocolversion = n.protocolversion;
 | 
				
			||||||
 | 
					        this.vhost = n.vhost;
 | 
				
			||||||
 | 
					        this.reconnectretries = n.reconnectretries;
 | 
				
			||||||
 | 
					        this.reconnectdelay = n.reconnectdelay;
 | 
				
			||||||
        this.name = n.name;
 | 
					        this.name = n.name;
 | 
				
			||||||
        this.username = this.credentials.user;
 | 
					        this.username = this.credentials.user;
 | 
				
			||||||
        this.password = this.credentials.password;
 | 
					        this.password = this.credentials.password;
 | 
				
			||||||
@@ -40,59 +44,64 @@ module.exports = function(RED) {
 | 
				
			|||||||
        this.topic = n.topic;
 | 
					        this.topic = n.topic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.serverConfig = RED.nodes.getNode(this.server);
 | 
					        this.serverConfig = RED.nodes.getNode(this.server);
 | 
				
			||||||
        this.host = this.serverConfig.server;
 | 
					        this.stompClientOpts = {
 | 
				
			||||||
        this.port = this.serverConfig.port;
 | 
					            address: this.serverConfig.server,
 | 
				
			||||||
        this.userid = this.serverConfig.username;
 | 
					            port: this.serverConfig.port * 1,
 | 
				
			||||||
        this.password = this.serverConfig.password;
 | 
					            user: this.serverConfig.username,
 | 
				
			||||||
 | 
					            pass: this.serverConfig.password,
 | 
				
			||||||
 | 
					            protocolVersion: this.serverConfig.protocolversion,
 | 
				
			||||||
 | 
					            reconnectOpts: {
 | 
				
			||||||
 | 
					                retries: this.serverConfig.reconnectretries * 1,
 | 
				
			||||||
 | 
					                delay: this.serverConfig.reconnectdelay * 1
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        if (this.serverConfig.vhost) {
 | 
				
			||||||
 | 
					          this.stompClientOpts.vhost = this.serverConfig.vhost;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var node = this;
 | 
					        var node = this;
 | 
				
			||||||
        var msg = {topic:this.topic};
 | 
					        var msg = {topic:this.topic};
 | 
				
			||||||
        var closing = false;
 | 
					        node.client = new StompClient(node.stompClientOpts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        node.client = new StompClient(node.host, node.port, node.userid, node.password, '1.0');
 | 
					        node.client.on("connect", function() {
 | 
				
			||||||
        node.status({fill:"grey",shape:"ring",text:"connecting"});
 | 
					          node.status({fill:"green",shape:"dot",text:"connected"});
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var doConnect = function() {
 | 
					        node.client.on("reconnecting", function() {
 | 
				
			||||||
            node.client.connect(function(sessionId) {
 | 
					            node.status({fill:"red",shape:"ring",text:"reconnecting"});
 | 
				
			||||||
                node.status({fill:"green",shape:"dot",text:"connected"});
 | 
					            node.warn("reconnecting");
 | 
				
			||||||
                node.log('subscribed to: '+node.topic);
 | 
					 | 
				
			||||||
                node.client.subscribe(node.topic, function(body, headers) {
 | 
					 | 
				
			||||||
                    try {
 | 
					 | 
				
			||||||
                        msg.payload = JSON.parse(body);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    catch(e) {
 | 
					 | 
				
			||||||
                        msg.payload = body;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    msg.headers = headers;
 | 
					 | 
				
			||||||
                    msg.topic = node.topic;
 | 
					 | 
				
			||||||
                    node.send(msg);
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            }, function(error) {
 | 
					 | 
				
			||||||
                node.status({fill:"grey",shape:"dot",text:"error"});
 | 
					 | 
				
			||||||
                node.warn(error);
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        node.client.on("disconnect", function() {
 | 
					 | 
				
			||||||
            node.status({fill:"red",shape:"ring",text:"disconnected"});
 | 
					 | 
				
			||||||
            if (!closing) {
 | 
					 | 
				
			||||||
                setTimeout( function () { doConnect(); }, 15000);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        node.client.on("error", function(error) {
 | 
					        node.client.on("error", function(error) {
 | 
				
			||||||
            node.status({fill:"grey",shape:"dot",text:"error"});
 | 
					            node.status({fill:"grey",shape:"dot",text:"error"});
 | 
				
			||||||
            node.log(error);
 | 
					            node.warn(error);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doConnect();
 | 
					        node.status({fill:"grey",shape:"ring",text:"connecting"});
 | 
				
			||||||
 | 
					        node.client.connect(function(sessionId) {
 | 
				
			||||||
 | 
					            node.log('subscribing to: '+node.topic);
 | 
				
			||||||
 | 
					            node.client.subscribe(node.topic, function(body, headers) {
 | 
				
			||||||
 | 
					                try {
 | 
				
			||||||
 | 
					                    msg.payload = JSON.parse(body);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                catch(e) {
 | 
				
			||||||
 | 
					                    msg.payload = body;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                msg.headers = headers;
 | 
				
			||||||
 | 
					                msg.topic = node.topic;
 | 
				
			||||||
 | 
					                node.send(msg);
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }, function(error) {
 | 
				
			||||||
 | 
					            node.status({fill:"grey",shape:"dot",text:"error"});
 | 
				
			||||||
 | 
					            node.warn(error);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        node.on("close", function(done) {
 | 
					        node.on("close", function(done) {
 | 
				
			||||||
            closing = true;
 | 
					 | 
				
			||||||
            if (node.client) {
 | 
					            if (node.client) {
 | 
				
			||||||
                node.client.disconnect(function() { done(); });
 | 
					                // disconnect can accept a callback - but it is not always called.
 | 
				
			||||||
 | 
					                node.client.disconnect();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else { done(); }
 | 
					            done();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    RED.nodes.registerType("stomp in",StompInNode);
 | 
					    RED.nodes.registerType("stomp in",StompInNode);
 | 
				
			||||||
@@ -104,34 +113,43 @@ module.exports = function(RED) {
 | 
				
			|||||||
        this.topic = n.topic;
 | 
					        this.topic = n.topic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.serverConfig = RED.nodes.getNode(this.server);
 | 
					        this.serverConfig = RED.nodes.getNode(this.server);
 | 
				
			||||||
        this.host = this.serverConfig.server;
 | 
					        this.stompClientOpts = {
 | 
				
			||||||
        this.port = this.serverConfig.port;
 | 
					            address: this.serverConfig.server,
 | 
				
			||||||
        this.userid = this.serverConfig.username;
 | 
					            port: this.serverConfig.port * 1,
 | 
				
			||||||
        this.password = this.serverConfig.password;
 | 
					            user: this.serverConfig.username,
 | 
				
			||||||
 | 
					            pass: this.serverConfig.password,
 | 
				
			||||||
 | 
					            protocolVersion: this.serverConfig.protocolversion,
 | 
				
			||||||
 | 
					            reconnectOpts: {
 | 
				
			||||||
 | 
					                retries: this.serverConfig.reconnectretries * 1,
 | 
				
			||||||
 | 
					                delay: this.serverConfig.reconnectdelay * 1
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        if (this.serverConfig.vhost) {
 | 
				
			||||||
 | 
					          this.stompClientOpts.vhost = this.serverConfig.vhost;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var node = this;
 | 
					        var node = this;
 | 
				
			||||||
        var msg = {topic:this.topic};
 | 
					        node.client = new StompClient(node.stompClientOpts);
 | 
				
			||||||
        var closing = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        node.client = new StompClient(node.host, node.port, node.userid, node.password, '1.0');
 | 
					        node.client.on("connect", function() {
 | 
				
			||||||
        node.status({fill:"grey",shape:"ring",text:"connecting"});
 | 
					          node.status({fill:"green",shape:"dot",text:"connected"});
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        node.client.connect( function(sessionId) {
 | 
					        node.client.on("reconnecting", function() {
 | 
				
			||||||
            node.status({fill:"green",shape:"dot",text:"connected"});
 | 
					            node.status({fill:"red",shape:"ring",text:"reconnecting"});
 | 
				
			||||||
        }, function(error) {
 | 
					            node.warn("reconnecting");
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        node.client.on("error", function(error) {
 | 
				
			||||||
            node.status({fill:"grey",shape:"dot",text:"error"});
 | 
					            node.status({fill:"grey",shape:"dot",text:"error"});
 | 
				
			||||||
            node.warn(error);
 | 
					            node.warn(error);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        node.client.on("disconnect", function() {
 | 
					        node.status({fill:"grey",shape:"ring",text:"connecting"});
 | 
				
			||||||
            node.status({fill:"red",shape:"ring",text:"disconnected"});
 | 
					        node.client.connect(function(sessionId) {
 | 
				
			||||||
            if (!closing) {
 | 
					        }, function(error) {
 | 
				
			||||||
                setTimeout( function () { node.client.connect(); }, 15000);
 | 
					            node.status({fill:"grey",shape:"dot",text:"error"});
 | 
				
			||||||
            }
 | 
					            node.warn(error);
 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        node.client.on("error", function(error) {
 | 
					 | 
				
			||||||
            node.log(error);
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        node.on("input", function(msg) {
 | 
					        node.on("input", function(msg) {
 | 
				
			||||||
@@ -139,13 +157,13 @@ module.exports = function(RED) {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        node.on("close", function(done) {
 | 
					        node.on("close", function(done) {
 | 
				
			||||||
            closing = true;
 | 
					 | 
				
			||||||
            if (node.client) {
 | 
					            if (node.client) {
 | 
				
			||||||
                node.client.disconnect(function() { done(); });
 | 
					                // disconnect can accept a callback - but it is not always called.
 | 
				
			||||||
 | 
					                node.client.disconnect();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else { done(); }
 | 
					            done();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    RED.nodes.registerType("stomp out",StompOutNode);
 | 
					    RED.nodes.registerType("stomp out",StompOutNode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@
 | 
				
			|||||||
    "version"       : "0.0.7",
 | 
					    "version"       : "0.0.7",
 | 
				
			||||||
    "description"   : "A Node-RED node to publish and subscribe to/from a Stomp server",
 | 
					    "description"   : "A Node-RED node to publish and subscribe to/from a Stomp server",
 | 
				
			||||||
    "dependencies"  : {
 | 
					    "dependencies"  : {
 | 
				
			||||||
        "stomp-client"   : "0.6.*"
 | 
					        "stomp-client"   : "0.8.*"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "repository" : {
 | 
					    "repository" : {
 | 
				
			||||||
        "type":"git",
 | 
					        "type":"git",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user