1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

better filtering for XMPP messages, stop history when joining rooms

This commit is contained in:
Dave Conway-Jones 2018-09-28 21:42:36 +01:00
parent b856ee6439
commit 7bd255a341
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
3 changed files with 27 additions and 7 deletions

View File

@ -1,7 +1,7 @@
<script type="text/x-red" data-template-name="xmpp in">
<div class="form-row">
<label for="node-input-server"><i class="fa fa-bookmark"></i> Server</label>
<label for="node-input-server"><i class="fa fa-bookmark"></i> Connect as</label>
<input type="text" id="node-input-server">
</div>
<div class="form-row">
@ -50,7 +50,7 @@
<script type="text/x-red" data-template-name="xmpp out">
<div class="form-row">
<label for="node-input-server"><i class="fa fa-bookmark"></i> Server</label>
<label for="node-input-server"><i class="fa fa-bookmark"></i> Connect as</label>
<input type="text" id="node-input-server">
</div>
<div class="form-row">

View File

@ -78,18 +78,32 @@ module.exports = function(RED) {
xmpp.on('online', function(data) {
node.status({fill:"green",shape:"dot",text:"connected"});
if ((node.join) && (node.from !== "")) {
xmpp.join(node.to+'/'+node.nick);
// disable chat history
var to = node.to+'/'+node.nick;
var stanza = new xmpp.Element('presence', {"to": to}).
c('x', { xmlns: 'http://jabber.org/protocol/muc' }).
c('history', { maxstanzas:0, seconds:1 });
xmpp.conn.send(stanza);
xmpp.join(to);
}
});
xmpp.on('chat', function(from, message) {
var msg = { topic:from, payload:message };
node.send([msg,null]);
if (!node.join && ((node.from === "") || (node.from === from))) {
node.send([msg,null]);
}
});
xmpp.on('groupchat', function(conference, from, message, stamp) {
if (!stamp) {stamp = Date.now(); }
//else { console.log("STAMP",stamp) }
var msg = { topic:from, payload:message, room:conference, ts:stamp };
if (from != node.nick) { node.send([msg,null]); }
if (from != node.nick) {
if ((node.join) && (node.from === conference)) {
node.send([msg,null]);
}
}
});
//xmpp.on('chatstate', function(from, state) {
@ -170,7 +184,13 @@ module.exports = function(RED) {
xmpp.on('online', function(data) {
node.status({fill:"green",shape:"dot",text:"connected"});
if ((node.join) && (node.from !== "")) {
xmpp.join(node.to+'/'+node.nick);
// disable chat history
var to = node.to+'/'+node.nick;
var stanza = new xmpp.Element('presence', {"to": to}).
c('x', { xmlns: 'http://jabber.org/protocol/muc' }).
c('history', { maxstanzas:0, seconds:1 });
xmpp.conn.send(stanza);
xmpp.join(to);
}
});

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-xmpp",
"version" : "0.2.0",
"version" : "0.2.1",
"description" : "A Node-RED node to talk to an XMPP server",
"dependencies" : {
"simple-xmpp" : "^1.3.0"