音视频
This commit is contained in:
@@ -1,13 +1,89 @@
|
||||
package com.lld.im.service.call.controller;
|
||||
|
||||
|
||||
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;
|
||||
import com.lld.im.service.call.dao.ImCallHistoryEntity;
|
||||
import com.lld.im.service.call.dao.mapper.ImCallHistoryMapper;
|
||||
import com.lld.im.service.call.model.HistoryListReq;
|
||||
import com.lld.im.service.call.service.ImCallHistoryService;
|
||||
import com.lld.im.service.message.service.P2PMessageService;
|
||||
import com.lld.im.service.user.dao.ImUserDataEntity;
|
||||
import com.lld.im.service.user.service.ImUserService;
|
||||
import com.lld.im.service.utils.SnowflakeIdWorker;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("v1/im_call_history")
|
||||
public class ImCallHistoryController {
|
||||
@Autowired
|
||||
ImCallHistoryService callHistoryService;
|
||||
|
||||
@Autowired
|
||||
ImUserService imUserService;
|
||||
|
||||
@Autowired
|
||||
ImCallHistoryMapper callHistoryMapper;
|
||||
|
||||
|
||||
|
||||
@PostMapping("/queryList")
|
||||
public ResponseVO queryList(@RequestBody HistoryListReq req) {
|
||||
|
||||
if(req.getLimit()!=null){
|
||||
Page<ImCallHistoryEntity> objectPage = new Page<>(req.getOffset(),req.getLimit());
|
||||
QueryWrapper<ImCallHistoryEntity> query=new QueryWrapper<>();
|
||||
query.eq("invite_id",req.getUid());
|
||||
query.orderByDesc("create_time");
|
||||
IPage<ImCallHistoryEntity> imCallHistoryEntityIPage=callHistoryMapper.selectPage(objectPage,query);
|
||||
|
||||
return ResponseVO.successResponse(imCallHistoryEntityIPage);
|
||||
}else {
|
||||
return ResponseVO.errorResponse();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/callBegin")
|
||||
public ResponseVO callBegin(@RequestBody ImCallHistoryEntity imCallHistoryEntity) {
|
||||
imCallHistoryEntity.setCreateTime(new Date());
|
||||
imCallHistoryEntity.setStatus("1");
|
||||
|
||||
ResponseVO<ImUserDataEntity> inviteUserInfo = imUserService.getSingleUserInfo(imCallHistoryEntity.getRoomId(), 10000);
|
||||
ResponseVO<ImUserDataEntity> passiveUserInfo = imUserService.getSingleUserInfo(imCallHistoryEntity.getPassiveId(), 10000);
|
||||
|
||||
imCallHistoryEntity.setInviteName(inviteUserInfo.getData().getNickName());
|
||||
imCallHistoryEntity.setPassiveName(passiveUserInfo.getData().getNickName());
|
||||
|
||||
|
||||
imCallHistoryEntity.setSessionId(imCallHistoryEntity.getRoomId());
|
||||
|
||||
|
||||
|
||||
callHistoryService.add(imCallHistoryEntity);
|
||||
|
||||
return ResponseVO.successResponse(imCallHistoryEntity);
|
||||
}
|
||||
|
||||
@PostMapping("/callHangUp")
|
||||
public ResponseVO callHangUp(@RequestBody ImCallHistoryEntity imCallHistoryEntity) {
|
||||
callHistoryService.updateBySessionId(imCallHistoryEntity);
|
||||
|
||||
return ResponseVO.successResponse("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ public class ImCallHistoryEntity {
|
||||
|
||||
// 通话唯一uuid
|
||||
private String sessionId;
|
||||
private String type;
|
||||
|
||||
// 待开始,正在进行中,已结束
|
||||
private String status;
|
||||
|
||||
|
||||
private Date createTime;
|
||||
private Date endTime;
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.lld.im.service.call.dao.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lld.im.service.call.dao.ImCallHistoryEntity;
|
||||
import com.lld.im.service.user.dao.ImUserDataEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.lld.im.service.call.model;
|
||||
|
||||
import com.lld.im.common.model.RequestBase;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Data
|
||||
public class HistoryListReq extends RequestBase {
|
||||
@NotBlank(message = "用户不能为空")
|
||||
private String uid;
|
||||
|
||||
|
||||
//单次拉取数量
|
||||
private Integer limit;
|
||||
|
||||
//第几页
|
||||
private Integer offset;
|
||||
}
|
||||
@@ -1,8 +1,107 @@
|
||||
package com.lld.im.service.call.service;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.lld.im.common.ResponseVO;
|
||||
import com.lld.im.common.enums.DelFlagEnum;
|
||||
import com.lld.im.service.call.dao.ImCallHistoryEntity;
|
||||
import com.lld.im.service.call.dao.mapper.ImCallHistoryMapper;
|
||||
import com.lld.im.service.conversation.service.ConversationService;
|
||||
import com.lld.im.service.friendship.dao.mapper.ImFriendShipMapper;
|
||||
import com.lld.im.service.message.model.req.SendMessageReq;
|
||||
import com.lld.im.service.message.service.P2PMessageService;
|
||||
import com.lld.im.service.user.dao.ImUserDataEntity;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ImCallHistoryService {
|
||||
@Autowired
|
||||
ImCallHistoryMapper callHistoryMapper;
|
||||
|
||||
@Autowired
|
||||
P2PMessageService p2PMessageService;
|
||||
|
||||
|
||||
|
||||
public void add(ImCallHistoryEntity callHistory){
|
||||
QueryWrapper<ImCallHistoryEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("session_id",callHistory.getSessionId());
|
||||
queryWrapper.eq("status","1");
|
||||
|
||||
List<ImCallHistoryEntity> imCallHistoryEntityList = callHistoryMapper.selectList(queryWrapper);
|
||||
|
||||
for(ImCallHistoryEntity imCallHistory: imCallHistoryEntityList){
|
||||
imCallHistory.setStatus("2");
|
||||
callHistoryMapper.updateById(imCallHistory);
|
||||
}
|
||||
|
||||
callHistoryMapper.insert(callHistory);
|
||||
}
|
||||
public void updateBySessionId(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("2");
|
||||
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);
|
||||
|
||||
log.error("===================结束之后通知客户端");
|
||||
log.error("===================结束之后通知客户端");
|
||||
log.error("===================结束之后通知客户端");
|
||||
|
||||
|
||||
|
||||
//TODO 结束之后通知客户端
|
||||
SendMessageReq req= new SendMessageReq();
|
||||
|
||||
req.setAppId(10000);
|
||||
req.setFromId(imCallHistory.getInviteId());
|
||||
req.setToId(imCallHistory.getPassiveId());
|
||||
req.setMessageTime(System.currentTimeMillis());
|
||||
|
||||
// req.setMessageRandom();
|
||||
|
||||
req.setMessageBody(JSONObject.toJSONString(imCallHistory));
|
||||
req.setMessageId(UUID.randomUUID().toString().replace("-", ""));
|
||||
|
||||
|
||||
|
||||
req.setImei("uniapp");
|
||||
req.setClientType(1);
|
||||
|
||||
p2PMessageService.send(req);
|
||||
|
||||
|
||||
callHistoryMapper.updateById(imCallHistory);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
.excludePathPatterns("/v1/user/login")
|
||||
.excludePathPatterns("/v1/file/**")
|
||||
.excludePathPatterns("/v1/room/**")
|
||||
.excludePathPatterns("/v1/im_call_history/**")
|
||||
.excludePathPatterns("/v1/message/checkSend");
|
||||
}
|
||||
|
||||
|
||||
@@ -46,4 +46,8 @@ public class MessageController {
|
||||
return messageSyncService.syncOfflineMessage(req);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -51,24 +51,7 @@ public class RoomController {
|
||||
@PostMapping("/unpublish")
|
||||
public ResponseVO unpublish(@RequestBody SRSCallBackReq callBackReq) {
|
||||
log.info(callBackReq.toString());
|
||||
/*
|
||||
POST /api/v1/streams HTTP/1.1
|
||||
Content-Type: application-json
|
||||
Body:
|
||||
{
|
||||
"server_id": "vid-0xk989d",
|
||||
"action": "on_publish",
|
||||
"client_id": "341w361a",
|
||||
"ip": "127.0.0.1",
|
||||
"vhost": "__defaultVhost__",
|
||||
"app": "live",
|
||||
"tcUrl": "rtmp://127.0.0.1:1935/live?vhost=__defaultVhost__",
|
||||
"stream": "livestream",
|
||||
"param": "",
|
||||
"stream_url": "video.test.com/live/livestream",
|
||||
"stream_id": "vid-124q9y3"
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
ImRoomEntity roomEntity = new ImRoomEntity();
|
||||
roomEntity.setRoomId(callBackReq.getApp());
|
||||
|
||||
@@ -8,7 +8,7 @@ spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
password: beAs0LHX2GyTxMw4
|
||||
url: jdbc:mysql://43.139.191.204:3306/im-core?serverTimezone=UTC&useSSL=false&characterEncoding=UTF8
|
||||
url: jdbc:mysql://43.139.191.204:3306/im-core?serverTimezone=Asia/Shanghai&useSSL=false&characterEncoding=UTF8
|
||||
username: root
|
||||
|
||||
redis:
|
||||
|
||||
@@ -8,7 +8,7 @@ spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
password: beAs0LHX2GyTxMw4
|
||||
url: jdbc:mysql://43.139.191.204:3306/im-core?serverTimezone=UTC&useSSL=false&characterEncoding=UTF8
|
||||
url: jdbc:mysql://43.139.191.204:3306/im-core?serverTimezone=Asia/Shanghai&useSSL=false&characterEncoding=UTF8
|
||||
username: root
|
||||
|
||||
redis:
|
||||
|
||||
@@ -8,7 +8,7 @@ spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
password: Mars@23600800
|
||||
url: jdbc:mysql://172.16.2.3:3306/im-core?serverTimezone=UTC&useSSL=false&characterEncoding=UTF8
|
||||
url: jdbc:mysql://172.16.2.3:3306/im-core?serverTimezone=Asia/Shanghai&useSSL=false&characterEncoding=UTF8
|
||||
username: root
|
||||
|
||||
redis:
|
||||
@@ -101,7 +101,8 @@ mqQueueName: 123
|
||||
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# 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:
|
||||
|
||||
Reference in New Issue
Block a user