When building the original Hemlock framework, we chose ActionScript because it has widespread browser support, and lets us open a real socket connection. However, one of the biggest complaints we received was, of course, that we used ActionScript.
If you've been watching the progress of our flagship Hemlock product, Picklive (formerly known as Football3s), you've already heard the news:
Hemlock will now be developed primarily in JavaScript. No ActionScript/Flash necessary.
The revamped Picklive interface is written with the new Hemlock JS framework. If the browser supports Flash, Hemlock uses an invisible, pre-compiled Flash element called HemlockPixel to open a socket connection with the XMPP server. If Flash is unavailable, Hemlock falls back to BOSH and long polling via JavaScript (thanks to the Strophe project). Your app's business logic doesn't need to change based on the connection method: Hemlock detects each browser's capabilities, and switches connection methods automatically.
When Hemlock JS is production-ready, here's how your JavaScript app will send a data payload to everyone in the room:
app.sendData('game_move', {
locFrom: [10, 10],
locTo: [20, 20]
});
Here's how you'll receive a data payload:
// Adds a handler for incoming data
app.receiveData('game_move', function(elem, data){
var from = elem.getAttribute('from');
console.log(from + ' moved from ' +
data.locFrom + ' to ' + data.locTo);
});
And here's how you'll handle arbitrary stanzas, like <presence/>s for keeping track of users in the room:
app.receiveElement({
name: 'presence',
callback: function(elem, data){
var from = elem.getAttribute('from'),
type = elem.getAttribute('type');
switch(type){
case 'error':
/* ... */ break;
case 'unavailable':
console.log(from + ' disconnected'); break;
default:
console.log(from + ' joined the room'); break;
}
}
});
Since there are so many great tools for building user interfaces with JavaScript, Hemlock JS won't include interface helpers like in the ActionScript codebase. Hemlock provides the connection mechanisms; your app has full control over the rest.
Picklive has already made successful use of Hemlock on the iPad and iPhone with BOSH and long polling via JavaScript. While polling is sufficient for now, we intend to add support for HTML5's WebSocket API, which browser vendors are rushing to integrate.
With this new direction in mind, let's rethink the first Hemlock roadmap, posted back in September 2009. Hemlock 0.2 will be a production-ready version of Hemlock JS. It'll include BOSH support as planned, as well as a little example app. Down the road, we plan to add support for the WebSocket API. In browsers that don't yet support this API, Hemlock will fall back to a socket connection via Flash; failing that, Hemlock will fall back to BOSH via JS.
If you're interested in seeing our progress, or want to contribute to a real-time open source project, check out Hemlock on GitHub or Google Groups.




