1
0
Fork 0

broken room

master
Matthieu Lalonde 14 years ago committed by Mathieu Lecarme
parent 61c0a4aa93
commit d7c1994ffb

@ -29,7 +29,7 @@ var Client = function(params, callback) {
process.exit(1); process.exit(1);
}); });
this.xmpp.addListener('stanza', function(stanza) { this.xmpp.addListener('stanza', function(stanza) {
sys.debug('STANZA: '[jabber.color] + ('<' + stanza.name + '> ').bold[jabber.color] + stanza); //sys.debug('STANZA: '[jabber.color] + ('<' + stanza.name + '> ').bold[jabber.color] + stanza);
if(stanza.name == 'iq') { if(stanza.name == 'iq') {
if(stanza.attrs.type == 'result') { if(stanza.attrs.type == 'result') {
jabber._debug('IQ result: ' + stanza); jabber._debug('IQ result: ' + stanza);
@ -66,7 +66,7 @@ var Client = function(params, callback) {
if(stanza.name == 'message') { if(stanza.name == 'message') {
var from = stanza.attrs.from; var from = stanza.attrs.from;
if(stanza.attrs.type == 'groupchat') { if(stanza.attrs.type == 'groupchat') {
jabber.emit('groupchat', from, stanza); jabber.emit('groupchat', from, stanza.getChild('body').getText(), stanza);
} else { } else {
jabber._debug('MESSAGE: ' + stanza); jabber._debug('MESSAGE: ' + stanza);
jabber.emit('message', from, stanza.getChild('body').getText(), stanza); jabber.emit('message', from, stanza.getChild('body').getText(), stanza);
@ -78,15 +78,15 @@ var Client = function(params, callback) {
jabber.presence(); jabber.presence();
jabber.emit('online'); jabber.emit('online');
jabber.askForRoster(function(roster) { jabber.askForRoster(function(roster) {
jabber._debug("ROSTER : "[jabber.color] + JSON.stringify(roster)); //jabber._debug("ROSTER : "[jabber.color] + JSON.stringify(roster));
if(callback != null) { if(callback != null) {
callback.call(jabber); callback.call(jabber);
} }
}); });
}); });
this.addListener('groupchat', function(from, stanza) { this.addListener('groupchat', function(from, msg, stanza) {
fromName = from.split('@')[0]; fromName = from.split('/')[0];
jabber.rooms[fromName].emit('message', stanza); jabber.rooms[fromName].emit('message', 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);
@ -153,9 +153,8 @@ Client.prototype.registerIqHandler = function(xmlns, action) {
Client.prototype.message = function(to, message) { Client.prototype.message = function(to, message) {
this.xmpp.send(new xmpp.Element('message', { this.xmpp.send(new xmpp.Element('message', {
to: to, to: to,
type: 'chat'}). type: 'chat'})
c('body'). .c('body').t(message));
t(message));
}; };
Client.prototype.askForRoster = function(callback) { Client.prototype.askForRoster = function(callback) {
@ -210,8 +209,7 @@ Client.prototype.room = function(name, callback) {
Client.prototype.disconnect = function() { Client.prototype.disconnect = function() {
this.xmpp.send(new xmpp.Element('presence', {type: 'unavailable'}) this.xmpp.send(new xmpp.Element('presence', {type: 'unavailable'})
.c('status') .c('status').t('Logged out')
.t('Logged out')
.tree()); .tree());
var jabber = this; var jabber = this;
/* Object.keys(this.rooms).forEach(function(room) { /* Object.keys(this.rooms).forEach(function(room) {
@ -225,6 +223,7 @@ var Room = function(client, name, callback) {
events.EventEmitter.call(this); events.EventEmitter.call(this);
this.client = client; this.client = client;
this.room = name; this.room = name;
this.to = this.room + '/' + this.client.jid.user;
var room = this; var room = this;
this.addListener('presence', function(from, stanza) { this.addListener('presence', function(from, stanza) {
var jfrom = new xmpp.JID(from); var jfrom = new xmpp.JID(from);
@ -249,8 +248,9 @@ sys.inherits(Room, events.EventEmitter);
exports.Room = Room; exports.Room = Room;
Room.prototype.presence = function() { Room.prototype.presence = function() {
sys.debug(('presence: ' + this.room)[this.client.color]);
this.client.xmpp.send(new xmpp.Element('presence', { this.client.xmpp.send(new xmpp.Element('presence', {
to: this.room + '/' + this.client.jid.user to: this.to
}) })
.c('priority').t("5").up() .c('priority').t("5").up()
.c('x', {xmlns:"http://jabber.org/protocol/muc"}) .c('x', {xmlns:"http://jabber.org/protocol/muc"})
@ -258,6 +258,12 @@ Room.prototype.presence = function() {
); );
}; };
Room.prototype.message = function(msg) { Room.prototype.message = function(message) {
this.client.xmpp.send(new xmpp.Element('message', {
to: this.to,
type: 'groupchat'})
.c('body').t(message).up()
// .c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(this.client.jid.username)
.tree()
);
}; };

@ -48,7 +48,9 @@ exports.testClient = function(test) {
*/ */
exports.testRoom = function(test) { exports.testRoom = function(test) {
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 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);
@ -58,7 +60,14 @@ exports.testRoom = function(test) {
var a_room = a.room(ROOM, function(status) { var a_room = a.room(ROOM, function(status) {
sys.debug(status); sys.debug(status);
sys.debug(this.role); sys.debug(this.role);
test.done(); this.addListener('message', function(from, msg, stanza) {
sys.debug('message : ' + msg);
test.equals(MESSAGE, msg);
if(MESSAGE == msg) {
test.done();
}
});
b_room.message(MESSAGE);
}); });
}); });

Loading…
Cancel
Save