eirikb / gwt-channel-api Goto Github PK
View Code? Open in Web Editor NEWGAE Channel API in GWT
Home Page: http://gwt-channel-api.appspot.com
GAE Channel API in GWT
Home Page: http://gwt-channel-api.appspot.com
I am trying to control the disconnection of a client from a channel, trying to distinguish when a user close the browser of when the token was expired (to renew or create a new token in this last case).
Following the Channel API of Google (https://developers.google.com/appengine/docs/java/channel/overview#Tokens_and_Security), when a token expires 'the socket’s onerror() and onclose() callbacks are called' but I only can find the onReceive method within the ChannelListener, how can I access to this events?
Or how could I control the session of a user (expiration time) in other way?
Thanks so much.
Hi there, thanks for the great library.
In the Channel.join() method I noticed that the onError() callback for the RPC is empty, i.e. it will hide errors on failed calls to the server:
public void join() {
channelService.join(channelName, new AsyncCallback<String>() {
@Override
public void onFailure(Throwable throwable) {
// Exceptions disappear here
}
@Override
public void onSuccess(String t) {
token = t;
join(token);
}
});
}
This is probably a rare event, but potentially tricky to debug when it happens.
I can think of a few potential solutions. Here's the first two:
public interface ChannelListener extends RemoteService {
void onJoinError(Throwable caught);
void onMessage(String message);
void onOpen();
void onError(int code, String description);
void onClose();
}
public interface FailedJoinCallback {
void onFailedJoin(Throwable caught);
}
public void join(FailedJoinCallback callback) {
channelService.join(channelName, new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailedJoin(caught);
}
@Override
public void onSuccess(String t) {
token = t;
join(token);
}
});
I created one myself:
package no.eirikb.gwtchannelapi.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface ChannelListenerAsync { void onMessage(String message,AsyncCallback<Void> asyncCallback);
void onOpen(AsyncCallback<Void> asyncCallback);
void onError(int code, String description, AsyncCallback<Void> asyncCallback);
void onClose(AsyncCallback<Void> asyncCallback);
}
I am trying to get up and running with gwt-channel-api in an existing project. I have set up the required JARs and classpaths in Eclipse, and when I launch GWT Dev mode everything compiles properly.
However, when I load the app web page in the browser, I see an error for a missing resource:
/_ah/channel/jsapi
This is included in the index.jsp, as instructed here.
What is this? A JavaScript file? If so, should it be:
/_ah/channel/jsapi.js?
Where does this come from?
Is it generated by GWT compile?
Thanks,
Don
Your Server code uses "send" but your client code used "onMessage"
This also means there is a compiler error initially because it says you have not implemented "onMessage" in the server code
ChannelServer.java:
protected static void send(String channel, Object o) { AutoBean bean = AutoBeanUtils.getAutoBean(o); String serialized = AutoBeanCodex.encode(bean).getPayload(); ChannelServiceFactory.getChannelService().sendMessage(new ChannelMessage(channel, serialized)); }
Client:
public void send(String message, AsyncCallback<Void> callback) {
channelService.onMessage(token, channelName, message, callback);
}
Hi there.
I ran into a minor hurdle with this. It would be helpful to be able to configure the channel duration when creating the channel. For example, with the burstiness of my current project, I would be setting the duration to just 30 minutes or less, whereas the default is 2 hours.
For reference, the Channel API has rate-limiting for the number of channel-hours requested per minute...
One possible approach (which is also backwards-compatible) might look like this:
public abstract class ChannelServer extends RemoteServiceServlet implements ChannelService {
// ADDED THIS
/**
* Defaults to 2 hours. Override if needed.
*/
protected int getChannelDuration() {
return 2*60;
}
protected static void send(String channel, Object o) {
AutoBean bean = AutoBeanUtils.getAutoBean(o);
String serialized = AutoBeanCodex.encode(bean).getPayload();
ChannelServiceFactory.getChannelService().sendMessage(new ChannelMessage(channel, serialized));
}
@Override
public final String join(String channelName) {
// MODIFIED THIS
String token = ChannelServiceFactory.getChannelService().createChannel(channelName, getChannelDuration());
onJoin(token, channelName);
return token;
}
protected abstract void onJoin(String token, String channelName);
}
That's my 2 cents.
Cheers :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.