mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add room password, better error / status reporting
This commit is contained in:
parent
59361625cc
commit
4d7ba48797
@ -13,6 +13,10 @@
|
|||||||
<input type="checkbox" id="node-input-join" placeholder="" style="display:inline-block; width:auto; vertical-align:top;">
|
<input type="checkbox" id="node-input-join" placeholder="" style="display:inline-block; width:auto; vertical-align:top;">
|
||||||
<label for="node-input-join" style="width:70%;">Is a Chat Room ?</label>
|
<label for="node-input-join" style="width:70%;">Is a Chat Room ?</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row" id="node-room-pwd">
|
||||||
|
<label for="node-input-password"><i class="fa fa-lock"></i> Password</label>
|
||||||
|
<input type="password" id="node-input-password" placeholder="optional room password">
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-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">
|
||||||
@ -41,6 +45,9 @@
|
|||||||
to: {value:""},
|
to: {value:""},
|
||||||
join: {value:false}
|
join: {value:false}
|
||||||
},
|
},
|
||||||
|
credentials: {
|
||||||
|
password: {type:"password"}
|
||||||
|
},
|
||||||
inputs:0,
|
inputs:0,
|
||||||
outputs:2,
|
outputs:2,
|
||||||
icon: "xmpp.png",
|
icon: "xmpp.png",
|
||||||
@ -49,6 +56,16 @@
|
|||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
return (this.name)?"node_label_italic":"";
|
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(); }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@ -73,6 +90,10 @@
|
|||||||
<input type="checkbox" id="node-input-join" placeholder="" style="display: inline-block; width: auto; vertical-align: top;">
|
<input type="checkbox" id="node-input-join" placeholder="" style="display: inline-block; width: auto; vertical-align: top;">
|
||||||
<label for="node-input-join" style="width:70%;">Is a Chat Room ?</label>
|
<label for="node-input-join" style="width:70%;">Is a Chat Room ?</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row" id="node-room-pwd">
|
||||||
|
<label for="node-input-password"><i class="fa fa-lock"></i> Password</label>
|
||||||
|
<input type="password" id="node-input-password" placeholder="optional room password">
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-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">
|
||||||
@ -98,6 +119,9 @@
|
|||||||
join: {value:false},
|
join: {value:false},
|
||||||
sendObject: {value:false}
|
sendObject: {value:false}
|
||||||
},
|
},
|
||||||
|
credentials: {
|
||||||
|
password: {type:"password"}
|
||||||
|
},
|
||||||
inputs:1,
|
inputs:1,
|
||||||
outputs:0,
|
outputs:0,
|
||||||
icon: "xmpp.png",
|
icon: "xmpp.png",
|
||||||
@ -107,6 +131,16 @@
|
|||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
return (this.name)?"node_label_italic":"";
|
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(); }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@ -127,7 +161,7 @@
|
|||||||
<input type="text" id="node-config-input-nickname" placeholder="Joe (optional)">
|
<input type="text" id="node-config-input-nickname" placeholder="Joe (optional)">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-pass"><i class="fa fa-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>
|
||||||
|
@ -119,8 +119,8 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
if (RED.settings.verbose || LOGITALL) {that.log("Culprit: "+that.lastUsed.id); }
|
if (RED.settings.verbose || LOGITALL) {that.log("Culprit: "+that.lastUsed.id); }
|
||||||
if (typeof that.lastUsed !== "undefined") {
|
if (typeof that.lastUsed !== "undefined") {
|
||||||
that.lastUsed.status({fill:"red",shape:"ring",text:"error "+text});
|
that.lastUsed.status({fill:"yellow",shape:"dot",text:"warning. "+text});
|
||||||
that.lastUsed.warn("Error "+text);
|
that.lastUsed.warn("Warning. "+text);
|
||||||
if (that.lastUsed.join) {
|
if (that.lastUsed.join) {
|
||||||
// it was trying to MUC things up
|
// it was trying to MUC things up
|
||||||
clearMUC(that);
|
clearMUC(that);
|
||||||
@ -260,6 +260,15 @@ module.exports = function(RED) {
|
|||||||
xml("history", {maxstanzas:0, seconds:1}) // We don't want any history
|
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.used(node);
|
||||||
node.serverConfig.MUCs[mu] = "joined";
|
node.serverConfig.MUCs[mu] = "joined";
|
||||||
if (RED.settings.verbose || LOGITALL) { node.log("JOINED "+mu); }
|
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.
|
// this isn't for us, let the config node deal with it.
|
||||||
}
|
}
|
||||||
else {
|
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');
|
var state = stanza.getChild('show');
|
||||||
if (state) { state = state.getText(); }
|
if (state) { state = state.getText(); }
|
||||||
else { state = "available"; }
|
else { state = "available"; }
|
||||||
@ -573,7 +605,11 @@ module.exports = function(RED) {
|
|||||||
node.serverConfig.deregister(node, done);
|
node.serverConfig.deregister(node, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("xmpp in",XmppInNode);
|
RED.nodes.registerType("xmpp in",XmppInNode,{
|
||||||
|
credentials: {
|
||||||
|
password: {type: "password"}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
function XmppOutNode(n) {
|
function XmppOutNode(n) {
|
||||||
@ -653,8 +689,27 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
xmpp.on('stanza', async (stanza) => {
|
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
|
//register with config
|
||||||
@ -723,16 +778,15 @@ module.exports = function(RED) {
|
|||||||
// joinMUC will do nothing if we're already joined
|
// joinMUC will do nothing if we're already joined
|
||||||
joinMUC(node, xmpp, to+'/'+node.nick);
|
joinMUC(node, xmpp, to+'/'+node.nick);
|
||||||
}
|
}
|
||||||
// if (msg.subject) {
|
if (msg.subject) {
|
||||||
// var stanza = xml(
|
var stanza = xml(
|
||||||
// "message",
|
"message",
|
||||||
// { type:type, to:to },
|
{ type:type, to:to, from:node.serverConfig.jid },
|
||||||
// xml("subject", {}, msg.subject.toString())
|
xml("subject", {}, msg.subject.toString())
|
||||||
// );
|
);
|
||||||
// node.serverConfig.used(node);
|
node.serverConfig.used(node);
|
||||||
// console.log("SENDING",stanza.toString())
|
xmpp.send(stanza);
|
||||||
// xmpp.send(stanza);
|
}
|
||||||
// }
|
|
||||||
if (node.sendAll) {
|
if (node.sendAll) {
|
||||||
message = xml(
|
message = xml(
|
||||||
"message",
|
"message",
|
||||||
@ -756,8 +810,10 @@ module.exports = function(RED) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.serverConfig.used(node);
|
if (message) {
|
||||||
xmpp.send(message);
|
node.serverConfig.used(node);
|
||||||
|
xmpp.send(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -768,5 +824,9 @@ module.exports = function(RED) {
|
|||||||
node.serverConfig.deregister(node, done);
|
node.serverConfig.deregister(node, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("xmpp out",XmppOutNode);
|
RED.nodes.registerType("xmpp out",XmppOutNode,{
|
||||||
|
credentials: {
|
||||||
|
password: {type: "password"}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-xmpp",
|
"name": "node-red-node-xmpp",
|
||||||
"version": "0.4.2",
|
"version": "0.5.0",
|
||||||
"description": "A Node-RED node to talk to an XMPP server",
|
"description": "A Node-RED node to talk to an XMPP server",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@xmpp/client": "^0.12.0"
|
"@xmpp/client": "^0.12.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user