1
0
Fork 0

params and color debug

master
Matthieu Lalonde 14 years ago committed by Mathieu Lecarme
parent 69041e4c07
commit 72348a51dc

@ -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);
}

@ -18,7 +18,7 @@ exports.testJid = function(test) {
};
exports.testClientInit = function(test) {
var c = new Client('mathieu@gtalk.com', 'toto');
var c = new Client({jid: 'mathieu@gtalk.com', password:'toto'});
test.equals('gtalk.com', c.host);
test.done();
};
@ -26,7 +26,7 @@ exports.testClientInit = function(test) {
exports.testClient = function(test) {
test.expect(3);
var MESSAGE = "Beuha de test!";
var b = new Client(conf.b.jid, conf.b.password);
var b = new Client(conf.b);
b.addListener('message', function(from, msg, stanza){
sys.debug('Message from ' + from.red + ' : ' + msg.yellow);
test.equals(MESSAGE, msg);
@ -35,7 +35,7 @@ exports.testClient = function(test) {
b.addListener('online', function() {
sys.debug('b is connected'.red);
test.ok(true);
var a = new Client(conf.a.jid, conf.a.password);
var a = new Client(conf.a);
a.addListener('online', function() {
sys.debug('a is connected'.green);
sys.debug('a presences : ' + JSON.stringify(a.presences).green);

Loading…
Cancel
Save