| | |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.Objects; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * TextWebSocketFrame 表示一个文本桢 |
| | |
| | | |
| | | @Autowired |
| | | private WebSocketAuthHandler authHandler; |
| | | |
| | | Map<String, BusinessMsgHandler> businessMsgHandlers; |
| | | |
| | | public WebSocketTextFrameHandler(List<BusinessMsgHandler> handlers) { |
| | | this.businessMsgHandlers = handlers.stream() |
| | | .collect(Collectors.toMap( |
| | | BusinessMsgHandler::getMessageType, |
| | | Function.identity() |
| | | )); |
| | | } |
| | | |
| | | @Override |
| | | protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) throws Exception { |
| | |
| | | if (appUserId != null) { |
| | | log.info("收到用户 {} 的业务消息: {}", appUserId, messageObj.toJSONString()); |
| | | |
| | | businessMsgHandlers.get(messageObj.getString("type")).handle(appUserId, messageObj.getString("message")); |
| | | |
| | | // 回复消息 |
| | | JSONObject response = new JSONObject(); |
| | | response.put("type", "message_response"); |