123333
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ruoyi.cai.ws.handler;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import com.ruoyi.cai.chat.ChatManager;
|
||||
import com.ruoyi.cai.ws.bean.FdCtxData;
|
||||
import com.ruoyi.cai.ws.bean.Room;
|
||||
@@ -12,6 +13,7 @@ import com.ruoyi.cai.ws.service.CheckConnectionDTO;
|
||||
import com.ruoyi.cai.ws.service.RoomService;
|
||||
import com.ruoyi.cai.ws.util.WsExceptionUtil;
|
||||
import jodd.util.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
@@ -23,6 +25,7 @@ import java.util.Map;
|
||||
* ws消息处理器统一入口
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MessageHandleApplication {
|
||||
|
||||
@Autowired
|
||||
@@ -36,6 +39,7 @@ public class MessageHandleApplication {
|
||||
|
||||
public void processOn(WebSocketSession session, TextMessage message) {
|
||||
String payload = message.getPayload();
|
||||
log.info("调试日志:收到websocket的请求 message={}",payload);
|
||||
if(StringUtil.isEmpty(payload)){
|
||||
return;
|
||||
}
|
||||
@@ -48,17 +52,20 @@ public class MessageHandleApplication {
|
||||
WsToken wsToken = chatManager.getToken(String.valueOf(attributes.get("token")));
|
||||
if(wsToken == null){
|
||||
WsExceptionUtil.throwExceptionFast(session,"无效token");
|
||||
log.info("调试日志:无效的token token={}", attributes.get("token"));
|
||||
return;
|
||||
}
|
||||
Long roomId = wsToken.getRoomId();
|
||||
Room room = roomService.load(roomId);
|
||||
if(room == null){
|
||||
WsExceptionUtil.throwException(session, "房间不可用" ,HangUpEnums.OTHER, roomId);
|
||||
log.info("调试日志:房间不可用 wsToken={}", JSON.toJSONString(wsToken));
|
||||
return;
|
||||
}
|
||||
CheckConnectionDTO checkConnect = roomService.checkConnect(room);
|
||||
if(checkConnect != null){
|
||||
WsExceptionUtil.throwException(session,checkConnect.getMessage(),checkConnect.getHangUpEnums(),roomId);
|
||||
log.info("调试日志:链接已完毕 room={}", JSON.toJSONString(room));
|
||||
return;
|
||||
}
|
||||
IMessageHandler handler = map.get(String.valueOf(method));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ruoyi.cai.ws.job;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ruoyi.cai.domain.UserCall;
|
||||
import com.ruoyi.cai.notice.YunxinWsServiceV2;
|
||||
@@ -18,12 +19,14 @@ import com.ruoyi.cai.ws.service.SettleService;
|
||||
import com.ruoyi.cai.ws.util.RoomWebSocketUtil;
|
||||
import com.ruoyi.yunxin.Yunxin;
|
||||
import com.ruoyi.cai.notice.enums.CallNoticeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RoomCheckJobService {
|
||||
|
||||
@Autowired
|
||||
@@ -39,23 +42,33 @@ public class RoomCheckJobService {
|
||||
|
||||
public JobResp checkRoom(Long roomId){
|
||||
Room room = roomService.load(roomId);
|
||||
log.info("调试日志:开始检查房间 room={}" , JSON.toJSONString(room));
|
||||
if(room == null){
|
||||
return JobResp.builder().nextCreateJob(false).build();
|
||||
}
|
||||
// 检查是否三分钟没有接听
|
||||
log.info("调试日志:检查是否三分钟没有接听 roomId={}" , roomId);
|
||||
JobResp resp = this.checkRoomCallerTimeOut(room);
|
||||
if(!resp.isNextCreateJob()){
|
||||
log.info("调试日志:三分钟没有接听,可能关闭了 roomId={}" , roomId);
|
||||
return resp;
|
||||
}
|
||||
// 检查心跳
|
||||
log.info("调试日志:检查心跳是否超时 roomId={}" , roomId);
|
||||
JobResp heartbeat = checkRoomHeartbeat(room);
|
||||
if(!heartbeat.isNextCreateJob()){
|
||||
log.info("调试日志:心跳超时了,可能关闭了 roomId={}" , roomId);
|
||||
return heartbeat;
|
||||
}
|
||||
this.checkCanCallTime(room);
|
||||
// 尝试结算一下
|
||||
log.info("调试日志:开始尝试结算 roomId={}" , roomId);
|
||||
SettleResp settleResp = settleService.processOn(roomId);
|
||||
return JobResp.builder().nextCreateJob(settleResp.isNextRun()).build();
|
||||
JobResp build = JobResp.builder().nextCreateJob(settleResp.isNextRun()).build();
|
||||
if(!build.isNextCreateJob()){
|
||||
log.info("调试日志:结算成功了,可能关闭了 roomId={}" , roomId);
|
||||
}
|
||||
return build;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,11 +27,17 @@ public class WebSocketUtils {
|
||||
* @param message 消息文本
|
||||
*/
|
||||
public static void sendMessage(String sessionKey, String message) {
|
||||
if(sessionKey == null){
|
||||
return;
|
||||
}
|
||||
WebSocketSession session = WebSocketSessionHolder.getSessions(sessionKey);
|
||||
sendMessage(session, message);
|
||||
}
|
||||
|
||||
public static boolean close(String sessionKey) {
|
||||
if(sessionKey == null){
|
||||
return false;
|
||||
}
|
||||
WebSocketSession sessions = WebSocketSessionHolder.getSessions(sessionKey);
|
||||
return close(sessions);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user