Documentation
¶
Index ¶
- type Conn
- type Request
- type Response
- type SendError
- type WebSocket
- func (ws *WebSocket) Add(w http.ResponseWriter, r *http.Request, uid int32, heartbeat bool, ...) (*Conn, error)
- func (ws *WebSocket) Broadcast(resp Response) error
- func (ws *WebSocket) Cleanup()
- func (ws *WebSocket) GetActiveUsers() int
- func (ws *WebSocket) GetAllConnections() int
- func (ws *WebSocket) GetStats() WebSocketStats
- func (ws *WebSocket) GetUserConnections(uid int32) int
- func (ws *WebSocket) Remove(uid int32, conn *Conn) error
- func (ws *WebSocket) SetMessage(uid int32, resp Response) error
- type WebSocketStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
sync.RWMutex
UID int32
Conn *websocket.Conn
Send chan Response
OnClose func(*Conn) // 关闭回调函数
OnMessage func(*Conn, Request) // 消息回调函数
IsAlive bool // 连接是否活跃
LastActive time.Time // 最后活跃时间
// contains filtered or unexported fields
}
func (*Conn) DirectSend ¶
DirectSend 直接发送消息(绕过通道,用于紧急消息)
type Request ¶
type Request struct {
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
type WebSocket ¶
type WebSocket struct {
sync.RWMutex
Groups map[int32][]*Conn
Error error
Stats *WebSocketStats
HeartbeatTime time.Duration
}
func (*WebSocket) Add ¶
func (ws *WebSocket) Add(w http.ResponseWriter, r *http.Request, uid int32, heartbeat bool, handler func(*Conn, Request) (Response, error)) (*Conn, error)
Add 添加新的WebSocket连接
func (*WebSocket) GetAllConnections ¶
GetAllConnections 获取所有活跃连接数
func (*WebSocket) GetStats ¶
func (ws *WebSocket) GetStats() WebSocketStats
GetStats 获取WebSocket统计信息
func (*WebSocket) GetUserConnections ¶
GetUserConnections 获取指定用户的连接数
Click to show internal directories.
Click to hide internal directories.