websocket

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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 represents a single WebSocket connection.

func NewClient

func NewClient(hub *Hub, conn *websocket.Conn) *Client

NewClient creates a new Client.

func (*Client) ReadPump

func (c *Client) ReadPump(ctx context.Context)

ReadPump reads messages from the WebSocket connection. It exists primarily to detect client disconnect.

func (*Client) WritePump

func (c *Client) WritePump(ctx context.Context)

WritePump pumps messages from the send channel to the WebSocket connection.

type Hub

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

Hub manages WebSocket client connections and broadcasts messages. All map mutations happen inside Run, so no mutex is needed on the hot path.

func NewHub

func NewHub() *Hub

NewHub creates a new Hub.

func (*Hub) Broadcast

func (h *Hub) Broadcast(msg Message)

Broadcast enqueues a message for asynchronous fan-out. It is non-blocking: if the broadcast queue is full the message is dropped rather than stalling the caller (typically a store write path).

func (*Hub) ClientCount

func (h *Hub) ClientCount() int

ClientCount returns the number of connected clients.

func (*Hub) Register

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

Register adds a client to the hub.

func (*Hub) Run

func (h *Hub) Run(ctx context.Context)

Run starts the hub event loop. It blocks until ctx is cancelled. The Run goroutine is the sole owner of the clients map and the only writer to client.send, which means Broadcast callers never block on JSON marshaling.

func (*Hub) Unregister

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

Unregister removes a client from the hub.

type Message

type Message struct {
	Type store.SignalType `json:"type"`
	Data any              `json:"data"`
}

Message is sent to WebSocket clients.

Jump to

Keyboard shortcuts

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