diff --git a/lib/xmpp-client/client.js b/lib/xmpp-client/client.js index 6281e0f..9198c75 100644 --- a/lib/xmpp-client/client.js +++ b/lib/xmpp-client/client.js @@ -1,7 +1,8 @@ var sys = require('sys'), xmpp = require('node-xmpp'), colors = require('colors'), - events = require('events'); + events = require('events'), + Room = require('./room').Room; var BasicClient = function(params) { events.EventEmitter.call(this); @@ -289,57 +290,3 @@ Client.prototype.suscribe = function(to, node, callback) { ); }; -var Room = function(client, name, callback) { - events.EventEmitter.call(this); - this._isReady = false; - this.client = client; - this.room = name; - this.to = this.room + '/' + this.client.jid.user; - 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'); - if(! room._isReady) { - room._isReady = true; - callback.call(room, (status != null) ? status.attrs.code : '200'); - } - } - } - }); - this.presence(); -}; - -sys.inherits(Room, events.EventEmitter); - -exports.Room = Room; - -Room.prototype.presence = function() { - sys.debug(('presence: ' + this.room)[this.client.color]); - this.client.xmpp.send(new xmpp.Element('presence', { - to: this.to - }) - .c('priority').t("5").up() - .c('x', {xmlns:"http://jabber.org/protocol/muc"}) - .tree() - ); -}; - -Room.prototype.message = function(message) { - this.client.xmpp.send(new xmpp.Element('message', { - to: this.room, - type: 'groupchat', - id: this.client._iq++ - }) -// .c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(this.client.jid.username).up() - .c('body').t(message).up() - .tree() - ); -}; diff --git a/lib/xmpp-client/room.js b/lib/xmpp-client/room.js new file mode 100644 index 0000000..a2b4940 --- /dev/null +++ b/lib/xmpp-client/room.js @@ -0,0 +1,59 @@ +var sys = require('sys'), + xmpp = require('node-xmpp'), + colors = require('colors'), + events = require('events'); + +var Room = function(client, name, callback) { + events.EventEmitter.call(this); + this._isReady = false; + this.client = client; + this.room = name; + this.to = this.room + '/' + this.client.jid.user; + 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'); + if(! room._isReady) { + room._isReady = true; + callback.call(room, (status != null) ? status.attrs.code : '200'); + } + } + } + }); + this.presence(); +}; + +sys.inherits(Room, events.EventEmitter); + +exports.Room = Room; + +Room.prototype.presence = function() { + sys.debug(('presence: ' + this.room)[this.client.color]); + this.client.xmpp.send(new xmpp.Element('presence', { + to: this.to + }) + .c('priority').t("5").up() + .c('x', {xmlns:"http://jabber.org/protocol/muc"}) + .tree() + ); +}; + +Room.prototype.message = function(message) { + this.client.xmpp.send(new xmpp.Element('message', { + to: this.room, + type: 'groupchat', + id: this.client._iq++ + }) +// .c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(this.client.jid.username).up() + .c('body').t(message).up() + .tree() + ); +};