[FEATURE] Raw WebSocketFrame API

This commit is contained in:
Gravit 2020-04-27 05:22:49 +07:00
parent ea5449a196
commit fe21427d17
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -8,6 +8,8 @@
import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.NettyConnectContext; import pro.gravit.launchserver.socket.NettyConnectContext;
import pro.gravit.launchserver.socket.WebSocketService; import pro.gravit.launchserver.socket.WebSocketService;
import pro.gravit.utils.BiHookSet;
import pro.gravit.utils.HookSet;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
@ -22,6 +24,7 @@ public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocket
public final WebSocketService service; public final WebSocketService service;
private final UUID connectUUID = UUID.randomUUID(); private final UUID connectUUID = UUID.randomUUID();
public NettyConnectContext context; public NettyConnectContext context;
public BiHookSet<ChannelHandlerContext, WebSocketFrame> hooks = new BiHookSet<>();
private Client client; private Client client;
public WebSocketFrameHandler(NettyConnectContext context, LaunchServer srv, WebSocketService service) { public WebSocketFrameHandler(NettyConnectContext context, LaunchServer srv, WebSocketService service) {
@ -58,6 +61,7 @@ public void channelActive(ChannelHandlerContext ctx) {
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) { protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
// ping and pong frames already handled // ping and pong frames already handled
if(hooks.hook(ctx, frame)) return;
if (frame instanceof TextWebSocketFrame) { if (frame instanceof TextWebSocketFrame) {
service.process(ctx, (TextWebSocketFrame) frame, client, context.ip); service.process(ctx, (TextWebSocketFrame) frame, client, context.ip);
} else if ((frame instanceof PingWebSocketFrame)) { } else if ((frame instanceof PingWebSocketFrame)) {