mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Added INFO abour settings for xmpp. (Apologies for missing in first place...).
NOTE:... there is still a bug in the underlying simple-xmpp npm.. see https://github.com/simple-xmpp/node-simple-xmpp/issues/12 for both the probem and the fix (not yet pulled).
This commit is contained in:
parent
336ad7893d
commit
ea398f9e66
@ -47,11 +47,17 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="xmpp">
|
||||
<p>Connects to an XMPP server to send and receive messages.</p>
|
||||
<p>Incoming messages will appear as <b>msg.payload</b> on the first output, while <b>msg.topic</b> will contain who it is from.</p>
|
||||
<p>The second output will user presence and status in <b>msg.payload</b>.</p>
|
||||
<p>The <b>To</b> field is optional. If not set uses the <b>msg.topic</b> property of the message.</p>
|
||||
<p>If you are joining a room then the <b>To</b> field must be filled in.</p>
|
||||
<p>Connects to an XMPP server to send and receive messages.</p>
|
||||
<p>Incoming messages will appear as <b>msg.payload</b> on the first output, while <b>msg.topic</b> will contain who it is from.</p>
|
||||
<p>The second output will user presence and status in <b>msg.payload</b>.</p>
|
||||
<p>The <b>To</b> field is optional. If not set uses the <b>msg.topic</b> property of the message.</p>
|
||||
<p>If you are joining a room then the <b>To</b> field must be filled in.</p>
|
||||
<p>Uses the simple-xmpp module - you may also need to pre-configure your xmpp settings as per below.</p>
|
||||
<p>Either add to your settings.js file...</p>
|
||||
<p><pre>xmpp : { jid : "yourid", password: "password" },</pre></p>
|
||||
<p>Or create a file xmppkeys.js containing</p>
|
||||
<p><pre>module.exports = { jid: "yourid", password: "password" }</pre></p>
|
||||
<p>This <b>must</b> be located in the directory above node-red.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
@ -16,10 +16,10 @@
|
||||
|
||||
var orig=console.warn;
|
||||
console.warn=(function() { // suppress warning from stringprep when not needed)
|
||||
var orig=console.warn;
|
||||
return function() {
|
||||
//orig.apply(console, arguments);
|
||||
};
|
||||
var orig=console.warn;
|
||||
return function() {
|
||||
//orig.apply(console, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||
@ -27,92 +27,96 @@ var xmpp = require('simple-xmpp');
|
||||
console.warn = orig;
|
||||
|
||||
try {
|
||||
var xmppkey = require(process.env.NODE_RED_HOME+"/settings").xmpp || require(process.env.NODE_RED_HOME+"/../xmppkeys.js");
|
||||
var xmppkey = require(process.env.NODE_RED_HOME+"/settings").xmpp || require(process.env.NODE_RED_HOME+"/../xmppkeys.js");
|
||||
} catch(err) {
|
||||
throw new Error("Failed to load XMPP credentials");
|
||||
throw new Error("Failed to load XMPP credentials");
|
||||
}
|
||||
|
||||
function XmppNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.server = n.server;
|
||||
this.port = n.port;
|
||||
this.join = n.join || false;
|
||||
this.nick = n.nick || "Node-RED";
|
||||
this.sendAll = n.sendObject;
|
||||
this.to = n.to || "";
|
||||
var node = this;
|
||||
RED.nodes.createNode(this,n);
|
||||
this.server = n.server;
|
||||
this.port = n.port;
|
||||
this.join = n.join || false;
|
||||
this.nick = n.nick || "Node-RED";
|
||||
this.sendAll = n.sendObject;
|
||||
this.to = n.to || "";
|
||||
var node = this;
|
||||
|
||||
setTimeout(function() {
|
||||
xmpp.connect({
|
||||
jid : xmppkey.jid,
|
||||
password : xmppkey.password,
|
||||
host : this.server,
|
||||
port : this.port,
|
||||
skipPresence : true,
|
||||
reconnect : false
|
||||
});
|
||||
}, 5000);
|
||||
setTimeout(function() {
|
||||
xmpp.connect({
|
||||
jid : xmppkey.jid,
|
||||
password : xmppkey.password,
|
||||
host : this.server,
|
||||
port : this.port,
|
||||
skipPresence : true,
|
||||
reconnect : false
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
xmpp.on('online', function() {
|
||||
node.log('connected to '+node.server);
|
||||
xmpp.setPresence('online', node.nick+' online');
|
||||
if (node.join) {
|
||||
xmpp.join(node.to+'/'+node.nick);
|
||||
}
|
||||
});
|
||||
xmpp.on('online', function() {
|
||||
node.log('connected to '+node.server);
|
||||
xmpp.setPresence('online', node.nick+' online');
|
||||
if (node.join) {
|
||||
xmpp.join(node.to+'/'+node.nick);
|
||||
}
|
||||
});
|
||||
|
||||
xmpp.on('chat', function(from, message) {
|
||||
var msg = { topic:from, payload:message };
|
||||
node.send([msg,null]);
|
||||
});
|
||||
xmpp.on('chat', function(from, message) {
|
||||
var msg = { topic:from, payload:message };
|
||||
node.send([msg,null]);
|
||||
});
|
||||
|
||||
xmpp.on('groupchat', function(conference, from, message, stamp) {
|
||||
var msg = { topic:from, payload:message, room:conference };
|
||||
if (from != node.nick) { node.send([msg,null]); }
|
||||
});
|
||||
xmpp.on('groupchat', function(conference, from, message, stamp) {
|
||||
var msg = { topic:from, payload:message, room:conference };
|
||||
if (from != node.nick) { node.send([msg,null]); }
|
||||
});
|
||||
|
||||
//xmpp.on('chatstate', function(from, state) {
|
||||
//console.log('%s is currently %s', from, state);
|
||||
//var msg = { topic:from, payload:state };
|
||||
//node.send([null,msg]);
|
||||
//});
|
||||
//xmpp.on('chatstate', function(from, state) {
|
||||
//console.log('%s is currently %s', from, state);
|
||||
//var msg = { topic:from, payload:state };
|
||||
//node.send([null,msg]);
|
||||
//});
|
||||
|
||||
xmpp.on('buddy', function(jid, state, statusText) {
|
||||
node.log(jid+" is "+state+" : "+statusText);
|
||||
var msg = { topic:jid, payload: { presence:state, status:statusText} };
|
||||
node.send([null,msg]);
|
||||
});
|
||||
xmpp.on('buddy', function(jid, state, statusText) {
|
||||
node.log(jid+" is "+state+" : "+statusText);
|
||||
var msg = { topic:jid, payload: { presence:state, status:statusText} };
|
||||
node.send([null,msg]);
|
||||
});
|
||||
|
||||
xmpp.on('error', function(err) {
|
||||
console.error(err);
|
||||
});
|
||||
xmpp.on('error', function(err) {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
xmpp.on('close', function(err) {
|
||||
node.log('connection closed');
|
||||
});
|
||||
xmpp.on('close', function(err) {
|
||||
node.log('connection closed');
|
||||
});
|
||||
|
||||
xmpp.on('subscribe', function(from) {
|
||||
xmpp.acceptSubscription(from);
|
||||
});
|
||||
xmpp.on('subscribe', function(from) {
|
||||
xmpp.acceptSubscription(from);
|
||||
});
|
||||
|
||||
this.on("input", function(msg) {
|
||||
var to = msg.topic;
|
||||
if (node.to != "") { to = node.to; }
|
||||
if (node.sendAll) {
|
||||
xmpp.send(to, JSON.stringify(msg), node.join);
|
||||
}
|
||||
else {
|
||||
xmpp.send(to, msg.payload, node.join);
|
||||
}
|
||||
});
|
||||
this.on("input", function(msg) {
|
||||
var to = msg.topic;
|
||||
if (node.to != "") { to = node.to; }
|
||||
if (node.sendAll) {
|
||||
xmpp.send(to, JSON.stringify(msg), node.join);
|
||||
}
|
||||
else {
|
||||
xmpp.send(to, msg.payload, node.join);
|
||||
}
|
||||
});
|
||||
|
||||
this.on("close", function() {
|
||||
xmpp.setPresence('offline');
|
||||
//xmpp.conn.end();
|
||||
// TODO - DCJ NOTE... this is not good. It leaves the connection up over a restart - which will end up with bad things happening...
|
||||
// (but requires the underlying xmpp lib to be fixed (which does have an open bug request on fixing the close method)).
|
||||
this.warn("Due to an underlying bug in the xmpp library this does not disconnect old sessions. This is bad... A restart would be better.");
|
||||
});
|
||||
this.on("close", function() {
|
||||
xmpp.setPresence('offline');
|
||||
try {
|
||||
xmpp.disconnect();
|
||||
// TODO - DCJ NOTE... this is not good. It leaves the connection up over a restart - which will end up with bad things happening...
|
||||
// (but requires the underlying xmpp lib to be fixed, which does have an open bug request on fixing the close method - and a work around.
|
||||
// see - https://github.com/simple-xmpp/node-simple-xmpp/issues/12 for the fix
|
||||
} catch(e) {
|
||||
this.warn("Due to an underlying bug in the xmpp library this does not disconnect old sessions. This is bad... A restart would be better.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("xmpp",XmppNode);
|
||||
|
Loading…
Reference in New Issue
Block a user