bak
This commit is contained in:
@@ -2,6 +2,7 @@ package com.lld.im.service.call.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.lld.im.common.ResponseVO;
|
||||
@@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -61,9 +63,25 @@ public class ImCallHistoryController {
|
||||
|
||||
@PostMapping("/callBegin")
|
||||
public ResponseVO callBegin(@RequestBody ImCallHistoryEntity imCallHistoryEntity) {
|
||||
|
||||
//判断当前房间是否有通话
|
||||
QueryWrapper<ImCallHistoryEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("session_id",imCallHistoryEntity.getSessionId());
|
||||
queryWrapper.eq("status",1);
|
||||
|
||||
List<ImCallHistoryEntity> imCallHistoryEntityList = callHistoryMapper.selectList(queryWrapper);
|
||||
|
||||
//如果存在则直接返回旧的记录
|
||||
if(imCallHistoryEntityList.size()>0){
|
||||
return ResponseVO.successResponse(imCallHistoryEntityList.get(0));
|
||||
}
|
||||
|
||||
// 如果不存在则插入新的记录
|
||||
imCallHistoryEntity.setCreateTime(new Date());
|
||||
imCallHistoryEntity.setStatus("1");
|
||||
|
||||
|
||||
|
||||
ResponseVO<ImUserDataEntity> inviteUserInfo = imUserService.getSingleUserInfo(imCallHistoryEntity.getRoomId(), 10000);
|
||||
ResponseVO<ImUserDataEntity> passiveUserInfo = imUserService.getSingleUserInfo(imCallHistoryEntity.getPassiveId(), 10000);
|
||||
|
||||
|
||||
@@ -28,5 +28,6 @@ public class ImCallHistoryEntity {
|
||||
|
||||
// 持续时间(秒)
|
||||
private Integer continueSecond;
|
||||
private Integer checkTimes;
|
||||
|
||||
}
|
||||
|
||||
@@ -39,12 +39,15 @@ public class ImCallHistoryService {
|
||||
|
||||
List<ImCallHistoryEntity> imCallHistoryEntityList = callHistoryMapper.selectList(queryWrapper);
|
||||
|
||||
for(ImCallHistoryEntity imCallHistory: imCallHistoryEntityList){
|
||||
imCallHistory.setStatus("2");
|
||||
callHistoryMapper.updateById(imCallHistory);
|
||||
if(imCallHistoryEntityList.size()>0){
|
||||
for(ImCallHistoryEntity imCallHistory: imCallHistoryEntityList){
|
||||
imCallHistory.setStatus("1");
|
||||
callHistoryMapper.updateById(imCallHistory);
|
||||
}
|
||||
}else {
|
||||
callHistoryMapper.insert(callHistory);
|
||||
}
|
||||
|
||||
callHistoryMapper.insert(callHistory);
|
||||
}
|
||||
|
||||
public List<ImCallHistoryEntity> queryListByStatus(String status){
|
||||
@@ -55,6 +58,62 @@ public class ImCallHistoryService {
|
||||
}
|
||||
|
||||
|
||||
public void updateCallHistory(ImCallHistoryEntity callHistory){
|
||||
callHistoryMapper.updateById(callHistory);
|
||||
}
|
||||
|
||||
|
||||
public void closeCallRoomWithError(ImCallHistoryEntity callHistory){
|
||||
Date _now=new Date();
|
||||
QueryWrapper<ImCallHistoryEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("session_id",callHistory.getSessionId());
|
||||
queryWrapper.eq("status",1);
|
||||
|
||||
// end_time
|
||||
ImCallHistoryEntity imCallHistory = callHistoryMapper.selectOne(queryWrapper);
|
||||
|
||||
if(!ObjectUtils.isEmpty(imCallHistory)){
|
||||
imCallHistory.setEndTime(_now);
|
||||
imCallHistory.setStatus("3");
|
||||
Duration duration = Duration.between(imCallHistory.getCreateTime().toInstant(),_now.toInstant());
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(duration.toMillis());
|
||||
Integer i = Long.valueOf(seconds).intValue();
|
||||
imCallHistory.setContinueSecond(i);
|
||||
|
||||
|
||||
//TODO 结束之后通知客户端
|
||||
SendMessageReq req= new SendMessageReq();
|
||||
req.setAppId(10000);
|
||||
req.setFromId(imCallHistory.getInviteId());
|
||||
req.setToId(imCallHistory.getPassiveId());
|
||||
req.setMessageTime(System.currentTimeMillis());
|
||||
// req.setMessageRandom();
|
||||
|
||||
req.setMessageId(UUID.randomUUID().toString().replace("-", ""));
|
||||
req.setImei("uniapp");
|
||||
req.setClientType(1);
|
||||
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("userId", imCallHistory.getInviteId());
|
||||
data.put("msgType", "CALL_"+imCallHistory.getType());
|
||||
data.put("content", JSONObject.toJSONString(imCallHistory));
|
||||
|
||||
req.setMessageBody(JSONObject.toJSONString(data));
|
||||
|
||||
p2PMessageService.send(req);
|
||||
|
||||
|
||||
callHistoryMapper.updateById(imCallHistory);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void updateBySessionId(ImCallHistoryEntity callHistory){
|
||||
Date _now=new Date();
|
||||
QueryWrapper<ImCallHistoryEntity> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
@@ -26,6 +26,7 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
.excludePathPatterns("/v1/file/**")
|
||||
.excludePathPatterns("/v1/room/**")
|
||||
.excludePathPatterns("/v1/im_call_history/**")
|
||||
.excludePathPatterns("/v1/message/listMessage")
|
||||
.excludePathPatterns("/v1/message/checkSend");
|
||||
}
|
||||
|
||||
|
||||
@@ -30,29 +30,29 @@ public class CallHistoryTask {
|
||||
ImRoomService roomService;
|
||||
|
||||
|
||||
@Scheduled(cron="0/10 * * * * ? ")
|
||||
@Scheduled(cron="0/2 * * * * ? ")
|
||||
public void executeTask(){
|
||||
List<ImCallHistoryEntity> callHistoryEntities = callHistoryService.queryListByStatus("1");
|
||||
for(ImCallHistoryEntity callHistoryEntity: callHistoryEntities){
|
||||
ImRoomEntity imRoomEntity = new ImRoomEntity();
|
||||
imRoomEntity.setRoomId(callHistoryEntity.getRoomId());
|
||||
List<ImRoomEntity> serviceRoomInfo = roomService.getRoomInfo(imRoomEntity);
|
||||
if(serviceRoomInfo.size()<2){
|
||||
log.info("{}房间里面的流少于2路,关掉全部视频流并且判断异常中断",callHistoryEntity.getSessionId());
|
||||
//房间里面的流少于2路,关掉全部视频流并且判断异常中断
|
||||
closeAll(callHistoryEntity,serviceRoomInfo);
|
||||
if(callHistoryEntity.getCheckTimes()>2){
|
||||
ImRoomEntity imRoomEntity = new ImRoomEntity();
|
||||
imRoomEntity.setRoomId(callHistoryEntity.getRoomId());
|
||||
List<ImRoomEntity> serviceRoomInfo = roomService.getRoomInfo(imRoomEntity);
|
||||
if(serviceRoomInfo.size()==0){
|
||||
log.info("{}房间里面没有流,关掉全部视频流并且设置状态为异常中断",callHistoryEntity.getSessionId());
|
||||
//房间里面没有流,关掉全部视频流并且判断异常中断
|
||||
// closeAll(callHistoryEntity,serviceRoomInfo);
|
||||
}
|
||||
}else {
|
||||
callHistoryEntity.setCheckTimes(callHistoryEntity.getCheckTimes()+1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void closeAll(ImCallHistoryEntity callHistoryEntity,List<ImRoomEntity> roomList){
|
||||
callHistoryEntity.setStatus("3");
|
||||
callHistoryService.updateBySessionId(callHistoryEntity);
|
||||
|
||||
if(roomList.size()>0){
|
||||
roomService.deleteAllUserFromRoom(roomList.get(0).getRoomId());
|
||||
}
|
||||
callHistoryService.closeCallRoomWithError(callHistoryEntity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ public class SRSStreamTask {
|
||||
List<StreamEntity> streamEntityList = response.getStreams();
|
||||
for (StreamEntity streamEntity:streamEntityList){
|
||||
String webRTCUrl=streamEntity.getTcUrl()+"/"+streamEntity.getName();
|
||||
//如果流存在,则
|
||||
if(StringUtils.equals(roomEntity.getWebrtcUrl(),webRTCUrl)){
|
||||
hasStream=true;
|
||||
break;
|
||||
@@ -71,7 +72,7 @@ public class SRSStreamTask {
|
||||
if(!hasStream){
|
||||
roomService.addCheckTimes(roomEntity,roomEntity.getCheckTimes()+1);
|
||||
if(roomEntity.getCheckTimes()>4){
|
||||
roomService.deleteRoomById(roomEntity.getId());
|
||||
// roomService.deleteRoomById(roomEntity.getId());
|
||||
}
|
||||
}else {
|
||||
roomService.addCheckTimes(roomEntity,0);
|
||||
|
||||
Reference in New Issue
Block a user