Permalink
Browse files

c2s: don't emit events on server but on connection

  • Loading branch information...
1 parent 2ab0164 commit 21e91a0e8324dee85d2e2e8f9b8433627dda158d @astro astro committed Nov 3, 2011
Showing with 20 additions and 26 deletions.
  1. +18 −19 examples/c2s.js
  2. +2 −7 lib/xmpp/c2s.js
View
37 examples/c2s.js
@@ -14,30 +14,29 @@ var c2s = new xmpp.C2SServer({
});
-// Allows the developer to authenticate users against anything they want.
-c2s.on("authenticate", function(jid, password, client, cb) {
- cb(true); // cb(false);
-});
-
-// Allows the developer to register the jid against anything they want
-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.
c2s.on("connect", function(client) {
// That's the way you add mods to a given server.
- // Per-client stanza handling, alternative to c2s.on("stanza", cb)
- client.on("stanza", function(stanza) {
+ // Allows the developer to register the jid against anything they want
+ c2s.on("register", function(opts, cb) {
+ cb(true);
});
-});
-// On Disconnect event. When a client disconnects
-c2s.on("disconnect", function(client) {
-});
+ // Allows the developer to authenticate users against anything they want.
+ client.on("authenticate", function(opts, cb) {
+ cb(null); // cb(false);
+ });
+ client.on("online", function() {
+ client.send(new xmpp.Message({ type: 'chat' }).c('body').t("Hello there, little client."));
+ });
-// 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) {
+ // Stanza handling
+ client.on("stanza", function(stanza) {
+ });
-});
+ // On Disconnect event. When a client disconnects
+ client.on("disconnect", function(client) {
+ });
+
+});
View
9 lib/xmpp/c2s.js
@@ -70,14 +70,9 @@ function C2SStream(socket, server) {
// We need to remove this user's connection, if authed:
if (self.jid) {
self.emit("disconnect", self);
- self.server.emit("disconnect", self);
}
});
- this.addListener('outStanza', function(stanza) {
- self.send(stanza);
- });
-
return self;
};
util.inherits(C2SStream, Connection.Connection);
@@ -162,15 +157,15 @@ C2SStream.prototype.onRawStanza = function(stanza) {
}
else {
if (this.authenticated) {
- this.server.emit('inStanza', this, stanza); // We make the distinction between inStanza (coming from the C2SStream), and outStanza (going to the C2SStream)
+ this.emit('stanza', stanza); // We make the distinction between inStanza (coming from the C2SStream), and outStanza (going to the C2SStream)
}
}
};
C2SStream.prototype.authenticate = function(username, password) {
var self = this;
var jid = new JID(username, this.server.options.domain);
- this.server.emit('authenticate', { jid: jid, username: username, password: password, client: this },
+ this.emit('authenticate', { jid: jid, username: username, password: password, client: this },
function(error) {
if (!error) {
self.emit('auth-success', jid);

0 comments on commit 21e91a0

Please sign in to comment.