server

package
v0.2.14 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: AGPL-3.0 Imports: 17 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 server exposes hub streams as MPEG-TS over HTTP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequireLogin added in v0.2.5

func RequireLogin(next http.Handler, user, pass string) http.Handler

RequireLogin puts HTTP Basic authentication in front of next, with the same login the RTSP listener asks for, so a recorder holds one login for reostream whichever output it reads. An empty user returns next as it is: the streaming port has always been open, and stays open unless a login is configured.

/api/status and /metrics stay open. They carry no picture, and they are what a container health check and a Prometheus scrape point at, neither of which should need a recorder's password to say the daemon is up.

Types

type HubSource

type HubSource interface {
	Hub(name string) (*hub.Hub, bool)
	HubNames() []string
}

HubSource supplies the hubs a Server routes to. It is an interface rather than a map because reload adds and removes streams while the server is running, so a snapshot taken at construction goes stale the first time a camera is added.

func StaticHubs

func StaticHubs(m map[string]*hub.Hub) HubSource

StaticHubs wraps a fixed hub map as a HubSource.

type Server

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

Server routes GET /<cam>.ts, /<cam>_sub.ts and /<cam>_extern.ts to the matching hub, plus /api/status and /metrics for the whole fleet.

func New

func New(src HubSource) *Server

New builds a Server over src. The header each client receives on connect comes from the hub itself (hub.Header), not from a value passed in here: the header is the muxer's PAT/PMT pair, which does not exist until the muxer has seen a first frame and learned the codec, which is after the server is constructed.

func (*Server) AllowWake added in v0.2.0

func (s *Server) AllowWake() *Server

AllowWake lets this server's viewers wake battery cameras. Only for a listener behind the control password: an open port would let any recorder hold a battery camera awake.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP handler serving all configured streams.

func (*Server) SetSupervisor

func (s *Server) SetSupervisor(sup *supervisor.Supervisor)

SetSupervisor attaches sup so status and metrics can report whether each stream is actually connected, not just how many hub subscribers it has. Optional: a Server with no supervisor attached still lists every stream, with Connected and Restarts reading false and 0 rather than the endpoint erroring or omitting the entry, which is what TestStatusReportsEveryStream guards against a stream that never got wired up.

func (*Server) StreamHandler

func (s *Server) StreamHandler() http.Handler

StreamHandler returns only the per-camera video and keyframe routes, without /api/status or /metrics. It exists so a second listener can offer the same hub subscriptions without also exposing the status endpoints a second time; see internal/control's mount of this under /stream/, which is what makes the operator page's live tiles same-origin.

func (*Server) StreamStats

func (s *Server) StreamStats() map[string]StreamStatus

StreamStats builds the current status for every configured stream, keyed the same way hubs are: "<camera>/<stream>". Exported because the control page renders exactly this and must not compute a second, drifting version of it.

type StreamStatus

type StreamStatus struct {
	Connected           bool    `json:"connected"`
	Streaming           bool    `json:"streaming"`
	Clients             int     `json:"clients"`
	DroppedClients      int     `json:"dropped_clients"`
	Restarts            int     `json:"restarts"`
	LastError           string  `json:"last_error,omitempty"`
	LastErrorAgeSeconds float64 `json:"last_error_age_seconds,omitempty"`
	FPS                 float64 `json:"fps"`
	BitrateBps          float64 `json:"bitrate_bps"`
	LastFrameAgeSeconds float64 `json:"last_frame_age_seconds"`
	AudioFrames         int     `json:"audio_frames"`
	DroppedAudio        int     `json:"dropped_audio"`
	// OnDemand is a battery camera's stream, asleep unless someone watches.
	OnDemand bool `json:"on_demand,omitempty"`
	// Privacy is a camera in privacy mode: off on purpose, not failing.
	Privacy bool `json:"privacy,omitempty"`
}

StreamStatus is one stream's entry in GET /api/status.

Restarts and LastError are only populated once a Supervisor has been attached with SetSupervisor; a Server built for tests or for the single camera command form reports zero values for both rather than omitting the fields, which would make "never restarted" indistinguishable from "no supervisor is wired up".

FPS, BitrateBps, LastFrameAgeSeconds and DroppedAudio come from hub.Hub.Stats(), which internal/stream updates as it publishes: the hub itself has no notion of a frame or a codec, only bytes to broadcast, so this is the one place that data is allowed to surface above it. LastFrameAgeSeconds is 0 only when there is no connection attempt in flight at all; a stream that is connected but has never delivered a frame reports its actual, growing time since connecting, not a permanent 0 (see hub.FrameStats.Age). A stream that never produced a frame reporting 0 forever, indistinguishable from one that just published, is exactly how two streams sat unnoticed for 25+ seconds in the 2026-09-08 incident this field's Streaming sibling exists to surface.

DroppedAudio existing here at all is the point of exposing it: an ADPCM camera silently losing its audio, with the recorder's config still declaring an audio role, is exactly the failure that went unnoticed in production for days before anyone thought to check. A count that only lived inside a log line would have the same problem again.

AudioFrames exists alongside DroppedAudio, not instead of it, because every stream now declares an audio track whether or not its camera ever sends one (see ts.NewMuxerWithAudio): DroppedAudio and AudioFrames both read 0 for a camera with no audio at all, exactly the same as for one whose audio is flowing perfectly, and an ffprobe of either looks identical too since the declared track is there regardless. AudioFrames > 0 is the only signal that audio is actually reaching a client; AudioFrames == 0 with DroppedAudio == 0 means no audio ever arrived, distinct from DroppedAudio > 0 meaning audio arrives but gets discarded. Streaming is deliberately its own field rather than a change to what Connected means. Connected already had an established meaning before this existed (the supervisor's goroutine for this stream is currently running, see supervisor.StreamStat.Running) and a dashboard built against that contract is entitled to keep reading it that way; changing Connected's truth condition out from under it, rather than adding a new field, is exactly the kind of silent field-meaning change the field name comment (below) warns against for LastFrameAgeSeconds. Streaming answers a narrower, newer question: is this connection actually delivering video right now, not just present. A stream can be Connected and not Streaming (a fresh connection still waiting on its first frame, or a held session the watchdog has not yet timed out), but never the reverse.

Jump to

Keyboard shortcuts

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