1
0
Fork 0

basic roster

master
Matthieu Lalonde 15 years ago committed by Mathieu Lecarme
parent 5da3ec3a17
commit d36115bc76

@ -74,9 +74,7 @@ var Client = function(_jid, password, host) {
this.xmpp.addListener('online', function() { this.xmpp.addListener('online', function() {
jabber._debug("[Info] xmpp connection"); jabber._debug("[Info] xmpp connection");
jabber.presence(); jabber.presence();
jabber.iq(new xmpp.Element('query', {xmlns: 'jabber:iq:roster'}), function(iq) { jabber.askForRoster();
jabber._debug("MY ROSTER" + iq);
});
jabber.emit('online'); jabber.emit('online');
}); });
this.addListener('groupchat', function(from, stanza) { this.addListener('groupchat', function(from, stanza) {
@ -108,6 +106,19 @@ Client.prototype.message = function(to, message) {
t(message)); t(message));
}; };
Client.prototype.askForRoster = function() {
var jabber = this;
this.iq(new xmpp.Element('query', {xmlns: 'jabber:iq:roster'}), function(iq) {
iq.getChild('query', 'jabber:iq:roster').children.forEach(function(child) {
jabber.roster[child.attrs.jid] = {
name: child.attrs.name,
subscription: child.attrs.subscription};
});
jabber._debug("ROSTER : " + JSON.stringify(jabber.roster));
jabber.emit('roster', iq);
});
};
Client.prototype.iq = function(iq, callback) { Client.prototype.iq = function(iq, callback) {
var n = this._iq++; var n = this._iq++;
this._iqCallback[n] = callback; this._iqCallback[n] = callback;

Loading…
Cancel
Save