Permalink
Browse files

Fixed issues

Fixed the following issues:
- Added URL to the constructor of the component in favor of hostname
and port.
- Fixed some issues that I was having when starting a session.
- The send method now first gets the top the XML structure.
- Changed the example to work with the new API.
  • Loading branch information...
1 parent 8c51275 commit 6e95d60d1e71eb49090a26f4bc89446573aff312 Eelco committed Dec 15, 2011
Showing with 45 additions and 31 deletions.
  1. +3 −4 { → examples}/exampleclient.js
  2. 0 { → lib}/autil.js
  3. +23 −9 { → lib}/boshclient.js
  4. +19 −18 package.json
@@ -1,13 +1,12 @@
-var xmpp = require("./boshclient.js");
+var xmpp = require("../lib/boshclient.js");
//change this data accordingly
var myjid = "me@example.com";
var mypassword = "keepitsecret";
var friend = "she@example.com";
-var host = "localhost";
-var portno = "5280";
+var bosh = "http://localhost:5280/http-bind";
-var me = new xmpp.Client(myjid + "/office", mypassword, host, portno);
+var me = new xmpp.Client(myjid + "/office", mypassword, bosh);
me.on('error', function(exception) {
console.log("Error: " + exception);
File renamed without changes.
@@ -23,6 +23,7 @@ var ltx = require("ltx");
var util = require("util");
var events = require("events");
var autil = require("./autil.js"); //my utilities
+var url = require("url");
var NS_CLIENT = "jabber:client";
@@ -42,12 +43,18 @@ var STATE_FIRST = 0,
STATE_TERM = 7,
STATE_OVER = 8;
-function nxbClient(jid, password, host, port, route)
+/**
+ * jid: jid of the user.
+ * password: password of the user.
+ * bosh: string that contains the URL of the bosh server: http://www.example.com/http-bind/
+ * (optional) route: the XMPP server where the BOSH server should route the XMPP to.
+ */
+function nxbClient(jid, password, bosh, route)
{
events.EventEmitter.call(this);
this.sess_attr = {
- rid : 5292811, //any random rid
+ rid : Math.round(Math.random() * 10000),
jid : autil.jid_parse(jid),
password : password
};
@@ -59,10 +66,13 @@ function nxbClient(jid, password, host, port, route)
this.hasNextTick = false;
this.state = STATE_FIRST;
+
+ var u = url.parse(bosh);
+
this.options = {
- host : host,
- port : port,
- path : "/http-bind/",
+ host : u.hostname,
+ port : u.port,
+ path : u.pathname,
method : "POST",
agent : false
};
@@ -135,7 +145,7 @@ function nxbClient(jid, password, host, port, route)
}
catch(err)
{
- this.pError("xml parsing ERROR");
+ this.pError("xml parsing ERROR: " + response);
return;
}
@@ -195,7 +205,9 @@ function nxbClient(jid, password, host, port, route)
if(this.state == STATE_AUTH)
{
- if(success = body.getChild("success", NS_CLIENT))
+ autil.logIt("DEBUG", "STATE_AUTH with body: " + body.getChild("success", "urn:ietf:params:xml:ns:xmpp-sasl") + " and NS_CLIENT: " + NS_CLIENT);
+
+ if(success = body.getChild("success", "urn:ietf:params:xml:ns:xmpp-sasl"))
{
autil.logIt("DEBUG", "Authentication Success: " + this.sess_attr.jid);
this.state = STATE_AUTHED;
@@ -258,7 +270,7 @@ function nxbClient(jid, password, host, port, route)
if(this.sessionSupport)
{
- var iq = new ltx.Element("iq", {to : "example.com", type : "set", id : "sess_1"});
+ var iq = new ltx.Element("iq", {to : this.sess_attr["jid"].domain, type : "set", id : "sess_1"});
iq.c("session", {xmlns : NS_XMPP_SESSION});
this.sendXml(iq);
this.state = STATE_SESSION;
@@ -443,6 +455,8 @@ function nxbClient(jid, password, host, port, route)
//puts ltx-element into pending[] to be sent later
this.send = function(ltxe)
{
+ ltxe = ltxe.tree();
+
if(this.state != STATE_ONLINE)
{
this.emit("error", "can send something only when u are ONLINE!!!");
@@ -524,4 +538,4 @@ exports.$pres = function(attrib){
return new ltx.Element("presence", attrib);
}
-exports.setLogLevel = autil.setLogLevel;
+exports.setLogLevel = autil.setLogLevel;
View
@@ -1,19 +1,20 @@
-{ "name": "node-xmpp-via-bosh"
-,"version": "0.0.1"
-,"description": "xmpp library via bosh"
-,"author": "Anoop Chaurasiya"
-,"dependencies": {"node-expat": ">=1.2.0"
- ,"ltx": ">= 0.0.4"
- }
-,"repositories": [{"type": "git"
- ,"path": "https://github.com/anoopc/node-xmpp-via-bosh"
- }]
-,"homepage": "https://github.com/anoopc/node-xmpp-via-bosh"
-,"bugs": "https://github.com/anoopc/node-xmpp-via-bosh/issues"
-,"maintainers": [{"name": "Anoop Chaurasiya"
- ,"email": "anoopchaurasiya1@gmail.com"
- }]
-,"engines": {
- "node": ">=0.4.0"
- }
+{
+ "name": "node-xmpp-via-bosh",
+ "version": "0.1.0",
+ "description": "XMPP via BOSH",
+ "author": "Anoop Chaurasiya & Eelco Cramer",
+ "keywords": ["xmpp", "bosh", "http", "jabber"],
+ "dependencies": { "node-expat": ">=1.2.0", "ltx": ">= 0.0.4" },
+ "repositories": [
+ { "type": "git", "path": "https://github.com/eelcocramer/node-xmpp-via-bosh" },
+ { "type": "git", "path": "https://github.com/anoopc/node-xmpp-via-bosh" }
+ ],
+ "homepage": "https://github.com/eelcocramer/node-xmpp-via-bosh",
+ "bugs": "https://github.com/eelcocramer/node-xmpp-via-bosh/issues",
+ "maintainers": [
+ { "name": "Anoop Chaurasiya", "email": "anoopchaurasiya1@gmail.com" },
+ { "name": "Eelco Cramer", "email": "eelco.cramer@gmail.com" }
+ ],
+ "engines": { "node": ">=0.4.0" },
+ "main": "./lib/boshclient.js"
}

0 comments on commit 6e95d60

Please sign in to comment.