1
0
Fork 0
master
Matthieu Lalonde 14 years ago committed by Mathieu Lecarme
parent 112a8e6302
commit 8ce3836be9

@ -1,2 +1,3 @@
exports.BasicClient = require('./xmpp-client/basic-client').BasicClient;
exports.Client = require('./xmpp-client/client').Client;
exports.Jid = require('./xmpp-client/client').Jid;

@ -11,6 +11,8 @@ var sys = require('sys'),
var BasicClient = function(params, callback) {
events.EventEmitter.call(this);
this._iq = 0;
this._iqCallback = {};
this._iqHandler = {};
var jabber = this;
this.jid = new xmpp.JID(params.jid);
this.host = (params.host == null) ? this.jid.domain : params.host;
@ -38,6 +40,12 @@ var BasicClient = function(params, callback) {
break;
default:
jabber.emit('iq', stanza);
var q = stanza.getChild('query');
if(q.attrs.xmlns != null && jabber._iqHandler[q.attrs.xmlns] != null) {
jabber._iqHandler[q.attrs.xmlns].call(jabber, stanza);
} else {
jabber.emit('iq:unknow', stanza);
}
break;
}
break;
@ -53,7 +61,6 @@ var BasicClient = function(params, callback) {
break;
}
});
this._iqCallback = {};
this.xmpp.addListener('online', function() {
callback.apply(jabber);
});
@ -87,3 +94,7 @@ BasicClient.prototype.iq = function(to, query, callback, error) {
this.xmpp.send(new xmpp.Element('iq', attrs).cnode(query).tree());
return n;
};
BasicClient.prototype.registerIqHandler = function(xmlns, action) {
this._iqHandler[xmlns] = action;
};

@ -8,7 +8,6 @@ var sys = require('sys'),
exports.testInit = function(test) {
test.expect(1);
var b = new BasicClient(conf.b, function() {
sys.debug('just connected');
test.ok(true, 'connected');
test.done();
});
@ -19,9 +18,29 @@ exports.testIq = function(test) {
new BasicClient(conf.b, function() {
this.iq(null, new xmpp.Element('query', {xmlns: 'jabber:iq:roster'}), function(iq) {
var roster = iq.getChild('query', 'jabber:iq:roster').getChildren('item');
sys.debug(roster);
//sys.debug(roster);
test.notEqual(null, roster, 'roster');
test.done();
});
});
};
exports.testPresence = function(test) {
test.expect(1);
var b = new BasicClient(conf.b, function() {
this.addListener('presence', function(presence) {
//sys.debug(presence.attrs.from.split('/')[0].red);
if(presence.attrs.from.split('/')[0] == conf.a.jid) {
test.ok(true, "B is present");
test.done();
}
});
var a = new BasicClient(conf.a, function() {
this.addListener('presence', function(presence) {
//sys.debug(presence.toString().yellow);
});
this.presence();
b.presence();
});
});
};
Loading…
Cancel
Save