From 5da3ec3a1740246f77adf04393a10afe18b23a49 Mon Sep 17 00:00:00 2001 From: Matthieu Lalonde Date: Wed, 4 Aug 2010 23:51:39 +0200 Subject: [PATCH] battle with presences --- lib/xmpp-client/client.js | 6 +++++- test/test.js | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/xmpp-client/client.js b/lib/xmpp-client/client.js index 03bc3c6..f003b76 100644 --- a/lib/xmpp-client/client.js +++ b/lib/xmpp-client/client.js @@ -25,6 +25,7 @@ var Client = function(_jid, password, host) { this.rooms = {}; this._iq = 0; this._iqCallback = {}; + this.presences = {}; this.roster = {}; this.xmpp = new xmpp.Client({ host: this.host, @@ -57,7 +58,7 @@ var Client = function(_jid, password, host) { if(fromm[1] == 'conference.' + this.jid.domain) { jabber.rooms[fromm[0]].emit('presence', stanza); } else { - jabber.emit('presence', stanza); + jabber.emit('presence', stanza.attrs.from, stanza); } } if(stanza.name == 'message') { @@ -85,6 +86,9 @@ var Client = function(_jid, password, host) { this.addListener('iqResult', function(id, stanza){ jabber._iqCallback[id].call(jabber, stanza); }); + this.addListener('presence', function(from, stanza) { + jabber.presences[from] = stanza.attrs.type; + }); }; sys.inherits(Client, events.EventEmitter); diff --git a/test/test.js b/test/test.js index 02d4a0d..de48308 100644 --- a/test/test.js +++ b/test/test.js @@ -38,6 +38,8 @@ exports.testClient = function(test) { var a = new Client(conf.a.jid, conf.a.password); a.addListener('online', function() { sys.debug('a is connected'.green); + sys.debug('a presences : ' + JSON.stringify(a.presences).green); +// test.equals('available', a.presences['' + b.jid]); test.ok(true); a.message(conf.b.jid, MESSAGE); });