判断wsurl 不为空

pull/3/head
liuhanqing 2021-02-01 22:33:56 +08:00
parent b3da7f3139
commit c08308a7d4
1 changed files with 10 additions and 5 deletions

View File

@ -75,11 +75,16 @@ public class WebSocketManager {
* @author liuhanqing * @author liuhanqing
* @date 2021/1/24 22:11 * @date 2021/1/24 22:11
*/ */
public static void sendMessage(Long userId, String message){ public static void sendMessage(Long userId, String message) {
for(Session userSession: getSessionByUserId(userId)){ List<Session> sessionList = getSessionByUserId(userId);
// 增加判断不为空
if (!CollectionUtils.isEmpty(sessionList)) {
for (Session userSession : sessionList) {
userSession.getAsyncRemote().sendText(message); userSession.getAsyncRemote().sendText(message);
} }
} }
}
/** /**
* *
* *
@ -87,7 +92,7 @@ public class WebSocketManager {
* @author liuhanqing * @author liuhanqing
* @date 2021/1/24 22:11 * @date 2021/1/24 22:11
*/ */
public static void sendMessageToAll(String message){ public static void sendMessageToAll(String message) {
for (Long userId : WebSocketManager.getUserList()) { for (Long userId : WebSocketManager.getUserList()) {
sendMessage(userId, message); sendMessage(userId, message);
} }