1
0
Fork 0

Jid as an object

master
Matthieu Lalonde 15 years ago committed by Mathieu Lecarme
parent 64b6b95935
commit 4ba32f922e

@ -1,2 +1,2 @@
exports.Client = require('./xmpp-client/client').Client; exports.Client = require('./xmpp-client/client').Client;
exports.jid = require('./xmpp-client/client').jid; exports.Jid = require('./xmpp-client/client').Jid;

@ -2,21 +2,21 @@ var sys = require('sys'),
xmpp = require('xmpp'), xmpp = require('xmpp'),
events = require('events'); events = require('events');
var jid = function(plain) { var Jid = function(plain) {
var tmp = plain.split('/'); var tmp = plain.split('/');
var j = {}; this.resource = (tmp.length == 1) ? null : tmp[1];
j.resource = (tmp.length == 1) ? null : tmp[1];
tmp = tmp[0].split('@'); tmp = tmp[0].split('@');
j.node = tmp[0]; this.node = tmp[0];
j.domain = tmp[1]; this.domain = tmp[1];
return j;
}; };
exports.jid = jid; exports.Jid = Jid;
var Client = function(host, jid, password) { var Client = function(_jid, password, host) {
events.EventEmitter.call(this); events.EventEmitter.call(this);
var jabber = this; var jabber = this;
this.jid = new Jid(_jid);
this.host = (host == null) ? this.jid.domain : host;
}; };
sys.inherits(Client, events.EventEmitter); sys.inherits(Client, events.EventEmitter);

@ -1,19 +1,25 @@
var sys = require('sys'), var sys = require('sys'),
client = require('../lib/xmpp-client').Client, Client = require('../lib/xmpp-client').Client,
jid = require('../lib/xmpp-client').jid; Jid = require('../lib/xmpp-client').Jid;
exports.testJid = function(test) { exports.testJid = function(test) {
var j = jid('mathieu@gtalk.com'); var j = new Jid('mathieu@gtalk.com');
//sys.debug(JSON.stringify(j)); //sys.debug(JSON.stringify(j));
test.equals('mathieu', j.node); test.equals('mathieu', j.node);
test.equals('gtalk.com', j.domain); test.equals('gtalk.com', j.domain);
test.equals(null, j.resource); test.equals(null, j.resource);
j = jid('mathieu@jabber.org/node'); j = new Jid('mathieu@jabber.org/node');
//sys.debug(JSON.stringify(j)); //sys.debug(JSON.stringify(j));
test.equals('node', j.resource); test.equals('node', j.resource);
test.done(); test.done();
}; };
exports.testClient = function(test) {
var c = new Client('mathieu@gtalk.com', 'toto');
test.equals('gtalk.com', c.host);
test.done();
};
if(module.id == '.'){ if(module.id == '.'){
var testrunner = require('nodeunit').testrunner; var testrunner = require('nodeunit').testrunner;
testrunner.run([__filename]); testrunner.run([__filename]);

Loading…
Cancel
Save