|
@@ -48,12 +48,16 @@ public class WebSocketService extends AbstractWebSocketHandler {
|
|
|
this.sessionService = sessionService;
|
|
|
}
|
|
|
|
|
|
+ public boolean isConnected(String key) {
|
|
|
+ return SESSION_MAP.get(key) != null;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
|
|
- SESSION_MAP.put(session.getId(), session);
|
|
|
Map<String, Object> attributes = session.getAttributes();
|
|
|
String sessionId = (String) attributes.get("JSESSIONID");
|
|
|
String username = (String) attributes.get("username");
|
|
|
+ SESSION_MAP.put(username, session);
|
|
|
log.info("afterConnectionEstablished: {} -> {} -> {}", session.getId(), sessionId, username);
|
|
|
}
|
|
|
|
|
@@ -73,7 +77,7 @@ public class WebSocketService extends AbstractWebSocketHandler {
|
|
|
String username = (String) attributes.get("username");
|
|
|
log.info("afterConnectionClosed: {}, {} -> {} -> {}", closeStatus, session.getId(), sessionId, username);
|
|
|
sessionService.invalidate(username);
|
|
|
- SESSION_MAP.remove(session.getId());
|
|
|
+ SESSION_MAP.remove(username);
|
|
|
}
|
|
|
@Override
|
|
|
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
|
|
@@ -100,8 +104,8 @@ public class WebSocketService extends AbstractWebSocketHandler {
|
|
|
String username = (String) attributes.get("username");
|
|
|
log.info("handlePongMessage: {} -> {} -> {} -> {}", session.getId(), sessionId, username,
|
|
|
message.getPayload());
|
|
|
- PING_MAP.put(session.getId(), LocalDateTime.now());
|
|
|
- TIMEOUT_MAP.put(session.getId(), new AtomicInteger(0));
|
|
|
+ PING_MAP.put(username, LocalDateTime.now());
|
|
|
+ TIMEOUT_MAP.put(username, new AtomicInteger(0));
|
|
|
}
|
|
|
|
|
|
@Scheduled(fixedDelay = 2000)
|