forked from xmppjs/xmpp.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c2s.js
48 lines (38 loc) · 1.42 KB
/
c2s.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
var xmpp = require('../lib/node-xmpp');
/* This is a very basic C2S server example. One of the key design decisions of node-xmpp is to keep it very lightweight */
/* If you need a full blown server check out https://github.com/superfeedr/xmpp-server */
// Sets up the server.
var c2s = new xmpp.C2SServer({
port: 5222,
domain: 'localhost'//,
// tls: {
// keyPath: './examples/localhost-key.pem',
// certPath: './examples/localhost-cert.pem'
// }
});
// On Connect event. When a client connects.
c2s.on("connect", function(client) {
// That's the way you add mods to a given server.
// Allows the developer to register the jid against anything they want
c2s.on("register", function(opts, cb) {
console.log("REGISTER");
cb(true);
});
// Allows the developer to authenticate users against anything they want.
client.on("authenticate", function(opts, cb) {
console.log("AUTH" + opts.jid + " -> " +opts.password);
cb(null); // cb(false);
});
client.on("online", function() {
console.log("ONLINE");
client.send(new xmpp.Message({ type: 'chat' }).c('body').t("Hello there, little client."));
});
// Stanza handling
client.on("stanza", function(stanza) {
console.log("STANZA" + stanza);
});
// On Disconnect event. When a client disconnects
client.on("disconnect", function(client) {
console.log("DISCONNECT");
});
});