|
@@ -3,6 +3,9 @@ package com.ym.service.Impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.microsvc.toolkit.middleware.rtc.RTCRoomPluginContext;
|
|
|
+import com.microsvc.toolkit.middleware.rtc.RTCRoomPluginService;
|
|
|
+import com.microsvc.toolkit.middleware.rtc.impl.TencentCloudRTCPlugin;
|
|
|
import com.ym.common.ApiException;
|
|
|
import com.ym.common.BaseResponse;
|
|
|
import com.ym.common.DisplayEnum;
|
|
@@ -105,6 +108,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
private TenantAssetsInfoService tenantAssetsInfoService;
|
|
|
@Autowired
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
+ @Autowired
|
|
|
+ private RTCRoomPluginContext rtcRoomPluginContext;
|
|
|
|
|
|
@Override
|
|
|
public Integer getCurrentCourseId(String roomId) {
|
|
@@ -247,7 +252,58 @@ public class RoomServiceImpl implements RoomService {
|
|
|
userResult.setJoinTime(member.getJoinDt());
|
|
|
}
|
|
|
// imHelper.joinGroup(new String[]{userId}, roomId, roomId);
|
|
|
- this.joinImGroup(roomId,courseSchedule.getActualTeacherId());
|
|
|
+
|
|
|
+ // 获取RTC服务提供方
|
|
|
+ String rtcServiceProvider = Optional.ofNullable(sysConfigDao.findConfigValue("rtc_service_provider")).orElse("rongCloud");
|
|
|
+
|
|
|
+ RTCRoomPluginService pluginService = rtcRoomPluginContext.getPluginService(rtcServiceProvider);
|
|
|
+ if (TencentCloudRTCPlugin.PLUGIN_NAME.equals(rtcServiceProvider)) {
|
|
|
+ // 腾讯云RTC
|
|
|
+ // 用户IM帐号创建
|
|
|
+ String userSig = "";
|
|
|
+ try {
|
|
|
+ userSig = pluginService.register(String.valueOf(sysUser.getId()), sysUser.getUsername(), sysUser.getAvatar());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("直播房间用户注册失败: userId={}", sysUser.getId(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 主讲老师信息
|
|
|
+ SysUser teacherInfo = sysUserFeignService.queryUserById(courseSchedule.getActualTeacherId());
|
|
|
+ if (Objects.isNull(teacherInfo)) {
|
|
|
+ throw new BizException("主讲老师不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String joinImGroupKey = "joinImGroup:" + roomId;
|
|
|
+ // VIP课或网络课,IM群聊已创建标识
|
|
|
+ Boolean exists = redisTemplate.opsForValue().setIfAbsent(joinImGroupKey, roomId, 1L, TimeUnit.DAYS);
|
|
|
+
|
|
|
+ // 缓存RTC服务提供方
|
|
|
+ String rtcRoomPluginKey = "rtcRoomPlugin:" + roomId;
|
|
|
+ redisTemplate.opsForValue().setIfAbsent(rtcRoomPluginKey, pluginService.pluginName(), 1L, TimeUnit.DAYS);
|
|
|
+
|
|
|
+ if (Optional.ofNullable(exists).orElse(false)) {
|
|
|
+ // 创建群组
|
|
|
+ log.info("createImGroup: roomId = {}, userId = {}", roomId, teacherInfo.getId());
|
|
|
+ pluginService.chatRoomCreate(roomId, courseSchedule.getName(), teacherInfo.getAvatar());
|
|
|
+
|
|
|
+ List<CourseScheduleStudentPayment> payments = courseScheduleStudentPaymentDao.findByCourseSchedule(Long.parseLong(roomId.substring(1)));
|
|
|
+ // 学生信息
|
|
|
+ List<String> collect = payments.stream().map(e -> e.getUserId().toString()).collect(Collectors.toList());
|
|
|
+ // 老师信息
|
|
|
+ collect.add(teacherInfo.getId().toString());
|
|
|
+ // 加入群组成员
|
|
|
+ log.info("joinImGroup: roomId = {}, userIds = {}", roomId, collect);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回配置参数
|
|
|
+ roomResult.userSig(userSig)
|
|
|
+ .rtcRoomConfig(rtcRoomPluginContext.getPluginService().getRTCRoomConfig(String.valueOf(sysUser.getId())))
|
|
|
+ .setGroupId(roomId);
|
|
|
+ } else {
|
|
|
+ // 融云RTC
|
|
|
+ // 创建IM群聊
|
|
|
+ this.joinImGroup(roomId, courseSchedule.getActualTeacherId());
|
|
|
+ }
|
|
|
|
|
|
List<CourseScheduleStudentMusicScore> scheduleStudentMusicScores = courseScheduleStudentMusicScoreDao.queryByScoreIdAndCourseId(null, courseId, null, null, null);
|
|
|
Room room = roomDao.findByRid(roomId);
|