|
@@ -1,7 +1,12 @@
|
|
|
package com.ym.service.Impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.microsvc.toolkit.middleware.live.LivePluginContext;
|
|
|
+import com.microsvc.toolkit.middleware.live.impl.TencentCloudLivePlugin;
|
|
|
+import com.microsvc.toolkit.middleware.live.message.RTCRequest;
|
|
|
+import com.microsvc.toolkit.middleware.live.message.RTCRoom;
|
|
|
import com.ym.http.HttpHelper;
|
|
|
import com.ym.mec.biz.dal.entity.ImLiveRoomVideo;
|
|
|
import com.ym.mec.biz.service.ImLiveRoomVideoService;
|
|
@@ -9,7 +14,6 @@ import com.ym.mec.common.entity.ImRoomMessage;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.im.IMHelper;
|
|
|
import com.ym.mec.thirdparty.storage.StoragePluginContext;
|
|
|
-import com.ym.mec.thirdparty.storage.provider.KS3StoragePlugin;
|
|
|
import com.ym.pojo.IMApiResultInfo;
|
|
|
import com.ym.pojo.IMUserOnlineInfo;
|
|
|
import com.ym.pojo.RecordConfig;
|
|
@@ -17,6 +21,7 @@ import com.ym.pojo.RecordNotify;
|
|
|
import com.ym.service.LiveRoomService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.joda.time.DateTime;
|
|
|
import org.redisson.api.RBucket;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -44,6 +49,8 @@ public class LiveRoomServiceImpl implements LiveRoomService {
|
|
|
private ImLiveRoomVideoService imLiveRoomVideoService;
|
|
|
@Autowired
|
|
|
private StoragePluginContext storagePluginContext;
|
|
|
+ @Autowired
|
|
|
+ private LivePluginContext livePluginContext;
|
|
|
|
|
|
/**
|
|
|
* 创建房间-聊天室
|
|
@@ -319,4 +326,81 @@ public class LiveRoomServiceImpl implements LiveRoomService {
|
|
|
return sessionId;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建tencent云直播录制记录
|
|
|
+ *
|
|
|
+ * @param streamId 推流Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void strartTencentLiveVideoRecord(String streamId) {
|
|
|
+
|
|
|
+ // 直播间ROOM_UID
|
|
|
+ String roomId = streamId.split("_")[0];
|
|
|
+
|
|
|
+ // 创建直播录制
|
|
|
+ RTCRequest.RecordStart recordStart = RTCRequest.RecordStart.builder()
|
|
|
+ .streamName(streamId)
|
|
|
+ .extra("")
|
|
|
+ .endTime(DateTime.now().plusHours(23).getMillis())
|
|
|
+ .build();
|
|
|
+ // 创建录制任务失败,重试3次后,发送IM消息通知主播老师
|
|
|
+ int maxRetry = 0;
|
|
|
+ // 录制任务ID
|
|
|
+ String taskId = "";
|
|
|
+ do {
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 创建录制任务
|
|
|
+ RTCRoom.RecordResp resp = livePluginContext.getPluginService(TencentCloudLivePlugin.PLUGIN_NAME)
|
|
|
+ .rtcRoomRecordStart(recordStart);
|
|
|
+
|
|
|
+ taskId = resp.getRecordId();
|
|
|
+ if (StringUtils.isNotBlank(taskId)) {
|
|
|
+ maxRetry = 3;
|
|
|
+ }
|
|
|
+ log.info("createTencentLiveRoomVideoRecord resp={}", JSON.toJSONString(resp));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("创建直播录制失败", e);
|
|
|
+ }
|
|
|
+ } while (maxRetry++ < 3);
|
|
|
+
|
|
|
+ // 生成录制记录
|
|
|
+ ImLiveRoomVideo video = imLiveRoomVideoService.getOne(new QueryWrapper<ImLiveRoomVideo>()
|
|
|
+ .eq("room_uid_", roomId)
|
|
|
+ .eq("record_id_", taskId)
|
|
|
+ .eq("type", 0));
|
|
|
+ if (Objects.nonNull(video)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ imLiveRoomVideoService.save(initImLiveRoomVideo(roomId, taskId, new Date()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关闭tencent云直播录制记录
|
|
|
+ *
|
|
|
+ * @param streamId 推流Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void stopTencentLiveVideoRecord(String streamId) {
|
|
|
+
|
|
|
+ // 关闭录制任务失败,重试3次后,发送IM消息通知主播老师
|
|
|
+ int maxRetry = 0;
|
|
|
+ do {
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 关闭直播录制
|
|
|
+ RTCRoom.RecordResp ret = livePluginContext.getPluginService(TencentCloudLivePlugin.PLUGIN_NAME)
|
|
|
+ .rtcRoomRecordStop(streamId);
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(ret.getRequestId())) {
|
|
|
+ // 重试最大次数
|
|
|
+ maxRetry = 3;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("关闭直播录制失败", e);
|
|
|
+ }
|
|
|
+ } while (maxRetry++ < 3);
|
|
|
+
|
|
|
+ }
|
|
|
}
|