feat(websocket): integrate WebSocket support and refactor SSE handling
All checks were successful
Build Backend / build (push) Successful in 18m57s
Build Backend / build-docker (push) Successful in 1m4s

- Added WebSocket support by introducing a new WSHandler and related infrastructure.
- Replaced SSE implementations with WebSocket equivalents across message and QR code handlers.
- Updated service and repository layers to utilize WebSocket for real-time messaging.
- Removed obsolete SSE hub and related code, streamlining the application for WebSocket usage.
- Enhanced router to include WebSocket endpoints for real-time communication.
This commit is contained in:
lafay
2026-03-26 21:17:49 +08:00
parent c6848aba06
commit 6d335e393d
19 changed files with 1277 additions and 315 deletions

View File

@@ -2,7 +2,7 @@ package wire
import (
"carrot_bbs/internal/handler"
"carrot_bbs/internal/pkg/sse"
"carrot_bbs/internal/pkg/ws"
"carrot_bbs/internal/service"
"github.com/google/wire"
@@ -35,6 +35,7 @@ var HandlerSet = wire.NewSet(
ProvideSystemMessageHandler,
ProvideGroupHandler,
ProvideScheduleHandler,
ProvideWSHandler,
)
// ProvideUserHandler 提供用户处理器
@@ -91,9 +92,9 @@ func ProvideMessageHandler(
messageService *service.MessageService,
userService service.UserService,
groupService service.GroupService,
sseHub *sse.Hub,
wsHub *ws.Hub,
) *handler.MessageHandler {
return handler.NewMessageHandler(chatService, messageService, userService, groupService, sseHub)
return handler.NewMessageHandler(chatService, messageService, userService, groupService, wsHub)
}
// ProvideSystemMessageHandler 提供系统消息处理器
@@ -118,3 +119,13 @@ func ProvideScheduleHandler(
) *handler.ScheduleHandler {
return handler.NewScheduleHandler(scheduleService, scheduleSyncService)
}
// ProvideWSHandler 提供WebSocket处理器
func ProvideWSHandler(
wsHub *ws.Hub,
chatService service.ChatService,
groupService service.GroupService,
jwtService *service.JWTService,
) *handler.WSHandler {
return handler.NewWSHandler(wsHub, chatService, groupService, jwtService)
}