Skip to content

kevzlou7979/gwt-channel-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

This is a wrapper of Google App Engine Channel API for Google Web Toolkit.

Setup

Maven

Add this to your pom.xml:

<dependency>
    <groupId>no.eirikb.gwtchannelapi</groupId>
    <artifactId>gwt-channel-api</artifactId>
    <version>0.3</version>
</dependency>

Module

Add this to your Module.gwt.xml:

<inherits name="no.eirikb.gwtchannelapi.GwtChannelApi" />

HTML

Add this to your index.html:

<script src="/_ah/channel/jsapi"></script>

Usage

Server

Extend no.eirikb.gwtchannelapi.server.ChannelServer to create a servlet listening for joins and messages.

public class MyServer extends ChannelServer {
    public void onJoin(String token, String channelName) {
    }

    public void onMessage(String token, String channelName, String message) {
        // Send the message to everyone in the channel
        send(channelName, message);
    }
}

This servlet receives GWT RPC calls on RemoteServiceRelativePath channel, so make sure to implement this in web.xml:

...
<servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/MyModule/channel</url-pattern>
</servlet-mapping>
...

Client

channel = new Channel("SomeRandomChannel");
channel.addChannelListener(new ChannelListener() {

    @Override
    public void onMessage(String message) {
    }

    @Override
    public void onOpen() {
    }

    @Override
    public void onError(int code, String description) {
    }

    @Override
    public void onClose() {
    }
});
channel.join();

Send messages with channel.send(String).

AutoBean

The current version of gwt-channel-api only support sending and receiving Strings.
Previous versions used IsSerializable, but without proper RPC support it is better to let users handle this themselves.
One of the current preferable ways to handle serialization is to use AutoBean, please see examples in the demo:

Demo

There should be a working demo at http://gwt-channel-api.appspot.com/ .
To build and run the demo in demo folder locally run mvn gwt:run.

Not using maven

It should be possible to download the jar manually from here:
http://repo1.maven.org/maven2/no/eirikb/gwt-channel-api/0.3/gwt-channel-api-0.3.jar

Packages

No packages published

Languages

  • Java 98.3%
  • HTML 1.7%