jquery.comet
jquery.comet copied to clipboard
A Comet (Bayeux) Plugin for JQuery, with an async_sinatra server
= jquery.comet
A lightweight clean implementation of the Bayeux (COMET) protocol as a jQuery plugin, with a test server in Sinatra (uses async_sinatra under Thin).
== Usage
When you publish a message, it won't get sent immediately. You can publish as many as you like within the one function, and even return to where other queued callbacks will publish additional messages, and your messages will be batched and sent all together when the browser pauses.
If a poll fails, messages will be queued until it comes back again. Once a message has been sent however, there's no guarantee it will be delivered in the case of a server crash.
== Running the demo
You need to have Ruby installed. Then:
gem install thin async_sinatra rack bayeux-rack cd chat_server rackup --server thin
Now visit localhost:8080 with one or more browsers. Because it uses async_sinatra, which uses EventMachine, it won't work in Passenger. Sorry about that, but Apache doesn't really like long-polling anyhow.
== License
The jquery.comet.js and chat_server are subject to the MIT license.
The client_demo directory contains a chat client written by Morgan Allen, and subject to the GPL v2. See his original code at http://code.google.com/p/jquerycomet/.
== Compatibility
Tested on Chrome, Safari, and FF3.5.
JSONP (cross-domain) support requires jQuery >= 1.5.0
== Developing
Fork on github https://github.com/cjheath/jquery.comet or just clone to play:
git clone git://github.com/cjheath/jquery.comet.git
Patches welcome! Fork and send a pull request. Please follow coding conventions already in use. Please use jslint if you can. There are currently no warnings, please keep it that way.
== Status
Current release has a happy path (working ok), but other paths are less well tested:
- Callback polling
- Cross-domain polling using JSONP
- Renegotiating the handshake
Some enhancements are on the cards:
- Multiple subscriptions to the same channel
- Wildcard subscriptions (/channel/*/foo, /channel/**, etc)