Eric 2 éve
szülő
commit
78ba6e8364

+ 21 - 0
mec-im/src/main/java/com/ym/pojo/RoomResult.java

@@ -2,7 +2,9 @@ package com.ym.pojo;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.microsvc.toolkit.middleware.rtc.message.RTCRoomConfig;
 import com.ym.mec.biz.dal.entity.CourseScheduleStudentMusicScore;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.Getter;
 import lombok.Setter;
@@ -35,6 +37,23 @@ public class RoomResult {
     private @Getter @Setter MemberResult userInfo;
     private @Getter @Setter String randomNumeric = "0";
 
+    @ApiModelProperty("RTC接入参数")
+    private @Getter @Setter RTCRoomConfig rtcRoomConfig;
+    @ApiModelProperty("直播间用户签名")
+    private @Getter @Setter String userSig;
+    @ApiModelProperty("群组id")
+    private @Getter @Setter String groupId;
+
+    public RoomResult rtcRoomConfig(RTCRoomConfig rtcRoomConfig) {
+        this.rtcRoomConfig = rtcRoomConfig;
+        return this;
+    }
+
+    public RoomResult userSig(String userSig) {
+        this.userSig = userSig;
+        return this;
+    }
+
     @Data
     public static class MemberResult {
         String userId;
@@ -93,4 +112,6 @@ public class RoomResult {
             whiteboards.add(r);
         }
     }
+
+
 }

+ 57 - 1
mec-im/src/main/java/com/ym/service/Impl/RoomServiceImpl.java

@@ -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())
+                    .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);