zouxuan há 2 anos atrás
pai
commit
b5416dfcb7

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

@@ -10,8 +10,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Lists;
 import com.microsvc.toolkit.middleware.live.LivePluginContext;
 import com.microsvc.toolkit.middleware.live.LivePluginContext;
 import com.microsvc.toolkit.middleware.live.LivePluginService;
 import com.microsvc.toolkit.middleware.live.LivePluginService;
-import com.microsvc.toolkit.middleware.live.impl.TencentCloudLivePlugin;
-import com.microsvc.toolkit.middleware.live.message.LiveRoomConfig;
+import com.microsvc.toolkit.middleware.live.message.LiveRoomMessage;
 import com.microsvc.toolkit.middleware.live.message.LiveRoomUser;
 import com.microsvc.toolkit.middleware.live.message.LiveRoomUser;
 import com.microsvc.toolkit.middleware.live.message.RTCRoom;
 import com.microsvc.toolkit.middleware.live.message.RTCRoom;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.client.SysUserFeignService;
@@ -36,7 +35,6 @@ import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageUtil;
 import com.ym.mec.common.page.PageUtil;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.common.tenant.TenantContextHolder;
-import com.ym.mec.im.ImFeignService;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.date.DateUtil;
@@ -53,7 +51,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
@@ -82,8 +79,6 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
     @Autowired
     @Autowired
     private SysUserFeignService sysUserFeignService;
     private SysUserFeignService sysUserFeignService;
     @Autowired
     @Autowired
-    private ImFeignService imFeignService;
-    @Autowired
     private RedissonClient redissonClient;
     private RedissonClient redissonClient;
     @Autowired
     @Autowired
     private SysMessageService sysMessageService;
     private SysMessageService sysMessageService;
@@ -99,9 +94,6 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
     private ImLiveRoomReservationService imLiveRoomReservationService;
     private ImLiveRoomReservationService imLiveRoomReservationService;
     @Autowired
     @Autowired
     private ImLiveRoomBlackService imLiveRoomBlackService;
     private ImLiveRoomBlackService imLiveRoomBlackService;
-    @Autowired
-    @Lazy
-    private TencentCloudLivePlugin tencentCloudLivePlugin;
 
 
     @Autowired
     @Autowired
     private LivePluginContext livePluginContext;
     private LivePluginContext livePluginContext;
@@ -226,21 +218,18 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         if (count > 0) {
         if (count > 0) {
             room.setBlacklistFlag(1);
             room.setBlacklistFlag(1);
         }
         }
-
+        LivePluginService pluginService = livePluginContext.getPluginService(room.getServiceProvider());
         // 直播房间配置信息
         // 直播房间配置信息
         String userSig = "";
         String userSig = "";
         try {
         try {
-            userSig = tencentCloudLivePlugin.register(String.valueOf(sysUser.getId()), sysUser.getUsername(),
+            userSig = pluginService.register(String.valueOf(sysUser.getId()), sysUser.getUsername(),
                     sysUser.getAvatar());
                     sysUser.getAvatar());
-
         } catch (Exception e) {
         } catch (Exception e) {
             log.error("直播房间用户注册失败: userId={}", sysUser.getId(), e);
             log.error("直播房间用户注册失败: userId={}", sysUser.getId(), e);
         }
         }
 
 
         // 直播间配置信息
         // 直播间配置信息
