From 4ba32f922e4ffcaca5ec95c31bdcdcaab1930c6c Mon Sep 17 00:00:00 2001 From: Matthieu Lalonde Date: Wed, 4 Aug 2010 20:29:59 +0200 Subject: [PATCH] Jid as an object --- lib/xmpp-client.js | 2 +- lib/xmpp-client/client.js | 16 ++++++++-------- test/test.js | 14 ++++++++++---- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/xmpp-client.js b/lib/xmpp-client.js index ea64f43..41e33cd 100644 --- a/lib/xmpp-client.js +++ b/lib/xmpp-client.js @@ -1,2 +1,2 @@ exports.Client = require('./xmpp-client/client').Client; -exports.jid = require('./xmpp-client/client').jid; \ No newline at end of file +exports.Jid = require('./xmpp-client/client').Jid; \ No newline at end of file diff --git a/lib/xmpp-client/client.js b/lib/xmpp-client/client.js index a947564..336b951 100644 --- a/lib/xmpp-client/client.js +++ b/lib/xmpp-client/client.js @@ -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); diff --git a/test/test.js b/test/test.js index 9df4c98..c07eb80 100644 --- a/test/test.js +++ b/test/test.js @@ -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]);