Have you ever wished of a wordpress plugin capable of providing a facebook style chat bar on your blog post. In this blog post, I will lay down the details of how Jaxl‘s bosh support comes in handy for building such browser based real time application. Specifically, I will explain how I achieved building a plugin for my wordpress blog. If everything goes perfect over next few weeks, this plugin might be submitted in wordpress plugin’s directory.
Jaxl BOSH Support Framework
Jaxl BOSH support comprise of three main parts:
- jaxl.jquery.js: JQuery extension written for Jaxl bosh support
- jaxl4bosh.class.php: Connection manager in PHP
- jaxl UI: Integrated UI framework for changing your application skin on the fly. Your application skin can be a simple facebook style chat bar (as on this page) or chesspark style whole html page
jaxl.jquery.js is responsible for initiating and maintaining a connection between the browser and the PHP connection manager. While
jaxl4bosh.class.php implements the BOSH protocol and maintain a persistent connection with the jabber server.
jaxl.jquery.js provide a few basic methods like:
- jaxl.connect: Call for initiating the connection
- jaxl.sendMessage: Call for sending a message to other jid’s
- jaxl.ping: Call to maintain the connection and gather any incoming data
- jaxl.disconnect: Call for disconnecting
jaxl4bosh.class.php provide wordpress style filter/hooks which can be used to modify every incoming and outgoing messages.
- jaxl_pre_connect: Call to perform initialization before jaxl connects to jabber server
- jaxl_post_connect: Call to perform shutdown after jaxl is connected to jabber server
- jaxl_send_message: Call to perform actions on outgoing messages from jaxl
- jaxl_recv_message: Call to perform actions on incoming messages to jaxl
- jaxl_send_presence: Call to perform actions on outgoing presence from jaxl
- jaxl_recv_presence: Call to perform actions on incoming presence from jaxl
- jaxl_pre_disconnect: Call to perform initialization before jaxl disconnects to jabber server
- jaxl_post_disconnect: Call to perform shutdown after jaxl is disconnected to jabber server
Jaxl and WordPress
Using Jaxl bosh support require you to only edit the configuration file. Here are the config variables:
// JAXL config define('JAXL_BOSH_HOST', 'localhost'); define('JAXL_BOSH_SERVER', 'localhost'); define('JAXL_BOSH_URL', 'http://localhost:7070/http-bind/'); define('JAXL_ADMIN_JID', '[email protected]');
You can configure Jaxl to use any of the available public xmpp services. However, I choose to host my own jabber server for my blog.
JAXL_ADMIN_JID is the admin jid to which Jaxl should route all incoming messages, added specifically for wordpress related requirement. PHP connection manager can be extended to route different chat sessions to different admins.
jaxl_recv_message handler is used to embed smiley’s and youtube videos by parsing the incoming chat messages.
A few other hooks like
jaxl_post_connect are used to notify
JAXL_ADMIN_JID about the newly connected user.
Below is a screen shot of how an admin desktop will look like while chatting with his site visitors:
Let me know if you are having any issues chatting using the chat bar at the bottom of the page. Code and installation might be buggy at times, and would appreciate any help from you on it.