|
@@ -10,6 +10,8 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
import com.microsvc.toolkit.middleware.live.LivePluginContext;
|
|
import com.microsvc.toolkit.middleware.live.LivePluginContext;
|
|
import com.microsvc.toolkit.middleware.live.LivePluginService;
|
|
import com.microsvc.toolkit.middleware.live.LivePluginService;
|
|
|
|
+import com.microsvc.toolkit.middleware.live.impl.RongCloudLivePlugin;
|
|
|
|
+import com.microsvc.toolkit.middleware.live.impl.TencentCloudLivePlugin;
|
|
import com.microsvc.toolkit.middleware.live.message.LiveRoomMessage;
|
|
import com.microsvc.toolkit.middleware.live.message.LiveRoomMessage;
|
|
import com.microsvc.toolkit.middleware.live.message.LiveRoomUser;
|
|
import com.microsvc.toolkit.middleware.live.message.LiveRoomUser;
|
|
import com.microsvc.toolkit.middleware.live.message.RTCRequest;
|
|
import com.microsvc.toolkit.middleware.live.message.RTCRequest;
|
|
@@ -65,7 +67,6 @@ import java.io.IOException;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
import java.text.MessageFormat;
|
|
import java.text.MessageFormat;
|
|
-import java.time.LocalDateTime;
|
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.CompletableFuture;
|
|
@@ -833,14 +834,26 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
//从在线人员列表删除该人员
|
|
//从在线人员列表删除该人员
|
|
onlineUserInfo.fastRemove(userId);
|
|
onlineUserInfo.fastRemove(userId);
|
|
|
|
|
|
|
|
+ log.info("opsRoom>>>> looker userInfo: {}", JSONObject.toJSONString(userInfo));
|
|
|
|
+ // 在线用户消息同步
|
|
|
|
+ sendOnlineUserCount(roomVo, userId, onlineUserInfo.size());
|
|
|
|
+
|
|
|
|
+ // 直播间统计数据
|
|
|
|
+ sendLiveRoomStatMessage(userid, roomVo);
|
|
|
|
+
|
|
// 更新用户离线状态
|
|
// 更新用户离线状态
|
|
ImLiveBroadcastRoomMember roomMember = new ImLiveBroadcastRoomMember();
|
|
ImLiveBroadcastRoomMember roomMember = new ImLiveBroadcastRoomMember();
|
|
roomMember.setOnlineStatus(0);
|
|
roomMember.setOnlineStatus(0);
|
|
|
|
|
|
// 用户离开直播间
|
|
// 用户离开直播间
|
|
if (user.getStatus().equals("3")) {
|
|
if (user.getStatus().equals("3")) {
|
|
|
|
+ // 直播间用户离开状态
|
|
roomMember.setLiveRoomStatus(0);
|
|
roomMember.setLiveRoomStatus(0);
|
|
|
|
+
|
|
|
|
+ // 直播间用户离开直播间消息
|
|
|
|
+ sendLiveRoomLoginOutMessage(userid, roomVo);
|
|
}
|
|
}
|
|
|
|
+
|
|
// 更新用户在线状态为离线
|
|
// 更新用户在线状态为离线
|
|
liveBroadcastRoomMemberService.lambdaUpdate()
|
|
liveBroadcastRoomMemberService.lambdaUpdate()
|
|
.eq(ImLiveBroadcastRoomMember::getTenantId, roomVo.getTenantId())
|
|
.eq(ImLiveBroadcastRoomMember::getTenantId, roomVo.getTenantId())
|
|
@@ -848,16 +861,6 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
.eq(ImLiveBroadcastRoomMember::getUserId, userId)
|
|
.eq(ImLiveBroadcastRoomMember::getUserId, userId)
|
|
.update(roomMember);
|
|
.update(roomMember);
|
|
|
|
|
|
- log.info("opsRoom>>>> looker userInfo: {}", JSONObject.toJSONString(userInfo));
|
|
|
|
- // 在线用户消息同步
|
|
|
|
- sendOnlineUserCount(roomVo, userId, onlineUserInfo.size());
|
|
|
|
-
|
|
|
|
- // 直播间统计数据
|
|
|
|
- sendLiveRoomStatMessage(userid, roomVo);
|
|
|
|
-
|
|
|
|
- // 直播间用户离开消息
|
|
|
|
- sendLiveRoomLoginOutMessage(userid, roomVo);
|
|
|
|
-
|
|
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -945,9 +948,12 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
.content(messageContent)
|
|
.content(messageContent)
|
|
.build();
|
|
.build();
|
|
try {
|
|
try {
|
|
|
|
+ // TODO: 取消用户离开事件消息发送
|
|
//用户离开直播间发送退出房间消息给主讲人
|
|
//用户离开直播间发送退出房间消息给主讲人
|
|
|
|
+ /*
|
|
LivePluginService pluginService = livePluginContext.getPluginService(roomVo.getServiceProvider());
|
|
LivePluginService pluginService = livePluginContext.getPluginService(roomVo.getServiceProvider());
|
|
pluginService.sendChatRoomMessage(message);
|
|
pluginService.sendChatRoomMessage(message);
|
|
|
|
+ */
|
|
log.info("sendLiveRoomLoginOutMessage>>>> looker LOOKER_LOGIN_OUT : roomId={}, userId={}", roomVo.getRoomUid(), userid);
|
|
log.info("sendLiveRoomLoginOutMessage>>>> looker LOOKER_LOGIN_OUT : roomId={}, userId={}", roomVo.getRoomUid(), userid);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("sendLiveRoomLoginOutMessage>>>> looker error LOOKER_LOGIN_OUT {}", e.getMessage());
|
|
log.error("sendLiveRoomLoginOutMessage>>>> looker error LOOKER_LOGIN_OUT {}", e.getMessage());
|
|
@@ -1023,6 +1029,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
|
|
|
|
RBucket<RoomSpeakerInfo> speakerCache = getRoomSpeakerInfoCache(roomUid, userid);
|
|
RBucket<RoomSpeakerInfo> speakerCache = getRoomSpeakerInfoCache(roomUid, userid);
|
|
if (!speakerCache.isExists()) {
|
|
if (!speakerCache.isExists()) {
|
|
|
|
+ log.info("isSpeaker>>>> 主播用户缓存不存在, roomId: {}, userId={}", roomUid, userid);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1034,7 +1041,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
if (user.getStatus().equals("0")) {
|
|
if (user.getStatus().equals("0")) {
|
|
|
|
|
|
speakerInfo.setJoinRoomTime(now);
|
|
speakerInfo.setJoinRoomTime(now);
|
|
- log.info("opsRoom>>>> join speakerCache {}", JSONObject.toJSONString(speakerInfo));
|
|
|
|
|
|
+ log.info("isSpeaker>>>> join speakerCache {}", JSONObject.toJSONString(speakerInfo));
|
|
speakerCache.set(speakerInfo);
|
|
speakerCache.set(speakerInfo);
|
|
//将本次进入房间的clientIp添加到主讲人最后一次clientIp缓存中
|
|
//将本次进入房间的clientIp添加到主讲人最后一次clientIp缓存中
|
|
if (StringUtils.isNotBlank(user.getClientIp())) {
|
|
if (StringUtils.isNotBlank(user.getClientIp())) {
|
|
@@ -1050,17 +1057,31 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- //校验本次退出直播间的clientIp 是不是上次进入房间的clientIp
|
|
|
|
- if (StringUtils.isNotBlank(user.getClientIp())) {
|
|
|
|
- if (lastClientIp.isExists()) {
|
|
|
|
- //如果是上次进入房间的clientIp和本次退出房间的clientIp不相同,则直接忽略
|
|
|
|
- if (!user.getClientIp().equals(lastClientIp.get())) {
|
|
|
|
- return true;
|
|
|
|
|
|
+
|
|
|
|
+ //直播间信息
|
|
|
|
+ ImLiveBroadcastRoomVo roomVo = this.getImLiveBroadcastRoomVo(roomUid);
|
|
|
|
+ if (Objects.isNull(roomVo)) {
|
|
|
|
+ log.info("isSpeaker>>>> roomVo is null, roomId: {}, userId={}", roomUid, userid);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (roomVo.getServiceProvider().equals(RongCloudLivePlugin.PLUGIN_NAME)) {
|
|
|
|
+
|
|
|
|
+ //校验本次退出直播间的clientIp 是不是上次进入房间的clientIp
|
|
|
|
+ if (StringUtils.isNotBlank(user.getClientIp())) {
|
|
|
|
+ if (lastClientIp.isExists()) {
|
|
|
|
+ //如果是上次进入房间的clientIp和本次退出房间的clientIp不相同,则直接忽略
|
|
|
|
+ if (!user.getClientIp().equals(lastClientIp.get())) {
|
|
|
|
+ log.info("isSpeaker>>>> 上次进入房间的clientIp和本次退出房间的clientIp不相同, roomId: {}, userId={}", roomUid, userid);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
//如果退出时间大于进入时间就无需再次退出-直接返回
|
|
//如果退出时间大于进入时间就无需再次退出-直接返回
|
|
if (compareDate.apply(speakerInfo.getExitRoomTime(), speakerInfo.getJoinRoomTime())) {
|
|
if (compareDate.apply(speakerInfo.getExitRoomTime(), speakerInfo.getJoinRoomTime())) {
|
|
|
|
+ log.info("isSpeaker>>>> 退出时间大于进入时间, roomId: {}, userId={}", roomUid, userid);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1072,19 +1093,19 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
log.info("opsRoom>>>> exit speakerCache {}", JSONObject.toJSONString(speakerInfo));
|
|
log.info("opsRoom>>>> exit speakerCache {}", JSONObject.toJSONString(speakerInfo));
|
|
speakerCache.set(speakerInfo);
|
|
speakerCache.set(speakerInfo);
|
|
|
|
|
|
- //向直播间发送当前在线人数消息
|
|
|
|
- ImLiveBroadcastRoomVo roomVo = this.getImLiveBroadcastRoomVo(roomUid);
|
|
|
|
- if (Objects.isNull(roomVo)) {
|
|
|
|
- log.info("opsRoom>>>> roomVo is null, roomId: {}, userId={}", roomUid, userid);
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
ImLiveBroadcastRoom room = new ImLiveBroadcastRoom();
|
|
ImLiveBroadcastRoom room = new ImLiveBroadcastRoom();
|
|
room.setSpeakerStatus(0);
|
|
room.setSpeakerStatus(0);
|
|
|
|
|
|
- // 更新推流状态
|
|
|
|
|
|
+ // 主播离开直播间事件
|
|
if (user.getStatus().equals("3")) {
|
|
if (user.getStatus().equals("3")) {
|
|
|
|
+ // 更新推流状态
|
|
room.setPushStatus(0);
|
|
room.setPushStatus(0);
|
|
|
|
+
|
|
|
|
+ // 腾讯云直播方案,推送主播离开消息
|
|
|
|
+ if (roomVo.getServiceProvider().equals(TencentCloudLivePlugin.PLUGIN_NAME)) {
|
|
|
|
+ // 主播离开消息通知
|
|
|
|
+ sendLiveRoomLoginOutMessage(userid, roomVo);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
// 更新主播状态
|
|
// 更新主播状态
|
|
lambdaUpdate()
|
|
lambdaUpdate()
|
|
@@ -1092,12 +1113,6 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
|
|
.eq(ImLiveBroadcastRoom::getSpeakerId, Integer.parseInt(userid))
|
|
.eq(ImLiveBroadcastRoom::getSpeakerId, Integer.parseInt(userid))
|
|
.update(room);
|
|
.update(room);
|
|
|
|
|
|
- // 腾讯云直播方案,推送主播离开消息
|
|
|
|
- if (roomVo.getServiceProvider().equals("tencentCloud")) {
|
|
|
|
- // 主播离开消息通知
|
|
|
|
- sendLiveRoomLoginOutMessage(userid, roomVo);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|