package com.ruoyi.cai.ws.handler.message;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.cai.ws.bean.FdCtxData;
import com.ruoyi.cai.ws.bean.Room;
import com.ruoyi.cai.ws.dto.WsRMsgGen;
import com.ruoyi.cai.ws.handler.IMessageHandler;
import com.ruoyi.cai.ws.handler.AbstractMessageHandle;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * 聊天消息处理
 */
@Component("message")
public class MessageHandler extends AbstractMessageHandle implements IMessageHandler {
    @Override
    public void processOn(Room room, FdCtxData fdCtxData, JSONObject map) {
        String txt = map.getString("txt");
        if(StringUtils.isEmpty(txt) || !room.isOnline()){
            return;
        }
        sendToAll(room.getRoomId(),WsRMsgGen.chatData(txt,fdCtxData.getUserId(),fdCtxData.getTarUserId()));
    }
}
