Documentation
¶
Index ¶
- func Echo(conn *websocket.Conn, ctx context.Context)
- func Upgrader(handler Handler, opts *Options) gin.HandlerFunc
- type Client
- type Handler
- type Hub
- func (h *Hub) Broadcast(room string, msgType websocket.MessageType, data []byte)
- func (h *Hub) BroadcastOthers(room string, sender *Client, msgType websocket.MessageType, data []byte)
- func (h *Hub) Clients(room string) []*Client
- func (h *Hub) Handler(onConnect func(*Client)) gin.HandlerFunc
- func (h *Hub) Join(client *Client, room string)
- func (h *Hub) Leave(client *Client, room string)
- func (h *Hub) Remove(client *Client)
- func (h *Hub) Rooms() []string
- func (h *Hub) Send(clientID string, msgType websocket.MessageType, data []byte) error
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub manages WebSocket clients and rooms.
func (*Hub) Broadcast ¶
func (h *Hub) Broadcast(room string, msgType websocket.MessageType, data []byte)
Broadcast sends a message to all clients in the named room.
func (*Hub) BroadcastOthers ¶
func (h *Hub) BroadcastOthers(room string, sender *Client, msgType websocket.MessageType, data []byte)
BroadcastOthers sends a message to all clients in the named room except the sender.
func (*Hub) Clients ¶
Clients returns a snapshot of all clients in the named room. Returns nil if the room does not exist.
func (*Hub) Handler ¶
func (h *Hub) Handler(onConnect func(*Client)) gin.HandlerFunc
Handler returns a gin.HandlerFunc that upgrades the HTTP connection to WebSocket, creates a Client, registers it with the Hub, and calls onConnect. The client is automatically removed when onConnect returns.
func (*Hub) Join ¶
Join adds the client to the named room. The room is created if it does not exist. Joining the same room twice is a no-op.
func (*Hub) Leave ¶
Leave removes the client from the named room. The room is deleted if it becomes empty.