This is a wrapper of Google App Engine Channel API for Google Web Toolkit.
Add this to your pom.xml:
<dependency>
<groupId>no.eirikb.gwtchannelapi</groupId>
<artifactId>gwt-channel-api</artifactId>
<version>0.3</version>
</dependency>
Add this to your Module.gwt.xml:
<inherits name="no.eirikb.gwtchannelapi.GwtChannelApi" />
Add this to your index.html:
<script src="/_ah/channel/jsapi"></script>
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>
...
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)
.
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:
- ChatServerImpl.java serializing with MyFactory.java and MyMessage.java.
- GwtChannelApiDemo.java Deserializing client side.
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
.
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