webrtc

package
v0.0.0-nightly.2.7de83... Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package webrtc provides shared video transport and WebSocket signaling.

Index

Constants

View Source
const (
	PayloaderVP8  = "vp8"
	PayloaderH264 = "h264"
)
View Source
const (
	InputEventPointerAbsolute = remoteinput.EventPointerAbsolute
	InputEventPointerRelative = remoteinput.EventPointerRelative
	InputEventPointerButton   = remoteinput.EventPointerButton
	InputEventPointerScroll   = remoteinput.EventPointerScroll
	InputEventKeyboardKey     = remoteinput.EventKeyboardKey
)

Variables

View Source
var (
	ErrInputBusy                 = remoteinput.ErrBusy
	ErrInputDisabled             = remoteinput.ErrDisabled
	ErrInputPointerUnauthorized  = remoteinput.ErrPointerUnauthorized
	ErrInputKeyboardUnauthorized = remoteinput.ErrKeyboardUnauthorized
	ErrInputNotReady             = remoteinput.ErrNotReady
	ErrInputNotOwner             = remoteinput.ErrNotOwner
	ErrInputOverloaded           = remoteinput.ErrOverloaded
	ErrInputClosed               = remoteinput.ErrClosed
)

Functions

This section is empty.

Types

type AudioSample

type AudioSample struct {
	Data     []byte
	PTS      time.Duration
	Duration time.Duration
}

AudioSample is one encoded Opus frame ready for transport.

type AudioSource

type AudioSource interface {
	Samples() <-chan AudioSample
}

AudioSource supplies optional encoded Opus audio.

type ClipboardController

type ClipboardController interface {
	Enabled() bool
	Set(context.Context, clipboard.Content) error
	Latest() (clipboard.Content, bool)
	Subscribe() (<-chan clipboard.Content, func())
}

ClipboardController synchronizes clipboard content with peers.

type Config

type Config struct {
	AudioEnabled        bool
	ICEServers          []string
	ICEUsername         string
	ICECredential       string
	UDPPortMin          uint16
	UDPPortMax          uint16
	Subprotocols        []string
	MaxPeers            int
	ReplaceExistingPeer bool
	AllowedOrigins      []string
	TracingEnabled      bool
	Observer            Observer
}

Config contains static WebRTC and signaling settings.

func (Config) Validate

func (cfg Config) Validate() error

Validate checks the implemented transport settings.

type EncoderProfile

type EncoderProfile struct {
	DefaultOption     string
	Options           map[string]QualityOption
	FrontendTransform string
	Codec             RTPCodec
}

EncoderProfile contains the profile metadata needed by the WebRTC transport.

type InputCapabilities

type InputCapabilities = remoteinput.Capabilities

InputCapabilities reports the input classes available to a peer.

type InputController

type InputController interface {
	Acquire(uint64, func(uint64, error)) (InputCapabilities, error)
	Release(uint64) error
	Owns(uint64) bool
	Submit(uint64, InputEvent) error
}

InputController owns peer input leases and dispatches validated events.

type InputEvent

type InputEvent = remoteinput.Event

InputEvent is one validated remote input transition or motion.

type InputEventType

type InputEventType = remoteinput.EventType

InputEventType identifies one input event.

type MediaSource

type MediaSource interface {
	Samples() <-chan VideoSample
	Quality() Quality
	Profile(string) (EncoderProfile, bool)
	UpdateQuality(Quality) error
	RequestKeyframe() error
	SetActive(bool)
}

MediaSource supplies one shared encoded video stream.

type Observer

type Observer interface {
	PeerOpened(PeerInfo)
	PeerStateChanged(PeerInfo, string)
	PeerClosed(PeerInfo)
}

Observer receives peer lifecycle notifications.

type PeerInfo

type PeerInfo struct {
	ID          uint64
	ActivePeers int
}

PeerInfo identifies one transport peer.

type Quality

type Quality struct {
	Profile     string `json:"profile"`
	Option      string `json:"option"`
	Width       int    `json:"width"`
	Height      int    `json:"height"`
	Framerate   int    `json:"framerate"`
	BitrateKbps int    `json:"bitrate_kbps"`
}

Quality contains runtime-adjustable video settings.

type QualityOption

type QualityOption struct {
	Label       string `json:"label"`
	Width       int    `json:"width"`
	Height      int    `json:"height"`
	Framerate   int    `json:"framerate"`
	BitrateKbps int    `json:"bitrate_kbps"`
}

QualityOption is one complete video quality tuple exposed to clients.

func (QualityOption) Quality

func (option QualityOption) Quality(profileName, optionName string) Quality

Quality resolves this option into runtime encoder settings.

type RTCPFeedback

type RTCPFeedback struct {
	Type      string
	Parameter string
}

RTCPFeedback describes one negotiated RTCP feedback mechanism.

type RTPCodec

type RTPCodec struct {
	ID           string
	MimeType     string
	ClockRate    uint32
	Channels     uint16
	PayloadType  uint8
	Payloader    string
	SDPFmtpLine  string
	RTCPFeedback []RTCPFeedback
	SDP          SDPRequirements
}

RTPCodec contains codec, RTP, packetizer, and SDP settings.

func (RTPCodec) Compatible

func (codec RTPCodec) Compatible(other RTPCodec) bool

Compatible reports whether two codec definitions can share an active peer connection.

type SDPRequirements

type SDPRequirements struct {
	OfferFmtp  map[string]string
	AnswerFmtp map[string]string
}

SDPRequirements controls offer validation and answer parameter rewriting.

type Service

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

Service fans one encoded media source out to active peer connections.

func New

func New(
	cfg Config,
	source MediaSource,
	audio AudioSource,
	inputController InputController,
	clipboardController ClipboardController,
	logger *zap.Logger,
) (*Service, error)

New constructs a reusable WebRTC service without opening listeners.

func (*Service) Close

func (s *Service) Close()

Close stops signaling and closes every active peer.

func (*Service) Handler

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

Handler returns the signaling handler for mounting behind application middleware.

func (*Service) PeerCount

func (s *Service) PeerCount() int

PeerCount returns the number of active and initializing peers.

func (*Service) Run

func (s *Service) Run(ctx context.Context) error

Run forwards encoded samples until the context ends or media stops.

type VideoSample

type VideoSample struct {
	Data       []byte
	Codec      string
	ProducedAt time.Time
	PTS        time.Duration
	PTSValid   bool
	Duration   time.Duration
	KeyFrame   bool
}

VideoSample is one encoded video frame ready for transport.

Jump to

Keyboard shortcuts

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