diff --git a/social/xmpp/92-xmpp.html b/social/xmpp/92-xmpp.html
index dbf3eb9a..cdfc3569 100644
--- a/social/xmpp/92-xmpp.html
+++ b/social/xmpp/92-xmpp.html
@@ -13,6 +13,10 @@
+
+
+
+
@@ -41,6 +45,9 @@
to: {value:""},
join: {value:false}
},
+ credentials: {
+ password: {type:"password"}
+ },
inputs:0,
outputs:2,
icon: "xmpp.png",
@@ -49,6 +56,16 @@
},
labelStyle: function() {
return (this.name)?"node_label_italic":"";
+ },
+ oneditprepare: function() {
+ $('#node-input-join').change(function() {
+ if ($("#node-input-join").is(':checked') && $("#node-input-to").val() && $("#node-input-to").val().indexOf(':') === -1) { $("#node-room-pwd").show(); }
+ else { $("#node-room-pwd").hide(); }
+ });
+ $('#node-input-to').change(function() {
+ if ($("#node-input-join").is(':checked') && $("#node-input-to").val() && $("#node-input-to").val().indexOf(':') === -1) { $("#node-room-pwd").show(); }
+ else { $("#node-room-pwd").hide(); }
+ });
}
});
@@ -73,6 +90,10 @@
+
+
+
+
@@ -98,6 +119,9 @@
join: {value:false},
sendObject: {value:false}
},
+ credentials: {
+ password: {type:"password"}
+ },
inputs:1,
outputs:0,
icon: "xmpp.png",
@@ -107,6 +131,16 @@
},
labelStyle: function() {
return (this.name)?"node_label_italic":"";
+ },
+ oneditprepare: function() {
+ $('#node-input-join').change(function() {
+ if ($("#node-input-join").is(':checked') && $("#node-input-to").val() && $("#node-input-to").val().indexOf(':') === -1) { $("#node-room-pwd").show(); }
+ else { $("#node-room-pwd").hide(); }
+ });
+ $('#node-input-to').change(function() {
+ if ($("#node-input-join").is(':checked') && $("#node-input-to").val() && $("#node-input-to").val().indexOf(':') === -1) { $("#node-room-pwd").show(); }
+ else { $("#node-room-pwd").hide(); }
+ });
}
});
@@ -127,7 +161,7 @@
-
+
diff --git a/social/xmpp/92-xmpp.js b/social/xmpp/92-xmpp.js
index 7219c06e..d7eb0f7b 100644
--- a/social/xmpp/92-xmpp.js
+++ b/social/xmpp/92-xmpp.js
@@ -119,8 +119,8 @@ module.exports = function(RED) {
}
if (RED.settings.verbose || LOGITALL) {that.log("Culprit: "+that.lastUsed.id); }
if (typeof that.lastUsed !== "undefined") {
- that.lastUsed.status({fill:"red",shape:"ring",text:"error "+text});
- that.lastUsed.warn("Error "+text);
+ that.lastUsed.status({fill:"yellow",shape:"dot",text:"warning. "+text});
+ that.lastUsed.warn("Warning. "+text);
if (that.lastUsed.join) {
// it was trying to MUC things up
clearMUC(that);
@@ -260,6 +260,15 @@ module.exports = function(RED) {
xml("history", {maxstanzas:0, seconds:1}) // We don't want any history
)
);
+ if (node.hasOwnProperty("credentials") && node.credentials.hasOwnProperty("password")) {
+ stanza = xml('presence',
+ {"to":name},
+ xml("x",'http://jabber.org/protocol/muc',
+ xml("history", {maxstanzas:0, seconds:1}), // We don't want any history
+ xml("password", {}, node.credentials.password) // Add the password
+ )
+ );
+ }
node.serverConfig.used(node);
node.serverConfig.MUCs[mu] = "joined";
if (RED.settings.verbose || LOGITALL) { node.log("JOINED "+mu); }
@@ -458,6 +467,29 @@ module.exports = function(RED) {
// this isn't for us, let the config node deal with it.
}
else {
+ if (stanza.attrs.type === 'error') {
+ var error = stanza.getChild('error');
+ if (error.attrs.code) {
+ try {
+ var reas = error.toString().split('><')[1].split(" xml")[0].trim();
+ if (reas == "registration-required") { reas = "membership-required"; }
+ }
+ catch(e) {};
+ var msg = {
+ topic:stanza.attrs.from,
+ payload: {
+ code:error.attrs.code,
+ status:"error",
+ reason:reas,
+ name:node.serverConfig.MUCs[stanza.attrs.from.split('/')[0]]
+ }
+ };
+ node.send([null,msg]);
+ node.status({fill:"red",shape:"ring",text:"error : "+error.attrs.code+", "+error.attrs.type+", "+reas});
+ node.error(error.attrs.type+" error. "+error.attrs.code+" "+reas,msg);
+ }
+ }
+
var state = stanza.getChild('show');
if (state) { state = state.getText(); }
else { state = "available"; }
@@ -573,7 +605,11 @@ module.exports = function(RED) {
node.serverConfig.deregister(node, done);
});
}
- RED.nodes.registerType("xmpp in",XmppInNode);
+ RED.nodes.registerType("xmpp in",XmppInNode,{
+ credentials: {
+ password: {type: "password"}
+ }
+ });
function XmppOutNode(n) {
@@ -653,8 +689,27 @@ module.exports = function(RED) {
});
xmpp.on('stanza', async (stanza) => {
- // if (stanza.is('presence')) {
- // }
+ if (stanza.attrs.type === 'error') {
+ var error = stanza.getChild('error');
+ if (error.attrs.code) {
+ try {
+ var reas = error.toString().split('><')[1].split(" xml")[0].trim();
+ if (reas == "registration-required") { reas = "membership-required"; }
+ }
+ catch(e) {};
+ var msg = {
+ topic:stanza.attrs.from,
+ payload: {
+ code:error.attrs.code,
+ status:"error",
+ reason:reas,
+ name:node.serverConfig.MUCs[stanza.attrs.from.split('/')[0]]
+ }
+ };
+ node.status({fill:"red",shape:"ring",text:"error : "+error.attrs.code+", "+error.attrs.type+", "+reas});
+ node.error(error.attrs.type+" error. "+error.attrs.code+" "+reas,msg);
+ }
+ }
});
//register with config
@@ -723,16 +778,15 @@ module.exports = function(RED) {
// joinMUC will do nothing if we're already joined
joinMUC(node, xmpp, to+'/'+node.nick);
}
- // if (msg.subject) {
- // var stanza = xml(
- // "message",
- // { type:type, to:to },
- // xml("subject", {}, msg.subject.toString())
- // );
- // node.serverConfig.used(node);
- // console.log("SENDING",stanza.toString())
- // xmpp.send(stanza);
- // }
+ if (msg.subject) {
+ var stanza = xml(
+ "message",
+ { type:type, to:to, from:node.serverConfig.jid },
+ xml("subject", {}, msg.subject.toString())
+ );
+ node.serverConfig.used(node);
+ xmpp.send(stanza);
+ }
if (node.sendAll) {
message = xml(
"message",
@@ -756,8 +810,10 @@ module.exports = function(RED) {
);
}
}
- node.serverConfig.used(node);
- xmpp.send(message);
+ if (message) {
+ node.serverConfig.used(node);
+ xmpp.send(message);
+ }
}
}
});
@@ -768,5 +824,9 @@ module.exports = function(RED) {
node.serverConfig.deregister(node, done);
});
}
- RED.nodes.registerType("xmpp out",XmppOutNode);
+ RED.nodes.registerType("xmpp out",XmppOutNode,{
+ credentials: {
+ password: {type: "password"}
+ }
+ });
}
diff --git a/social/xmpp/package.json b/social/xmpp/package.json
index 4bafae0a..67f60f84 100644
--- a/social/xmpp/package.json
+++ b/social/xmpp/package.json
@@ -1,6 +1,6 @@
{
"name": "node-red-node-xmpp",
- "version": "0.4.2",
+ "version": "0.5.0",
"description": "A Node-RED node to talk to an XMPP server",
"dependencies": {
"@xmpp/client": "^0.12.0"