| File was renamed from ard-work/src/main/java/com/ard/tianyu/websocket/handler/TyMessageHandler.java |
| | |
| | | package com.ard.tianyu.websocket.handler; |
| | | package com.ard.tianyu.component.websocket.handler; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.TypeReference; |
| | | import com.ard.tianyu.component.websocket.WebSocketSessionManager; |
| | | import com.ard.tianyu.domain.message.*; |
| | | import com.ard.tianyu.service.control.UavControlService; |
| | | import com.ard.tianyu.websocket.domain.*; |
| | | import com.ard.tianyu.websocket.utils.WebSocketUtil; |
| | | import com.ard.tianyu.component.websocket.utils.WebSocketUtil; |
| | | 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; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | |
| | |
| | | Long userId = Long.parseLong(userIdStr); |
| | | String payload = message.getPayload(); |
| | | log.info("【cmd】Received message: {}", payload); |
| | | log.info("【cmd】size: {}", WebSocketUtil.ONLINE_USER_SESSIONS.size()); |
| | | log.info("【cmd】size: {}", WebSocketSessionManager.getOnlineUserCount()); |
| | | |
| | | BaseMessage<?> baseMessage = JSON.parseObject(payload, BaseMessage.class); |
| | | switch (baseMessage.getType()) { |
| | |
| | | log.info("【cmd】Connected: {}", session.getId()); |
| | | String userIdStr = (String) session.getAttributes().get("userId"); |
| | | Long userId = Long.parseLong(userIdStr); |
| | | WebSocketUtil.ONLINE_USER_SESSIONS.put(userId, session); |
| | | log.info("【cmd】size: {}", WebSocketUtil.ONLINE_USER_SESSIONS.size()); |
| | | WebSocketSessionManager.addSession(userId, session); |
| | | log.info("【cmd】size: {}", WebSocketSessionManager.getOnlineUserCount()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | log.info("【cmd】Disconnected: {}", session.getId()); |
| | | String userIdStr = (String) session.getAttributes().get("userId"); |
| | | Long userId = Long.parseLong(userIdStr); |
| | | WebSocketUtil.ONLINE_USER_SESSIONS.remove(userId); |
| | | log.info("【cmd】size: {}", WebSocketUtil.ONLINE_USER_SESSIONS.size()); |
| | | WebSocketSessionManager.removeSession(userId); |
| | | log.info("【cmd】size: {}", WebSocketSessionManager.getOnlineUserCount()); |
| | | // 停止用户的所有流 |
| | | uavStreamManager.stopAllPullStreamByUser(userId); |
| | | if (userId != null) { |