Reputation: 7044
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.
Upvotes: 2
Views: 390
Reputation: 6748
For me, this turned out to be caused by the Disconnect plugin for Chrome, which was blocking the URL that /_ah/channel/jsapi redirects to. The only solution was to disable Disconnect for that page.
I'm gonna try to tell the Disconnect developer that that URL shouldn't be blocked, since it's likely to provide vital functionality for any page that loads it.
Upvotes: 1
Reputation: 403
I had same problem. See if you added the following code just before the </body>
balise.
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
This fixed my "goog is not found" error.
Upvotes: 1