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