I have a simple complete app that uses the GAE channel api. It works on my local machine but when I upload it to appspot the url where the channel api is supposed to be appears to be empty and the app fails with the message "goog is not found".
The server:
import webapp2
import jinja2
import os
import time
import logging
channel_key = 'key'
class MainHandler(webapp2.RequestHandler):
def get(self):
token = channel.create_channel("1")
template_values = {'token': token}
template = env.get_template('index.html')
self.response.write(template.render(template_values))
class OpenedHandler(webapp2.RequestHandler):
def post(self):
channel.send_message("1", "hi")
logging.info("send hi");
env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
app = webapp2.WSGIApplication([
('/', MainHandler),
('/opened', OpenedHandler)
], debug=True)
The client:
<!DOCTYPE html>
<html>
<body>
<div id="debug">_</div>
<!--
<script src="https://talkgadget.google.com/talkgadget/channel.js"></script>
<script type="text/javascript" src="/static/channel.js"></script>
-->
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
<script>
function debug(s) {
document.getElementById("debug").innerHTML = s;
}
my_func = function() {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/opened');
xhr.send();
}
onOpened = function() {
debug("open");
setTimeout(my_func, 2000);
};
onMessage = function(message) {
alert("something recieved");
alert(message);
}
channel = new goog.appengine.Channel("{{token}}") // this is where it fails
socket = channel.open();
socket.onopen = onOpened;
socket.onmessage = onMessage;
socket.onerror = function(e){
alert("error:"+e['description']);
};
socket.onclose = function(){
alert("close");
};
</script>
</body>
</html>
On my local machine, the onOpened function gets called and the message gets sent. When installed on appspot, I get
"Uncaught ReferenceError: goog is not defined"
right after
channel = new goog.appengine.Channel("{{token}}")
When I look in the Resources tab of the Developer tools window and click on "jsapi" it appears to be empty:
(source: crb at www.sonic.net)
I have tried other urls, you can see these commented out in the html, but nothing works. I am pretty sure this is correct, I can't explain why the api appears to be empty and thus 'goog' is not defined.
Thanks for any suggestions.