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.rooms = {};
this._iq = 0; this._iq = 0;
this._iqCallback = {}; this._iqCallback = {};
this.roster = {};
this.xmpp = new xmpp.Client({ this.xmpp = new xmpp.Client({
host: this.host, host: this.host,
jid: '' + this.jid, jid: '' + this.jid,
@ -44,7 +45,7 @@ var Client = function(_jid, password, host) {
sys.debug('STANZA: ' + stanza); sys.debug('STANZA: ' + stanza);
if(stanza.name == 'iq') { if(stanza.name == 'iq') {
if(stanza.attrs.type == 'result') { if(stanza.attrs.type == 'result') {
this._debug('IQ result: ' + stanza); jabber._debug('IQ result: ' + stanza);
jabber.emit('iqResult', stanza.attrs.id, stanza); jabber.emit('iqResult', stanza.attrs.id, stanza);
} else { } else {
this._debug('IQ: ' + stanza); this._debug('IQ: ' + stanza);
@ -53,7 +54,7 @@ var Client = function(_jid, password, host) {
} }
if(stanza.name == 'presence') { if(stanza.name == 'presence') {
var fromm = stanza.attrs.from.split('/')[0].split('@'); 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); jabber.rooms[fromm[0]].emit('presence', stanza);
} else { } else {
jabber.emit('presence', stanza); jabber.emit('presence', stanza);
@ -64,8 +65,8 @@ var Client = function(_jid, password, host) {
if(stanza.attrs.type == 'groupchat') { if(stanza.attrs.type == 'groupchat') {
jabber.emit('groupchat', from, stanza); jabber.emit('groupchat', from, stanza);
} else { } else {
this._debug('MESSAGE: ' + stanza); jabber._debug('MESSAGE: ' + stanza);
jabber.emit('message', from, 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._debug("[Info] xmpp connection");
jabber.presence(); jabber.presence();
jabber.iq(new xmpp.Element('query', {xmlns: 'jabber:iq:roster'}), function(iq) { 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'); jabber.emit('online');
}); });

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

Loading…
Cancel
Save