|
|
|
@ -1,24 +1,23 @@
|
|
|
|
|
var sys = require('sys'),
|
|
|
|
|
xmpp = require('xmpp'),
|
|
|
|
|
colors = require('colors'),
|
|
|
|
|
events = require('events');
|
|
|
|
|
|
|
|
|
|
var Client = function(_jid, password, host) {
|
|
|
|
|
var Client = function(params) {
|
|
|
|
|
events.EventEmitter.call(this);
|
|
|
|
|
this.color = (params.color != null) ? params.color : 'blue';
|
|
|
|
|
this.debug = true;
|
|
|
|
|
var jabber = this;
|
|
|
|
|
this.jid = new xmpp.JID(_jid);
|
|
|
|
|
this.host = (host == null) ? this.jid.domain : host;
|
|
|
|
|
this.jid = new xmpp.JID(params.jid);
|
|
|
|
|
this.host = (params.host == null) ? this.jid.domain : params.host;
|
|
|
|
|
this.rooms = {};
|
|
|
|
|
this._iq = 0;
|
|
|
|
|
this._iqCallback = {};
|
|
|
|
|
this.presences = {};
|
|
|
|
|
this.roster = {};
|
|
|
|
|
this.xmpp = new xmpp.Client({
|
|
|
|
|
host: this.host,
|
|
|
|
|
jid: '' + this.jid,
|
|
|
|
|
password: password });
|
|
|
|
|
this.xmpp = new xmpp.Client(params);
|
|
|
|
|
this.xmpp.addListener('rawStanza', function(stanza) {
|
|
|
|
|
sys.debug("RAW: " + stanza);
|
|
|
|
|
sys.debug("RAW: "[jabber.color] + stanza.toString().white);
|
|
|
|
|
});
|
|
|
|
|
this.xmpp.addListener('authFail', function() {
|
|
|
|
|
sys.error("[Error] Jabber : Authentication failure");
|
|
|
|
@ -29,7 +28,7 @@ var Client = function(_jid, password, host) {
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
|
|
|
|
this.xmpp.addListener('stanza', function(stanza) {
|
|
|
|
|
sys.debug('STANZA: ' + stanza);
|
|
|
|
|
sys.debug('STANZA: '[jabber.color] + stanza);
|
|
|
|
|
if(stanza.name == 'iq') {
|
|
|
|
|
if(stanza.attrs.type == 'result') {
|
|
|
|
|
jabber._debug('IQ result: ' + stanza);
|
|
|
|
@ -40,9 +39,9 @@ var Client = function(_jid, password, host) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(stanza.name == 'presence') {
|
|
|
|
|
var fromm = stanza.attrs.from.split('/')[0].split('@');
|
|
|
|
|
if(fromm[1] == 'conference.' + this.jid.domain) {
|
|
|
|
|
jabber.rooms[fromm[0]].emit('presence', stanza);
|
|
|
|
|
var fromm = new xmpp.JID(stanza.attrs.from);
|
|
|
|
|
if(fromm.domain == 'conference.' + this.jid.domain) {
|
|
|
|
|
jabber.rooms[fromm.user].emit('presence', stanza);
|
|
|
|
|
} else {
|
|
|
|
|
jabber.emit('presence', stanza.attrs.from, stanza);
|
|
|
|
|
}
|
|
|
|
|