Versions in this module Expand all Collapse all v0 v0.1.0 Mar 20, 2026 Changes in this version + const DefaultBroadcastBuf + const DefaultChannelTimeout + const DefaultMaxMessageSize + const DefaultPingInterval + const DefaultRegisterBuf + const DefaultSendBufSize + const DefaultWriteWait + var ErrHubStopped = errors.New("wskit: hub is stopped") + type AcceptFunc func(w http.ResponseWriter, r *http.Request, opts *websocket.AcceptOptions) (*websocket.Conn, error) + type Client struct + func Accept(ctx context.Context, w http.ResponseWriter, r *http.Request, hub *Hub, ...) (*Client, error) + func NewClient(hub *Hub, conn *websocket.Conn, ctx context.Context, opts ...ClientOption) *Client + func (c *Client) ReadPump() + func (c *Client) Send(data []byte) (sent bool) + func (c *Client) SendErr(data []byte) error + func (c *Client) WritePump() + type ClientConfig struct + MaxMessageSize int64 + PingInterval time.Duration + SendBufSize int + WriteWait time.Duration + type ClientOption func(*ClientConfig) + func WithMaxMessageSize(n int64) ClientOption + func WithPingInterval(d time.Duration) ClientOption + func WithSendBufSize(n int) ClientOption + func WithWriteWait(d time.Duration) ClientOption + type Conn interface + Close func(code websocket.StatusCode, reason string) error + Ping func(ctx context.Context) error + Read func(ctx context.Context) (websocket.MessageType, []byte, error) + SetReadLimit func(limit int64) + Writer func(ctx context.Context, typ websocket.MessageType) (io.WriteCloser, error) + type Event struct + Payload any + Timestamp time.Time + Type string + func NewEvent(typ string, payload any) Event + type Hub struct + func NewHub(opts ...HubOption) *Hub + func (h *Hub) Broadcast(data []byte) + func (h *Hub) BroadcastEvent(ctx context.Context, event any) error + func (h *Hub) BroadcastJSON(ctx context.Context, typ string, payload any) error + func (h *Hub) ClientCount() int + func (h *Hub) Register(client *Client) + func (h *Hub) Run(ctx context.Context) + func (h *Hub) SubscribeToRedis(ctx context.Context) + func (h *Hub) Unregister(client *Client) + type HubOption func(*Hub) + func WithBroadcastBuf(n int) HubOption + func WithChannelTimeout(d time.Duration) HubOption + func WithOnConnect(fn OnConnect) HubOption + func WithOnTimeout(fn func(op string)) HubOption + func WithRedis(client *redis.Client, channel string) HubOption + func WithRegisterBuf(n int) HubOption + type OnConnect func(client *Client)