Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at CFinNC 2009 (Raleigh, North Carolina) with:

Pusher.cfc - ColdFusion Component For Realtime Notification With HTML5 WebSockets

Posted by Ben Nadel

Lately, I have been playing around a lot with a service called Pusher. Pusher provides realtime push notification services for your web applications using HTML5 WebSockets (or Flash for non-compatible browsers). While using the Pusher service is extremely simple, digitally signing your HTTP request is not; I've had a good deal of back and forth with the Pusher support team, trying to squash a few bugs in my code. Having finally figured out where my HEX-encoding was failing, I figured I would roll this up into a ColdFusion component and a tiny demo project that anyone could download.

 
 
 
 
 
 
 
 
 
 

The code for my Pusher.cfc ColdFusion component and my demo application is available on my Pusher.cfc project page. If you'd like to try the online demo, click here.




Reader Comments

Hah... very timely. I've been digging through the docs on BlazeDS/LCDS for the last few days and really wishing Web Sockets were here today.

Reply to this Comment

@Brian,

People who have seen me play with the Pusher stuff have suggested that I look into BlazeDS - but I kind of love the idea of "as needed" communication rather than long polling.

Reply to this Comment

Ben, do you think could CF Gateways could perform a similar service as Pusher? Have you heard of anyone using CF Gateways with the HTML5 WebSockets?

We have a gateway set up to push IM messages to users and are intrigued at the possibility of doing the same thing with HTML5.

Reply to this Comment

@Paul,

I don't know how true this is anymore; but, I think at one time, pretty much all "Gateway" activity in ColdFusion was Enterprise edition only. As such, I never really played around with any of the gateway stuff. I think that may have been changed in recent editions of ColdFusion (I think Standard can do more gateway stuff).

I'll have to look into it one day.

Reply to this Comment

You're right and I always forget that. That probably explains why information for CF Gateways is so hard to come by.

Thanks!

Reply to this Comment

@Paul,

Yeah, but again, I think it has changed in recent releases. I just never really got into playing with it.

Reply to this Comment

Was the encoding issue the root cause of the 401 Unauthorized errors you were seeing? I have been busy with other projects lately and I haven't really had time to work on my pusher app. Looking forward to playing with it more.

Reply to this Comment

@Robert,

Yeah it was. In 90% of the cases, the hex encoding resulted in the needed 64 characters. In 10% of the cases, it only resulted in 63 characters and I needed to pad with one zero... which I was foolishly padding on the *wrong* side of the encoded signature :(

@Elias,

Looks cool, but I can't use it - all of my servers are Windows; with all the little I know about VirtualBox stuff, it seems like too much overhead for me to play with at this time.

Reply to this Comment

@Ben Nadel,

Well in that case I think you are going to love this. This one looks very easy to implement.

Go to http://www.stream-hub.com/ and download the community edition

To Run the server
--------------------------
On Unix execute runExamples.sh,
on Windows runExamples.bat.

This will start StreamHub at http://localhost:7979/ -
open that page in your browser to view the examples.

Im on a Mac and I don't know how to execute the runExamples.sh script :(

Im going to try it on a windows box I will let you know the results.

Reply to this Comment

@Elias,

That also looks very cool. I'm really digging the realtime notification mindset. Now, I just gonna figure out what some of the better practices are.

Reply to this Comment

@Elias,

On a Mac, it should be:

> cd /wherever/you/stored/the/sh/file
> ./runExamples.sh

Or just:

> /wherever/you/stored/the/sh/file/runExamples.sh

-Joe

Reply to this Comment

@Joe Rinehart,

Thanks Joe. I actually got it to run.

I was looking into the JAVA samples they have. Im trying to send msgs to the StreamHub Server via CFC using the java API.

If anyone has any idea on how to implement this I'll truly appreciate it.

Reply to this Comment

Hey Ben - I was playing around with Pusher and was alerted to http://beaconpush.com/

You may want to check it out.

Way easier to use than Pusher (no need to complex key encoding/encryption) and works across all the major browser without needing Flash socket fallback.

Reply to this Comment

@Johans,

Looks cool. It appears there are quite a number of HTML5 Push services now. This stuff is really catching on (and getting easier and easier to implement).

Reply to this Comment

Ben,

I've tried to run the demo on your site and also download it and run from my system with my own API key, etc. and connecting to pusher just stays there. The connection_established event seems to never get fired. If I bypass the server connection test and post a message to the server, I see that the message is posted successfully, but none of the triggers are fired. I thought maybe it was my browser, so I updated to the latest version of Safari and still nothing, both on your demo and my locally installed demo. I'll keep trying to figure it out, but any help would be greatly appreciated. I know it's probably something really stupid and obvious that I'm missing.

Reply to this Comment

Well I just tried it from another PC and it worked! ... Not sure why this is happening?

Reply to this Comment

@Peter,

I've definitely seen the Pusher API just seem to give out from time to time. I just tried it on Safari on Mac (for the first time - was on a PC when I wrote this post) and it worked. Glad it finally got working for you.

Reply to this Comment

Have you tried using web sockets tied in with cfthread? In other words... Fire off 100 threads or so doing long requests, as each one finishes it pushes some data to the browser.

Would that work?

Reply to this Comment

@Steve,

I've played around with integrating Pusher into jQuery as part of a long-running AJAX request:

http://www.bennadel.com/blog/2017-Proof-Of-Concept-Adding-Pusher-Powered-Update-Support-To-jQuery-AJAX.htm

Basically, I added an "update" callback for the $.ajax() method which allows communication to take place after the AJAX request has completed.

Now, granted, in that example, I am not making any communication in an actual CFThread - but there's not that much difference to do something from within a CFThread. At the end of the day, you'll just be posting to the PusherApp API using CFHTTP.

Reply to this Comment

Ben,

Have you worked with the presence and private channel auth at all with pusher? I exchanged an email with Bradley Lambert who said he's not really worked with it since he posted the cfc so it's probably his pusher-cfc will probably not get developed further. Wonder if perhaps we could expand on it to provide the presenceAuth and and socketAuth capabilities like the php library has in your cfc.

I've personally been struggling with the SHA-HMAC256 signing of the JSON message, or I'd add myself. (CF9 Standard).

I'm seriously about to do a cfhttp call to the dang PHP component to work around for now…(ugh) but at least it's working.

It's simply a matter for presence to sign

  • <socket_id>:<channel_name>:<JSON encoded user data>

and return Like

  • {"auth":"278d425bdf160c739803:afaed3695da2ffd16931f457e338e6c9f2921fa133ce7dac49f529792be6304c","channel_data":"{\"user_id\":10,\"user_info\":{\"name\":\"Mr. Pusher\"}}"}

I do see the merit behind this process and notice the authenticated private channels are absent in other push "services" out there hence my continued interest with the Pusher service as an option for a project I'm working on.

The details for pusher's auth signature is here:
http://pusher.com/docs/auth_signatures

Regards,

Jim

Reply to this Comment

Post A Comment

?
You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.