Giter Club home page Giter Club logo

gwt-channel-api's Introduction

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

gwt-channel-api's People

Contributors

eirikb avatar slugmandrew avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.