app

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package app composes the shared HTTP service, site access, embedded assets, media listeners, and startup/shutdown lifecycle for Hosted Server and App.

Locking

signal.Server owns the one mutex that guards the room store, the media router and every session. This package never takes it: everything a request can mutate goes through the signaling server. Server.mu below guards only this struct's own lifecycle bookkeeping.

The lock order is one-directional: Server.mu may be held while the signaling mutex is taken (reconcile calls signal.New under it, and signal.New locks the server it is still building), never the reverse. Nothing reachable under the signaling mutex may take Server.mu, which is why the one callback this package hands to signal, SiteAccessAtUpgrade, only reads the lock-free site-access gate. Keep it that way or the two locks can deadlock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Config is the loaded server configuration; cmd owns config.Load / Local.
	Config config.Config
	// Listener is optional prebound TCP ownership transferred on successful New.
	// It lets the Local Client reserve its HTTP port before opening a tunnel.
	Listener *net.TCPListener
	// Assets is the built Browser UI. A nil FS serves the API only, which is
	// the TS frontend mode "none"; webassets.FS() returns nil the same way
	// when no build was embedded.
	Assets fs.FS
	// Now returns Unix milliseconds; nil uses the wall clock.
	Now func() int64
	// Logger receives the request-failure record; nil uses slog.Default().
	Logger *slog.Logger

	AuthenticationTimeoutMs             int
	ViewerDisconnectGraceMs             int
	HeartbeatIntervalMs                 int
	MaxSignalConnections                int
	MaxUnauthenticatedSignalConnections int
	SiteAccessTTLSeconds                int

	// AfterFunc is the signaling timer factory; nil uses time.AfterFunc.
	AfterFunc func(time.Duration, func()) func() bool
	// RoomStore replaces the store this package would build from Config.
	RoomStore *room.Store
}

Options is CreateServerOptions. Every zero value means the TS `undefined`.

type Server

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

Server is PiikServer.

func New

func New(options Options) (*Server, error)

New is createPiikServer minus the listening: it builds the SFU fallback, the room store, the site-access issuer, the frontend handler and the HTTP server, none of which performs I/O.

func (*Server) Close

func (s *Server) Close(ctx context.Context) error

Close stops accepting traffic, closes signaling, the HTTP/STUN listeners and the room store, and leaves the rooms in place. Hosted restarts use it.

func (*Server) End

func (s *Server) End(ctx context.Context) error

End is Close preceded by ending every room. The Client uses it, because its authority dies with the process.

func (*Server) Listen

func (s *Server) Listen(ctx context.Context) (int, error)

Listen binds application sockets before recovering room authority and accepting traffic.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request)

ServeHTTP dispatches requests and contains handler panics at the HTTP boundary.

Jump to

Keyboard shortcuts

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