feat: 添加 WebSocket 基础设施
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.webgame.webgamebackend.config;
|
||||
|
||||
import com.webgame.webgamebackend.ws.RoomWebSocketHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||
|
||||
/**
|
||||
* WebSocket 配置
|
||||
*
|
||||
* 注册房间 WebSocket 端点,路径为 /ws/room。
|
||||
* 客户端通过 ws://host/ws/room?roomId=xxx&token=xxx 连接。
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebSocket
|
||||
@RequiredArgsConstructor
|
||||
public class WebSocketConfig implements WebSocketConfigurer {
|
||||
|
||||
private final RoomWebSocketHandler roomWebSocketHandler;
|
||||
|
||||
@Override
|
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||
registry.addHandler(roomWebSocketHandler, "/ws/room")
|
||||
.setAllowedOrigins("*");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user