sockets

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 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

Overview

Package sockets serves the runtime's JSON sockets: /api/status (tab states, background work, the prompt queue, pane intents, limits) and /api/sync (layout and workspace changes, toasts and commands to the page). One of the clients is usually the machine agent's relay into the cluster stream; the rest are pages.

Index

Constants

View Source
const (
	PingFrame = `{"type":"ping"}`
	PongFrame = `{"type":"pong"}`
)

PingFrame and PongFrame are the page's own heartbeat: a browser cannot see protocol pings, so a socket the network dropped silently looks open to it for minutes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Relay bool // the machine agent's socket (?relay=1)
	// contains filtered or unexported fields
}

Client is one open socket.

func (*Client) Close

func (c *Client) Close(code websocket.StatusCode, reason string)

Close ends the socket once.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done is closed when the socket ends.

func (*Client) Send

func (c *Client) Send(raw []byte) bool

Send queues one message; false when the client is gone or too far behind (the message is dropped).

func (*Client) SendJSON

func (c *Client) SendJSON(v any) bool

SendJSON queues a value written as JSON.stringify writes it.

type Hub

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

Hub is the set of open sockets of one kind.

func NewHub

func NewHub() *Hub

func (*Hub) Broadcast

func (h *Hub) Broadcast(v any, exclude *Client)

Broadcast sends v to every client but exclude; a client too far behind misses it.

func (*Hub) Count

func (h *Hub) Count() int

Count is the number of open sockets, the relay included.

func (*Hub) Shutdown

func (h *Hub) Shutdown()

Shutdown closes every socket.

type StatusServer

type StatusServer struct {
	Hub    *Hub
	Source StatusSource
}

StatusServer is /api/status.

func (*StatusServer) ServeHTTP

func (s *StatusServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP upgrades and serves one status socket. Authentication is the caller's.

type StatusSource

type StatusSource interface {
	// RateLimits is the last limits content, or nil before the first one.
	RateLimits() any
	// Tabs is every tab as the page sees it; Background every tab with background work.
	Tabs() any
	Background() any
	// Queues and Intents are read after the snapshot; they may take a moment.
	Queues() any
	Intents() any
	// History is the clipped session history, sent only when a page asks (it is large and one panel reads it).
	History() any
	// Dismiss: a page acknowledged a finished turn. A page's own socket gets no echo; the relay does, because it
	// carries the messages of every page reading the cluster stream.
	Dismiss(tabID string, exclude *Client)
	Ack(tabID string, seq float64)
	IntentsApplied(tabID string, ids []string, device string)
	Warn(msg string)
}

StatusSource is what the status socket reads and where the page's messages go.

type SyncServer

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

SyncServer is /api/sync: what changed (layouts, workspaces), toasts, and commands for the page. The page sends nothing but its heartbeat.

func (*SyncServer) Broadcast

func (s *SyncServer) Broadcast(event any)

Broadcast sends an event to every sync socket.

func (*SyncServer) ServeHTTP

func (s *SyncServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP upgrades and serves one sync socket. Authentication is the caller's.

func (*SyncServer) Toast

func (s *SyncServer) Toast(key string, toast any)

Toast is shown now and to every socket that connects later; the key replaces an earlier toast of the same kind.

Jump to

Keyboard shortcuts

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