1
0
Fork 0
master
Matthieu Lalonde 14 years ago committed by Mathieu Lecarme
parent 2ad8122354
commit 96abbdcb86

@ -12,6 +12,7 @@ var Client = function(params, callback) {
this.host = (params.host == null) ? this.jid.domain : params.host;
this.rooms = {};
this._iq = 0;
this._iqHandler = {};
this._iqCallback = {};
this.presences = {};
this.roster = {};
@ -36,6 +37,12 @@ var Client = function(params, callback) {
} else {
jabber._debug(('IQ: ' + stanza)[jabber.color]);
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);
}
}
}
if(stanza.name == 'presence') {
@ -72,11 +79,11 @@ var Client = function(params, callback) {
jabber.emit('online');
jabber.askForRoster(function(roster) {
jabber._debug("ROSTER : "[jabber.color] + JSON.stringify(roster));
});
if(callback != null) {
callback.call(jabber);
}
});
});
this.addListener('groupchat', function(from, stanza) {
fromName = from.split('@')[0];
jabber.rooms[fromName].emit('message', stanza);
@ -95,10 +102,7 @@ var Client = function(params, callback) {
jabber.presences[from] = stanza.attrs.type;
}
});
this.addListener('iq', function(stanza) {
sys.debug(stanza.getChild('query').toString().yellow);
var query = stanza.getChild('query', 'http://jabber.org/protocol/disco#info');
if(query != null) {
this.registerIqHandler('http://jabber.org/protocol/disco#info', function(stanza) {
sys.debug((stanza.attrs.from + " wont to disco!")[jabber.color]);
jabber.resultIq(stanza, new xmpp.Element('query', {xmlns: 'http://jabber.org/protocol/disco#info'})
.c('feature', {'var': 'http://jabber.org/protocol/disco#info'}).up()
@ -111,25 +115,25 @@ var Client = function(params, callback) {
}).up()
.tree()
);
}
query = stanza.getChild('query', 'jabber:iq:last');
if(query != null) {
});
this.registerIqHandler('jabber:iq:last', function(stanza) {
sys.debug((stanza.attrs.from + ' wonts last')[jabber.color]);
//[FIXME] giving a good last time
jabber.resultIq(stanza, new xmpp.Element('query', {
xmlns: 'jabber:iq:last', seconds:'1'})
.tree()
);
}
query = stanza.getChild('query', 'jabber:iq:version');
if(query != null) {
});
this.registerIqHandler('jabber:iq:version', function(stanza) {
jabber.resultIq(stanza, new xmpp.Element('query', {xmlns:'jabber:iq:version'})
.c('name').t('node-xmpp-client').up()
.c('version').t('0.0.1').up()
.c('os').t('mac').up()
.tree()
);
}
});
this.addListener('iq', function(stanza) {
sys.debug(stanza.getChild('query').toString().yellow);
});
};
@ -142,6 +146,10 @@ Client.prototype._debug = function(txt) {
}
};
Client.prototype.registerIqHandler = function(xmlns, action) {
this._iqHandler[xmlns] = action;
};
Client.prototype.message = function(to, message) {
this.xmpp.send(new xmpp.Element('message', {
to: to,

@ -57,6 +57,7 @@ exports.testRoom = function(test) {
sys.debug('a is connected'.green);
var a_room = a.room(ROOM, function(status) {
sys.debug(status);
sys.debug(this.role);
test.done();
});
});

Loading…
Cancel
Save