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

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 接收心跳检测
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/6/1 16:12
 */
@Slf4j
@Component
public class PongWsFrameHandle extends WsFrameHandle {
    /**
     * 执行链
     *
     * @param event t
     */
    @Override
    public void doChain(WsFrameEvent event) {
        PongWebSocketFrame pongWebSocketFrame;
        WebSocketFrame frame = event.getFrame();
        ChannelHandlerContext ctx = event.getCtx();
        if (frame instanceof PongWebSocketFrame) {
            pongWebSocketFrame = (PongWebSocketFrame) frame;
            log.info("接收心跳检测");
            ctx.channel().writeAndFlush(new PongWebSocketFrame(pongWebSocketFrame.content().retain()));
            return;
        }
        handle.doChain(event);
    }
}
