wshub

package
v0.0.0-...-6b3b694 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHubConfig = HubConfig{
	MaxMessageSize: 1024 * 1024,

	PingWait:   10 * time.Second,
	PingPeriod: 1 * time.Minute,
	PongWait:   10 * time.Second,

	WriteWait: 10 * time.Second,
}

Functions

This section is empty.

Types

type Client

type Client struct {
	// The websocket connection.
	Conn *websocket.Conn

	// Buffered channel of outbound messages.
	Send chan *ws.PreparedMessage

	// Buffered channel of inbound messages.
	Recv chan []byte

	// Channel to signal the termination of client
	Done chan struct{}

	// The hub.
	Hub *Hub

	// The client's ID.
	ID string
	// contains filtered or unexported fields
}

func (*Client) Destroy

func (c *Client) Destroy()

func (*Client) SendClose

func (c *Client) SendClose() error

func (*Client) Spin

func (c *Client) Spin()

type Hub

type Hub struct {
	// The map of all the clients, indexed by the client's ID.
	Clients sync.Map

	Config *HubConfig
}

func NewHub

func NewHub(config ...HubConfig) *Hub

func (*Hub) Add

func (h *Hub) Add(c *Client)

func (*Hub) Broadcast

func (h *Hub) Broadcast(msg *ws.PreparedMessage)

func (*Hub) NewClient

func (h *Hub) NewClient(conn *websocket.Conn, id string) *Client

func (*Hub) Remove

func (h *Hub) Remove(c *Client)

type HubConfig

type HubConfig struct {
	MaxMessageSize int64

	PingWait   time.Duration
	PingPeriod time.Duration
	PongWait   time.Duration

	WriteWait time.Duration
}

Jump to

Keyboard shortcuts

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