Eric 2 년 전
부모
커밋
a7ed0ec9f2

+ 6 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ImLiveBroadcastRoomService.java

@@ -156,5 +156,11 @@ public interface ImLiveBroadcastRoomService extends IService<ImLiveBroadcastRoom
      * 直播间销毁定时任务
      */
     void destroyLiveRoom();
+
+    /**
+     * 更新直播推流时间
+     * @param event TencentData.CallbackStreamStateEvent
+     */
+    void updateLiveRoomPushStreamTime(TencentData.CallbackStreamStateEvent event);
 }
 

+ 29 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveBroadcastRoomServiceImpl.java

@@ -48,7 +48,6 @@ import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.excel.POIUtil;
-import com.ym.mec.util.http.HttpUtil;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -2059,6 +2058,35 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         }
     }
 
+    /**
+     * 更新直播推流时间
+     *
+     * @param event TencentData.CallbackStreamStateEvent
+     */
+    @Override
+    public void updateLiveRoomPushStreamTime(TencentData.CallbackStreamStateEvent event) {
+
+        // 直播间ROOM_UID
+        String roomId = event.getStreamId().split("_")[0];
+
+        ImLiveBroadcastRoomVo room = getImLiveBroadcastRoomVo(roomId);
+        if (Objects.isNull(room)) {
+            log.warn("updateLiveRoomPushStreamTime 无效的直播间ID, roomId:{}", roomId);
+            return;
+        }
+
+        // 更新直播时长
+        ImLiveBroadcastRoom entity = new ImLiveBroadcastRoom();
+        // 主键ID
+        entity.setId(room.getId());
+        // 直播累积播放时长
+        int liveTotalTime = Optional.ofNullable(room.getLiveTotalTime()).orElse(0) + Integer.parseInt(event.getPushDuration());
+        // 累积播放时长
+        entity.setLiveTotalTime(liveTotalTime);
+
+        updateById(entity);
+    }
+
 
     /**
      * 查询直播间所有用户信息

+ 5 - 2
mec-im/src/main/java/com/ym/controller/UserController.java

@@ -12,6 +12,7 @@ import com.ym.service.LiveRoomService;
 import com.ym.service.UserService;
 import io.rong.models.user.UserModel;
 import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -109,13 +110,15 @@ public class UserController {
         // 断流事件通知
         if (event.getEventType() == 0) {
             // 自动关闭录制
-            // liveRoomService.stopTencentLiveVideoRecord(event.getStreamId());
+            if (StringUtils.isNotBlank(event.getPushDuration()) && event.getPushDuration().matches("\\d+")) {
+                // 更新直播推流时长
+                imLiveBroadcastRoomService.updateLiveRoomPushStreamTime(event);
+            }
         }
 
         // 推流事件通知
         if (event.getEventType() == 1) {
             // 自动开启录制
-            // liveRoomService.startTencentLiveVideoRecord(event.getStreamId());
         }
 
         return TencentData.StreamEventCallbackResult.builder().code(0).build();

+ 0 - 88
mec-im/src/main/java/com/ym/service/Impl/LiveRoomServiceImpl.java

@@ -1,12 +1,7 @@
 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.dto.TencentData;
 import com.ym.mec.biz.dal.entity.ImLiveRoomVideo;
@@ -50,8 +45,6 @@ public class LiveRoomServiceImpl implements LiveRoomService {
     private ImLiveRoomVideoService imLiveRoomVideoService;
     @Autowired
     private StoragePluginContext storagePluginContext;
-    @Autowired
-    private LivePluginContext livePluginContext;
 
     /**
      * 创建房间-聊天室
@@ -327,87 +320,6 @@ public class LiveRoomServiceImpl implements LiveRoomService {
         return sessionId;
     }
 
-
-    /**
-     * 创建tencent云直播录制记录
-     *
-     * @param streamId 推流Id
-     */
-    @Override
-    public void startTencentLiveVideoRecord(String streamId) {
-
-        DateTime now = DateTime.now();
-        // 创建直播录制
-        RTCRequest.RecordStart recordStart = RTCRequest.RecordStart.builder()
-                .streamName(streamId)
-                .extra("")
-                .startTime(now.getMillis())
-                .endTime(now.plusDays(1).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);
-
-        log.info("startTencentLiveVideoRecord taskId={}", taskId);
-        // 生成录制记录
-        // 直播间ROOM_UID
-        String roomId = streamId.split("_")[0];
-
-        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);
-
-    }
-
     /**
      * 生成直播录制信息
      *

+ 0 - 12
mec-im/src/main/java/com/ym/service/LiveRoomService.java

@@ -65,18 +65,6 @@ public interface LiveRoomService {
     boolean removeUserUnableSpeak(String roomUid, String userId);
 
     /**
-     * 开始tencent云直播录制记录
-     * @param streamId 推流Id
-     */
-    void startTencentLiveVideoRecord(String streamId);
-
-    /**
-     * 关闭tencent云直播录制记录
-     * @param streamId 推流Id
-     */
-    void stopTencentLiveVideoRecord(String streamId);
-
-    /**
      * 生成直播录制信息
      * @param event TencentData.CallbackSteamRecordEvent
      */

+ 0 - 1
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)表控制层