Categories
General

Setting up JSJaC with Openfire 3.5.2

I am using Openfire, an XMPP (Jabber) server, to facilitate instant messaging in a closed system I am building. Part of my design had users rely on browsers as instant messaging (IM) clients. As Meebo showed, it can be done quite well and an open source JavaScript library, JSJaC, apparently provides this ability. JSJaC is the backbone of a full-blown browser-based IM client called JWChat, but for me, the plumbing was what was necessary.

Only thing is that JSJaC is not the easiest to set up with Openfire.

JSJaC uses HTTP-binding, which according to Wikipedia allows for long-lasting HTTP requests instead of polling, which just periodically checks the server to see if there is a message waiting. To do that, JSJaC needs to connect to the server and that is done by accessing a somewhat tricky port, 7070 is the default in version 3.5.2. What’s tricky about it? Browsers do not like to let JavaScript access services using XMLHttpRequest, the lifeblood of AJAX, on URLs and ports unlike the one which the current URL relies on. This is normally solved using a proxy or a URL rewrite, which forward requests to the desired ports and pass back responses, all as if you used the ‘appropriate’ ports. Luckily, Apache’s HTTPd has great modules that do just that. The instructions in JSJaC’s readme file recommended using a rewrite. That caused repeated 503 errors from Apache. Using its proxy did work for me. As usual, you spend time, read here and read there, and finally, you normally find a way to make it work. This how I did it.

  1. After downloading JSJaC, open jsjac.js. Change the line
    var JSJACHBC_USE_BOSH_VER=false;

    to

    var JSJACHBC_USE_BOSH_VER=true;
  2. To allow Apache HTTPd’s proxy to work, enable proxy_module and proxy_http_module in Apache HTTPd’s httpd.conf file
  3. Add a virtual host that will map a certain URL to the proxy, and set up the proxy to point at the Openfire http-binding port:
    <virtualhost 127.0.0.1:80>
    	DocumentRoot "C:/www/root"  <!-- This is the document root for your server -->
    	AddDefaultCharset UTF-8
    	ProxyRequests On
    	ProxyPass /http-bind/ http://127.0.0.1:7070/http-bind/ <!-- This is where your Openfire server can be accessed -->
    </virtualhost>
  4. To test this configuration, use JSJaC’s simpleclient.html, its sample client, to try and connect to the server. Make sure you add the following line
    oArgs.authtype = 'nonsasl';

    above

    con.connect(oArgs);
  5. Start Apache HTTPd and open simpleclient.js
  6. simpleclient asks for 4 fields:

    • The server’s base URL: This is the proxied URL, for example, http://127.0.0.1/http-bind/ (note the trailing slash) in my case.
    • Server name/domain: The domain Openfire was set up to use. In XMPP, if the server’s name is myserver, users will be known on it with IDs like joe@myserver
    • User name of existing user
    • The password for that user
  7. Connect!

I highly recommend using Firebug to ensure the request is sent properly and is being received properly from Openfire. Odd Firefox object initialization errors are due to the fact that an attempt is made to access a port JavaScript is not allowed to access.

Share

16 replies on “Setting up JSJaC with Openfire 3.5.2”

Thanks for this useful write up. Two foot notes, in the designated code lines above, ‘ ‘ is displayed. Second changing var JSJACHBC_USE_BOSH_VER = false; to ‘true’ caused ‘Service Unavailable’ errors to appear. Only when changing ‘true’ to ‘false’, did it then work. Believe me, it was not easy to figure out.

Hi,

I use Aprelium Abyss Webserver for running php5.2, so I added a rule that translates /http-bind/ into http://127.0.0.1:7070/http-bind/ and use Proxy (status code 305)
I am trying to apply these settings but still in vain. I still get the error “Service Unavailable” although Firebug shows that the request has been correctly sent :

Response
Location http://127.0.0.1:7070/http-bind/
Content-Type text/html
Content-Length 444
Connection Keep-Alive
Keep-Alive timeout=150000, max=10
Date Mon, 10 Nov 2008 12:17:30 GMT
Server Abyss/2.5.0.0-X1-Win32 AbyssLib/2.5.0.0

