聊天室

This commit is contained in:
曹磊 2024-08-30 11:54:23 +08:00
parent e136f303a7
commit a2d5cb2d6e
1 changed files with 3 additions and 6 deletions

View File

@ -35,8 +35,6 @@ public class AppChatSocket {//用户聊天
*/
private static Map<String, AppChatSocket> clients = new ConcurrentHashMap<String, AppChatSocket>();
private static Map<String, Session> sessionMap = new ConcurrentHashMap<String, Session>();
private static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 会话
@ -80,7 +78,6 @@ public class AppChatSocket {//用户聊天
clients.remove(userId);
}
clients.put(userId, this);
sessionMap.put(userId,session);
/*sendMessageTo("恭喜你连接成功!",wxUserId);*/
}
@ -143,9 +140,9 @@ public class AppChatSocket {//用户聊天
// }
List<ChatContent> toUsers = chatContentService.selectUserByConversationId(Long.parseLong(chatConversationId));
for(ChatContent toUser :toUsers){
Session userSession = sessionMap.get(toUser.getUserId());
if (userSession!=null) {
userSession.getAsyncRemote().sendText(message);
AppChatSocket chatSocket = clients.get(toUser.getUserId());
if (chatSocket!=null) {
chatSocket.session.getAsyncRemote().sendText(message);
System.err.println(this.userId+"发送成功:"+userId);
}
}