|
@@ -1,12 +1,14 @@
|
|
|
package com.keao.edu.im.mec.im;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+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.http.HttpHelper;
|
|
|
import com.keao.edu.im.pojo.IMApiResultInfo;
|
|
|
import com.keao.edu.im.pojo.IMTokenInfo;
|
|
|
+import com.keao.edu.im.pojo.RoomMember;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -14,8 +16,10 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.validation.constraints.Size;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by weiqinxiao on 2019/2/28.
|
|
@@ -227,15 +231,14 @@ public class IMHelper {
|
|
|
|
|
|
/**
|
|
|
* 开始录制
|
|
|
- * @param hostUserId
|
|
|
+ * @param roomId
|
|
|
+ * @param registrationId
|
|
|
+ * @param roomMembers
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Async
|
|
|
- public IMApiResultInfo startRecord(String hostUserId, String roomId,Long registrationId) throws Exception {
|
|
|
- if (hostUserId == null) {
|
|
|
- throw new IllegalArgumentException("Paramer 'hostUserId' is required");
|
|
|
- }
|
|
|
+ public IMApiResultInfo startRecord(String roomId, Long registrationId, List<RoomMember> roomMembers) throws Exception {
|
|
|
if (roomId == null) {
|
|
|
throw new IllegalArgumentException("Paramer 'roomId' is required");
|
|
|
}
|
|
@@ -244,13 +247,43 @@ public class IMHelper {
|
|
|
jsonObject.put("videoFormat","mp4");
|
|
|
jsonObject.put("audioFormat","mp3");
|
|
|
jsonObject.put("videoResolution","640x480");
|
|
|
- jsonObject.put("mixLayout",2);
|
|
|
+ jsonObject.put("mixLayout",1);
|
|
|
jsonObject.put("sliceMin",30);
|
|
|
- jsonObject.put("hostUserId",hostUserId);
|
|
|
+ jsonObject.put("renderMode",1);
|
|
|
+ jsonObject.put("hostUserId","");
|
|
|
+ jsonObject.put("hostStreamId","");
|
|
|
+
|
|
|
JSONObject json = new JSONObject();
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ boolean isMaster = true;
|
|
|
+ for (int i = 0; i < roomMembers.size(); i++) {
|
|
|
+ RoomMember roomMember = roomMembers.get(i);
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ jsonObject1.put("userId",roomMember.getUid());
|
|
|
+ jsonObject1.put("streamId",roomMember.getUid());
|
|
|
+ if((roomMember.getRole() == 3 && isMaster) || (i == roomMembers.size() - 1 && isMaster)){
|
|
|
+ jsonObject1.put("x",0);
|
|
|
+ jsonObject1.put("y",0);
|
|
|
+ jsonObject1.put("width",0.5);
|
|
|
+ jsonObject1.put("height",0.5);
|
|
|
+ isMaster = false;
|
|
|
+ }else {
|
|
|
+ jsonObject1.put("x",0.5);
|
|
|
+ jsonObject1.put("y",0.5);
|
|
|
+ jsonObject1.put("width",0.5);
|
|
|
+ jsonObject1.put("height",0.5);
|
|
|
+ }
|
|
|
+ jsonArray.add(jsonObject1);
|
|
|
+ }
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ jsonObject1.put("video",jsonArray);
|
|
|
+ jsonObject.put("input",jsonObject1);
|
|
|
+
|
|
|
+
|
|
|
json.put("sessionId",roomQuery(roomId));
|
|
|
json.put("config",jsonObject);
|
|
|
|
|
|
+
|
|
|
String body = json.toJSONString();
|
|
|
|
|
|
Thread.sleep(1000l);
|
|
@@ -264,30 +297,88 @@ public class IMHelper {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 结束录制
|
|
|
- * @param hostUserId
|
|
|
+ * 更改录制布局
|
|
|
+ * @param roomId
|
|
|
+ * @param registrationId
|
|
|
+ * @param roomMembers
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public IMApiResultInfo stopRecord(String hostUserId, String roomId) throws Exception {
|
|
|
- if (hostUserId == null) {
|
|
|
- throw new IllegalArgumentException("Paramer 'userId' is required");
|
|
|
+ @Async
|
|
|
+ public IMApiResultInfo configRecord(String roomId, Long registrationId, List<RoomMember> roomMembers) throws Exception {
|
|
|
+ if (roomId == null) {
|
|
|
+ throw new IllegalArgumentException("Paramer 'roomId' is required");
|
|
|
}
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("mixLayout",1);
|
|
|
+ jsonObject.put("renderMode",1);
|
|
|
+ jsonObject.put("hostUserId","");
|
|
|
+ jsonObject.put("hostStreamId","");
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("sessionId",roomQuery(roomId));
|
|
|
+ json.put("config",jsonObject);
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ boolean isMaster = true;
|
|
|
+ for (int i = 0; i < roomMembers.size(); i++) {
|
|
|
+ RoomMember roomMember = roomMembers.get(i);
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ jsonObject1.put("userId",roomMember.getUid());
|
|
|
+ jsonObject1.put("streamId",roomMember.getUid());
|
|
|
+ if((roomMember.getRole() == 3 && isMaster) || (i == roomMembers.size() - 1 && isMaster)){
|
|
|
+ jsonObject1.put("x",0);
|
|
|
+ jsonObject1.put("y",0);
|
|
|
+ jsonObject1.put("width",0.5);
|
|
|
+ jsonObject1.put("height",0.5);
|
|
|
+ isMaster = false;
|
|
|
+ }else {
|
|
|
+ jsonObject1.put("x",0.5);
|
|
|
+ jsonObject1.put("y",0.5);
|
|
|
+ jsonObject1.put("width",0.5);
|
|
|
+ jsonObject1.put("height",0.5);
|
|
|
+ }
|
|
|
+ jsonArray.add(jsonObject1);
|
|
|
+ }
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ jsonObject1.put("video",jsonArray);
|
|
|
+ json.put("input",jsonObject1);
|
|
|
|
|
|
- if (hostUserId == null) {
|
|
|
- throw new IllegalArgumentException("Paramer 'groupId' is required");
|
|
|
+ String body = json.toJSONString();
|
|
|
+
|
|
|
+ Thread.sleep(1000l);
|
|
|
+ HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/record/config.json", "application/json",roomId);
|
|
|
+ httpHelper.setBodyParameter(body, conn);
|
|
|
+ IMApiResultInfo resultInfo = JSON.parseObject(httpHelper.returnResult(conn, body), IMApiResultInfo.class);
|
|
|
+ if(resultInfo.getResultCode() == 10000){
|
|
|
+ redisTemplate.opsForValue().set(resultInfo.getRecordId(),registrationId.toString());
|
|
|
}
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
+ return resultInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结束录制
|
|
|
+ * @param roomId
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public IMApiResultInfo stopRecord(String roomId) throws Exception {
|
|
|
+ if (roomId == null) {
|
|
|
+ throw new IllegalArgumentException("Paramer 'roomId' is required");
|
|
|
+ }
|
|
|
+
|
|
|
+// if (hostUserId == null) {
|
|
|
+// throw new IllegalArgumentException("Paramer 'groupId' is required");
|
|
|
+// }
|
|
|
+ /*JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("mode",3);
|
|
|
jsonObject.put("videoFormat","mp4");
|
|
|
jsonObject.put("audioFormat","mp3");
|
|
|
jsonObject.put("videoResolution","640x480");
|
|
|
jsonObject.put("mixLayout",2);
|
|
|
jsonObject.put("sliceMin",30);
|
|
|
- jsonObject.put("hostUserId",hostUserId);
|
|
|
+ jsonObject.put("hostUserId",hostUserId);*/
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("sessionId",roomQuery(roomId));
|
|
|
- json.put("config",jsonObject);
|
|
|
+// json.put("config",jsonObject);
|
|
|
|
|
|
String body = json.toJSONString();
|
|
|
|