Request
Host 127.0.0.1:8000
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Content-Type text/xml; charset=utf-8
Referer http://127.0.0.1:8000/jsjac/examples/simpleclient.html
Content-Length 180
Cookie JSESSIONID=9stzxkn9w96n
Pragma no-cache
Cache-Control no-cache

any idea please ?

Something I am not sure about from the response that you received is that it was not generated by Jetty (Openfire’s built-in application server). It therefore looks to me like a proxy error generated by your web server.

I am using Apache and it would issue error 503 until the proxy rules worked.

Hope this is of help…

Yuval

Hi Yuval,

“2. To allow Apache HTTPd’s proxy to work, enable proxy_module and proxy_http_module in Apache HTTPd’s httpd.conf file.”

Kindly let me know, whether above mentioned step indicates uncommenting the following lines in httpd.conf file or not.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Please let me know, if my understanding is incorrect.

Also , I tried with all the steps, but I am getting following error on the page.

[Exception… “Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]” nsresult: “0xc1f30001 (NS_ERROR_NOT_INITIALIZED)” location: “JS frame :: http://localhost:8080/JsJac/jsjac.js :: anonymous :: line 215″ data: no]

Please provide me some insight about it.

Thanks,
Mari

Hi Mari,

The uncommenting for mod_proxy is indeed in the httpd.conf file.
With regards to the error you are seeing, it is caused by security limitations on JavaScript in your browser. JSJaC uses XMLHttpRequest objects to contact an XMPP server and as such has to comply with security limitations in the browser.

Essentially, JavaScript is allowed to access only the hostname the page it appears in was downloaded from. So if the web page has a URL of https://www.enavigo.com/somepage.html , JavaScript will only be allowed to send requests to https://www.enavigo.com and nowhere else.

What could be happening to you is that you are downloading the page from http://localhost:8080. This allows JavaScript to send requests ONLY to that hostname, even if it is the same machine as 127.0.0.1. In all likelihood, though, if you are using Apache to proxy requests, the URL you are using should be, most likely, http://localhost or http://127.0.0.1 – both loopback URLs pointing at your own machine. So make sure that your Apache web server proxy is set up.

In that case, make sure that JSJaC sample client uses the information I have in bullet 6 in my instructions.

I hope this does not further confuse you…

Yuval

Hi Yuval,

Thanks a lot for your clear explanation and your time in answering my query.

Now I am able to configure and run simpleclient.html 🙂

Thanks Yuval.

Cheers,
Mari

Are you disabling SASL because JSJaC can’t connect to OpenFire using SASL? Is this a missing feature or some defect in JSJaC or OpenFire?

Tony,

I am honestly not sure where the shortcoming is – on the JsJAC or Openfire. I was frankly trying to just get things done and this worked. The directive to turn SASL off in the JsJAC configuration came, to the best I can recall, from an Openfire discussion board.

Yuval

Hi Yuval,

Disabling SASL definitely makes the difference between working and not working. I get timeout errors if I enable SASL or even SASLANON.

Thanks for documenting how to get this going.

Cheers,
Tony.

i did what all you said but nothiing works. i am really too much frustrated. pls post a video or something for this. i need it v badly. hoping u wud show it clearly in video thx in advance

Thanx. This article really helped me resolve issues I was facing connecting to my Open fire server.
But its working only with IE after enabling cross-domain. I cannot create a virtual host and enable proxy as mentioned in step 2 because my chat client web application is hosted on Tomcat server.

Can u guys plz suggest me how achieve cross-domain on Tomcat.

Hi,
thanks for the post .I follow it succeed .But I need to transfer chat in between.Suppose I am
chatting with person1 and some how he got disconnected then I want to transfer the hole chat
to person2. Don't get how to do it .Can you please suggest it .Thanks in advance .

Hi Yuval, On localhost everything is going very good with IE8, Firefox, Chrome. But when I uploaded simplehtmlclient.html and other files and tried to run it then Firefox and chrome run very nicely but IE8 gives
Error: Unspecified error.
But on IE 10 it is again running good. As per Github(https://github.com/sstrigler/JSJaC/) notes Microsoft Internet Explorer 10 is known to work with WebSocket.
Please suggest if we can make it run for IE8 in another way.
Thanks.

Leave a Reply

Your email address will not be published.

 

Share