1
0
Fork 0

muc with callback

master
Matthieu Lalonde 14 years ago committed by Mathieu Lecarme
parent 70eb95508a
commit d18443dbff

@ -72,7 +72,7 @@ var Client = function(params, callback) {
jabber.emit('online');
jabber.askForRoster();
if(callback != null) {
callback.apply(jabber);
callback.call(jabber);
}
});
this.addListener('groupchat', function(from, stanza) {
@ -193,10 +193,10 @@ Client.prototype.canonicalRoomName = function(room) {
}
};
Client.prototype.room = function(name) {
Client.prototype.room = function(name, callback) {
var room = this.canonicalRoomName(name);
if(this.rooms[room] == null) {
this.rooms[room] = new Room(this, room);
this.rooms[room] = new Room(this, room, callback);
}
return this.rooms[room];
};
@ -214,10 +214,26 @@ Client.prototype.disconnect = function() {
sys.debug("disconnect from XMPP");
};
var Room = function(client, room, callback) {
var Room = function(client, name, callback) {
events.EventEmitter.call(this);
this.client = client;
this.room = room;
this.room = name;
var room = this;
this.addListener('presence', function(from, stanza) {
var jfrom = new xmpp.JID(from);
if(name == jfrom.user + '@' + jfrom.domain) {
var x = stanza.getChild('x', 'http://jabber.org/protocol/muc#user');
if(x != null) {
var item = x.getChild('item');
if(item != null) {
room.affiliation = item.attrs.affiliation;
room.role = item.attrs.role;
}
var status = x.getChild('status');
callback.call(room, (status != null) ? status.attrs.code : '200');
}
}
});
this.presence();
};

@ -52,12 +52,16 @@ exports.testRoom = function(test) {
var b = new Client(conf.b, function() {
sys.debug('b is connected'.red);
sys.debug(('enter in ' + ROOM).green);
var b_room = b.room(ROOM);
var a = new Client(conf.a, function() {
sys.debug('a is connected'.green);
var a_room = a.room(ROOM);
var b_room = b.room(ROOM, function(status) {
var a = new Client(conf.a, function() {
sys.debug('a is connected'.green);
var a_room = a.room(ROOM, function(status) {
sys.debug(status);
test.done();
});
});
});
//test.done();
});
};

Loading…
Cancel
Save