1
0
Fork 0
Matthieu Lalonde 15 years ago committed by Mathieu Lecarme
parent 4ec71b3f5d
commit 2e4be0d8d2

@ -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) {
/* <query xmlns='jabber:iq:version'>
<name>Exodus</name>
<version>0.7.0.4</version>
<os>Windows-XP 5.01.2600</os>
</query>*/
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) {
};

@ -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;

Loading…
Cancel
Save