Compare commits

..

1 Commits

Author SHA1 Message Date
393e26e8de fix: 允许服务端为缺失 sessionId 自动生成会话ID 2026-03-06 07:02:08 +08:00

View File

@@ -9,6 +9,7 @@ import (
"github.com/gofiber/contrib/v3/websocket" "github.com/gofiber/contrib/v3/websocket"
"github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3"
"github.com/google/uuid"
"github.com/vmihailenco/msgpack/v5" "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) { 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, "") h.sendError(s, "invalid_session", "invalid sessionId", false, "")
return return
} }