websocket

package
v0.0.0-...-ed52701 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRoomRequired is returned when a subscribe/unsubscribe message omits
	// the room field.
	ErrRoomRequired = errors.New("room is required")
	// ErrRoomInvalid is returned when a room name does not satisfy the room
	// naming contract enforced by validateRoom.
	ErrRoomInvalid = errors.New("invalid room name")
)

Functions

func Read

func Read(ctx context.Context, conn *websocket.Conn, v any) error

Read is a adapter for the wsjson, it serve as a wrapper around it.

func Write

func Write(ctx context.Context, conn *websocket.Conn, v any) error

Types

type Client

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

func NewClient

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

type Hub

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

func NewHub

func NewHub() *Hub

func (*Hub) AddClient

func (h *Hub) AddClient(client *Client)

func (*Hub) Publish

func (h *Hub) Publish(
	room string,
	event string,
	data any,
)

func (*Hub) RemoveClient

func (h *Hub) RemoveClient(client *Client)

func (*Hub) Subscribe

func (h *Hub) Subscribe(client *Client, room string) error

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(client *Client, room string) error

type RoomProvider

type RoomProvider interface {
	Stream(ctx context.Context, room string) (<-chan protocol.StreamEvent, error)
}

RoomProvider supplies ordered per-subscriber event streams for rooms that back real-time data (for example execution event rooms). A provider-backed room delivers history plus live events to each subscriber independently, mirroring the SSE endpoint. Providers return a nil channel when they do not recognize the room.

type WebSocketHandler

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

func NewWebSocketHandler

func NewWebSocketHandler() *WebSocketHandler

func (*WebSocketHandler) HandleWebSocket

func (s *WebSocketHandler) HandleWebSocket(
	w http.ResponseWriter,
	r *http.Request,
)

HandleWebSocket upgrades a request to a WebSocket session.

Origin verification is left to the coder/websocket default, which rejects an Origin that does not match the request Host. Disabling it would let any page a user visits open an authenticated connection to the local daemon through their browser.

func (*WebSocketHandler) Hub

func (s *WebSocketHandler) Hub() *Hub

func (*WebSocketHandler) SetRoomProvider

func (s *WebSocketHandler) SetRoomProvider(provider RoomProvider)

SetRoomProvider registers the provider that backs streaming rooms. It must be called before the handler serves connections.

Jump to

Keyboard shortcuts

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