mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Move nodes over from main repo
This commit is contained in:
80
social/xmpp/92-xmpp.html
Normal file
80
social/xmpp/92-xmpp.html
Normal file
@@ -0,0 +1,80 @@
|
||||
<!--
|
||||
Copyright 2013 IBM Corp.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<script type="text/x-red" data-template-name="xmpp">
|
||||
<div class="form-row">
|
||||
<label for="node-input-server"><i class="icon-bookmark"></i> Server</label>
|
||||
<input type="text" id="node-input-server" placeholder="talk.google.com" style="width: 40%;" >
|
||||
<label for="node-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
|
||||
<input type="text" id="node-input-port" placeholder="Port" style="width:45px">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label> </label>
|
||||
<input type="checkbox" id="node-input-sendObject" placeholder="" style="display: inline-block; width: auto; vertical-align: top;">
|
||||
<label for="node-input-sendObject" style="width: 70%;">Send complete msg object ?</label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-to"><i class="icon-envelope"></i> To</label>
|
||||
<input type="text" id="node-input-to" placeholder="joe@gmail.com">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label> </label>
|
||||
<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>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-nick"><i class="icon-user"></i> Nickname</label>
|
||||
<input type="text" id="node-input-nick" placeholder="Joe">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips">The <b>To</b> field is optional. If not set uses the <b>msg.topic</b> property of the message.</div>
|
||||
</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>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xmpp',{
|
||||
category: 'advanced-function',
|
||||
color:"Silver",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
server: { value:"",required:true},
|
||||
port: {value:5222,required:true},
|
||||
to: {value:""},
|
||||
join: {value:false},
|
||||
sendObject: {value:false},
|
||||
nick: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:2,
|
||||
icon: "xmpp.png",
|
||||
label: function() {
|
||||
return this.name||this.server||"xmpp";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return (this.name||!this.server)?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
</script>
|
118
social/xmpp/92-xmpp.js
Normal file
118
social/xmpp/92-xmpp.js
Normal file
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Copyright 2013 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
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 RED = require("../../red/red");
|
||||
var xmpp = require('simple-xmpp');
|
||||
console.warn = orig;
|
||||
|
||||
try {
|
||||
var xmppkey = require("../../settings").xmpp || require("../../../xmppkeys.js");
|
||||
} catch(err) {
|
||||
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;
|
||||
|
||||
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('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('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('error', function(err) {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
xmpp.on('close', function(err) {
|
||||
node.log('connection closed');
|
||||
});
|
||||
|
||||
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("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.");
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("xmpp",XmppNode);
|
BIN
social/xmpp/icons/xmpp.png
Normal file
BIN
social/xmpp/icons/xmpp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Reference in New Issue
Block a user