Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

start eliminating the 'rawStanza' event

  • Loading branch information...
commit e82b978792de7a128a9d5fbb675dade794d0a486 1 parent 0e44b82
Astro astro authored
2  lib/xmpp/bosh.js
View
@@ -62,7 +62,7 @@ BOSHConnection.prototype.processResponse = function(bodyEl) {
for(var i = 0; i < bodyEl.children.length; i++) {
var child = bodyEl.children[i];
if (child.name && child.attrs && child.children)
- this.emit('rawStanza', child);
+ this.emit('stanza', child);
}
}
};
24 lib/xmpp/c2s.js
View
@@ -55,21 +55,22 @@ function C2SStream(socket, server) {
var self = this;
this.authenticated = false;
this.server = server;
- Connection.Connection.call(this, socket);
+ this.connection = new Connection.Connection(socket);
+ this.connection.xmlns[''] = NS_CLIENT;
+ this.connection.xmppVersion = '1.0';
- this.xmlns[''] = NS_CLIENT;
- this.xmppVersion = '1.0';
-
- this.addListener('streamStart', function(streamAttrs) {
+ this.connection.addListener('streamStart', function(streamAttrs) {
+ console.log("C2SStream <<", streamAttrs);
this.domain = streamAttrs.to;
self.startStream(streamAttrs);
});
- this.addListener('rawStanza', function(stanza) {
- self.onRawStanza(stanza);
+ this.connection.addListener('stanza', function(stanza) {
+ console.log("C2SStream <<", stanza.toString());
+ self.onStanza(stanza);
});
- this.socket.addListener('end', function() {
+ this.connection.addListener('end', function() {
self.emit('end');
});
@@ -78,6 +79,11 @@ function C2SStream(socket, server) {
util.inherits(C2SStream, Connection.Connection);
exports.C2SStream = C2SStream;
+C2SStream.prototype.send = function(stanza) {
+ console.log("C2SStream >>", stanza.root().toString());
+ this.connection.send(stanza);
+};
+
C2SStream.prototype.startStream = function(streamAttrs) {
var attrs = {};
for(var k in this.xmlns) {
@@ -129,7 +135,7 @@ C2SStream.prototype.sendFeatures = function() {
this.send(features);
};
-C2SStream.prototype.onRawStanza = function(stanza) {
+C2SStream.prototype.onStanza = function(stanza) {
var bind, session;
if (this.jid) {
10 lib/xmpp/client.js
View
@@ -82,7 +82,7 @@ function Client(params) {
if (params.host) {
self.connection.socket.connect(params.port || 5222, params.host);
- self.connection.socket.on('connect', function() {
+ self.connection.on('connect', function() {
self.connection.startStream();
});
} else if (!SRV) {
@@ -105,7 +105,7 @@ function Client(params) {
this.connection.xmlns[''] = NS_CLIENT;
this.connection.xmppVersion = "1.0";
this.connection.streamTo = this.jid.domain;
- this.connection.addListener('rawStanza', this.onRawStanza.bind(this));
+ this.connection.addListener('stanza', this.onStanza.bind(this));
this.connection.addListener('end', function() {
self.state = STATE_PREAUTH;
@@ -124,7 +124,7 @@ Client.prototype.end = function() {
this.connection.end();
};
-Client.prototype.onRawStanza = function(stanza) {
+Client.prototype.onStanza = function(stanza) {
/* Actually, we shouldn't wait for <stream:features/> if
this.streamAttrs.version is missing, but who uses pre-XMPP-1.0
these days anyway? */
@@ -262,7 +262,7 @@ Client.prototype.doRegister = function() {
var that = this;
var onReply = function(reply) {
if (reply.is('iq') && reply.attrs.id === id) {
- that.removeListener('rawStanza', onReply);
+ that.removeListener('stanza', onReply);
if (reply.attrs.type === 'result') {
/* Registration successful, proceed to auth */
@@ -272,7 +272,7 @@ Client.prototype.doRegister = function() {
}
}
};
- this.on('rawStanza', onReply);
+ this.on('stanza', onReply);
};
var decode64, encode64, Buffer;
7 lib/xmpp/component.js
View
@@ -17,6 +17,7 @@ var NS_COMPONENT = 'jabber:component:accept';
*/
function Component(params) {
var self = this;
+ // TODO: don't inherit, compose!
Connection.Connection.call(this);
if (typeof params.jid == 'string')
@@ -30,8 +31,8 @@ function Component(params) {
this.addListener('streamStart', function(streamAttrs) {
self.onStreamStart(streamAttrs);
});
- this.addListener('rawStanza', function(stanza) {
- self.onRawStanza(stanza);
+ this.addListener('stanza', function(stanza) {
+ self.onStanza(stanza);
});
var connect = function() {
@@ -56,7 +57,7 @@ Component.prototype.onStreamStart = function(streamAttrs) {
this.send(new ltx.Element('handshake').t(digest));
};
-Component.prototype.onRawStanza = function(stanza) {
+Component.prototype.onStanza = function(stanza) {
if (stanza.is('handshake')) {
this.emit('online');
} else {
21 lib/xmpp/connection.js
View
@@ -13,10 +13,6 @@ var NS_XMPP_STREAMS = 'urn:ietf:params:xml:ns:xmpp-streams';
Base class for connection-based streams.
The socket parameter is optional for incoming connections.
-
- A note on events: this base class will emit 'rawStanza' and leaves
- 'stanza' to Client & Component. Therefore we won't confuse the
- user with stanzas before authentication has finished.
*/
var MAX_RECONNECT_DELAY = 30 * 1000;
@@ -33,8 +29,13 @@ function Connection(socket) {
this.setupStream();
if (this.socket.readable)
this.startParser();
- else
- this.socket.on('connect', this.startParser.bind(this));
+ else {
+ var that = this;
+ this.socket.on('connect', function() {
+ that.startParser();
+ that.emit('connect');
+ });
+ }
this.mixins = [];
}
@@ -119,10 +120,12 @@ Connection.prototype.send = function(stanza) {
};
Connection.prototype.startParser = function() {
+console.log("Connection startParser")
var self = this;
this.parser = new StreamParser.StreamParser(this.maxStanzaSize);
- this.parser.addListener('start', function(attrs) {
+ this.parser.addListener('streamStart', function(attrs) {
+console.log("Connection streamStart", attrs)
self.streamAttrs = attrs;
/* We need those xmlns often, store them extra */
self.streamNsAttrs = {};
@@ -219,7 +222,7 @@ Connection.prototype.setSecure = function(credentials, isServer) {
/**
* This is not an event listener, but takes care of the TLS handshake
- * before 'rawStanza' events are emitted to the derived classes.
+ * before 'stanza' events are emitted to the derived classes.
*/
Connection.prototype.onStanza = function(stanza) {
if (stanza.is('error', NS_STREAM)) {
@@ -236,7 +239,7 @@ Connection.prototype.onStanza = function(stanza) {
/* Server is waiting for TLS handshake */
this.setSecure();
} else {
- this.emit('rawStanza', stanza);
+ this.emit('stanza', stanza);
}
};
2  lib/xmpp/websockets.js
View
@@ -83,7 +83,7 @@ WSConnection.prototype.onStanza = function(stanza) {
/* TODO: extract error text */
this.emit('error', stanza);
} else {
- this.emit('rawStanza', stanza);
+ this.emit('stanza', stanza);
}
};
2  test/tcp-test.js
View
@@ -46,6 +46,8 @@ describe("TCP client/server", function() {
});
});
+ // registering client
+
/*'client fails login': "pending",
'auto reconnect': "pending"*/
Please sign in to comment.
Something went wrong with that request. Please try again.