code refactor

This commit is contained in:
laker
2024-03-26 14:13:10 +08:00
parent c5f52fb167
commit 592e2551da
18 changed files with 79 additions and 84 deletions

View File

@@ -19,20 +19,24 @@ public class WebSocketConfig implements WebSocketConfigurer {
@Autowired
LakerChatHandler webSocketHandler;
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(webSocketHandler, "/websocket/**")
// 添加拦截器可以获取连接的param和 header 用作认证鉴权
.addInterceptors(new LakerSessionHandshakeInterceptor())
// 设置运行跨域
.setAllowedOrigins("*");
// 添加拦截器可以获取连接的param和 header 用作认证鉴权
.addInterceptors(new LakerSessionHandshakeInterceptor())
// 设置运行跨域
.setAllowedOrigins("*");
}
/**
* 该配置也会影响stomp方式的websocket
*/
@Bean
public ServletServerContainerFactoryBean createWebSocketContainer() {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
// 设置默认会话空闲超时 以毫秒为单位 非正值意味着无限超时,默认值 0 ,默认10s检查一次空闲就关闭
container.setMaxSessionIdleTimeout(10 * 1000L);
// 设置默认会话空闲超时 以毫秒为单位 非正值意味着无限超时,默认值 0 ,默认10s检查一次空闲就关闭
container.setMaxSessionIdleTimeout(30 * 1000L);
// 设置异步发送消息的默认超时时间 以毫秒为单位 非正值意味着无限超时 ,默认值-1还没看到作用
// container.setAsyncSendTimeout(10 * 1000L);
// 设置文本消息的默认最大缓冲区大小 以字符为单位,默认值 8 * 1024