package com.ard.work.websocket.handler;
|
|
import com.ard.work.websocket.utils.PTZWebSocketUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Component;
|
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;
|
|
@Component
|
@Slf4j
|
public class PTZWebSocketHandler extends TextWebSocketHandler {
|
|
@Override
|
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
|
// 处理接收到的消息
|
String payload = message.getPayload();
|
log.info("【ptz_websocket】Received message: " + payload);
|
log.info("【ptz_websocket】size: " + PTZWebSocketUtils.ONLINE_USER_SESSIONS.size());
|
}
|
|
@Override
|
public void afterConnectionEstablished(WebSocketSession session) {
|
log.info("【ptz_websocket】Connected: " + session.getId());
|
String userId = (String) session.getAttributes().get("userId");
|
PTZWebSocketUtils.ONLINE_USER_SESSIONS.put(userId, session);
|
log.info("【ptz_websocket】size: " + PTZWebSocketUtils.ONLINE_USER_SESSIONS.size());
|
|
}
|
|
@Override
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
|
log.info("【ptz_websocket】Disconnected: " + session.getId());
|
String userId = (String) session.getAttributes().get("userId");
|
PTZWebSocketUtils.ONLINE_USER_SESSIONS.remove(userId);
|
log.info("【ptz_websocket】size: " + PTZWebSocketUtils.ONLINE_USER_SESSIONS.size());
|
}
|
}
|