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