|
@@ -13,7 +13,6 @@ import com.ym.pojo.RecordConfig;
|
|
|
import com.ym.pojo.RecordNotify;
|
|
|
import com.ym.service.LiveRoomService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.redisson.api.RBucket;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -24,6 +23,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* @author hgw
|
|
@@ -167,10 +167,11 @@ public class LiveRoomServiceImpl implements LiveRoomService {
|
|
|
if (Objects.isNull(video)) {
|
|
|
return;
|
|
|
}
|
|
|
- video.setEndTime(new Date());
|
|
|
+ Date now = new Date();
|
|
|
+ video.setEndTime(now);
|
|
|
video.setType(2);
|
|
|
video.setUrl(fileUrl);
|
|
|
- video.setCreatedTime(new Date());
|
|
|
+ video.setCreatedTime(now);
|
|
|
imLiveRoomVideoService.updateById(video);
|
|
|
} catch (Exception e) {
|
|
|
log.error("recordSync >>>> error : {}", e.getMessage());
|
|
@@ -179,32 +180,57 @@ public class LiveRoomServiceImpl implements LiveRoomService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询用户是否在聊天室
|
|
|
+ *
|
|
|
+ * @param chatroomId 要查询的聊天室 ID(必传)
|
|
|
+ * @param userId 要查询的用户 ID(必传)
|
|
|
+ * @return true 在聊天室,false 不在聊天室
|
|
|
+ */
|
|
|
+ public boolean userExistInRoom(String chatroomId, String userId) {
|
|
|
+ log.info("userExistInRoom chatroomId : {} userId : {}", chatroomId, userId);
|
|
|
+ IMApiResultInfo resultInfo;
|
|
|
+ try {
|
|
|
+ resultInfo = imHelper.isInChartRoom(chatroomId, userId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException("查询失败" + e.getMessage());
|
|
|
+ }
|
|
|
+ if (!resultInfo.isSuccess()) {
|
|
|
+ log.error("userExistInRoom chatroomId : {} userId : {}", chatroomId, userId);
|
|
|
+ throw new BizException("查询失败!");
|
|
|
+ }
|
|
|
+ return resultInfo.isSuccess() && resultInfo.getIsInChrm();
|
|
|
+ }
|
|
|
+
|
|
|
public String getRoomSessionId(String roomId) {
|
|
|
RBucket<String> bucket = redissonClient.getBucket("sessionId:" + roomId);
|
|
|
- String sessionId = bucket.get();
|
|
|
- if (StringUtils.isNotEmpty(sessionId)) {
|
|
|
- return sessionId;
|
|
|
+ if (bucket.isExists()) {
|
|
|
+ return bucket.get();
|
|
|
}
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("roomId", roomId);
|
|
|
+ HttpURLConnection conn;
|
|
|
+ JSONObject resultObject;
|
|
|
|
|
|
- HttpURLConnection conn = null;
|
|
|
try {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("roomId", roomId);
|
|
|
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();
|
|
|
- bucket.set(sessionId);
|
|
|
- } else {
|
|
|
- log.error("获取sessionId失败 returnResult:{}", returnResult);
|
|
|
- throw new BizException("获取sessionId失败");
|
|
|
- }
|
|
|
+ resultObject = JSONObject.parseObject(returnResult);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ throw new BizException("获取sessionId失败", e.getCause());
|
|
|
}
|
|
|
+
|
|
|
+ String sessionId;
|
|
|
+ if ("200".equals(resultObject.getString("code"))) {
|
|
|
+ sessionId = resultObject.getString("sessionId");
|
|
|
+ bucket.set(sessionId, 1, TimeUnit.HOURS);
|
|
|
+ log.info("getRoomSessionId roomId : {} sessionId : {}", roomId, sessionId);
|
|
|
+ } else {
|
|
|
+ log.error("获取sessionId失败 roomId : {} returnResult:{}", roomId, resultObject);
|
|
|
+ throw new BizException("获取sessionId失败");
|
|
|
+ }
|
|
|
+
|
|
|
return sessionId;
|
|
|
}
|
|
|
|