zouxuan 5 年之前
父节点
当前提交
2ba0c34d8c

+ 11 - 17
edu-im/edu-im-server/src/main/java/com/keao/edu/im/mec/im/IMHelper.java

@@ -238,7 +238,7 @@ public class IMHelper {
      * @return
      * @throws Exception
      */
-    public void startRecord(String roomId, Long registrationId, String msid) throws Exception {
+    public void startRecord(String roomId, Long registrationId) throws Exception {
         if (roomId == null) {
             throw new IllegalArgumentException("Paramer 'roomId' is required");
         }
@@ -261,19 +261,16 @@ public class IMHelper {
 
 //        config.put("input",getInput(roomMembers));
 //        paramJson.put("config",config);
-        againRecord(paramJson,registrationId,roomId,config,msid);
+        againRecord(paramJson,registrationId,roomId,config);
     }
 
     @Async
-    public void againRecord(JSONObject paramJson,Long registrationId,String roomId,JSONObject config,String msid) throws Exception {
+    public void againRecord(JSONObject paramJson,Long registrationId,String roomId,JSONObject config) throws Exception {
         List<RoomMember> roomMembers = roomMemberDao.findByRidAndMsidFlag(roomId,true);
         if (roomMembers == null || roomMembers.size() == 0) {
             throw new IllegalArgumentException("Paramer 'roomMembers' is can not be null");
         }
-        if(StringUtils.isEmpty(msid)){
-            return;
-        }
-        config.put("input",getInput(roomMembers,msid));
+        config.put("input",getInput(roomMembers));
         paramJson.put("config",config);
         String body = paramJson.toJSONString();
         HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/record/start.json", "application/json",roomId);
@@ -290,7 +287,7 @@ public class IMHelper {
                 if (members == null || members.size() == 0) {
                     throw new IllegalArgumentException("Paramer 'roomMembers' is can not be null");
                 }
-                config.put("input",getInput(roomMembers,msid));
+                config.put("input",getInput(roomMembers));
                 paramJson.put("config",config);
                 body = paramJson.toJSONString();
                 HttpURLConnection connection = httpHelper.createIMRtcPostHttpConnection("/rtc/record/start.json", "application/json", roomId);
@@ -314,21 +311,18 @@ public class IMHelper {
     /**
      * 更改录制布局
      * @param roomId
-     * @param roomMembers
      * @return
      * @throws Exception
      */
     @Async
-    public IMApiResultInfo configRecord(String roomId, List<RoomMember> roomMembers,String msid) throws Exception {
+    public IMApiResultInfo configRecord(String roomId) throws Exception {
         if (roomId == null) {
             throw new IllegalArgumentException("Paramer 'roomId' is required");
         }
-        if (roomMembers == null || roomMembers.size() == 0) {
+        List<RoomMember> members = roomMemberDao.findByRidAndMsidFlag(roomId,true);
+        if (members == null || members.size() == 0) {
             throw new IllegalArgumentException("Paramer 'roomMembers' is can not be null");
         }
-        if(StringUtils.isEmpty(msid)){
-            throw new IllegalArgumentException("调整录制布局失败:获取流失败");
-        }
         JSONObject paramJson = new JSONObject();
         paramJson.put("sessionId",roomQuery(roomId));
 //        paramJson.put("sessionId",roomQuery(roomId));
@@ -337,7 +331,7 @@ public class IMHelper {
         paramJson.put("hostUserId","");
         paramJson.put("hostStreamId","");
 
-        paramJson.put("input",getInput(roomMembers,msid));
+        paramJson.put("input",getInput(members));
         String body = paramJson.toJSONString();
 
         HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/record/config.json", "application/json",roomId);
@@ -346,7 +340,7 @@ public class IMHelper {
         return resultInfo;
     }
 
-    private JSONObject getInput(List<RoomMember> roomMembers,String msid){
+    private JSONObject getInput(List<RoomMember> roomMembers){
 
         JSONArray videos = new JSONArray();
         boolean isMaster = true;
@@ -358,7 +352,7 @@ public class IMHelper {
             RoomMember roomMember = roomMembers.get(i);
             JSONObject video = new JSONObject();
             video.put("userId",roomMember.getUid());
-            video.put("streamId",msid);
+            video.put("streamId",roomMember.getUid() + "_RongCloudRTC");
             if((roomMember.getRole() == 3 && isMaster) || (i == size - 1 && isMaster) || (i == 5 && isMaster)){
                 video.put("x",0);
                 video.put("y",0);

+ 48 - 17
edu-im/edu-im-server/src/main/java/com/keao/edu/im/service/Impl/RoomServiceImpl.java

@@ -78,7 +78,7 @@ public class RoomServiceImpl implements RoomService {
     }
 
     @Transactional(rollbackFor = Exception.class, isolation = Isolation.SERIALIZABLE)
-    public void joinRoomSuccess(Long registrationId,String roomId,String userId,String msid) throws Exception {
+    public void joinRoomSuccess(Long registrationId,String roomId,String userId) throws Exception {
         StudentExamResultApiDto examResult = null;
         log.info("joinRoomSuccess: roomId={}, isAudience={}, isDisableCamera={},isMusicMode={}", roomId);
 
@@ -160,10 +160,10 @@ public class RoomServiceImpl implements RoomService {
             }
             this.publishMessage(eduUserFeignService.getPublishMessage(registrationId));
             eduUserFeignService.upsetStudentAttendance(registrationId,0);
-            imHelper.startRecord(roomId, registrationId,msid);
+            imHelper.startRecord(roomId, registrationId);
         }else {
             eduUserFeignService.upsetTeacherAttendance(examRoom.getId(),sysUser.getId(),0);
-            imHelper.configRecord(roomId,roomMembers,msid);
+            imHelper.configRecord(roomId);
         }
     }
 
@@ -286,7 +286,7 @@ public class RoomServiceImpl implements RoomService {
     }
 
     @Transactional(rollbackFor = Exception.class, isolation = Isolation.SERIALIZABLE)
-    public void leaveRoomSuccess(Long registrationId,String roomId,String userId,String msid) throws Exception {
+    public void leaveRoomSuccess(Long registrationId,String roomId,String userId) throws Exception {
         if(registrationId != null){
             StudentExamResultApiDto examResult = eduUserFeignService.getExamResult(registrationId);
             roomId = examResult.getRoomId();
@@ -327,7 +327,7 @@ public class RoomServiceImpl implements RoomService {
             imHelper.stopRecord(roomId);
         }else {
             eduUserFeignService.upsetTeacherAttendance(Long.parseLong(roomId),Integer.parseInt(userId),1);
-            imHelper.configRecord(roomId,roomMemberDao.findByRidAndMsidFlag(roomId,true),msid);
+            imHelper.configRecord(roomId);
         }
     }
 
@@ -1258,14 +1258,9 @@ public class RoomServiceImpl implements RoomService {
         }
     }
 
-    @Override
-    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
-    public boolean statusSync(ChannelStateNotify notify) throws Exception {
-        log.info("statusSync notify:{}",notify);
-        String roomId = notify.getChannelId();
-        String userId = notify.getUserId();
-        RoomMember roomMember = roomMemberDao.findByRidAndUid(roomId, userId);
-        log.info("statusSync roomMember:{}",roomMember);
+    public static void main(String[] args) {
+        String body = "{\"members\":[],\"appKey\":\"mgb7ka1nme0yg\",\"sessionId\":\"hjcKwEaRIm8scdSeDHgF7A\",\"event\":11,\"userId\":\"113\",\"channelId\":\"31\",\"timestamp\":1598235225551,\"token\":\"\"}";
+        ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
         String msidStr = null;
         boolean msidFlag = false;
         List<Member> members = notify.getMembers();
@@ -1279,6 +1274,17 @@ public class RoomServiceImpl implements RoomService {
                 }
             }
         }
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+    public boolean statusSync(ChannelStateNotify notify) throws Exception {
+        log.info("statusSync notify:{}",notify);
+        String roomId = notify.getChannelId();
+        String userId = notify.getUserId();
+        RoomMember roomMember = roomMemberDao.findByRidAndUid(roomId, userId);
+        log.info("statusSync roomMember:{}",roomMember);
+
         if(roomMember == null){
             return false;
         }
@@ -1291,14 +1297,39 @@ public class RoomServiceImpl implements RoomService {
             redisTemplate.delete("sessionId:" + roomId);
         }else if(notify.getEvent() == 11){
             //成员加入
-            roomMemberDao.updateMsidByRidAndUid(roomId,userId,msidFlag);
-            joinRoomSuccess(roomMember.getExamRegistrationId(),roomId,userId,msidStr);
+//            roomMemberDao.updateMsidByRidAndUid(roomId,userId,msidFlag);
+            joinRoomSuccess(roomMember.getExamRegistrationId(),roomId,userId);
         }else if(notify.getEvent() == 12){
             //成员退出
-            roomMemberDao.updateMsidByRidAndUid(roomId,userId,msidFlag);
-            leaveRoomSuccess(roomMember.getExamRegistrationId(),roomId,userId,msidStr);
+//            roomMemberDao.updateMsidByRidAndUid(roomId,userId,msidFlag);
+            leaveRoomSuccess(roomMember.getExamRegistrationId(),roomId,userId);
         }else if(notify.getEvent() == 20){
+            boolean msidFlag = false;
+            Integer state = null;
+            List<Member> members = notify.getMembers();
+            if(members != null && members.size() != 0){
+                Object uris = JSONObject.parseObject(members.get(0).getData().toJSONString()).get("uris");
+                if(uris != null){
+                    List<UrisDto> jsonArray = JSONObject.parseArray(uris.toString(),UrisDto.class);
+                    for (UrisDto urisDto : jsonArray) {
+                        //视频流
+                        if(urisDto.getMediaType() == 1){
+                            state = urisDto.getState();
+                            if(state == 1){
+                                msidFlag = true;
+                            }
+                        }else {
+                            //音频流
+                        }
+                    }
+                }
+            }
+            //同步录制资源
             //资源发生变动
+            if(state == null || state == 0 || !msidFlag){
+                roomMemberDao.updateMsidByRidAndUid(roomId,userId,msidFlag);
+                imHelper.configRecord(roomId);
+            }
         }
         return true;
     }