|
@@ -150,10 +150,15 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
|
|
|
*/
|
|
|
@Override
|
|
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
|
|
- //从session中获取客服id
|
|
|
- Long kfUserId = Long.valueOf(session.getAttributes().get("kfUserId").toString());
|
|
|
//关闭连接
|
|
|
session.close();
|
|
|
+ //判断会话是否保存
|
|
|
+ Object kfUserIdObject = session.getAttributes().get("kfUserId");
|
|
|
+ if (kfUserIdObject == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //从session中获取客服id
|
|
|
+ Long kfUserId = Long.valueOf(kfUserIdObject.toString());
|
|
|
//移除连接
|
|
|
kfMsgWebSocketSessionRegistry.removeSession(kfUserId);
|
|
|
}
|
|
@@ -361,7 +366,8 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
|
|
|
return Boolean.FALSE;
|
|
|
}
|
|
|
//添加会话
|
|
|
- if (kfMsgWebSocketSessionRegistry.getSession(SecurityUtil.getUserId()) == null) {
|
|
|
+ WebSocketSession webSocketSession = kfMsgWebSocketSessionRegistry.getSession(SecurityUtil.getUserId());
|
|
|
+ if (webSocketSession == null) {
|
|
|
session.getAttributes().put("kfUserId", SecurityUtil.getUserId());
|
|
|
kfMsgWebSocketSessionRegistry.addSession(SecurityUtil.getUserId(), session);
|
|
|
}
|