liujunchi 2 years ago
parent
commit
896441cb70

+ 41 - 21
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveBroadcastRoomServiceImpl.java

@@ -44,6 +44,7 @@ import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageUtil;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.tenant.TenantContextHolder;
+import com.ym.mec.im.ImFeignService;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
@@ -114,6 +115,9 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
     @Autowired
     private LivePluginContext livePluginContext;
 
+    @Autowired
+    private ImFeignService imFeignService;
+
     //待替换的变量
     public static final String USER_ID = "${userId}";
     public static final String ROOM_UID = "${roomUid}";
@@ -1314,8 +1318,6 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         if (intEquals(roomSpeakerInfo.getWhetherVideo(), 0)) {
             //开始录制视频
             try {
-//                imFeignService.startRecord(roomUid, videoResolution);
-
                 // 查询房间信息
                 ImLiveBroadcastRoomVo imLiveBroadcastRoomVo = getImLiveBroadcastRoomVo(roomUid);
                 if (Objects.isNull(imLiveBroadcastRoomVo)) {
@@ -1329,19 +1331,23 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
                     return;
                 }
 
-                // 直播开始时间
-                DateTime dateTime = new DateTime(imLiveBroadcastRoomVo.getLiveStartTime());
-
-                RTCRoom.RecordResp recordResp = pluginService.rtcRoomRecordStart(RTCRequest.RecordStart.builder()
-                        .startTime(dateTime.plusMillis(5).getMillis() / 1000)
-                        .endTime(dateTime.plusDays(1).getMillis() / 1000)
-                        .streamName(MessageFormat.format("{0}_{1}", imLiveBroadcastRoomVo.getRoomUid(), String.valueOf(imLiveBroadcastRoomVo.getSpeakerId())))
-                        .sessionId(rtcRoom.getSessionId())
-                        .config(RTCRequest.RecordConfig.builder()
-                                .videoResolution(videoResolution)
-                                .build())
-                        .build());
-                log.info("startLive 直播录录开启: recordResp={}", JSON.toJSONString(recordResp));
+                if (imLiveBroadcastRoomVo.getServiceProvider().equals(RongCloudLivePlugin.PLUGIN_NAME)) {
+                    imFeignService.startRecord(roomUid, videoResolution);
+                } else if (imLiveBroadcastRoomVo.getServiceProvider().equals(TencentCloudLivePlugin.PLUGIN_NAME) && roomSpeakerInfo.getVideoTemplate() == 0) {
+                    // 直播开始时间
+                    DateTime dateTime = new DateTime(imLiveBroadcastRoomVo.getLiveStartTime());
+
+                    RTCRoom.RecordResp recordResp = pluginService.rtcRoomRecordStart(RTCRequest.RecordStart.builder()
+                           .startTime(dateTime.getMillis() )
+                           .endTime(dateTime.plusDays(1).getMillis() )
+                           .streamName(MessageFormat.format("{0}_{1}", imLiveBroadcastRoomVo.getRoomUid(), String.valueOf(imLiveBroadcastRoomVo.getSpeakerId())))
+                           .build());
+                    roomSpeakerInfo.setVideoTemplate(1);
+
+                    log.info("startLive 直播录录开启: recordResp={}", JSON.toJSONString(recordResp));
+                }
+
+
             } catch (Exception e) {
                 log.error("startRecord error: {}", e.getMessage());
             }
@@ -1403,12 +1409,10 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
                     return;
                 }
 
-                // 若返回的sessionId为空,则手动查询录制任务taskId
-                if (StringUtils.isBlank(rtcRoom.getSessionId())) {
-                    // FIXME: 获取腾讯云直播录制任务Id
+                // 融云停止录制 腾讯云录制在直播间销毁时自动停止
+                if (imLiveBroadcastRoomVo.getServiceProvider().equals(RongCloudLivePlugin.PLUGIN_NAME)) {
+                    pluginService.rtcRoomRecordStop(rtcRoom.getSessionId());
                 }
-
-                pluginService.rtcRoomRecordStop(rtcRoom.getSessionId());
             } catch (Exception e) {
                 log.error("stopRecord error: {}", e.getMessage());
             }
@@ -1520,8 +1524,10 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
             // 创建直播间IM群
             pluginService.chatRoomCreate(room.getRoomUid(), room.getRoomTitle(),sysUser.getId().toString());
 
+            Boolean whetherVideoFlag = getRoomConfig(room.getRoomConfig()).map(o -> o.getWhether_video() == 0).orElse(true);
+
             // 腾讯云直播,提前生成录制规则
