From 2ad812235414901d0e132b7443ee1b7a35ea5b60 Mon Sep 17 00:00:00 2001 From: Matthieu Lalonde Date: Sat, 7 Aug 2010 22:19:46 +0200 Subject: [PATCH] event and callback for roster --- lib/xmpp-client/client.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/xmpp-client/client.js b/lib/xmpp-client/client.js index dd2956a..81121ab 100644 --- a/lib/xmpp-client/client.js +++ b/lib/xmpp-client/client.js @@ -70,7 +70,9 @@ var Client = function(params, callback) { jabber._debug("[Info] xmpp connection"); jabber.presence(); jabber.emit('online'); - jabber.askForRoster(); + jabber.askForRoster(function(roster) { + jabber._debug("ROSTER : "[jabber.color] + JSON.stringify(roster)); + }); if(callback != null) { callback.call(jabber); } @@ -121,11 +123,6 @@ var Client = function(params, callback) { } query = stanza.getChild('query', 'jabber:iq:version'); if(query != null) { - /* - Exodus - 0.7.0.4 - Windows-XP 5.01.2600 - */ 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() @@ -153,7 +150,7 @@ Client.prototype.message = function(to, message) { t(message)); }; -Client.prototype.askForRoster = function() { +Client.prototype.askForRoster = function(callback) { 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) { @@ -161,8 +158,10 @@ Client.prototype.askForRoster = function() { name: child.attrs.name, subscription: child.attrs.subscription}; }); - jabber._debug("ROSTER : "[jabber.color] + JSON.stringify(jabber.roster)); - jabber.emit('roster', iq); + if(callback != null) { + callback.call(jabber, jabber.roster); + } + jabber.emit('roster', jabber.roster); }); };