host

package
v2.0.0-...-30997d8 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Broadcast

func Broadcast(name string, payload any, opts ...BroadcastOption)

Broadcast sends the given payload to all connections subscribed to the component name.

func Div

func Div(name string, value any) string

func Join

func Join(parts ...string) string

func ListenAndServe

func ListenAndServe(addr, root string) error

ListenAndServe starts an HTTP server using NewMux to serve files and the WebSocket endpoint.

func ListenAndServeTLS

func ListenAndServeTLS(addr, root string) error

ListenAndServeTLS starts an HTTPS server using a self-signed certificate and NewMux to serve files and the WebSocket endpoint.

func ListenAndServeTLSWithMux

func ListenAndServeTLSWithMux(addr string, mux *http.ServeMux) error

ListenAndServeTLSWithMux starts an HTTPS server using a self-signed certificate and the provided mux, preserving any additional routes registered by callers.

func ListenAndServeWithMux

func ListenAndServeWithMux(addr string, mux *http.ServeMux) error

ListenAndServeWithMux starts an HTTP server using the provided mux.

func NewMux

func NewMux(root string) *http.ServeMux

NewMux returns an HTTP mux that serves static files from root and the WebSocket handler at /ws.

func P

func P(name string, value any) string

func Raw

func Raw(html string) string

func Register

func Register(hc *HostComponent)

Register adds a HostComponent to the global registry so incoming messages can be routed to it.

func RegisterComponent

func RegisterComponent(c Component)

RegisterComponent creates a HostComponent from a struct implementing Component and registers it in the global registry. This is the recommended way to define host components — it provides type safety and clean separation.

func ReleaseSession

func ReleaseSession(session *Session)

func ResolveRoot

func ResolveRoot(root string) string

func Span

func Span(name string, value any) string

func Start

func Start(root string) error

Start launches HTTP and HTTPS servers serving files from root. The HTTPS port is the HTTP port + 1.

func StartAuto

func StartAuto() error

StartAuto launches HTTP and HTTPS servers serving files from the default client build directory. It resolves the root path from rfw.json or falls back to "build/client". This is the recommended way to start the host server.

func Tag

func Tag(tag, name string, value any) string

Types

type BroadcastOption

type BroadcastOption func(*BroadcastOptions)

BroadcastOption configures a broadcast call.

func WithSessionTarget

func WithSessionTarget(sessionID string) BroadcastOption

WithSessionTarget limits a broadcast to a specific session ID.

type BroadcastOptions

type BroadcastOptions struct {
	Session string
}

BroadcastOptions holds optional parameters for Broadcast.

type Component

type Component interface {
	Name() string
	Serve(*Session, map[string]any) any
}

Component is the interface for struct-based host components. Register a struct implementing Component via RegisterComponent.

type Handler

type Handler func(payload map[string]any) any

Handler processes inbound payloads for a HostComponent and returns a response payload to send back to the wasm runtime. Returning nil results in no message being sent.

type HandlerWithSession

type HandlerWithSession func(*Session, map[string]any) any

HandlerWithSession processes inbound payloads with the associated Session.

type HostComponent

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

HostComponent represents server-side logic backing an HTML component.

func Get

func Get(name string) (*HostComponent, bool)

Get returns a registered HostComponent by name.

func NewHostComponent

func NewHostComponent(name string, handler Handler) *HostComponent

NewHostComponent registers a handler for the given component name.

func NewHostComponentWithSession

func NewHostComponentWithSession(name string, handler HandlerWithSession) *HostComponent

NewHostComponentWithSession registers a session-aware handler.

func (*HostComponent) Handle

func (hc *HostComponent) Handle(payload map[string]any) any

Handle executes the component's handler.

func (*HostComponent) HandleWithSession

func (hc *HostComponent) HandleWithSession(session *Session, payload map[string]any) any

HandleWithSession executes the session-aware handler when available.

func (*HostComponent) Name

func (hc *HostComponent) Name() string

func (*HostComponent) SessionAware

func (hc *HostComponent) SessionAware() bool

SessionAware reports whether the component registered a session handler.

func (*HostComponent) StoreManager

func (hc *HostComponent) StoreManager(session *Session) *state.StoreManager

StoreManager returns the session-specific store manager when available. If session is nil a reference to the global manager is returned for backward compatibility with legacy handlers.

func (*HostComponent) WithInitSnapshot

func (hc *HostComponent) WithInitSnapshot(fn func(*Session, map[string]any) *InitSnapshot) *HostComponent

WithInitSnapshot registers a callback that produces an InitSnapshot when a resync is requested.

type Inbound

type Inbound struct {
	Component string         `json:"component"`
	Payload   map[string]any `json:"payload"`
}

type InitSnapshot

type InitSnapshot struct {
	HTML string   `json:"html"`
	Vars []string `json:"vars,omitempty"`
}

InitSnapshot represents markup the host can send to force the client to repaint a fragment.

type Outbound

type Outbound struct {
	Component string `json:"component"`
	Payload   any    `json:"payload,omitempty"`
	Session   string `json:"session"`
}

type Session

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

Session represents per-connection state for a WebSocket client. It exposes an isolated StoreManager and a context bag for arbitrary data.

func AllocateSession

func AllocateSession() *Session

func SessionByID

func SessionByID(id string) (*Session, bool)

SessionByID retrieves a session for the given ID.

func (*Session) ContextDelete

func (s *Session) ContextDelete(key string)

ContextDelete removes a value from the session context.

func (*Session) ContextGet

func (s *Session) ContextGet(key string) (any, bool)

ContextGet retrieves a value from the session context.

func (*Session) ContextSet

func (s *Session) ContextSet(key string, value any)

ContextSet stores a value in the session context.

func (*Session) ID

func (s *Session) ID() string

func (*Session) Snapshot

func (s *Session) Snapshot() map[string]map[string]map[string]any

Snapshot returns a copy of all stores registered in this session.

func (*Session) StoreManager

func (s *Session) StoreManager() *state.StoreManager

Jump to

Keyboard shortcuts

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