-        LiveRoomConfig liveRoomConfig = tencentCloudLivePlugin.getLiveRoomConfig();
-
-        return room.userSig(userSig).liveRoomConfig(liveRoomConfig);
+        return room.userSig(userSig).liveRoomConfig(pluginService.getLiveRoomConfig());
     }
     }
 
 
     /**
     /**
@@ -617,12 +606,13 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 
 
         //向聊天室发自定义消息踢出所有人
         //向聊天室发自定义消息踢出所有人
         try {
         try {
-            ImRoomMessage message = new ImRoomMessage();
+            LiveRoomMessage message = new LiveRoomMessage();
             message.setIsIncludeSender(1);
             message.setIsIncludeSender(1);
             message.setFromUserId(speakerId.toString());
             message.setFromUserId(speakerId.toString());
-            message.setToChatroomId(roomUid);
+            message.setToChatRoomId(roomUid);
             message.setObjectName(ImRoomMessage.FORCED_OFFLINE);
             message.setObjectName(ImRoomMessage.FORCED_OFFLINE);
-            imFeignService.publishRoomMsg(message);
+            LivePluginService pluginService = livePluginContext.getPluginService(room.getServiceProvider());
+            pluginService.sendChatRoomMessage(message);
             log.info("roomDestroy>>>> FORCED_OFFLINE {}", JSONObject.toJSONString(message));
             log.info("roomDestroy>>>> FORCED_OFFLINE {}", JSONObject.toJSONString(message));
             //销毁直播间
             //销毁直播间
 //            imFeignService.destroyLiveRoom(roomUid);
 //            imFeignService.destroyLiveRoom(roomUid);
@@ -790,17 +780,19 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
             //从在线人员列表删除该人员
             //从在线人员列表删除该人员
             onlineUserInfo.fastRemove(userId);
             onlineUserInfo.fastRemove(userId);
             //向直播间发送当前在线人数消息
             //向直播间发送当前在线人数消息
-            this.sendOnlineUserCount(roomUid, userId, onlineUserInfo.size());
+            ImLiveBroadcastRoomVo roomVo = this.getImLiveBroadcastRoomVo(roomUid);
+            this.sendOnlineUserCount(roomVo, userId, onlineUserInfo.size());
             log.info("opsRoom>>>> looker userInfo: {}", JSONObject.toJSONString(userInfo));
             log.info("opsRoom>>>> looker userInfo: {}", JSONObject.toJSONString(userInfo));
             //用户离开直播间发送退出房间消息给主讲人
             //用户离开直播间发送退出房间消息给主讲人
-            ImRoomMessage message = new ImRoomMessage();
+            LiveRoomMessage message = new LiveRoomMessage();
             message.setIsIncludeSender(1);
             message.setIsIncludeSender(1);
             message.setFromUserId(userId.toString());
             message.setFromUserId(userId.toString());
-            message.setToChatroomId(roomUid);
+            message.setToChatRoomId(roomUid);
             message.setObjectName(ImRoomMessage.LOOKER_LOGIN_OUT);
             message.setObjectName(ImRoomMessage.LOOKER_LOGIN_OUT);
             message.setContent(userId);
             message.setContent(userId);
             try {
             try {
-                imFeignService.publishRoomMsg(message);
+                LivePluginService pluginService = livePluginContext.getPluginService(roomVo.getServiceProvider());
+                pluginService.sendChatRoomMessage(message);
                 log.info("opsRoom>>>> looker LOOKER_LOGIN_OUT : {}", JSONObject.toJSONString(userInfo));
                 log.info("opsRoom>>>> looker LOOKER_LOGIN_OUT : {}", JSONObject.toJSONString(userInfo));
             } catch (Exception e) {
             } catch (Exception e) {
                 log.error("opsRoom>>>>  looker error LOOKER_LOGIN_OUT {}", e.getMessage());
                 log.error("opsRoom>>>>  looker error LOOKER_LOGIN_OUT {}", e.getMessage());
@@ -812,27 +804,28 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
     /**
     /**
      * 向直播间发送当前在线人数消息
      * 向直播间发送当前在线人数消息
      *
      *
-     * @param roomUid    房间uid
+     * @param roomVo    直播间
      * @param fromUserId 发送人id
      * @param fromUserId 发送人id
      * @param count      人数
      * @param count      人数
      */
      */
