Playing with Pusher
A couple of weeks ago Ben Nadel did a few excellent blog posts about Pusher, a service in beta stages that offers “real time client push to HTML5 browsers” that support web sockets and falls back to a flash plug-in on browsers that do not support web sockets.
This evening I finally had a few minutes to play around with it between working on other projects. I thought it would be a bit of an ordeal getting things going, but it was surprisingly fast. Pusher is in open beta so getting an account setup took all of a minute (literally).
Since that was far too easy, the next hurdle would be communicating with the service. If you check Ben’s demo code quite a bit of it was more or less preparing the data to be sent to Pusher so it could be pushed to the clients. Ben had a link to pusher.cfc by Bradley Lambert which actually alleviated the hassle.
That is the heavy lifting of setting up your pusher app. I did actually write a few lines of code to setup the remote facade for interacting with pusher.cfc, aside from that everything just worked out of the gate. For those interested, the remote facade for pusher.cfc.
<cfcomponent output="false"> <cffunction name="push" access="remote" returntype="any" returnformat="json"> <cfargument name="channel" type="string" required="true"> <cfargument name="event" type="string" require="true"> <cfargument name="data" type="any" required="true"> <cfargument name="socketID" type="string" required="false" default=""> <cfscript> var push = getPusher().triggerPush(arguments.channel, arguments.event, serializeJSON(arguments.data), arguments.socketID); return push; </cfscript> </cffunction> <cffunction name="getPusher" access="private" returntype="any"> <cfscript> var pusher = createObject("component", "com.pusher"); return pusher; </cfscript> </cffunction> </cfcomponent>
I bound to a few simple events on a test page so I could make sure everything was working, but I did not get much further this evening. Before I started going wild binding to events, I wanted to take a little time and think things out a little bit. What I will say is, if you are looking for real time client push and you don’t feel like dealing the the added complexity of running Blaze/LCDS or the other alternatives, I cannot think of a better way of spending 30 minutes.