mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
improve debugging and better handling of messages from oneself
This commit is contained in:
parent
179a9e5533
commit
5530612372
@ -3,7 +3,7 @@ module.exports = function(RED) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
const {client, xml, jid} = require('@xmpp/client')
|
const {client, xml, jid} = require('@xmpp/client')
|
||||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
||||||
const LOGITALL=true;
|
const LOGITALL=false;
|
||||||
|
|
||||||
function XMPPServerNode(n) {
|
function XMPPServerNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
@ -22,7 +22,7 @@ module.exports = function(RED) {
|
|||||||
this.port = 5222;
|
this.port = 5222;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
this.port = n.port;
|
this.port = parseInt(n.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The password is obfuscated and stored in a separate location
|
// The password is obfuscated and stored in a separate location
|
||||||
@ -32,11 +32,15 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
// The basic xmpp client object, this will be referred to as "xmpp" in the nodes.
|
// The basic xmpp client object, this will be referred to as "xmpp" in the nodes.
|
||||||
// note we're not actually connecting here.
|
// note we're not actually connecting here.
|
||||||
|
var proto = "xmpp";
|
||||||
|
if(this.port === 5223){
|
||||||
|
proto = "xmpps";
|
||||||
|
}
|
||||||
if (RED.settings.verbose || LOGITALL) {
|
if (RED.settings.verbose || LOGITALL) {
|
||||||
this.log("Setting up connection xmpp: {service: xmpp://"+this.server+":"+this.port+", username: "+this.username+", password: "+this.password+"}");
|
this.log("Setting up connection xmpp: {service: "+proto+"://"+this.server+":"+this.port+", username: "+this.username+", password: "+this.password+"}");
|
||||||
}
|
}
|
||||||
this.client = client({
|
this.client = client({
|
||||||
service: 'xmpp://' + this.server + ':' + this.port,
|
service: proto+'://' + this.server + ':' + this.port,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
password: this.password
|
password: this.password
|
||||||
});
|
});
|
||||||
@ -214,6 +218,7 @@ module.exports = function(RED) {
|
|||||||
this.nick = this.serverConfig.nickname || this.serverConfig.username.split("@")[0];
|
this.nick = this.serverConfig.nickname || this.serverConfig.username.split("@")[0];
|
||||||
this.join = n.join || false;
|
this.join = n.join || false;
|
||||||
this.sendAll = n.sendObject;
|
this.sendAll = n.sendObject;
|
||||||
|
// Yes, it's called "from", don't ask me why; I don't know why
|
||||||
this.from = n.to || "";
|
this.from = n.to || "";
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
@ -275,7 +280,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
// Should we listen on other's status (chatstate) or a chatroom state (groupbuddy)?
|
// Should we listen on other's status (chatstate) or a chatroom state (groupbuddy)?
|
||||||
xmpp.on('error', err => {
|
xmpp.on('error', err => {
|
||||||
if (RED.settings.verbose || LOGITALL) { node.log(err); }
|
if (RED.settings.verbose || LOGITALL) { node.log("XMPP Error: "+err); }
|
||||||
if (err.hasOwnProperty("stanza")) {
|
if (err.hasOwnProperty("stanza")) {
|
||||||
if (err.stanza.name === 'stream:error') { node.error("stream:error - bad login id/pwd ?",err); }
|
if (err.stanza.name === 'stream:error') { node.error("stream:error - bad login id/pwd ?",err); }
|
||||||
else { node.error(err.stanza.name,err); }
|
else { node.error(err.stanza.name,err); }
|
||||||
@ -294,6 +299,10 @@ module.exports = function(RED) {
|
|||||||
node.error("Authentication failure! "+err,err);
|
node.error("Authentication failure! "+err,err);
|
||||||
node.status({fill:"red",shape:"ring",text:"XMPP authentication failure"});
|
node.status({fill:"red",shape:"ring",text:"XMPP authentication failure"});
|
||||||
}
|
}
|
||||||
|
else if (err.name === "SASLError") {
|
||||||
|
node.error("Authorization error! "+err.condition,err);
|
||||||
|
node.status({fill:"red",shape:"ring",text:"XMPP authorization failure"});
|
||||||
|
}
|
||||||
else if (err == "TimeoutError") {
|
else if (err == "TimeoutError") {
|
||||||
// Suppress it!
|
// Suppress it!
|
||||||
node.warn("Timed out! ");
|
node.warn("Timed out! ");
|
||||||
@ -321,7 +330,8 @@ module.exports = function(RED) {
|
|||||||
msg.topic = stanza.attrs.from
|
msg.topic = stanza.attrs.from
|
||||||
}
|
}
|
||||||
else { msg.topic = ids[0]; }
|
else { msg.topic = ids[0]; }
|
||||||
if (!node.join && ((node.from === "") || (node.from === stanza.attrs.from))) {
|
// if (RED.settings.verbose || LOGITALL) {node.log("Received a message from "+stanza.attrs.from);}
|
||||||
|
if (!node.join && ((node.from === "") || (node.from === stanza.attrs.to))) {
|
||||||
node.send([msg,null]);
|
node.send([msg,null]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -400,7 +410,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
node.error("Bad xmpp configuration; service: "+xmpp.options.service+" jid: "+node.serverConfig.jid);
|
node.error("Bad xmpp configuration; service: "+xmpp.options.service+" jid: "+node.serverConfig.jid);
|
||||||
node.warn(e);
|
// node.warn(e);
|
||||||
node.warn(e.stack);
|
node.warn(e.stack);
|
||||||
node.status({fill:"red",shape:"ring",text:"node-red:common.status.disconnected"});
|
node.status({fill:"red",shape:"ring",text:"node-red:common.status.disconnected"});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user