You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
Java
34 lines
1.1 KiB
Java
2 years ago
|
package com.supervision.websocket.handler;
|
||
|
|
||
|
import com.supervision.websocket.cache.WebSocketUserCache;
|
||
|
import lombok.extern.slf4j.Slf4j;
|
||
|
import org.springframework.web.socket.CloseStatus;
|
||
|
import org.springframework.web.socket.TextMessage;
|
||
|
import org.springframework.web.socket.WebSocketSession;
|
||
|
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||
|
|
||
|
@Slf4j
|
||
|
public class AskWebSocketHandler extends TextWebSocketHandler {
|
||
|
|
||
|
@Override
|
||
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||
|
// 获取本次
|
||
|
String id = session.getId();
|
||
|
WebSocketUserCache.login(id, session);
|
||
|
// 连接建立时的处理逻辑
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
|
||
|
// 处理接收到的文本消息
|
||
|
log.info("收到消息:{}", message.toString());
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
|
||
|
// 连接关闭时的处理逻辑
|
||
|
String id = session.getId();
|
||
|
WebSocketUserCache.logout(id);
|
||
|
}
|
||
|
}
|