| | |
| | | package com.xcong.excoin.configurations; |
| | | |
| | | import com.xcong.excoin.websocket.handler.FishHitWebSocketHandler; |
| | | import com.xcong.excoin.websocket.handler.FishHitWebSocketHandshakeInterceptor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.socket.config.annotation.EnableWebSocket; |
| | | import org.springframework.web.socket.config.annotation.WebSocketConfigurer; |
| | | import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; |
| | | import org.springframework.web.socket.server.standard.ServerEndpointExporter; |
| | | |
| | | //@Configuration |
| | | public class WebSocketConfig { |
| | | @Slf4j |
| | | @Configuration |
| | | public class WebSocketConfig implements WebSocketConfigurer { |
| | | |
| | | @Autowired |
| | | private FishHitWebSocketHandler fishHitWebSocketHandler; |
| | | @Autowired |
| | | private FishHitWebSocketHandshakeInterceptor fishHitWebSocketHandshakeInterceptor; |
| | | |
| | | /** |
| | | * 注入一个ServerEndpointExporter,该Bean会自动注册使用@ServerEndpoint注解申明的websocket endpoint |
| | | */ |
| | |
| | | public ServerEndpointExporter serverEndpointExporter() { |
| | | return new ServerEndpointExporter(); |
| | | } |
| | | |
| | | @Override |
| | | public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { |
| | | registry.addHandler(fishHitWebSocketHandler, "websocket/fish/hit") |
| | | .setAllowedOrigins("*") |
| | | .addInterceptors(fishHitWebSocketHandshakeInterceptor); |
| | | } |
| | | } |