Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add c2s support #30

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
112 changes: 16 additions & 96 deletions examples/c2s.js
@@ -1,119 +1,39 @@
var xmpp = require('../lib/node-xmpp'); var xmpp = require('../lib/node-xmpp');
var SoftwareVersion = require('./c2s_mods/software_version');


/* /* This is a very basic C2S example. One of the key design decisions of node-xmpp is to keep it very lightweight */
* TODO /* If you need a full blown server check out https://github.com/superfeedr/xmpp-server */
* - support for Presence module
* - Support for TLS () : https://groups.google.com/group/nodejs/browse_thread/thread/1e8e6501493d63b8#
* - Admin tools
* - Component interface
* - Plugins for 'well-known' services (Roster, PubSub, PEP)
* - Logging
* - Shapers
* - In-band registration
* - mods :
* - presence
* - offline
* - announce
* - caps
* - muc
* - roster
* - PEP
*/


// Sets up the server. // Sets up the server.
var c2s = new xmpp.C2S({ var c2s = new xmpp.C2S({
port: 5222, port: 5222,
domain: 'localhost', domain: 'localhost'//,
tls: { // tls: {
keyPath: './examples/localhost-key.pem', // keyPath: './examples/localhost-key.pem',
certPath: './examples/localhost-cert.pem' // certPath: './examples/localhost-cert.pem'
} // }

}); });


// Allows the developer to authenticate users against anything they want. // Allows the developer to authenticate users against anything they want.
c2s.on("authenticate", function(jid, password, client) { c2s.on("authenticate", function(jid, password, client, cb) {
if(password == "password") { cb(true); // cb(false);
client.emit("auth-success", jid); });
}
else { // Allows the developer to register the jid against anything they want
client.emit("auth-fail", jid); c2s.on("register", function(jid, password, client, cb) {
} cb(true); // cb(false, {code: "406", type: "modify", text: "not-acceptable"});
}); });


// On Connect event. When a client connects. // On Connect event. When a client connects.
c2s.on("connect", function(client) { c2s.on("connect", function(client) {
// That's the way you add mods to a given server. // That's the way you add mods to a given server.
SoftwareVersion.name = "Node XMPP server example";
SoftwareVersion.version = "0.0.0.1";
SoftwareVersion.os = "Mac OS X 10.7 Lion";
client.addMixin(SoftwareVersion.mod);
}); });


// On Disconnect event. When a client disconnects // On Disconnect event. When a client disconnects
c2s.on("disconnect", function(client) { c2s.on("disconnect", function(client) {

}); });


// Most imoortant pieces of code : that is where you can configure your XMPP server to support only what you care about/need. // Most imoortant pieces of code : that is where you can configure your XMPP server to support only what you care about/need.
c2s.on("stanza", function(stanza, client) { c2s.on("stanza", function(stanza, client) {
var query, vCard;
// We should provide a bunch of "plugins" for the functionalities below.

// No roster support in this server!
if (stanza.is('iq') && (session = stanza.getChild('query', 'jabber:iq:roster'))) {
stanza.attrs.type = "error";
stanza.attrs.to = stanza.attrs.from;
delete stanza.attrs.from;
client.send(stanza);
}
// No private support on this server
else if (stanza.is('iq') && (query = stanza.getChild('query', "jabber:iq:private"))) {
stanza.attrs.type = "error";
stanza.attrs.to = stanza.attrs.from;
delete stanza.attrs.from;
client.send(stanza);
}
// No vCard support on this server.
else if (stanza.is('iq') && (vCard = stanza.getChild('vCard', "vcard-temp"))) {
stanza.attrs.type = "error";
stanza.attrs.to = stanza.attrs.from;
delete stanza.attrs.from;
client.send(stanza);
}
// No DiscoInfo on this server.
else if (stanza.is('iq') && (query = stanza.getChild('query', "http://jabber.org/protocol/disco#info"))) {
stanza.attrs.type = "error";
stanza.attrs.to = stanza.attrs.from;
delete stanza.attrs.from;
client.send(stanza);
}
// No Version support on this server.
else {

}
})




// You can also decide to rewrite many things, like for example the way you route stanzas. });
// This will allow for clustering for your node-xmpp server, using redis's PubSub feature.
// To run this example in its full "power", just run node exmaple c2s.js from 2 different machines, as long as they share the redis server, they should be able to communicate!
// var sys = require("sys");
// var redis = require("redis-node");
// var redispub = redis.createClient();
// var redissub = redis.createClient();
//
// xmpp.C2S.prototype.route = function(stanza) {
// var self = this;
// if(stanza.attrs && stanza.attrs.to) {
// var toJid = new xmpp.JID(stanza.attrs.to);
// redispub.publish(toJid.bare().toString(), stanza.toString());
// }
// }
// xmpp.C2S.prototype.registerRoute = function(jid, client) {
// redissub.subscribeTo(jid.bare().toString(), function(channel, stanza, pattern) {
// client.send(stanza);
// });
// return true;
// }
46 changes: 0 additions & 46 deletions examples/c2s_mods/software_version.js

This file was deleted.

13 changes: 0 additions & 13 deletions examples/localhost-cert.pem

This file was deleted.

11 changes: 0 additions & 11 deletions examples/localhost-csr.pem

This file was deleted.

15 changes: 0 additions & 15 deletions examples/localhost-key.pem

This file was deleted.