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