3

So I'm trying to use the GAE Channel API with Angular.js to do real-time data-bound updates (which would be really cool, right!?). I'm told the correct way to do this is to wrap the Channel API Javascript Client in an Angular.js service (and make sure to use $apply()). But what does that mean exactly?

To my understanding, for the Channel API, I'm pretty much supposed to have a 1:1 client:channel connection, so all my updates will have to flow down that one channel for all the models in my entire app. How do I then broadcast to possibly multiple scopes that a model (generally an ngResource) has been updated? $watch? $emit? $broadcast? $digest?

Community
  • 1
  • 1
SteveShaffer
  • 1,577
  • 1
  • 10
  • 14
  • Okay, after some coding, I settled on one option for now, which is to pub-sub data on the client using a Channel service that stores keys and callbacks (added by the controllers). When the server sends down a key, any callbacks (usually a bunch of `$get()s`) with that correspond with that key get called. Working for me now, but I'm still not sure that's the right way to do it... – SteveShaffer Oct 31 '12 at 08:10
  • 1
    Not exactly a solution to your problem, but something to consider at least trying, is the http://www.pubnub.com/ The Channel API supports 1:1 connections, which means if you want to broadcast one message to many clients you have to send many messages, while using PubNub you're sending only one and who ever is connected gets the message.. – Lipis Oct 31 '12 at 11:06
  • Thanks, PubNub looks great; I'll take a look. I'm getting more used to using 1:1 Channel API connections as a secure, locked-down way to broadcast for this application, but PubNub looks like it would be helpful for other projects. – SteveShaffer Nov 01 '12 at 15:27

1 Answers1

6

I had the same requirement and solved it with an Angular service. I described my solution here :

http://david-codes.blogspot.com/2013/03/app-engine-channel-api-and-angular-js.html

David
  • 5,481
  • 2
  • 20
  • 33