websocket

package
v1.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultRedisTopic = "nimbus:websocket:broadcast"

Variables

View Source
var ErrBackpressure = errors.New("websocket: broadcast queue full")
View Source
var ErrClosed = errors.New("websocket: hub closed")
View Source
var ErrMessageTooLarge = errors.New("websocket: message exceeds configured limit")

Functions

This section is empty.

Types

type Conn

type Conn struct {
	*websocket.Conn
	// contains filtered or unexported fields
}

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

func NewHub

func NewHub() *Hub

func NewHubWithOptions added in v1.15.2

func NewHubWithOptions(o HubOptions) *Hub

func (*Hub) Broadcast

func (h *Hub) Broadcast(msg []byte)

Broadcast retains the original convenience API. Use BroadcastContext when the caller needs to handle cancellation, oversize or saturation errors explicitly.

func (*Hub) BroadcastContext added in v1.15.2

func (h *Hub) BroadcastContext(ctx context.Context, msg []byte) error

func (*Hub) Close added in v1.9.1

func (h *Hub) Close() error

Close stops admission, closes clients/subscription and waits for owned pumps. It is idempotent and also works when Run was never called.

func (*Hub) Len added in v1.9.1

func (h *Hub) Len() int

func (*Hub) Run

func (h *Hub) Run()

Run delivers broadcasts until Close. Calling it more than once shares one loop.

func (*Hub) SetAllowedOrigins

func (h *Hub) SetAllowedOrigins(origins []string)

func (*Hub) Upgrade

func (h *Hub) Upgrade(w http.ResponseWriter, r *http.Request) (*Conn, error)

func (*Hub) UseRedis added in v1.9.1

func (h *Hub) UseRedis(client *redis.Client, topic string) error

UseRedis subscribes once, before Run. Forwarding and subscription stop at Close.

type HubOptions added in v1.15.2

type HubOptions struct {
	MaxMessageBytes int64         // default 64 KiB (inbound and broadcasts)
	MaxConnections  int           // default 1024, including pending upgrades
	SendBuffer      int           // default 32 messages per client
	WriteTimeout    time.Duration // default 10s
	PongTimeout     time.Duration // default 60s
	PingInterval    time.Duration // default 25s, always below PongTimeout
	PublishTimeout  time.Duration // default 5s
}

HubOptions bounds per-connection and hub resources. Nonpositive values use safe defaults. Configure before serving; options are immutable after creation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL