use of com.corundumstudio.socketio.messages.PacketsMessage in project netty-socketio by mrniko.
the class PollingTransport method onPost.
private void onPost(UUID sessionId, ChannelHandlerContext ctx, String origin, ByteBuf content) throws IOException {
ClientHead client = clientsBox.get(sessionId);
if (client == null) {
log.error("{} is not registered. Closing connection", sessionId);
sendError(ctx);
return;
}
// release POST response before message processing
ctx.channel().writeAndFlush(new XHRPostMessage(origin, sessionId));
Boolean b64 = ctx.channel().attr(EncoderHandler.B64).get();
if (b64 != null && b64) {
Integer jsonIndex = ctx.channel().attr(EncoderHandler.JSONP_INDEX).get();
content = decoder.preprocessJson(jsonIndex, content);
}
ctx.pipeline().fireChannelRead(new PacketsMessage(client, content, Transport.POLLING));
}
use of com.corundumstudio.socketio.messages.PacketsMessage in project netty-socketio by mrniko.
the class WebSocketTransport method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof CloseWebSocketFrame) {
ctx.channel().close();
ReferenceCountUtil.release(msg);
} else if (msg instanceof BinaryWebSocketFrame || msg instanceof TextWebSocketFrame) {
ByteBufHolder frame = (ByteBufHolder) msg;
ClientHead client = clientsBox.get(ctx.channel());
if (client == null) {
log.debug("Client with was already disconnected. Channel closed!");
ctx.channel().close();
frame.release();
return;
}
ctx.pipeline().fireChannelRead(new PacketsMessage(client, frame.content(), Transport.WEBSOCKET));
frame.release();
} else if (msg instanceof FullHttpRequest) {
FullHttpRequest req = (FullHttpRequest) msg;
QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri());
String path = queryDecoder.path();
List<String> transport = queryDecoder.parameters().get("transport");
List<String> sid = queryDecoder.parameters().get("sid");
if (transport != null && NAME.equals(transport.get(0))) {
try {
if (!configuration.getTransports().contains(Transport.WEBSOCKET)) {
log.debug("{} transport not supported by configuration.", Transport.WEBSOCKET);
ctx.channel().close();
return;
}
if (sid != null && sid.get(0) != null) {
final UUID sessionId = UUID.fromString(sid.get(0));
handshake(ctx, sessionId, path, req);
} else {
ClientHead client = ctx.channel().attr(ClientHead.CLIENT).get();
// first connection
handshake(ctx, client.getSessionId(), path, req);
}
} finally {
req.release();
}
} else {
ctx.fireChannelRead(msg);
}
} else {
ctx.fireChannelRead(msg);
}
}
Aggregations