mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
tidy up xmpp node
This commit is contained in:
parent
770ad94e95
commit
3b7fb0aa95
2
.gitignore
vendored
2
.gitignore
vendored
@ -6,3 +6,5 @@ puball.sh
|
|||||||
setenv.sh
|
setenv.sh
|
||||||
/.project
|
/.project
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
social/xmpp/92-xmpp.old
|
||||||
|
*.tgz
|
||||||
|
@ -109,7 +109,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/html" data-template-name="xmpp-server">
|
<script type="text/html" data-template-name="xmpp-server">
|
||||||
<div class="form-row node-input-server">
|
<div class="form-row">
|
||||||
<label for="node-config-input-server"><i class="fa fa-bookmark"></i> Server</label>
|
<label for="node-config-input-server"><i class="fa fa-bookmark"></i> Server</label>
|
||||||
<input class="input-append-left" type="text" id="node-config-input-server" placeholder="blah.im" style="width: 40%;" >
|
<input class="input-append-left" type="text" id="node-config-input-server" placeholder="blah.im" 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>
|
||||||
|
@ -12,17 +12,17 @@ module.exports = function(RED) {
|
|||||||
this.username = n.user.split('@')[0];
|
this.username = n.user.split('@')[0];
|
||||||
// The user may elect to just specify the jid in the settings,
|
// The user may elect to just specify the jid in the settings,
|
||||||
// in which case extract the server from the jid and default the port
|
// in which case extract the server from the jid and default the port
|
||||||
if("undefined" === typeof n.server || n.server === ""){
|
if ("undefined" === typeof n.server || n.server === "") {
|
||||||
this.server = n.user.split('@')[1];
|
this.server = n.user.split('@')[1];
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
this.server = n.server;
|
this.server = n.server;
|
||||||
}
|
}
|
||||||
if("undefined" === typeof n.port || n.port === ""){
|
if ("undefined" === typeof n.port || n.port === "") {
|
||||||
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,8 +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) {
|
||||||
|
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
|
||||||
});
|
});
|
||||||
@ -48,7 +55,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
// function for a node to tell us it has us as config
|
// function for a node to tell us it has us as config
|
||||||
this.register = function(xmppThat) {
|
this.register = function(xmppThat) {
|
||||||
if (RED.settings.verbose || LOGITALL) {that.log("registering "+xmppThat.id);}
|
if (RED.settings.verbose || LOGITALL) {that.log("registering "+xmppThat.id); }
|
||||||
that.users[xmppThat.id] = xmppThat;
|
that.users[xmppThat.id] = xmppThat;
|
||||||
// So we could start the connection here, but we already have the logic in the thats.
|
// So we could start the connection here, but we already have the logic in the thats.
|
||||||
// if (Object.keys(that.users).length === 1) {
|
// if (Object.keys(that.users).length === 1) {
|
||||||
@ -58,7 +65,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
// function for a node to tell us it's not using us anymore
|
// function for a node to tell us it's not using us anymore
|
||||||
this.deregister = function(xmppThat,done) {
|
this.deregister = function(xmppThat,done) {
|
||||||
if (RED.settings.verbose || LOGITALL) {that.log("deregistering "+xmppThat.id);}
|
if (RED.settings.verbose || LOGITALL) {that.log("deregistering "+xmppThat.id); }
|
||||||
delete that.users[xmppThat.id];
|
delete that.users[xmppThat.id];
|
||||||
if (that.closing) {
|
if (that.closing) {
|
||||||
return done();
|
return done();
|
||||||
@ -67,7 +74,6 @@ module.exports = function(RED) {
|
|||||||
if (that.client && that.client.connected) {
|
if (that.client && that.client.connected) {
|
||||||
return that.client.stop(done);
|
return that.client.stop(done);
|
||||||
} else {
|
} else {
|
||||||
that.client.stop();
|
|
||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,8 +84,8 @@ module.exports = function(RED) {
|
|||||||
this.lastUsed = undefined;
|
this.lastUsed = undefined;
|
||||||
// function for a node to tell us it has just sent a message to our server
|
// function for a node to tell us it has just sent a message to our server
|
||||||
// so we know which node to blame if it all goes Pete Tong
|
// so we know which node to blame if it all goes Pete Tong
|
||||||
this.used = function(xmppThat){
|
this.used = function(xmppThat) {
|
||||||
if (RED.settings.verbose || LOGITALL) {that.log(xmppThat.id+" sent a message to the xmpp server");}
|
if (RED.settings.verbose || LOGITALL) {that.log(xmppThat.id+" sent a message to the xmpp server"); }
|
||||||
that.lastUsed = xmppThat;
|
that.lastUsed = xmppThat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,26 +101,37 @@ module.exports = function(RED) {
|
|||||||
that.log(stanza);
|
that.log(stanza);
|
||||||
}
|
}
|
||||||
var err = stanza.getChild('error');
|
var err = stanza.getChild('error');
|
||||||
if(err){
|
if (err) {
|
||||||
var textObj = err.getChild('text');
|
var textObj = err.getChild('text');
|
||||||
var text = "node-red:common.status.error";
|
var text = "node-red:common.status.error";
|
||||||
if("undefined" !== typeof textObj){
|
if ("undefined" !== typeof textObj) {
|
||||||
text = textObj.getText();
|
text = textObj.getText();
|
||||||
}
|
}
|
||||||
if (RED.settings.verbose || LOGITALL) {that.log("Culprit: "+that.lastUsed);}
|
else{
|
||||||
if("undefined" !== typeof that.lastUsed){
|
textObj = err.getChild('code');
|
||||||
|
if ("undefined" !== typeof textObj) {
|
||||||
|
text = textObj.getText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (RED.settings.verbose || LOGITALL) {that.log("Culprit: "+that.lastUsed); }
|
||||||
|
if ("undefined" !== typeof that.lastUsed) {
|
||||||
that.lastUsed.status({fill:"red",shape:"ring",text:text});
|
that.lastUsed.status({fill:"red",shape:"ring",text:text});
|
||||||
that.lastUsed.warn(text);
|
that.lastUsed.warn(text);
|
||||||
}
|
}
|
||||||
|
if (RED.settings.verbose || LOGITALL) {
|
||||||
|
that.log("We did wrong: "+text);
|
||||||
|
that.log(stanza);
|
||||||
|
}
|
||||||
|
|
||||||
// maybe throw the message or summit
|
// maybe throw the message or summit
|
||||||
//that.error(text);
|
//that.error(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(stanza.is('presence')){
|
else if (stanza.is('presence')) {
|
||||||
if(['subscribe','subscribed','unsubscribe','unsubscribed'].indexOf(stanza.attrs.type) > -1){
|
if (['subscribe','subscribed','unsubscribe','unsubscribed'].indexOf(stanza.attrs.type) > -1) {
|
||||||
if (RED.settings.verbose || LOGITALL) {that.log("got a subscription based message");}
|
if (RED.settings.verbose || LOGITALL) {that.log("got a subscription based message"); }
|
||||||
switch(stanza.attrs.type){
|
switch(stanza.attrs.type) {
|
||||||
case 'subscribe':
|
case 'subscribe':
|
||||||
// they're asking for permission let's just say yes
|
// they're asking for permission let's just say yes
|
||||||
var response = xml('presence',
|
var response = xml('presence',
|
||||||
@ -128,7 +145,26 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (stanza.is('iq')) {
|
||||||
|
if (RED.settings.verbose || LOGITALL) {that.log("got an iq query"); }
|
||||||
|
if (stanza.attrs.type === 'error') {
|
||||||
|
if (RED.settings.verbose || LOGITALL) {that.log("oh noes, it's an error"); }
|
||||||
|
if (stanza.attrs.id === that.lastUsed.id) {
|
||||||
|
that.lastUsed.status({fill:"red", shape:"ring", text:stanza.getChild('error')});
|
||||||
|
that.lastUsed.warn(stanza.getChild('error'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (stanza.attrs.type === 'result') {
|
||||||
|
// AM To-Do check for 'bind' result with our current jid
|
||||||
|
var query = stanza.getChild('query');
|
||||||
|
if (RED.settings.verbose || LOGITALL) {that.log("result!"); }
|
||||||
|
if (RED.settings.verbose || LOGITALL) {that.log(query); }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// We shouldn't have any errors here that the input/output nodes can't handle
|
// We shouldn't have any errors here that the input/output nodes can't handle
|
||||||
// if you need to see everything though; uncomment this block
|
// if you need to see everything though; uncomment this block
|
||||||
// this.client.on('error', err => {
|
// this.client.on('error', err => {
|
||||||
@ -142,22 +178,29 @@ module.exports = function(RED) {
|
|||||||
that.connected = true;
|
that.connected = true;
|
||||||
await that.client.send(xml('presence'));
|
await that.client.send(xml('presence'));
|
||||||
// await that.client.send(xml('presence', {type: 'available'},xml('status', {}, 'available')));
|
// await that.client.send(xml('presence', {type: 'available'},xml('status', {}, 'available')));
|
||||||
if (RED.settings.verbose || LOGITALL) {that.log('connected as '+that.username+' to ' +that.server+':'+that.port);}
|
if (RED.settings.verbose || LOGITALL) {that.log('connected as '+that.username+' to ' +that.server+':'+that.port); }
|
||||||
});
|
});
|
||||||
|
|
||||||
// if the connection has gone away, not sure why!
|
// if the connection has gone away, not sure why!
|
||||||
this.client.on('offline', () => {
|
this.client.on('offline', () => {
|
||||||
that.connected = false;
|
that.connected = false;
|
||||||
if (RED.settings.verbose || LOGITALL) {that.log('connection closed');}
|
if (RED.settings.verbose || LOGITALL) {that.log('connection closed'); }
|
||||||
});
|
});
|
||||||
|
|
||||||
// gets called when the node is destroyed, e.g. if N-R is being stopped.
|
// gets called when the node is destroyed, e.g. if N-R is being stopped.
|
||||||
this.on("close", async done => {
|
this.on("close", async done => {
|
||||||
if(that.connected){
|
if (that.client.connected) {
|
||||||
await that.client.send(xml('presence', {type: 'unavailable'}));
|
await that.client.send(xml('presence', {type: 'unavailable'}));
|
||||||
|
try{
|
||||||
|
if (RED.settings.verbose || LOGITALL) {
|
||||||
|
that.log("Calling stop() after close, status is "+that.client.status);
|
||||||
|
}
|
||||||
|
await that.client.stop().then(that.log("XMPP client stopped")).catch(error=>{that.warn("Got an error whilst closing xmpp session: "+error)});
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
that.warn(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
that.client.stop().catch(that.error);
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -175,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;
|
||||||
|
|
||||||
@ -207,7 +251,7 @@ module.exports = function(RED) {
|
|||||||
{ maxstanzas:0, seconds:1 }
|
{ maxstanzas:0, seconds:1 }
|
||||||
);
|
);
|
||||||
node.serverConfig.used(node);
|
node.serverConfig.used(node);
|
||||||
xmpp.send(stanza);
|
xmpp.send(stanza).catch(error => {node.warn("Got error when sending presence: "+error)});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -236,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); }
|
||||||
@ -252,11 +296,21 @@ module.exports = function(RED) {
|
|||||||
node.status({fill:"red",shape:"ring",text:"bad address"});
|
node.status({fill:"red",shape:"ring",text:"bad address"});
|
||||||
}
|
}
|
||||||
else if (err === "XMPP authentication failure") {
|
else if (err === "XMPP authentication failure") {
|
||||||
node.error(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") {
|
||||||
|
// Suppress it!
|
||||||
|
node.warn("Timed out! ");
|
||||||
|
node.status({fill:"grey",shape:"dot",text:"opening"});
|
||||||
|
//node.status({fill:"red",shape:"ring",text:"XMPP timeout"});
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
node.error(err.errno,err);
|
node.error(err,err);
|
||||||
node.status({fill:"red",shape:"ring",text:"node-red:common.status.error"});
|
node.status({fill:"red",shape:"ring",text:"node-red:common.status.error"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,7 +319,7 @@ module.exports = function(RED) {
|
|||||||
// Meat of it, a stanza object contains chat messages (and other things)
|
// Meat of it, a stanza object contains chat messages (and other things)
|
||||||
xmpp.on('stanza', async (stanza) =>{
|
xmpp.on('stanza', async (stanza) =>{
|
||||||
// node.log("Received stanza");
|
// node.log("Received stanza");
|
||||||
if (RED.settings.verbose || LOGITALL) {node.log(stanza);}
|
if (RED.settings.verbose || LOGITALL) {node.log(stanza); }
|
||||||
if (stanza.is('message')) {
|
if (stanza.is('message')) {
|
||||||
if (stanza.attrs.type == 'chat') {
|
if (stanza.attrs.type == 'chat') {
|
||||||
var body = stanza.getChild('body');
|
var body = stanza.getChild('body');
|
||||||
@ -276,18 +330,19 @@ 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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(stanza.attrs.type == 'groupchat'){
|
else if (stanza.attrs.type == 'groupchat') {
|
||||||
const parts = stanza.attrs.from.split("/");
|
const parts = stanza.attrs.from.split("/");
|
||||||
var conference = parts[0];
|
var conference = parts[0];
|
||||||
var from = parts[1];
|
var from = parts[1];
|
||||||
var body = stanza.getChild('body');
|
var body = stanza.getChild('body');
|
||||||
var payload = "";
|
var payload = "";
|
||||||
if("undefined" !== typeof body){
|
if ("undefined" !== typeof body) {
|
||||||
payload = body.getText();
|
payload = body.getText();
|
||||||
}
|
}
|
||||||
var msg = { topic:from, payload:payload, room:conference };
|
var msg = { topic:from, payload:payload, room:conference };
|
||||||
@ -298,23 +353,23 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(stanza.is('presence')){
|
else if (stanza.is('presence')) {
|
||||||
if(['subscribe','subscribed','unsubscribe','unsubscribed'].indexOf(stanza.attrs.type) > -1){
|
if (['subscribe','subscribed','unsubscribe','unsubscribed'].indexOf(stanza.attrs.type) > -1) {
|
||||||
// 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{
|
||||||
var statusText="";
|
var statusText="";
|
||||||
if(stanza.attrs.type === 'unavailable'){
|
if (stanza.attrs.type === 'unavailable') {
|
||||||
// the user might not exist, but the server doesn't tell us that!
|
// the user might not exist, but the server doesn't tell us that!
|
||||||
statusText = "offline";
|
statusText = "offline";
|
||||||
}
|
}
|
||||||
var status = stanza.getChild('status');
|
var status = stanza.getChild('status');
|
||||||
if("undefined" !== typeof status){
|
if ("undefined" !== typeof status) {
|
||||||
statusText = status.getText();
|
statusText = status.getText();
|
||||||
}
|
}
|
||||||
// right, do we care if there's no status?
|
// right, do we care if there's no status?
|
||||||
if(statusText !== ""){
|
if (statusText !== "") {
|
||||||
var from = stanza.attrs.from;
|
var from = stanza.attrs.from;
|
||||||
var state = stanza.attrs.show;
|
var state = stanza.attrs.show;
|
||||||
var msg = {topic:from, payload: {presence:state, status:statusText} };
|
var msg = {topic:from, payload: {presence:state, status:statusText} };
|
||||||
@ -330,8 +385,6 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// xmpp.on('subscribe', from => {
|
// xmpp.on('subscribe', from => {
|
||||||
// xmpp.acceptSubscription(from);
|
// xmpp.acceptSubscription(from);
|
||||||
// });
|
// });
|
||||||
@ -340,13 +393,16 @@ module.exports = function(RED) {
|
|||||||
this.serverConfig.register(this);
|
this.serverConfig.register(this);
|
||||||
// Now actually make the connection
|
// Now actually make the connection
|
||||||
try {
|
try {
|
||||||
if(xmpp.status === "online"){
|
if (xmpp.status === "online") {
|
||||||
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
|
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"});
|
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"});
|
||||||
if(xmpp.status === "offline"){
|
if (xmpp.status === "offline") {
|
||||||
xmpp.start();
|
if (RED.settings.verbose || LOGITALL) {
|
||||||
|
node.log("starting xmpp client");
|
||||||
|
}
|
||||||
|
xmpp.start().catch(error => {node.warn("Got error on start: "+error); node.warn("XMPP Status is now: "+xmpp.status)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -392,7 +448,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
xmpp.on('online', function(data) {
|
xmpp.on('online', function(data) {
|
||||||
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
|
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
|
||||||
if ((node.join) && (node.from !== "")) {
|
if ((node.join) && (node.to !== "")) {
|
||||||
// disable chat history
|
// disable chat history
|
||||||
var to = node.to+'/'+node.nick;
|
var to = node.to+'/'+node.nick;
|
||||||
// the presence with the muc x element signifies we want to join the muc
|
// the presence with the muc x element signifies we want to join the muc
|
||||||
@ -444,7 +500,7 @@ module.exports = function(RED) {
|
|||||||
node.error("Timeout connecting to server",err);
|
node.error("Timeout connecting to server",err);
|
||||||
node.status({fill:"red",shape:"ring",text:"timeout"});
|
node.status({fill:"red",shape:"ring",text:"timeout"});
|
||||||
}
|
}
|
||||||
if (err.errno === "ENOTFOUND") {
|
else if (err.errno === "ENOTFOUND") {
|
||||||
node.error("Server doesn't exist "+xmpp.options.service,err);
|
node.error("Server doesn't exist "+xmpp.options.service,err);
|
||||||
node.status({fill:"red",shape:"ring",text:"bad address"});
|
node.status({fill:"red",shape:"ring",text:"bad address"});
|
||||||
}
|
}
|
||||||
@ -452,8 +508,14 @@ module.exports = function(RED) {
|
|||||||
node.error(err,err);
|
node.error(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 == "TimeoutError") {
|
||||||
|
// OK, this happens with OpenFire, suppress it.
|
||||||
|
node.status({fill:"grey",shape:"dot",text:"opening"});
|
||||||
|
node.log("Timed out! ",err);
|
||||||
|
// node.status({fill:"red",shape:"ring",text:"XMPP timeout"});
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
node.error(err.errno,err);
|
node.error("Unknown error: "+err,err);
|
||||||
node.status({fill:"red",shape:"ring",text:"node-red:common.status.error"});
|
node.status({fill:"red",shape:"ring",text:"node-red:common.status.error"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,12 +524,12 @@ module.exports = function(RED) {
|
|||||||
//register with config
|
//register with config
|
||||||
this.serverConfig.register(this);
|
this.serverConfig.register(this);
|
||||||
// Now actually make the connection
|
// Now actually make the connection
|
||||||
if(xmpp.status === "online"){
|
if (xmpp.status === "online") {
|
||||||
node.status({fill:"green",shape:"dot",text:"online"});
|
node.status({fill:"green",shape:"dot",text:"online"});
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"});
|
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"});
|
||||||
if(xmpp.status === "offline"){
|
if (xmpp.status === "offline") {
|
||||||
xmpp.start().catch(error => {
|
xmpp.start().catch(error => {
|
||||||
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(error);
|
node.warn(error);
|
||||||
@ -489,13 +551,24 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
else { node.warn("Can't set presence - invalid value: "+msg.presence); }
|
else { node.warn("Can't set presence - invalid value: "+msg.presence); }
|
||||||
}
|
}
|
||||||
else if(msg.command){
|
else if (msg.command) {
|
||||||
if(msg.command === "subscribe"){
|
if (msg.command === "subscribe") {
|
||||||
var stanza = xml('presence',
|
var stanza = xml('presence',
|
||||||
{type:'subscribe', to: msg.payload});
|
{type:'subscribe', to: msg.payload});
|
||||||
node.serverConfig.used(node);
|
node.serverConfig.used(node);
|
||||||
xmpp.send(stanza);
|
xmpp.send(stanza);
|
||||||
}
|
}
|
||||||
|
else if (msg.command === "get") {
|
||||||
|
var to = node.to || msg.topic || "";
|
||||||
|
var stanza = xml('iq',
|
||||||
|
{type:'get', id:node.id, to: to},
|
||||||
|
xml('query', 'http://jabber.org/protocol/muc#admin',
|
||||||
|
xml('item',{affiliation:msg.payload})));
|
||||||
|
node.serverConfig.used(node);
|
||||||
|
if (RED.settings.verbose || LOGITALL) {node.log("sending stanza "+stanza.toString()); }
|
||||||
|
xmpp.send(stanza);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var to = node.to || msg.topic || "";
|
var to = node.to || msg.topic || "";
|
||||||
@ -533,7 +606,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
node.on("close", function(removed, done) {
|
node.on("close", function(removed, done) {
|
||||||
if (RED.settings.verbose || LOGITALL) {node.log("Closing");}
|
if (RED.settings.verbose || LOGITALL) {node.log("Closing"); }
|
||||||
node.status({fill:"red",shape:"ring",text:"node-red:common.status.disconnected"});
|
node.status({fill:"red",shape:"ring",text:"node-red:common.status.disconnected"});
|
||||||
node.serverConfig.deregister(node, done);
|
node.serverConfig.deregister(node, done);
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-xmpp",
|
"name": "node-red-node-xmpp",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"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.11.1"
|
"@xmpp/client": "^0.11.1"
|
||||||
|
Loading…
Reference in New Issue
Block a user