1
0
Fork 0

send a message

master
Matthieu Lalonde 15 years ago committed by Mathieu Lecarme
parent 0588e020da
commit 17ca59835e

@ -25,6 +25,7 @@ var Client = function(_jid, password, host) {
this.rooms = {};
this._iq = 0;
this._iqCallback = {};
this.roster = {};
this.xmpp = new xmpp.Client({
host: this.host,
jid: '' + this.jid,
@ -44,7 +45,7 @@ var Client = function(_jid, password, host) {
sys.debug('STANZA: ' + stanza);
if(stanza.name == 'iq') {
if(stanza.attrs.type == 'result') {
this._debug('IQ result: ' + stanza);
jabber._debug('IQ result: ' + stanza);
jabber.emit('iqResult', stanza.attrs.id, stanza);
} else {
this._debug('IQ: ' + stanza);
@ -53,7 +54,7 @@ var Client = function(_jid, password, host) {
}
if(stanza.name == 'presence') {
var fromm = stanza.attrs.from.split('/')[0].split('@');
if(fromm[1] == 'conference.ohmforce.net') {
if(fromm[1] == 'conference.' + this.jid.domain) {
jabber.rooms[fromm[0]].emit('presence', stanza);
} else {
jabber.emit('presence', stanza);
@ -64,8 +65,8 @@ var Client = function(_jid, password, host) {
if(stanza.attrs.type == 'groupchat') {
jabber.emit('groupchat', from, stanza);
} else {
this._debug('MESSAGE: ' + stanza);
jabber.emit('message', from, stanza);
jabber._debug('MESSAGE: ' + stanza);
jabber.emit('message', from, stanza.getChild('body').getText(), stanza);
}
}
});
@ -73,7 +74,7 @@ var Client = function(_jid, password, host) {
jabber._debug("[Info] xmpp connection");
jabber.presence();
jabber.iq(new xmpp.Element('query', {xmlns: 'jabber:iq:roster'}), function(iq) {
this._debug("MY ROSTER" + iq);
jabber._debug("MY ROSTER" + iq);
});
jabber.emit('online');
});

@ -1,4 +1,5 @@
var sys = require('sys'),
colors = require('colors'),
Client = require('../lib/xmpp-client').Client,
Jid = require('../lib/xmpp-client').Jid,
conf = require('./conf').conf;
@ -23,14 +24,24 @@ exports.testClientInit = function(test) {
};
exports.testClient = function(test) {
test.expect(1);
var c = new Client(conf.jid, conf.password);
c.debug = true;
c.addListener('online', function() {
test.ok(true);
c.message(conf.to, "Beuha de test!");
test.expect(3);
var MESSAGE = "Beuha de test!";
var b = new Client(conf.b.jid, conf.b.password);
b.addListener('message', function(from, msg, stanza){
sys.debug('Message from ' + from.red + ' : ' + msg.yellow);
test.equals(MESSAGE, msg);
test.done();
});
b.addListener('online', function() {
sys.debug('b is connected'.red);
test.ok(true);
var a = new Client(conf.a.jid, conf.a.password);
a.addListener('online', function() {
sys.debug('a is connected'.green);
test.ok(true);
a.message(conf.b.jid, MESSAGE);
});
});
};
if(module.id == '.') {

Loading…
Cancel
Save