Documentation
¶
Overview ¶
Package ws 提供 WebSocket 实时双向通信能力: 连接管理(Hub)、广播、业务消息回调与心跳保活。 标准 http.Handler 实现,可配合 iris.FromStd 或直接用于 net/http。
Index ¶
- type Client
- type Hub
- func (h *Hub) Broadcast(data []byte)
- func (h *Hub) BroadcastRoom(room string, data []byte)
- func (h *Hub) Close()
- func (h *Hub) Count() int
- func (h *Hub) CountRoom(room string) int
- func (h *Hub) Handle(w http.ResponseWriter, r *http.Request)
- func (h *Hub) Join(room string, client *Client)
- func (h *Hub) Leave(room string, client *Client)
- func (h *Hub) OnJoin(fn RoomEvent) *Hub
- func (h *Hub) OnLeave(fn RoomEvent) *Hub
- func (h *Hub) Rooms() []string
- func (h *Hub) Run(ctx context.Context)
- func (h *Hub) WithPingInterval(interval time.Duration) *Hub
- type RoomEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 表示一个 WebSocket 连接。
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub 管理全部 WebSocket 客户端。 消息处理通过 onMessage 回调注入;广播用 Broadcast。
func (*Hub) BroadcastRoom ¶ added in v1.52.0
BroadcastRoom 向房间内全部客户端广播(非阻塞,队列满丢弃)。
func (*Hub) Handle ¶
func (h *Hub) Handle(w http.ResponseWriter, r *http.Request)
Handle 是标准 WebSocket 升级处理器。 用法:http.Handle("/ws", hub.Handle) 或 app.Get("/ws", iris.FromStd(hub.Handle))
Click to show internal directories.
Click to hide internal directories.