-    private void sendOnlineUserCount(String roomUid, Integer fromUserId, Integer count) {
+    private void sendOnlineUserCount(ImLiveBroadcastRoomVo roomVo, Integer fromUserId, Integer count) {
+        String roomUid = roomVo.getRoomUid();
         //校验传入参数,房间uid和发送人id不能为空
         //校验传入参数,房间uid和发送人id不能为空
         if (!WrapperUtil.checkObj(roomUid, fromUserId, count)) {
         if (!WrapperUtil.checkObj(roomUid, fromUserId, count)) {
             log.info(" sendOnlineUserCount>>>> param is null   roomUid: {}  fromUserId:{}  count:{}", roomUid, fromUserId, count);
             log.info(" sendOnlineUserCount>>>> param is null   roomUid: {}  fromUserId:{}  count:{}", roomUid, fromUserId, count);
             return;
             return;
         }
         }
-        ImRoomMessage message = new ImRoomMessage();
+        LiveRoomMessage message = new LiveRoomMessage();
         message.setIsIncludeSender(1);
         message.setIsIncludeSender(1);
         message.setObjectName(ImRoomMessage.MEMBER_COUNT);
         message.setObjectName(ImRoomMessage.MEMBER_COUNT);
-        message.setToChatroomId(roomUid);
+        message.setToChatRoomId(roomUid);
         HashMap<String, Integer> sendMap = new HashMap<>();
         HashMap<String, Integer> sendMap = new HashMap<>();
         sendMap.put("count", count);
         sendMap.put("count", count);
         message.setFromUserId(fromUserId.toString());
         message.setFromUserId(fromUserId.toString());
         message.setContent(sendMap);
         message.setContent(sendMap);
         //发送消息
         //发送消息
         try {
         try {
-            imFeignService.publishRoomMsg(message);
+            livePluginContext.getPluginService(roomVo.getServiceProvider()).sendChatRoomMessage(message);
             log.info("sendOnlineUserCount>>>> message: {}", JSONObject.toJSONString(message));
             log.info("sendOnlineUserCount>>>> message: {}", JSONObject.toJSONString(message));
         } catch (Exception e) {
         } catch (Exception e) {
             log.error("sendOnlineUserCount>>>> error {}", e.getMessage());
             log.error("sendOnlineUserCount>>>> error {}", e.getMessage());
@@ -962,7 +955,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         //进入房间写如在线人员列表
         //进入房间写如在线人员列表
         onlineUserInfo.fastPut(userId, JSONObject.toJSONString(userInfo));
         onlineUserInfo.fastPut(userId, JSONObject.toJSONString(userInfo));
         //向直播间发送当前在线人数消息
         //向直播间发送当前在线人数消息
-        this.sendOnlineUserCount(roomUid, userId, onlineUserInfo.size());
+        this.sendOnlineUserCount(imLiveBroadcastRoomVo, userId, onlineUserInfo.size());
         log.info("join sendOnlineUserCount>>>>   roomUid: {}  fromUserId:{}  count:{}", roomUid, userId, onlineUserInfo.size());
         log.info("join sendOnlineUserCount>>>>   roomUid: {}  fromUserId:{}  count:{}", roomUid, userId, onlineUserInfo.size());
         log.info("joinRoom>>>> userInfo: {}", JSONObject.toJSONString(userInfo));
         log.info("joinRoom>>>> userInfo: {}", JSONObject.toJSONString(userInfo));
     }
     }
@@ -987,7 +980,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         if (intEquals(roomSpeakerInfo.getWhetherVideo(), 0)) {
         if (intEquals(roomSpeakerInfo.getWhetherVideo(), 0)) {
             //开始录制视频
             //开始录制视频
             try {
             try {
-                imFeignService.startRecord(roomUid, videoResolution);
+//                imFeignService.startRecord(roomUid, videoResolution);
 
 
                 // 查询房间信息
                 // 查询房间信息
                 ImLiveBroadcastRoomVo imLiveBroadcastRoomVo = getImLiveBroadcastRoomVo(roomUid);
                 ImLiveBroadcastRoomVo imLiveBroadcastRoomVo = getImLiveBroadcastRoomVo(roomUid);