Jon
Jon

Reputation: 8531

Chrome - How To Load Channel Token?

I have an extension where I authenticate the user when they enable to app. The server then returns a channel token, which I use to establish a channel. The code for the authentication occurs in script.js, where-as the channel creation is in background.html. My question is how would I get the channelToken into background.html, when the authentication runs after background.html is loaded?

I want to note that I am running Google App Engine (Python) as my server. I have also copied the javascript code from here and placed it in my manifest as oppose to putting <script type="text/javascript" src="/_ah/channel/jsapi"></script> in background.html.

//background.html
var channel = new goog.appengine.Channel(channelToken);
var socket = channel.open()

socket.onopen = function() {
  // Do stuff right after opening a channel
  console.log('socket opened');
}

socket.onmessage = function(evt) {
  // Do more cool stuff when a channel message comes in
  console.log('message recieved');
  console.log(evt);
}

Upvotes: 0

Views: 187

Answers (1)

tobiasmueller
tobiasmueller

Reputation: 140

You should use messagePassing to inform the background.html if a channelToken is received. http://code.google.com/chrome/extensions/messaging.html

Upvotes: 1

Related Questions