From 2e4be0d8d28dc20c2ed9612699344accc4f243e4 Mon Sep 17 00:00:00 2001 From: Matthieu Lalonde Date: Sat, 7 Aug 2010 19:31:24 +0200 Subject: [PATCH] muc --- lib/xmpp-client/client.js | 60 +++++++++++++++++++++++++++++++++++++-- test/test.js | 18 +++++++++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/lib/xmpp-client/client.js b/lib/xmpp-client/client.js index c2312c9..6b6d0e9 100644 --- a/lib/xmpp-client/client.js +++ b/lib/xmpp-client/client.js @@ -34,7 +34,7 @@ var Client = function(params) { jabber._debug('IQ result: ' + stanza); jabber.emit('iqResult', stanza.attrs.id, stanza); } else { - jabber._debug('IQ: ' + stanza); + jabber._debug(('IQ: ' + stanza)[jabber.color]); jabber.emit('iq', stanza); } } @@ -59,8 +59,8 @@ var Client = function(params) { this.xmpp.addListener('online', function() { jabber._debug("[Info] xmpp connection"); jabber.presence(); - jabber.askForRoster(); jabber.emit('online'); + jabber.askForRoster(); }); this.addListener('groupchat', function(from, stanza) { fromName = from.split('@')[0]; @@ -73,6 +73,7 @@ var Client = function(params) { 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) { sys.debug((stanza.attrs.from + " wont to disco!")[jabber.color]); @@ -88,6 +89,29 @@ var Client = function(params) { .tree() ); } + query = stanza.getChild('query', 'jabber:iq:last'); + if(query != null) { + 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) { + /* + 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() + .c('os').t('mac').up() + .tree() + ); + } }); }; @@ -140,6 +164,13 @@ Client.prototype.presence = function(type) { this.xmpp.send(new xmpp.Element('presence', (type != null) ? {type: type} : {}).tree()); }; +Client.prototype.room = function(name) { + if(this.rooms[name] == null) { + this.rooms[name] = new Room(this, name); + } + return this.rooms[name]; +}; + Client.prototype.disconnect = function() { this.xmpp.send(new xmpp.Element('presence', {type: 'unavailable'}) .c('status') @@ -152,3 +183,28 @@ Client.prototype.disconnect = function() { this.xmpp.end(); sys.debug("disconnect from XMPP"); }; + +var Room = function(client, room) { + events.EventEmitter.call(this); + this.client = client; + this.room = room; + this.presence(); +}; + +sys.inherits(Room, events.EventEmitter); + +exports.Room = Room; + +Room.prototype.presence = function() { + this.client.xmpp.send(new xmpp.Element('presence', { + to: this.room + '@conference.' + this.client.jid.domain + '/' + this.client.jid.user + }) + .c('priority').t("5").up() + .c('x', {xmlns:"http://jabber.org/protocol/muc"}) + .tree() + ); +}; + +Room.prototype.message = function(msg) { + +}; \ No newline at end of file diff --git a/test/test.js b/test/test.js index ea35fba..70324ba 100644 --- a/test/test.js +++ b/test/test.js @@ -22,7 +22,7 @@ exports.testClientInit = function(test) { test.equals('gtalk.com', c.host); test.done(); }; - +/* exports.testClient = function(test) { test.expect(3); var MESSAGE = "Beuha de test!"; @@ -45,6 +45,22 @@ exports.testClient = function(test) { }); }); }; +*/ + +exports.testRoom = function(test) { + var ROOM = 'mushroom@conference.' + conf.b.jid.split('@')[1]; + var b = new Client(conf.b); + b.addListener('online', function() { + sys.debug('b is connected'.red); + var b_room = b.room(ROOM); + var a = new Client(conf.a); + a.addListener('online', function() { + sys.debug('a is connected'.green); + var a_room = a.room(ROOM); + }); + test.done(); + }); +}; if(module.id == '.') { var testrunner = require('nodeunit').testrunner;