Channel API Javascript Reference (Go)
Use the following reference when building JavaScript clients for the channel API.
Building your JavaScript client
Include the following in your html page before any JavaScript code that refers to it:
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
All other JavaScript code must be between the
<body>
tags of the page. For best performance, place your JavaScript code at the bottom of your HTML markup just before the
</body>
.
goog.appengine.Channel() Class
Constructors
goog.appengine.Channel(token)
-
Create a channel object using the token returned by the
channel.Create
call on the server.
Methods
open(optional_handler)
-
Open a socket on this channel.
open()
returns agoog.appengine.Socket
object. You can set the callback properties directly on the returned socket object or set them using an optional object handler with the following properties:-
onopen
-
onmessage
-
onerror
-
onclose
If the token specified during channel creation is invalid or expired then the
onerror
andonclose
callbacks will be called. Thecode
field for the error object will be 401 (Unauthorized) and thedescription
field will be'Invalid+token.'
or'Token+timed+out.'
respectively. Theonerror
callback is also called asynchronously whenever the token for the channel expires. Anonerror
call is always followed by anonclose
call and the channel object will have to be recreated after this event. -
goog.appengine.Socket() Class
Methods
close()
- Close the socket. The socket cannot be used again after calling close; the server must create a new socket.
Properties
onopen
- Set this to a function called when the socket is ready to receive messages.
onmessage
-
Set this to a function called when the socket receives a message. The function is passed one parameter: a message object. The
data
field of this object is the string passed to thesend_message
method on the server.
onerror
-
Set this property to a function called when an error occurs on the socket. The function is passed one parameter: an error object. The
description
field is a description of the error and thecode
field is an HTTP error code indicating the error.
onclose
-
Set this property to a function that called when the socket is closed. When the socket is closed, it cannot be reopened. Use the
open()
method on agoog.appengine.Channel
object to create a new socket.