|
|
@@ -500,10 +500,20 @@ public class WebSocketServer {
|
|
|
|
|
|
//发送消息
|
|
|
public void sendMessage(Session session, String message) throws IOException {
|
|
|
+ if (session == null || !session.isOpen()) {
|
|
|
+ log.warn("WebSocket 会话已关闭,跳过发送");
|
|
|
+ return;
|
|
|
+ }
|
|
|
session.getAsyncRemote().sendText(message);
|
|
|
}
|
|
|
|
|
|
public void sendIntegralMessage(Long liveId, Long userId,Long scoreAmount) {
|
|
|
+ ConcurrentHashMap<Long, Session> room = getRoom(liveId);
|
|
|
+ Session session = room.get(userId);
|
|
|
+ if (session == null || !session.isOpen()) {
|
|
|
+ log.warn("WebSocket 会话已关闭,跳过发送");
|
|
|
+ return;
|
|
|
+ }
|
|
|
SendMsgVo sendMsgVo = new SendMsgVo();
|
|
|
sendMsgVo.setLiveId(liveId);
|
|
|
sendMsgVo.setUserId(userId);
|
|
|
@@ -511,13 +521,20 @@ public class WebSocketServer {
|
|
|
sendMsgVo.setCmd("Integral");
|
|
|
sendMsgVo.setMsg("恭喜你成功获得观看奖励:" + scoreAmount + "芳华币");
|
|
|
sendMsgVo.setData(String.valueOf(scoreAmount));
|
|
|
- ConcurrentHashMap<Long, Session> room = getRoom(liveId);
|
|
|
- Session session = room.get(userId);
|
|
|
+
|
|
|
if(Objects.isNull( session)) return;
|
|
|
session.getAsyncRemote().sendText(JSONObject.toJSONString(R.ok().put("data", sendMsgVo)));
|
|
|
}
|
|
|
|
|
|
private void sendBlockMessage(Long liveId, Long userId) {
|
|
|
+
|
|
|
+ ConcurrentHashMap<Long, Session> room = getRoom(liveId);
|
|
|
+ Session session = room.get(userId);
|
|
|
+ if (session == null || !session.isOpen()) {
|
|
|
+ log.warn("WebSocket 会话已关闭,跳过发送");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
SendMsgVo sendMsgVo = new SendMsgVo();
|
|
|
sendMsgVo.setLiveId(liveId);
|
|
|
sendMsgVo.setUserId(userId);
|
|
|
@@ -525,8 +542,7 @@ public class WebSocketServer {
|
|
|
sendMsgVo.setCmd("blockUser");
|
|
|
sendMsgVo.setMsg("账号已被停用");
|
|
|
sendMsgVo.setData(null);
|
|
|
- ConcurrentHashMap<Long, Session> room = getRoom(liveId);
|
|
|
- Session session = room.get(userId);
|
|
|
+
|
|
|
if(Objects.isNull( session)) return;
|
|
|
session.getAsyncRemote().sendText(JSONObject.toJSONString(R.ok().put("data", sendMsgVo)));
|
|
|
}
|
|
|
@@ -603,6 +619,10 @@ public class WebSocketServer {
|
|
|
int attempts = 0;
|
|
|
while (attempts < maxRetries) {
|
|
|
try {
|
|
|
+ if (session == null || !session.isOpen()) {
|
|
|
+ log.warn("WebSocket 会话已关闭,跳过发送");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if(session.isOpen()) {
|
|
|
session.getAsyncRemote().sendText(message);
|
|
|
}
|