package com.ruoyi.cai.ws.util;

import com.ruoyi.cai.ws.constant.HangUpEnums;
import com.ruoyi.cai.ws.dto.WsRMsgGen;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class WsExceptionUtil {
    public static void throwException(String sessionKey, String message, HangUpEnums hangUpType, Long roomId){
        if(hangUpType == null){
            hangUpType = HangUpEnums.OTHER;
        }
        RoomWebSocketUtil.sendSendMessage(sessionKey, WsRMsgGen.hangup(message,roomId,hangUpType.getCode()));
        boolean close = WebSocketUtils.close(sessionKey);
        if(!close){
            log.warn("ws连接时发现异常：{}，sessionKey {} roomid {}", message, sessionKey, roomId);
        }

    }
}
