
Today we can use XMPP and BOSH and let the web page talk to my GTalk client, which runs all the time anyway.
- ejabberd XMPP server with BOSH
- Strophe JavaScript XMPP library
- jQuery JavaScript utilities
- Apache web server as BOSH proxy
- Google Talk or any other Jabber client
% {auth_method, internal}. % disabled
{auth_method, odbc}. % enabled
{odbc_server, {mysql, "localhost", "ejabberd", "mysql-user", "mysql-password"}}
{access, register, [{deny, all}]}.
% a2enmod proxy% a2enmod proxy_http
ProxyPass /xmpp-httpbind http://127.0.0.1:5280/http-bindProxyPassReverse /xmpp-httpbind http://127.0.0.1:5280/http-bind
ProxyRequests Off
<script type="text/javascript" src="jquery-1.4.2.min.js"></script><script type="text/javascript" src='strophe.min.js'></script>
var conn = new Strophe.Connection('/xmpp-httpbind');
conn.connect('test@wolfspelz.de', 'secret', OnConnectionStatus);
function OnConnectionStatus(nStatus){if (nStatus == Strophe.Status.CONNECTING) {} else if (nStatus == Strophe.Status.CONNFAIL) {} else if (nStatus == Strophe.Status.DISCONNECTING) {} else if (nStatus == Strophe.Status.DISCONNECTED) {} else if (nStatus == Strophe.Status.CONNECTED) {OnConnected();}}
function OnConnected(){conn.addHandler(OnPresenceStanza, null, "presence");conn.addHandler(OnMessageStanza, null, "message");conn.send($pres());}
function OnMessageStanza(stanza){var sFrom = $(stanza).attr('from');var sType = $(stanza).attr('type');var sBareJid = Strophe.getBareJidFromJid(sFrom);var sBody = $(stanza).find('body').text();// do something, e.g. show sBody with jQueryreturn true;}
function OnPresenceStanza(stanza){var sFrom = $(stanza).attr('from');var sBareJid = Strophe.getBareJidFromJid(sFrom);var sType = $(stanza).attr('type');var sShow = $(stanza).find('show').text();// do something, e.g. show status icon with jQueryreturn true;}
There is a patch, which allows for synchronous connection closing. The patch must be applied to the strophe.js file:
diff --git a/src/core.js b/src/core.js
index 5aeb06a..f79ae29 100644
--- a/src/core.js
+++ b/src/core.js
@@ -2161,7 +2161,8 @@ Strophe.Connection.prototype = {
req.date = new Date();
try {
- req.xhr.open("POST", this.service, true);
+ var async = !('sync' in this && this.sync === true);
+ req.xhr.open("POST", this.service, async);
} catch (e2) {
Strophe.error("XHR open failed.");
if (!this.connected) {
this.conn.flush();
this.conn.sync = true; // Set sync flag before calling disconnect()
this.conn.disconnect();
Of course, all these functions and callbacks should be prototype based and bind the instance to the closure. We should also use a model-view architecture and handle the protocol stuff in the model, while notifying the view of really important events.
- contact.html - the "driver" which loads everything and produces the GUI
- model.js - the model does it, classes: Model, Room, Participant
- view.js - the view shows it, the view registers listeners with the model
- utils.js - utility classes, logging, unit test, oberver pattern
- config.js - configurations for test and production
- setup.js - selects the appropriate configuration
- style.css
- lib/strophe.js - including the above patch
- lib/jquery-1.4.2.min.js
- lib/jquery-ui-1.8.5.custom.min.js