0

I am trying to create the smallest possible GAE app to show the use of the channel api. I have two handlers in the python, the first "TestPage" sends out the html shown below. The second "SendPage" tries to send a message over the channel to the test page. The code for the TestPage is

class TestPage(Handler):
    def get(self):
        token = channel.create_channel("1")
        self.render("test.html", token = token)

It just creates the channel with an id of "1" and reders the page with the token passed back from create_channel().

The SendPage is just:

class SendPage(Handler):
    def get(self):
        channel.send_message("1", "hello")
        self.write("sent hello to 1")

The html is as small as I could get it:

<!DOCTYPE HTML>
<html>
<body>
<br>Token is {{ token }}
<br>
<div id="debug">_</div>

<!--
<script src="https://talkgadget.google.com/talkgadget/channel.js"></script>
-->
<script src="static/channel.js"></script>
<script defer="defer">
    function debug(s) {
        document.getElementById("debug").innerHTML = s;
    }

    var channel = new goog.appengine.Channel( {{ token }} );
    var socket = channel.open();
    socket.onopen = function(e) {
        debug("open");
    }
    socket.onclose = function(e) {
        debug("close");
    }
    socket.onerror = function(e) {
        debug("error");
    }
    socket.onmessage = function(e) {
        debug("message");
    }
    debug("ready");

</script>
</body>
</html>

So, inside chrome I pull up TestPage and I see the "ready" message. Then I pull up the SendPage in another tab. And see the "sent message". Then when I go back to the TestPage I would expect to have "ready" replaced by "message". But this never happens. None of the socket handler functions are being called.

I'm stuck for the moment and would appreciate any help or suggestions.

Thank you.

Charlie Burns
  • 6,994
  • 20
  • 29
  • BTW, I am running this on my localhost with dev_appserver.py . The source code for the channel api is on my local machine and it was copied from https://talkgadget.google.com/talkgadget/channel.js . Please ask if you have any questions. Thanks. – Charlie Burns Jul 09 '13 at 01:35

1 Answers1

0

Ok, I figured it out. There were two problems. First, the template line

var channel = new goog.appengine.Channel( {{ token }} );

should have been

var channel = new goog.appengine.Channel( "{{token}}" );

as it was token was something like "channel-2052893164-1373347311-1" which quietly evaluated to a number.

Second, the correct script for the channel.js was

<script type="text/javascript" src="/_ah/channel/jsapi"></script>

The other scripts I had referenced were from other stack overflow answers and I guess they did not properly apply to this problem.

Thanks.

Charlie Burns
  • 6,994
  • 20
  • 29