zouxuan пре 5 година
родитељ
комит
6db40bc2e7
1 измењених фајлова са 23 додато и 8 уклоњено
  1. 23 8
      edu-im/edu-im-server/src/main/java/com/keao/edu/im/mec/im/IMHelper.java

+ 23 - 8
edu-im/edu-im-server/src/main/java/com/keao/edu/im/mec/im/IMHelper.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.keao.edu.common.exception.BizException;
 import com.keao.edu.im.api.entity.BaseMessage;
+import com.keao.edu.im.dao.RoomMemberDao;
 import com.keao.edu.im.http.HttpHelper;
 import com.keao.edu.im.pojo.IMApiResultInfo;
 import com.keao.edu.im.pojo.IMTokenInfo;
@@ -30,6 +31,8 @@ public class IMHelper {
 
     @Autowired
     HttpHelper httpHelper;
+    @Autowired
+    RoomMemberDao roomMemberDao;
 
     @Autowired
     private RedisTemplate<String,String> redisTemplate;
@@ -240,9 +243,7 @@ public class IMHelper {
         if (roomId == null) {
             throw new IllegalArgumentException("Paramer 'roomId' is required");
         }
-        if (roomMembers == null || roomMembers.size() == 0) {
-            throw new IllegalArgumentException("Paramer 'roomMembers' is can not be null");
-        }
+
         JSONObject paramJson = new JSONObject();
 
         String sessionId = redisTemplate.opsForValue().get("sessionId:" + roomId);
@@ -264,14 +265,20 @@ public class IMHelper {
         config.put("hostUserId","");
         config.put("hostStreamId","");
 
-        config.put("input",getInput(roomMembers));
-        paramJson.put("config",config);
-        String body = paramJson.toJSONString();
-        againRecord(body,registrationId,roomId);
+//        config.put("input",getInput(roomMembers));
+//        paramJson.put("config",config);
+        againRecord(paramJson,registrationId,roomId,config);
     }
 
     @Async
-    public void againRecord(String body,Long registrationId,String roomId) throws Exception {
+    public void againRecord(JSONObject paramJson,Long registrationId,String roomId,JSONObject config) throws Exception {
+        List<RoomMember> roomMembers = roomMemberDao.findByRid(roomId);
+        if (roomMembers == null || roomMembers.size() == 0) {
+            throw new IllegalArgumentException("Paramer 'roomMembers' is can not be null");
+        }
+        config.put("input",getInput(roomMembers));
+        paramJson.put("config",config);
+        String body = paramJson.toJSONString();
         HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/record/start.json", "application/json",roomId);
         httpHelper.setBodyParameter(body, conn);
         IMApiResultInfo resultInfo = JSON.parseObject(httpHelper.returnResult(conn, body), IMApiResultInfo.class);
@@ -282,6 +289,13 @@ public class IMHelper {
             int i = 1;
             while (i<=3){
                 Thread.sleep(5000l);
+                List<RoomMember> members = roomMemberDao.findByRid(roomId);
+                if (members == null || members.size() == 0) {
+                    throw new IllegalArgumentException("Paramer 'roomMembers' is can not be null");
+                }
+                config.put("input",getInput(members));
+                paramJson.put("config",config);
+                body = paramJson.toJSONString();
                 HttpURLConnection connection = httpHelper.createIMRtcPostHttpConnection("/rtc/record/start.json", "application/json", roomId);
                 httpHelper.setBodyParameter(body, connection);
                 IMApiResultInfo imApiResultInfo = JSON.parseObject(httpHelper.returnResult(connection, body), IMApiResultInfo.class);
@@ -338,6 +352,7 @@ public class IMHelper {
     }
 
     private JSONObject getInput(List<RoomMember> roomMembers){
+
         JSONArray videos = new JSONArray();
         boolean isMaster = true;