com.satori.composer.rtm.RtmChannel Maven / Gradle / Ivy
The newest version!
package com.satori.composer.rtm;
import com.satori.composer.rtm.core.*;
import com.satori.mods.core.async.*;
import io.vertx.core.*;
import io.vertx.core.http.*;
public class RtmChannel extends RtmBase implements IRtmContext {
public RtmPublisher publisher;
public RtmChannel(Vertx vertx, RtmBaseConfig config, String name) {
super(vertx, config);
this.name = name + ", " + this.name;
}
@Override
protected IRtmState createConnectedState(WebSocket ws) {
return new RtmConnectedState(this, ws) {
@Override
protected IRtmPipelineHandler createPipeline(WebSocket ws, IRtmPduHandler handler) {
RtmChannel ctx = RtmChannel.this;
publisher = new RtmPublisher(ctx, handler);
final RtmParser parser;
if (ctx.auth() != null) {
final RtmAuthenticator auth = new RtmAuthenticator(ctx, publisher);
parser = new RtmParser(ctx, auth);
} else {
parser = new RtmParser(ctx, publisher);
}
final WsPinger pinger = new WsPinger(ctx, parser);
final WebSockAdapter adapter = new WebSockAdapter(ws, ctx, pinger);
return adapter;
}
};
}
@Override
protected void leaveConnectedState(IRtmState state) {
publisher = null;
super.leaveConnectedState(state);
}
public String publish(String channel, T msg, IAsyncHandler cont) {
if (publisher == null) {
if (cont != null) {
cont.fail("not connected");
}
return null;
}
return publisher.publish(channel, msg, cont);
}
}