|  | @@ -235,23 +235,17 @@ public class IMHelper {
 | 
	
		
			
				|  |  |       * 开始录制
 | 
	
		
			
				|  |  |       * @param roomId
 | 
	
		
			
				|  |  |       * @param registrationId
 | 
	
		
			
				|  |  | -     * @param roomMembers
 | 
	
		
			
				|  |  |       * @return
 | 
	
		
			
				|  |  |       * @throws Exception
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    public void startRecord(String roomId, Long registrationId, List<RoomMember> roomMembers) throws Exception {
 | 
	
		
			
				|  |  | +    public void startRecord(String roomId, Long registrationId, String msid) throws Exception {
 | 
	
		
			
				|  |  |          if (roomId == null) {
 | 
	
		
			
				|  |  |              throw new IllegalArgumentException("Paramer 'roomId' is required");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          JSONObject paramJson = new JSONObject();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        String sessionId = redisTemplate.opsForValue().get("sessionId:" + roomId);
 | 
	
		
			
				|  |  | -        if(StringUtils.isEmpty(sessionId)){
 | 
	
		
			
				|  |  | -            sessionId = roomQuery(roomId);
 | 
	
		
			
				|  |  | -            redisTemplate.opsForValue().set("sessionId:" + roomId,sessionId);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        paramJson.put("sessionId",sessionId);
 | 
	
		
			
				|  |  | +        paramJson.put("sessionId",roomQuery(roomId));
 | 
	
		
			
				|  |  |  //        paramJson.put("sessionId",roomQuery(roomId));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          JSONObject config = new JSONObject();
 | 
	
	
		
			
				|  | @@ -267,16 +261,19 @@ public class IMHelper {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  //        config.put("input",getInput(roomMembers));
 | 
	
		
			
				|  |  |  //        paramJson.put("config",config);
 | 
	
		
			
				|  |  | -        againRecord(paramJson,registrationId,roomId,config);
 | 
	
		
			
				|  |  | +        againRecord(paramJson,registrationId,roomId,config,msid);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Async
 | 
	
		
			
				|  |  | -    public void againRecord(JSONObject paramJson,Long registrationId,String roomId,JSONObject config) throws Exception {
 | 
	
		
			
				|  |  | +    public void againRecord(JSONObject paramJson,Long registrationId,String roomId,JSONObject config,String msid) 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));
 | 
	
		
			
				|  |  | +        if(StringUtils.isEmpty(msid)){
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        config.put("input",getInput(roomMembers,msid));
 | 
	
		
			
				|  |  |          paramJson.put("config",config);
 | 
	
		
			
				|  |  |          String body = paramJson.toJSONString();
 | 
	
		
			
				|  |  |          HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/record/start.json", "application/json",roomId);
 | 
	
	
		
			
				|  | @@ -293,7 +290,7 @@ public class IMHelper {
 | 
	
		
			
				|  |  |                  if (members == null || members.size() == 0) {
 | 
	
		
			
				|  |  |                      throw new IllegalArgumentException("Paramer 'roomMembers' is can not be null");
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                config.put("input",getInput(members));
 | 
	
		
			
				|  |  | +                config.put("input",getInput(roomMembers,msid));
 | 
	
		
			
				|  |  |                  paramJson.put("config",config);
 | 
	
		
			
				|  |  |                  body = paramJson.toJSONString();
 | 
	
		
			
				|  |  |                  HttpURLConnection connection = httpHelper.createIMRtcPostHttpConnection("/rtc/record/start.json", "application/json", roomId);
 | 
	
	
		
			
				|  | @@ -303,7 +300,7 @@ public class IMHelper {
 | 
	
		
			
				|  |  |                  i++;
 | 
	
		
			
				|  |  |                  if(imApiResultInfo.getResultCode() == 10000){
 | 
	
		
			
				|  |  |                      redisTemplate.opsForValue().set(imApiResultInfo.getRecordId(),registrationId.toString());
 | 
	
		
			
				|  |  | -                    log.info("直播视频录制成功:第{}次重试",i);
 | 
	
		
			
				|  |  | +                    log.info("直播视频录制第{}次重试成功",i);
 | 
	
		
			
				|  |  |                      return;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  if(i > 3){
 | 
	
	
		
			
				|  | @@ -322,27 +319,25 @@ public class IMHelper {
 | 
	
		
			
				|  |  |       * @throws Exception
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      @Async
 | 
	
		
			
				|  |  | -    public IMApiResultInfo configRecord(String roomId, List<RoomMember> roomMembers) throws Exception {
 | 
	
		
			
				|  |  | +    public IMApiResultInfo configRecord(String roomId, List<RoomMember> roomMembers,String msid) throws Exception {
 | 
	
		
			
				|  |  |          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);
 | 
	
		
			
				|  |  | -        if(StringUtils.isEmpty(sessionId)){
 | 
	
		
			
				|  |  | -            sessionId = roomQuery(roomId);
 | 
	
		
			
				|  |  | -            redisTemplate.opsForValue().set("sessionId:" + roomId,sessionId);
 | 
	
		
			
				|  |  | +        if(StringUtils.isEmpty(msid)){
 | 
	
		
			
				|  |  | +            throw new IllegalArgumentException("调整录制布局失败:获取流失败");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        paramJson.put("sessionId",sessionId);
 | 
	
		
			
				|  |  | +        JSONObject paramJson = new JSONObject();
 | 
	
		
			
				|  |  | +        paramJson.put("sessionId",roomQuery(roomId));
 | 
	
		
			
				|  |  |  //        paramJson.put("sessionId",roomQuery(roomId));
 | 
	
		
			
				|  |  |          paramJson.put("mixLayout",1);
 | 
	
		
			
				|  |  |          paramJson.put("renderMode",1);
 | 
	
		
			
				|  |  |          paramJson.put("hostUserId","");
 | 
	
		
			
				|  |  |          paramJson.put("hostStreamId","");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        paramJson.put("input",getInput(roomMembers));
 | 
	
		
			
				|  |  | +        paramJson.put("input",getInput(roomMembers,msid));
 | 
	
		
			
				|  |  |          String body = paramJson.toJSONString();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/record/config.json", "application/json",roomId);
 | 
	
	
		
			
				|  | @@ -351,7 +346,7 @@ public class IMHelper {
 | 
	
		
			
				|  |  |          return resultInfo;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private JSONObject getInput(List<RoomMember> roomMembers){
 | 
	
		
			
				|  |  | +    private JSONObject getInput(List<RoomMember> roomMembers,String msid){
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          JSONArray videos = new JSONArray();
 | 
	
		
			
				|  |  |          boolean isMaster = true;
 | 
	
	
		
			
				|  | @@ -363,7 +358,7 @@ public class IMHelper {
 | 
	
		
			
				|  |  |              RoomMember roomMember = roomMembers.get(i);
 | 
	
		
			
				|  |  |              JSONObject video = new JSONObject();
 | 
	
		
			
				|  |  |              video.put("userId",roomMember.getUid());
 | 
	
		
			
				|  |  | -            video.put("streamId",roomMember.getUid() + "_RongCloudRTC");
 | 
	
		
			
				|  |  | +            video.put("streamId",msid);
 | 
	
		
			
				|  |  |              if((roomMember.getRole() == 3 && isMaster) || (i == size - 1 && isMaster) || (i == 5 && isMaster)){
 | 
	
		
			
				|  |  |                  video.put("x",0);
 | 
	
		
			
				|  |  |                  video.put("y",0);
 | 
	
	
		
			
				|  | @@ -405,19 +400,14 @@ public class IMHelper {
 | 
	
		
			
				|  |  |              throw new IllegalArgumentException("Paramer 'roomId' is required");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          JSONObject paramJson = new JSONObject();
 | 
	
		
			
				|  |  | -        String sessionId = redisTemplate.opsForValue().get("sessionId:" + roomId);
 | 
	
		
			
				|  |  | -        if(StringUtils.isEmpty(sessionId)){
 | 
	
		
			
				|  |  | -            sessionId = roomQuery(roomId);
 | 
	
		
			
				|  |  | -            redisTemplate.opsForValue().set("sessionId:" + roomId,sessionId);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        paramJson.put("sessionId",sessionId);
 | 
	
		
			
				|  |  | +        paramJson.put("sessionId",roomQuery(roomId));
 | 
	
		
			
				|  |  |  //        paramJson.put("sessionId",roomQuery(roomId));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          String body = paramJson.toJSONString();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/record/stop.json", "application/json",roomId);
 | 
	
		
			
				|  |  |          httpHelper.setBodyParameter(body, conn);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +        redisTemplate.delete("sessionId:" + roomId);
 | 
	
		
			
				|  |  |          return JSON.parseObject(httpHelper.returnResult(conn, body), IMApiResultInfo.class);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -427,24 +417,35 @@ public class IMHelper {
 | 
	
		
			
				|  |  |       * @return
 | 
	
		
			
				|  |  |       * @throws Exception
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    public String roomQuery(String roomId) throws Exception {
 | 
	
		
			
				|  |  | +    public String roomQuery(String roomId){
 | 
	
		
			
				|  |  |          if (StringUtils.isEmpty(roomId)) {
 | 
	
		
			
				|  |  |              throw new IllegalArgumentException("Paramer 'roomId' is required");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        String sessionId = redisTemplate.opsForValue().get("sessionId:" + roomId);
 | 
	
		
			
				|  |  | +        if(StringUtils.isNotEmpty(sessionId)){
 | 
	
		
			
				|  |  | +            return sessionId;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |          jsonObject.put("roomId",roomId);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/room/query.json", "application/json",null);
 | 
	
		
			
				|  |  | -        httpHelper.setBodyParameter(jsonObject.toJSONString(), conn);
 | 
	
		
			
				|  |  | -        String returnResult = httpHelper.returnResult(conn, jsonObject.toJSONString());
 | 
	
		
			
				|  |  | -        JSONObject resultObject = JSONObject.parseObject(returnResult);
 | 
	
		
			
				|  |  | -        String code = resultObject.get("code").toString();
 | 
	
		
			
				|  |  | -        if("200".equals(code)){
 | 
	
		
			
				|  |  | -            return resultObject.get("sessionId").toString();
 | 
	
		
			
				|  |  | -        }else {
 | 
	
		
			
				|  |  | -            log.error("获取sessionId失败 returnResult:{}",returnResult);
 | 
	
		
			
				|  |  | -            throw new BizException("获取sessionId失败");
 | 
	
		
			
				|  |  | +        HttpURLConnection conn = null;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            conn = httpHelper.createIMRtcPostHttpConnection("/rtc/room/query.json", "application/json",null);
 | 
	
		
			
				|  |  | +            httpHelper.setBodyParameter(jsonObject.toJSONString(), conn);
 | 
	
		
			
				|  |  | +            String returnResult = httpHelper.returnResult(conn, jsonObject.toJSONString());
 | 
	
		
			
				|  |  | +            JSONObject resultObject = JSONObject.parseObject(returnResult);
 | 
	
		
			
				|  |  | +            String code = resultObject.get("code").toString();
 | 
	
		
			
				|  |  | +            if("200".equals(code)){
 | 
	
		
			
				|  |  | +                sessionId = resultObject.get("sessionId").toString();
 | 
	
		
			
				|  |  | +                redisTemplate.opsForValue().set("sessionId:" + roomId,sessionId);
 | 
	
		
			
				|  |  | +            }else {
 | 
	
		
			
				|  |  | +                log.error("获取sessionId失败 returnResult:{}",returnResult);
 | 
	
		
			
				|  |  | +                throw new BizException("获取sessionId失败");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            e.printStackTrace();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        return sessionId;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 |