I’ve been using Google App Engine for a while now, and it is hard to go back to traditional java webapp development given how easy it is to deploy a demo version for a customer, and how great some of the tools provided in the App Engine SDK are.
Among those tools is the Channel API. It offers push messaging with
only a few lines of code. There are some drawbacks (mainly regarding the reliability of the communications) but it
still is a great tool to provide real-time notifications to the user.
I also recently discovered Angular JS. A great
site. The web-binding part is quite amazing.
Now, I read Angular JS provides some support for Comet notifications, but nothing for
the Channel API. On a project I’m developping on my spare time there’s this need to send chat messages to various
Here’s how I did it with AngularJS and the Channel API :
Create an AngularJS service to hold the list of the chats. This is not required but it is the recommended way to
share an observable array (which means with two-way data binding) between controllers.
Initiate the Channel API inside that service. Now there's the trick : for the modifications to the
observable array to be pushed to the controllers, we need to use the $rootScope method.
So here’s how the service looks ( the chat repository which receives the chats from the Channel API is