1
0
Fork 0

rooms without a blunderer

master
Matthieu Lalonde 14 years ago committed by Mathieu Lecarme
parent 81d13189a1
commit 739fbc7453

@ -11,6 +11,7 @@ var Client = function(params, callback) {
this.jid = new xmpp.JID(params.jid); this.jid = new xmpp.JID(params.jid);
this.host = (params.host == null) ? this.jid.domain : params.host; this.host = (params.host == null) ? this.jid.domain : params.host;
this.rooms = {}; this.rooms = {};
this._isReady = false;
this._iq = 0; this._iq = 0;
this._iqHandler = {}; this._iqHandler = {};
this._iqCallback = {}; this._iqCallback = {};
@ -86,7 +87,7 @@ var Client = function(params, callback) {
}); });
this.addListener('groupchat', function(from, msg, stanza) { this.addListener('groupchat', function(from, msg, stanza) {
fromName = from.split('/')[0]; fromName = from.split('/')[0];
jabber.rooms[fromName].emit('message', msg, stanza); jabber.rooms[fromName].emit('message', from, msg, stanza);
}); });
this.addListener('iqResult', function(id, stanza){ this.addListener('iqResult', function(id, stanza){
jabber._iqCallback[id].call(jabber, stanza); jabber._iqCallback[id].call(jabber, stanza);
@ -166,7 +167,10 @@ Client.prototype.askForRoster = function(callback) {
subscription: child.attrs.subscription}; subscription: child.attrs.subscription};
}); });
if(callback != null) { if(callback != null) {
callback.call(jabber, jabber.roster); if(! jabber._isReady) { //[FIXME] will not work if askForRoster is called again
jabber._isReady = true;
callback.call(jabber, jabber.roster);
}
} }
jabber.emit('roster', jabber.roster); jabber.emit('roster', jabber.roster);
}); });
@ -221,6 +225,7 @@ Client.prototype.disconnect = function() {
var Room = function(client, name, callback) { var Room = function(client, name, callback) {
events.EventEmitter.call(this); events.EventEmitter.call(this);
this._isReady = false;
this.client = client; this.client = client;
this.room = name; this.room = name;
this.to = this.room + '/' + this.client.jid.user; this.to = this.room + '/' + this.client.jid.user;
@ -236,7 +241,10 @@ var Room = function(client, name, callback) {
room.role = item.attrs.role; room.role = item.attrs.role;
} }
var status = x.getChild('status'); var status = x.getChild('status');
callback.call(room, (status != null) ? status.attrs.code : '200'); if(! room._isReady) {
room._isReady = true;
callback.call(room, (status != null) ? status.attrs.code : '200');
}
} }
} }
}); });

@ -48,34 +48,34 @@ exports.testClient = function(test) {
*/ */
exports.testRoom = function(test) { exports.testRoom = function(test) {
//test.expect(1); test.expect(1);
var ROOM = 'mushroom@conference.' + conf.b.jid.split('@')[1]; var ROOM = 'mushroom@conference.' + conf.b.jid.split('@')[1];
var MESSAGE = "Hello everybody"; var MESSAGE = "Hello everybody";
var cpt = 0;
var b = new Client(conf.b, function() { var b = new Client(conf.b, function() {
sys.debug('b is connected'.red); sys.debug('b is connected'.red);
sys.debug(('enter in ' + ROOM).green); sys.debug(('enter in ' + ROOM).green);
//console.log(sys.inspect(this, true, null)); //console.log(sys.inspect(this, true, null));
var b_room = b.room(ROOM, function(status) { var b_room = b.room(ROOM, function(status) {
sys.debug('b room is created'.green);
this.addListener('message', function(from, msg, stanza) { this.addListener('message', function(from, msg, stanza) {
sys.debug(msg.yellow); sys.debug(from.yellow);
test.done(); test.equals(MESSAGE, msg);
if(MESSAGE == msg) {
test.done();
}
}); });
this.message(MESSAGE); var a = new Client(conf.a, function() {
/* var a = new Client(conf.a, function() {
sys.debug('a is connected'.green); sys.debug('a is connected'.green);
var a_room = a.room(ROOM, function(status) { var a_room = a.room(ROOM, function(status) {
sys.debug(status); sys.debug(status.green);
sys.debug(this.role); sys.debug(this.role.green);
this.addListener('message', function(from, msg, stanza) { this.addListener('message', function(from, msg, stanza) {
sys.debug('message : ' + msg); sys.debug('message : ' + msg);
test.equals(MESSAGE, msg);
if(MESSAGE == msg) {
test.done();
}
}); });
b_room.message(MESSAGE); this.message(MESSAGE);
}); });
});*/ });
}); });
}); });
}; };

Loading…
Cancel
Save