This commit is contained in:
2023-12-10 14:33:58 +08:00
parent 2cc4c82cbd
commit e1e98de4b2
14 changed files with 216 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
package com.lld.im.service.call.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -63,7 +64,8 @@ public class ImCallHistoryController {
@PostMapping("/callBegin")
public ResponseVO callBegin(@RequestBody ImCallHistoryEntity imCallHistoryEntity) {
log.info("===========callBegin ");
log.info(JSONObject.toJSONString(imCallHistoryEntity));
//判断当前房间是否有通话
QueryWrapper<ImCallHistoryEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("session_id",imCallHistoryEntity.getSessionId());
@@ -100,6 +102,8 @@ public class ImCallHistoryController {
@PostMapping("/callHangUp")
public ResponseVO callHangUp(@RequestBody ImCallHistoryEntity imCallHistoryEntity) {
log.info("===========callHangUp ");
log.info(JSONObject.toJSONString(imCallHistoryEntity));
imCallHistoryEntity.setStatus("1");
callHistoryService.updateBySessionId(imCallHistoryEntity);

View File

@@ -64,6 +64,8 @@ public class ImCallHistoryService {
public void closeCallRoomWithError(ImCallHistoryEntity callHistory){
log.info("closeCallRoomWithError");
log.info(JSONObject.toJSONString(callHistory));
Date _now=new Date();
QueryWrapper<ImCallHistoryEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("session_id",callHistory.getSessionId());

View File

@@ -1,6 +1,7 @@
package com.lld.im.service.room.controller;
import com.alibaba.fastjson.JSONObject;
import com.lld.im.common.ResponseVO;
import com.lld.im.service.message.model.req.SendMessageReq;
import com.lld.im.service.message.service.P2PMessageService;
@@ -29,11 +30,15 @@ public class RoomController {
@PostMapping("/createRoom")
public ResponseVO createRoom(@RequestBody ImRoomEntity roomEntity, Integer appId) {
log.info("===========createRoom ");
log.info(JSONObject.toJSONString(roomEntity));
return ResponseVO.successResponse(roomService.createRoom(roomEntity));
}
@PostMapping("/joinRoom")
public ResponseVO joinRoom(@RequestBody ImRoomEntity roomEntity, Integer appId) {
log.info("===========joinRoom");
log.info(roomEntity.toString());
return ResponseVO.successResponse(roomService.joinRoom(roomEntity));
}
@@ -44,14 +49,15 @@ public class RoomController {
@PostMapping("/leaveRoom")
public ResponseVO leaveRoom(@RequestBody ImRoomEntity roomEntity, Integer appId) {
log.info("===========leaveRoom");
roomService.leaveRoom(roomEntity);
return ResponseVO.successResponse(roomEntity.getPublishName()+"离开视频房间");
}
@PostMapping("/unpublish")
public ResponseVO unpublish(@RequestBody SRSCallBackReq callBackReq) {
log.info(callBackReq.toString());
log.info("===========srs 回调");
log.info(JSONObject.toJSONString(callBackReq));
try {
ImRoomEntity roomEntity = new ImRoomEntity();
roomEntity.setRoomId(callBackReq.getApp());

View File

@@ -1,18 +1,23 @@
package com.lld.im.service.room.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lld.im.common.enums.DelFlagEnum;
import com.lld.im.service.message.dao.mapper.ImMessageBodyMapper;
import com.lld.im.service.room.dao.ImRoomEntity;
import com.lld.im.service.room.dao.mapper.ImRoomMapper;
import com.lld.im.service.user.dao.ImUserDataEntity;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Service
public class ImRoomService {
@Autowired
@@ -20,12 +25,17 @@ public class ImRoomService {
@Transactional
public ImRoomEntity createRoom(ImRoomEntity entity) {
log.info("createRoom");
log.info(JSONObject.toJSONString(entity));
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("room_id",entity.getRoomId());
queryWrapper.eq("publish_id",entity.getPublishId());
List<ImRoomEntity> roomEntityList = imRoomMapper.selectList(queryWrapper);
if(roomEntityList.size()>0){
imRoomMapper.delete(queryWrapper);
ImRoomEntity roomEntity = roomEntityList.get(0);
roomEntity.setWebrtcUrl(entity.getWebrtcUrl());
imRoomMapper.updateById(roomEntity);
return roomEntity;
}
imRoomMapper.insert(entity);
return entity;
@@ -33,15 +43,26 @@ public class ImRoomService {
@Transactional
public ImRoomEntity joinRoom(ImRoomEntity entity) {
log.info("joinRoom");
log.info(JSONObject.toJSONString(entity));
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("room_id",entity.getRoomId());
queryWrapper.eq("publish_id",entity.getPublishId());
List<ImRoomEntity> roomEntityList = imRoomMapper.selectList(queryWrapper);
if(roomEntityList.size()>0){
roomEntityList.get(0).setIsOver(0);
roomEntityList.get(0).setOffline(0);
roomEntityList.get(0).setWebrtcUrl(entity.getWebrtcUrl());
imRoomMapper.updateById(roomEntityList.get(0));
log.info("=============joinRoom:{}",entity.getWebrtcUrl());
if(StringUtils.isBlank(entity.getWebrtcUrl())){
return roomEntityList.get(0);
}else {
roomEntityList.get(0).setIsOver(0);
roomEntityList.get(0).setOffline(0);
roomEntityList.get(0).setWebrtcUrl(entity.getWebrtcUrl());
imRoomMapper.updateById(roomEntityList.get(0));
return roomEntityList.get(0);
}
}else {
entity.setOffline(0);
entity.setIsOver(0);
@@ -52,6 +73,9 @@ public class ImRoomService {
public void deleteUserFromRoom(ImRoomEntity entity){
log.info("deleteUserFromRoom");
log.info(JSONObject.toJSONString(entity));
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("room_id",entity.getRoomId());
queryWrapper.eq("publish_id",entity.getPublishId());
@@ -62,12 +86,18 @@ public class ImRoomService {
}
public void deleteRoomById(Integer id){
log.info("deleteRoomById");
log.info(id.toString());
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id",id);
imRoomMapper.delete(queryWrapper);
}
public void deleteAllUserFromRoom(String roomId){
log.info("deleteAllUserFromRoom");
log.info(roomId);
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("room_id",roomId);
imRoomMapper.delete(queryWrapper);
@@ -98,6 +128,9 @@ public class ImRoomService {
return roomEntityList;
}
public void leaveRoom (ImRoomEntity entity){
log.info("leaveRoom");
log.info(JSONObject.toJSONString(entity));
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("room_id",entity.getRoomId());
queryWrapper.eq("publish_id",entity.getPublishId());

View File

@@ -41,7 +41,7 @@ public class CallHistoryTask {
if(serviceRoomInfo.size()==0){
log.info("{}房间里面没有流,关掉全部视频流并且设置状态为异常中断",callHistoryEntity.getSessionId());
//房间里面没有流,关掉全部视频流并且判断异常中断
// closeAll(callHistoryEntity,serviceRoomInfo);
closeAll(callHistoryEntity,serviceRoomInfo);
}
}else {
callHistoryEntity.setCheckTimes(callHistoryEntity.getCheckTimes()+1);

View File

@@ -35,7 +35,7 @@ public class SRSStreamTask {
ImRoomService roomService;
@Scheduled(cron="0/2 * * * * ? ")
@Scheduled(cron="0/200 * * * * ? ")
public void executeTask() throws Exception {
log.info("====================== 执行定时任务 SRSStreamTask");
String _url = "http://"+host+":1985/api/v1/streams";
@@ -53,6 +53,7 @@ public class SRSStreamTask {
List<ImRoomEntity> roomList = roomService.getAllRoomList();
for (ImRoomEntity roomEntity:roomList){
if(StringUtils.isBlank(roomEntity.getWebrtcUrl())){
log.info("webRTC地址为空移除房间{}",roomEntity.getRoomId());
roomService.deleteRoomById(roomEntity.getId());
}else {
Boolean hasStream=false;
@@ -72,7 +73,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);

View File

@@ -101,8 +101,8 @@ mqQueueName: 123
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 会正常输出日志
# log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 会正常输出日志
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
mapper-locations: classpath*:mapper/*.xml
global-config:
db-config:

View File

@@ -3,4 +3,4 @@ spring:
time-zone: GMT+8
profiles:
active: dev
active: prod