-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmpp.js
executable file
·52 lines (43 loc) · 1.26 KB
/
xmpp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var xmpp = require('./node_modules/simple-xmpp/lib/simple-xmpp.js');
var argv = process.argv;
var mongoose = require('mongoose');
// Models
var Chat = require('./app/models/chat');
// Connect to the mongo database
mongoose.connect("localhost:27017");
var options = {
jid: argv[2],
password: argv[3],
host: argv[4],
nick: argv[2].substr(0, argv[2].indexOf('@')),
};
xmpp.on('online', function (data) {
console.log('Yes, I\'m connected! ' + 'general@' + options.host + '/' + options.nick);
xmpp.join('[email protected]/' + options.nick);
});
xmpp.on('subscribe', function (from) {
console.log(from);
});
xmpp.on('groupchat', function (conference, from, message, stamp) {
console.log('%s says %s on %s', from, message, conference);
// Record all the records in the DB.
var chat = new Chat();
chat.name = from;
chat.message = message;
chat.conference = conference;
chat.save(function(err) {
if (err) {
console.log(err);
}
console.log('\t Chat record saved!');
});
});
xmpp.on('error', function (err) {
console.error(err);
});
xmpp.connect({
jid: options.jid,
password: options.password,
host: options.host,
port: 5222
});