That was the story behind PusherCast. Well, not exactly because I wasn’t (and am not) going to stream any dog’s birthday in the Net ;). I was just searching for a real-world example of Pusher’s use and this idea popped into my head. I decided to write it adding one thing - local MongoDB storage. Why? Firstly to provide users that join the event after it started with history of what’s been already posted. Secondly to ease creating post-event log - reading the stream from Mongo and rendering it as a static HTML is a matter of one small Python script.
The app uses Tornado as a backend server. Why? Because Tornado provides non-blocking HTTP requests. That’s a cool feature that gives a lot of power. PusherCast uses this feature to post messages to Pusher backend. In order to do that I had to patch Pusher’s Python library replacing it’s blocking HTTP connection with Tornado’s mechanisms. The patched library is available here. If you’d prefer using not modified library then you’d have to add the TornadoChannel to the app manually.
The backend also serves HTML file for the client app. The client app is dead simple and minimal. It sets up Pusher client and allows publishing new messages. In a production app you’d want to implement some sort of auth mechanism so that only certain people can publish. You could also think of a few other features, e.g. photo attachments and better message parsing to enable links etc. But that’s not a production app so if you want those features consider forking it and implementing them. This is just a demo thingy.
Pusher is an awesome project. They provide hassle free service that’s very easy to implement. It took me about 2 hours to code backend posting and client handling of messages. I was really amazed, given the feature they provide. I tested the app with a bunch of friends and none of us experienced any problems. That’s really cool.
Have fun :).