The Virtual Commons

building extensible software for collective action research

real time in the browser

Real-time browser interactions

There's a few ways to get real-time in the browser - use a rich client interface like Flash or Flex with GraniteDS/BlazeDS, Shockwave, Java Applets, Silverlight, or go with a JavaScript solution. On the JavaScript side there appear to be two options - AJAX or server push via persistent socket connection (e.g., websockets / If using straight-up AJAX, we'd be polling the server periodically to check for new messages. A better solution is server push, we establish a long-lived, persistent connection via JavaScript to an asynchronous server process that can maintain many long-lived persistent connections.

Current work

The use case that requires this functionality is the ability to have a real-time chat within an Experiment's Group, and to be informed of when a round has finished. This should be implemented in a progressive enhancement spirit.. in this case JavaScript is always required, but perhaps a graceful degradation to AJAX polling should be implemented.

The current codebase has a successful prototype up and the Tornado python webserver and will continue to be refined as the forestry experiment is completed. However, true support for server push will require some kind of queuing mechanism between the Django process and our Tornado asynchronous server push process. This probably should be AMQP on our hosted environment but I'd also like to reduce the infrastructural burden on users wanting to run this locally (Tim for instance wants to be able to create his own network in remote areas and deploy it on his Mac; ideally we don't have to configure 5 separate pieces of software just to run the damn thing). Celery has a nice abstraction for this via their so-called "ghettoq" wrapper which can talk to Redis, beanstalkd, couchdb, mongodb, or the tables in whatever Django db is configured.

Links and other resources