fix: 允许服务端为缺失 sessionId 自动生成会话ID

This commit is contained in:
2026-03-06 07:02:08 +08:00
parent b309dca688
commit 393e26e8de

View File

@@ -9,6 +9,7 @@ import (
"github.com/gofiber/contrib/v3/websocket"
"github.com/gofiber/fiber/v3"
"github.com/google/uuid"
"github.com/vmihailenco/msgpack/v5"
)
@@ -230,7 +231,10 @@ func (h *Handler) handleTextMessage(s *session, data []byte) {
}
func (h *Handler) handleStart(s *session, msg ClientMsg) {
if msg.SessionID == "" || len(msg.SessionID) > 96 {
if msg.SessionID == "" {
msg.SessionID = uuid.NewString()
}
if len(msg.SessionID) > 96 {
h.sendError(s, "invalid_session", "invalid sessionId", false, "")
return
}