Commit cc8701fb by Future

单人音视频通话记录功能添加

parent d01c6121
package com.wecloud.im.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.geekidea.springbootplus.framework.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* @Author Future
* @Date 2022/5/22 23:40
* @Description 单人音视频记录表
*/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "单人音视频记录")
public class ImRtcRecord extends BaseEntity {
private static final long serialVersionUID = -523597842194055670L;
@NotNull(message = "主键id不能为空")
@ApiModelProperty("主键id")
@TableId(value = "id", type = IdType.INPUT)
private Long id;
@ApiModelProperty("应用appid")
private Long fkAppid;
@ApiModelProperty("频道id")
private Long channelId;
@ApiModelProperty("发起方clientId")
private String fromClientId;
@ApiModelProperty("接收方clientId")
private String toClientId;
/**
* 单人音视频状态枚举
* @see com.wecloud.im.sdk.enums.RtcStateEnum
*/
@ApiModelProperty("频道状态,1:音视频发起,2:音视频中,3:音视频结束")
private Integer state;
@ApiModelProperty("音视频开始时间")
private Date startTime;
@ApiModelProperty("音视频结束时间")
private Date endTime;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("修改时间")
private Date updateTime;
}
package com.wecloud.im.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wecloud.im.entity.ImRtcRecord;
import org.springframework.stereotype.Repository;
/**
* @Author Future
* @Date 2022/5/22 23:49
* @Description 单人音视频记录mapper
*/
@Repository
public interface ImRtcRecordMapper extends BaseMapper<ImRtcRecord> {
}
package com.wecloud.im.sdk.enums;
import io.geekidea.springbootplus.framework.common.enums.BaseEnum;
/**
* @Author Future
* @Date 2022/5/22 23:42
* @Description 单人音视频状态枚举
*/
public enum RtcStateEnum implements BaseEnum {
/**
* 1 - 音视频发起
*/
CREATED(1, "音视频发起"),
/**
* 2 - 音视频中
*/
ING(2, "音视频中"),
/**
* 3 - 音视频结束
*/
END(3, "音视频结束");
RtcStateEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
private final Integer code;
private final String desc;
@Override
public Integer getCode() {
return this.code;
}
@Override
public String getDesc() {
return this.desc;
}
}
package com.wecloud.im.service;
import com.wecloud.im.entity.ImRtcRecord;
import com.wecloud.im.param.rtc.CreateRtcChannelParam;
import io.geekidea.springbootplus.framework.common.service.BaseService;
/**
* @Author wenzhida
* @Date 2022/3/16 9:08
* @Description 单人音视频房记录服务接口
*/
public interface ImRtcRecordService extends BaseService<ImRtcRecord> {
/**
* 创建rtc通话记录
* @param param
* @param channelId
*/
void createRtcRecord(CreateRtcChannelParam param, Long channelId);
/**
* 更新音视频记录
* @param channelId
* @param type 1-同意进入频道 2-拒接进入频道 3-主动挂断(离开频道)
*/
void updateRtcRecord(Long channelId, Integer type);
}
package com.wecloud.im.service.impl;
import com.alibaba.fastjson.JSON;
import com.wecloud.im.entity.ImClient;
import com.wecloud.im.entity.ImRtcRecord;
import com.wecloud.im.mapper.ImRtcRecordMapper;
import com.wecloud.im.param.rtc.CreateRtcChannelParam;
import com.wecloud.im.sdk.enums.RtcStateEnum;
import com.wecloud.im.service.ImClientService;
import com.wecloud.im.service.ImRtcRecordService;
import com.wecloud.utils.SnowflakeUtil;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
* @Author Future
* @Date 2022/5/22 23:50
* @Description 单人音视频记录服务实现
*/
@Slf4j
@Service
public class ImRtcRecordServiceImpl extends BaseServiceImpl<ImRtcRecordMapper, ImRtcRecord> implements ImRtcRecordService {
@Autowired
private ImClientService imClientService;
@Override
public void createRtcRecord(CreateRtcChannelParam param, Long channelId) {
try {
ImClient currentClient = imClientService.getCurrentClient();
ImRtcRecord rtcRecord = new ImRtcRecord();
rtcRecord.setId(SnowflakeUtil.getId());
rtcRecord.setFkAppid(currentClient.getFkAppid());
rtcRecord.setChannelId(channelId);
rtcRecord.setFromClientId(currentClient.getClientId());
rtcRecord.setToClientId(param.getToClient());
rtcRecord.setState(RtcStateEnum.CREATED.getCode());
rtcRecord.setCreateTime(new Date());
this.save(rtcRecord);
} catch (Exception e) {
log.info("创建rtc通话记录异常 param {} channelId {} 异常 ", JSON.toJSONString(param), channelId, e);
}
}
/**
* 更新音视频记录
*
* @param channelId
* @param type 1-同意进入频道 2-拒接进入频道 3-主动挂断(离开频道)
*/
@Override
public void updateRtcRecord(Long channelId, Integer type) {
try {
ImRtcRecord rtcRecord = this.getById(channelId);
if (rtcRecord == null) {
return;
}
if (type == 1) {
// 同意进入频道
rtcRecord.setState(RtcStateEnum.ING.getCode());
rtcRecord.setStartTime(new Date());
} else if (type == 2) {
// 拒接进入频道
rtcRecord.setState(RtcStateEnum.END.getCode());
} else {
// 主动挂断(离开频道)
rtcRecord.setState(RtcStateEnum.END.getCode());
rtcRecord.setEndTime(new Date());
}
this.updateById(rtcRecord);
} catch (Exception e) {
log.info("更新rtc通话记录异常, channelId {}, type {} 异常 ", channelId, type, e);
}
}
}
...@@ -6,6 +6,7 @@ import com.wecloud.im.param.rtc.*; ...@@ -6,6 +6,7 @@ import com.wecloud.im.param.rtc.*;
import com.wecloud.im.service.ImApplicationService; import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientBlacklistService; import com.wecloud.im.service.ImClientBlacklistService;
import com.wecloud.im.service.ImClientService; import com.wecloud.im.service.ImClientService;
import com.wecloud.im.service.ImRtcRecordService;
import com.wecloud.im.ws.cache.UserStateCacheManager; import com.wecloud.im.ws.cache.UserStateCacheManager;
import com.wecloud.im.ws.cache.UserStateListener; import com.wecloud.im.ws.cache.UserStateListener;
import com.wecloud.rtc.entity.response.*; import com.wecloud.rtc.entity.response.*;
...@@ -47,6 +48,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -47,6 +48,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
@Autowired @Autowired
private ImClientBlacklistService imClientBlacklistService; private ImClientBlacklistService imClientBlacklistService;
@Autowired
private ImRtcRecordService imRtcRecordService;
@Override @Override
public void onLineEvent(Long client, Integer platform, String longChannelId) { public void onLineEvent(Long client, Integer platform, String longChannelId) {
// nothing need to do // nothing need to do
...@@ -101,6 +105,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -101,6 +105,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
wsRtcWrite.rtcCall(rtcCallResponse, toClient.getId()); wsRtcWrite.rtcCall(rtcCallResponse, toClient.getId());
// 创建通话记录 todo 优化为mq推送
imRtcRecordService.createRtcRecord(createRtcChannelParam, createRtcChannelResult.getChannelId());
// TODO 待开发 下发安卓和ios系统推送 // TODO 待开发 下发安卓和ios系统推送
return createRtcChannelResult; return createRtcChannelResult;
...@@ -132,6 +139,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -132,6 +139,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
wsRtcWrite.clientJoin(rtcSdpForwardResponse, Long.valueOf(toClientId)); wsRtcWrite.clientJoin(rtcSdpForwardResponse, Long.valueOf(toClientId));
} }
// 更新通话记录 todo 优化为mq推送
imRtcRecordService.updateRtcRecord(joinRtcChannelParam.getChannelId(), 1);
return true; return true;
} }
...@@ -162,6 +172,10 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -162,6 +172,10 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
mangerRtcCacheService.leave(Long.valueOf(clientListByRtcChannelId.get(0)), rejectRtcChannelParam.getChannelId()); mangerRtcCacheService.leave(Long.valueOf(clientListByRtcChannelId.get(0)), rejectRtcChannelParam.getChannelId());
mangerRtcCacheService.delChannelInfo(rejectRtcChannelParam.getChannelId()); mangerRtcCacheService.delChannelInfo(rejectRtcChannelParam.getChannelId());
} }
// 更新通话记录 todo 优化为mq推送
imRtcRecordService.updateRtcRecord(rejectRtcChannelParam.getChannelId(), 2);
return true; return true;
} }
...@@ -169,6 +183,10 @@ public class RtcServiceImpl extends UserStateListener implements RtcService { ...@@ -169,6 +183,10 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
public Boolean leave(LeaveRtcChannelParam leaveRtcChannelParam) { public Boolean leave(LeaveRtcChannelParam leaveRtcChannelParam) {
ImClient currentClient = imClientService.getCurrentClient(); ImClient currentClient = imClientService.getCurrentClient();
this.leave(leaveRtcChannelParam, currentClient); this.leave(leaveRtcChannelParam, currentClient);
// 更新通话记录 todo 优化为mq推送
imRtcRecordService.updateRtcRecord(leaveRtcChannelParam.getChannelId(), 3);
return true; return true;
} }
......
-- 在feature-cluster 2021年12月22日之后,需要执行的的sql增量脚本 -- 在feature-cluster 2021年12月22日之后,需要执行的的sql增量脚本
...@@ -161,5 +161,23 @@ ALTER TABLE im_conversation ...@@ -161,5 +161,23 @@ ALTER TABLE im_conversation
DROP TABLE IF EXISTS `im_rtc_record`;
CREATE TABLE `im_rtc_record`
(
`id` bigint NOT NULL COMMENT '主键id',
`fk_appid` bigint DEFAULT NULL COMMENT '应用appid',
`channel_id` bigint DEFAULT NULL COMMENT '频道id',
`from_client_id` varchar(200) DEFAULT NULL COMMENT '发起方clientId',
`to_client_id` varchar(200) DEFAULT NULL COMMENT '接收方clientId',
`state` tinyint NOT NULL DEFAULT '1' COMMENT '频道状态,1:音视频发起,2:音视频中,3:音视频结束',
`start_time` timestamp NULL DEFAULT NULL COMMENT '音视频开始时间',
`end_time` timestamp NULL DEFAULT NULL COMMENT '音视频结束时间',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
`update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_channel_id` (`channel_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='单人音视频聊天记录表';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment