Running Converse.js in conjunction with Bosh punjab on Apache 2.4 and a remote Openfire server, or how to fasten a jabber page out of the box

I decided to write this article because I did not find a description of the problems that I encountered during the installation and configuration of everything described in the header on the Russian-language Internet. Formally speaking, there is an article about punjab on Habré, but, to my regret, it didn’t help me much. The article is intended for a person who is not very versed in the tricks of administration, Pyton, etc. etc.

So, let's begin. My system is a server on Ubuntu 14.04 that runs Apache 2.4. He hosts a page to which there was a desire to fasten the Jabber-client. Customer choice fell on Converse.js, since it requires a minimum number of settings and works out of the box. Jabber Server - Openfire. It is located on a remote machine on the network, access to which I have only as an ordinary user. Only IP address and port were known to me about it.

Any JS - Jabber (self-recording, Strophe, converse) will require you to have a BOSH server. Roughly speaking, it is an echo server that forwards messages from JS-Jabbera to the jabber server and vice versa. Punjab was taken as BOSH .

With the introductory part finished - went to set.


To work, it requires: Python 2.6> =, Twisted 11.1> = . For Ubuntu, the repository has a python-twisted package. If you want to use TLS, you will need the pyopenssl package.
Our server works without encryption, so I did not install this package.
Next, either drive it to GitHub, or download the archive and unzip Punjab. We put it where we like, for example / usr / share / punjab. From this folder in the console, execute:

python install

Further, according to the description of the authors, it is proposed to immediately start the server. I recommend paying attention to the punjab.tac file.
It has a line like this:

 internet.TCPServer(5280, site).setServiceParent(application)

I did not find any other settings for the remote server port, and since our server runs on port 5222, I replaced this one from 5280 to 5222:

internet.TCPServer(5222, site).setServiceParent(application)

You may have a question: “Where to write the address of the jabber-server?”. In the configuration of nowhere. The server address is already indicated in the client as a record: vasyliy_pupkin@, where is the address of the jabber server.

Run Punjab through the console:

twistd -y punjab.tac

If everything went fine, the console will swallow this line, and the twistd.log file will appear in the punjab folder, in which you can see how our BOSH server is doing there.

Thin point: if DNS entries appear in the log, you need to add to punjab.tac immediately after the line:

bosh = HttpbService(1)
following code:
bosh.connect_srv = False 

We check the work:

.http: // server_address: punjab_port / will show a message of the form: A XEP-0124 - BOSH - component manager.
.http: // server_address: punjab_port / http-bind message like: XEP-0124 - BOSH

Apache 2.4

I assume that you have Apache. We need to enable the proxy modules, proxy_http. It is included by a simple command a2enmod proxy proxy_http.

We go to apache2.conf and add it there:

    ProxyRequests Off
    ProxyPass /http-bind http://localhost:5222/http-bind
    ProxyPassReverse /http-bind http://localhost:5222/http-bind

Let me remind you that I have port 5222.
Why is this needed. The browser cannot send a packet to the port, only to the address. Therefore, we replace the port with an address.


We put the files from the converse archive into the folder of the Apache website, open index.html for editing. At the very end of the file we find a fragment of the JS code:

            bosh_service_url: '', // Please use this connection manager only for testing purposes
            i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported
            keepalive: true,
            message_carbons: true,
            play_sounds: true,
            roster_groups: true,
            show_controlbox_by_default: true,
            xhr_user_search: false

In this code, specify the desired bosh_service_url and locales as desired.

Save, open the demo page in the browser. On it we indicate our credentials in the login form in the form: "Jabber_Id @ jabber_server" and password.

If everything went smoothly, you will see your contact list.

Also popular now: