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.jid = require('./xmpp-client/client').jid;
exports.Jid = require('./xmpp-client/client').Jid;

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

@ -1,19 +1,25 @@
var sys = require('sys'),
client = require('../lib/xmpp-client').Client,
jid = require('../lib/xmpp-client').jid;
Client = require('../lib/xmpp-client').Client,
Jid = require('../lib/xmpp-client').Jid;
exports.testJid = function(test) {
var j = jid('mathieu@gtalk.com');
var j = new Jid('mathieu@gtalk.com');
//sys.debug(JSON.stringify(j));
test.equals('mathieu', j.node);
test.equals('gtalk.com', j.domain);
test.equals(null, j.resource);
j = jid('mathieu@jabber.org/node');
j = new Jid('mathieu@jabber.org/node');
//sys.debug(JSON.stringify(j));
test.equals('node', j.resource);
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 == '.'){
var testrunner = require('nodeunit').testrunner;
testrunner.run([__filename]);

Loading…
Cancel
Save