package com.sjyt.icom.asst.context.handle.wsframe;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import org.springframework.stereotype.Component;

/**
 * 创建连接之后，客户端发送的消息都会在这里处理
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/6/1 16:10
 */
@Component
public class BinaryWsFrameHandle extends WsFrameHandle {
    /**
     * 执行链
     *
     * @param event t
     */
    @Override
    public void doChain(WsFrameEvent event) {
        BinaryWebSocketFrame binaryWebSocketFrame;
        WebSocketFrame frame = event.getFrame();
        ChannelHandlerContext ctx = event.getCtx();
        if (frame instanceof BinaryWebSocketFrame) {
            binaryWebSocketFrame = (BinaryWebSocketFrame) frame;
            ctx.channel().writeAndFlush(binaryWebSocketFrame.retain());
            return;
        }
        handle.doChain(event);
    }
}