-            if (room.getServiceProvider().equals(TencentCloudLivePlugin.PLUGIN_NAME)) {
+            if (room.getServiceProvider().equals(TencentCloudLivePlugin.PLUGIN_NAME) && whetherVideoFlag) {
 
                 DateTime now = DateTime.now();
 
@@ -1567,9 +1573,12 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         if (video) {
             //可以录制视频
             speakerInfo.setWhetherVideo(0);
+            // 设置模板
+            speakerInfo.setVideoTemplate(1);
         } else {
             //不可以录制视频
             speakerInfo.setWhetherVideo(1);
+            speakerInfo.setVideoTemplate(0);
         }
         speakerInfo.setOs(room.getOs());
         //写入主讲人信息
@@ -2258,6 +2267,17 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         //播出端-  pc网页端 移动端mobile
         private String os = "pc";
 
+        // 腾讯视频模板 0: 没有 1:有
+        private Integer videoTemplate;
+
+        public Integer getVideoTemplate() {
+            return videoTemplate;
+        }
+
+        public void setVideoTemplate(Integer videoTemplate) {
+            this.videoTemplate = videoTemplate;
+        }
+
         public Integer getSpeakerId() {
             return speakerId;
         }

+ 10 - 0
mec-im/src/main/java/com/ym/controller/UserController.java

@@ -110,17 +110,27 @@ public class UserController {
         if (event.getEventType() == 0) {
             // 自动关闭录制
             // liveRoomService.stopTencentLiveVideoRecord(event.getStreamId());
+            imLiveBroadcastRoomService.closeLive(getRoomUid(event.getStreamId()), getSpeakerId(event.getStreamId()));
         }
 
         // 推流事件通知
         if (event.getEventType() == 1) {
             // 自动开启录制
             // liveRoomService.startTencentLiveVideoRecord(event.getStreamId());
+            imLiveBroadcastRoomService.startLive(getRoomUid(event.getStreamId()), getSpeakerId(event.getStreamId()), null);
         }
 
         return TencentData.StreamEventCallbackResult.builder().code(0).build();
     }
 
+    private Integer getSpeakerId(String streamId) {
+        return Integer.parseInt(streamId.split("_")[1]);
+    }
+
+    private String getRoomUid(String streamId) {
+        return streamId.split("_")[0];
+    }
+
     @ApiOperation("腾讯云直播-录制 回调接口")
     @PostMapping(value = "/tencentStreamRecordCallback")
     public TencentData.StreamEventCallbackResult tencentStreamRecordCallback(@RequestBody String body) {

+ 9 - 9
mec-teacher/src/main/java/com/ym/mec/teacher/controller/TeacherImLiveBroadcastRoomController.java

@@ -116,20 +116,20 @@ public class TeacherImLiveBroadcastRoomController extends BaseController {
         return succeed();
     }
 
-    @ApiOperation("开启/关闭直播的录像")
+    @ApiOperation("开启/关闭直播的录像-接口废弃")
     @GetMapping("/opsLiveVideo")
     public HttpResponseResult<Object> opsLiveVideo(@ApiParam(value = "房间uid", required = true) String roomUid,
                                                    @ApiParam(value = "用户id", required = true) Integer userId,
                                                    @ApiParam(value = "type 1:开始直播-开始录像     2:关闭直播关闭录像", required = true) Integer type,
                                                    @ApiParam(value = "录制视频的尺寸-默认值是720x1280") String videoResolution) {
-        if (type == 1) {
-            videoResolution = Optional.ofNullable(videoResolution).orElse("720x1280");
-            imLiveBroadcastRoomService.startLive(roomUid, userId, videoResolution);
-        } else if (type == 2) {
-            imLiveBroadcastRoomService.closeLive(roomUid, userId);
-        } else {
-            failed("type参数错误");
-        }
+        // if (type == 1) {
+        //     videoResolution = Optional.ofNullable(videoResolution).orElse("720x1280");
+        //     imLiveBroadcastRoomService.startLive(roomUid, userId, videoResolution);
+        // } else if (type == 2) {
+        //     imLiveBroadcastRoomService.closeLive(roomUid, userId);
+        // } else {
+        //     failed("type参数错误");
+        // }
         return succeed();
     }
 

+ 9 - 9
mec-web/src/main/java/com/ym/mec/web/controller/ImLiveBroadcastRoomController.java

@@ -34,7 +34,6 @@ import javax.validation.Valid;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.CompletableFuture;
 
 /**
  * 直播房间管理表(ImLiveBroadcastRoom)表控制层
@@ -198,18 +197,19 @@ public class ImLiveBroadcastRoomController extends BaseController {
         return succeed();
     }
 
-    @ApiOperation("开启/关闭直播的录像")
+    @ApiOperation("开启/关闭直播的录像 -接口废弃")
     @GetMapping("/opsLiveVideo")
     public HttpResponseResult<Object> opsLiveVideo(@ApiParam(value = "房间uid", required = true) String roomUid,
                                                    @ApiParam(value = "用户id", required = true) Integer userId,
                                                    @ApiParam(value = "type 1:开始直播-开始录像     2:关闭直播关闭录像", required = true) Integer type) {
-        if (type == 1) {
-            imLiveBroadcastRoomService.startLive(roomUid, userId, null);
-        } else if (type == 2) {
-            imLiveBroadcastRoomService.closeLive(roomUid, userId);
-        } else {
-            failed("type参数错误");
-        }
+        // 接口废弃
+        // if (type == 1) {
+        //     imLiveBroadcastRoomService.startLive(roomUid, userId, null);
+        // } else if (type == 2) {
+        //     imLiveBroadcastRoomService.closeLive(roomUid, userId);
+        // } else {
+        //     failed("type参数错误");
+        // }
         return succeed();
     }