webrtc

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 11 Imported by: 1 module, 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 webrtc adapts one ordered, reliable Pion DataChannel to the transport-neutral session.FrameChannel contract.

Signaling, ICE policy, relay fallback, and peer selection intentionally live above this package. Keeping those decisions out of the adapter lets one lifecycle state machine own frame bounds, event-driven flow control, terminal acknowledgement, and close ordering. The PeerConnection owner forwards a permanent connection failure through Channel.Fail even after channel handoff; signaling cancellation and temporary disconnection do not end the channel.

Index

Constants

View Source
const (
	ChannelLabel    = "windshare-frame-channel"
	ChannelProtocol = "windshare-v2"
)
View Source
const DefaultLifecycleObservationCapacity = 256

DefaultLifecycleObservationCapacity retains a bounded prefix until the owner attaches a consumer. Callers must opt in by assigning it explicitly.

Variables

View Source
var (
	ErrNilDataChannel               = errors.New("webrtc: DataChannel must not be nil")
	ErrInvalidDataChannel           = errors.New("webrtc: DataChannel configuration is invalid")
	ErrInvalidFlowControl           = errors.New("webrtc: flow-control profile is invalid")
	ErrLifecycleObservationCapacity = errors.New("webrtc: lifecycle observation capacity is invalid")
	ErrChannelNotOpen               = errors.New("webrtc: channel is not open")
	ErrChannelClosed                = errors.New("webrtc: channel is closed")
	ErrFrameBounds                  = errors.New("webrtc: frame is outside the allowed size")
	ErrPeerProtocol                 = errors.New("webrtc: peer violated the DataChannel protocol")
	ErrTerminalNotAcknowledged      = errors.New("webrtc: terminal frame was not acknowledged")
	ErrRemoteClosed                 = errors.New("webrtc: peer closed the DataChannel")
	ErrTransport                    = errors.New("webrtc: DataChannel transport failed")
)

Functions

func DefaultDataChannelInit

func DefaultDataChannelInit() *pion.DataChannelInit

DefaultDataChannelInit returns a fresh in-band, ordered, reliable channel configuration. Pointer fields are intentionally recreated per call because Pion retains the caller's values while constructing the channel.

Types

type Channel

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

Channel is the sole owner of the callbacks installed on its Pion DataChannel. A wrapped DataChannel must not be sent through directly after construction.

func NewChannel

func NewChannel(dc *pion.DataChannel) (*Channel, error)

func NewChannelWithOptions added in v0.1.2

func NewChannelWithOptions(dc *pion.DataChannel, options ChannelOptions) (*Channel, error)

NewChannelWithOptions preserves the same transport contract while exposing optional structured lifecycle decisions to the owning runtime.

func (*Channel) Close

func (c *Channel) Close() error

Close waits behind either admitted terminal direction. This preserves the terminal owner's final-frame/ack sequence instead of racing it with Pion close.

func (*Channel) CompleteObservations added in v0.1.2

func (c *Channel) CompleteObservations() LifecycleObservationCompletion

CompleteObservations makes an immediate producer admission cut. Call it after channel shutdown when the result must include the final channel transition; it never waits for or makes claims about consumer execution.

func (*Channel) Done

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

func (*Channel) Err

func (c *Channel) Err() error

Err is stable after Done closes. A normal Close or acknowledged terminal has no terminal error.

func (*Channel) Fail added in v0.1.2

func (c *Channel) Fail(cause error)

Fail propagates a permanent failure of the owning PeerConnection even when Pion leaves the DataChannel open. Freeze sends immediately, then serialize the termination behind accepted callbacks so buffered final frames retain their authority. A provider callback must never wait for application backpressure.

func (*Channel) LifecycleTrace added in v0.1.2

func (c *Channel) LifecycleTrace() <-chan LifecycleTrace

LifecycleTrace returns nil when lifecycle observation was not activated. The receive-only capability cannot publish or close producer-owned admission.

func (*Channel) Opened

func (c *Channel) Opened() <-chan struct{}

func (*Channel) Recv

func (c *Channel) Recv() <-chan framechannel.Frame

func (*Channel) Send

func (c *Channel) Send(ctx context.Context, frame framechannel.Frame) error

func (*Channel) SendControl added in v0.1.2

func (c *Channel) SendControl(ctx context.Context, frame framechannel.Frame) error

SendControl borrows the shared control reserve without changing wire ordering.

func (*Channel) SendTerminal

func (c *Channel) SendTerminal(ctx context.Context, frame framechannel.Frame) error

func (*Channel) State

func (c *Channel) State() framechannel.ChannelState

type ChannelOptions added in v0.1.2

type ChannelOptions struct {
	SendCapacity                 *SendCapacity
	LifecycleObservationCapacity int
}

ChannelOptions carries optional process observability without allowing consumer execution to become transport work. Zero capacity disables it.

type LifecycleCause added in v0.1.2

type LifecycleCause string
const (
	LifecycleCauseNone                   LifecycleCause = "none"
	LifecycleCauseCanceled               LifecycleCause = "canceled"
	LifecycleCauseDeadline               LifecycleCause = "deadline"
	LifecycleCauseNotOpen                LifecycleCause = "not_open"
	LifecycleCauseNaturalRetirement      LifecycleCause = "natural_retirement"
	LifecycleCauseRemoteClosed           LifecycleCause = "remote_closed"
	LifecycleCauseTerminalUnacknowledged LifecycleCause = "terminal_unacknowledged"
	LifecycleCausePeerProtocol           LifecycleCause = "peer_protocol"
	LifecycleCauseTransport              LifecycleCause = "transport"
	LifecycleCauseOther                  LifecycleCause = "other"
)

func (LifecycleCause) DiagnosticName added in v0.1.2

func (value LifecycleCause) DiagnosticName() string

DiagnosticName belongs to the source vocabulary; recorders accept new values.

type LifecycleContractViolation added in v0.1.2

type LifecycleContractViolation uint8
const (
	LifecycleContractValid LifecycleContractViolation = iota
	LifecycleContractUnknownEnum
	LifecycleContractInvalidIdentity
	LifecycleContractInvalidStageFields
)

func ValidateLifecycleTrace added in v0.1.2

func ValidateLifecycleTrace(event LifecycleTrace) LifecycleContractViolation

ValidateLifecycleTrace owns the complete matrix emitted by the WebRTC lifecycle. Refusals use the state at admission, so connecting and closed are valid evidence rather than projection defects.

type LifecycleObservationCompletion added in v0.1.2

type LifecycleObservationCompletion struct {
	Enqueued uint64
	Loss     LifecycleObservationLoss
}

LifecycleObservationCompletion proves stream admission has closed. Enqueued does not imply that a consumer received or projected an observation.

type LifecycleObservationLoss added in v0.1.2

type LifecycleObservationLoss struct {
	CapacityDropped uint64
}

LifecycleObservationLoss describes only observations the bounded stream could not retain before the producer admission cut.

func (LifecycleObservationLoss) Total added in v0.1.2

func (loss LifecycleObservationLoss) Total() uint64

type LifecycleOperation added in v0.1.2

type LifecycleOperation string
const (
	LifecycleOperationChannel      LifecycleOperation = "channel"
	LifecycleOperationSend         LifecycleOperation = "send"
	LifecycleOperationSendTerminal LifecycleOperation = "send_terminal"
)

func (LifecycleOperation) DiagnosticName added in v0.1.2

func (value LifecycleOperation) DiagnosticName() string

DiagnosticName belongs to the source vocabulary; recorders accept new values.

type LifecycleTerminalState added in v0.1.2

type LifecycleTerminalState string
const (
	LifecycleTerminalNone          LifecycleTerminalState = "none"
	LifecycleTerminalLocalPending  LifecycleTerminalState = "local_pending"
	LifecycleTerminalRemotePending LifecycleTerminalState = "remote_pending"
)

func (LifecycleTerminalState) DiagnosticName added in v0.1.2

func (value LifecycleTerminalState) DiagnosticName() string

DiagnosticName belongs to the source vocabulary; recorders accept new values.

type LifecycleTrace added in v0.1.2

type LifecycleTrace struct {
	ChannelID   uint64
	OperationID uint64
	Operation   LifecycleOperation
	Transition  LifecycleTransition
	Disposition framechannel.SendDisposition
	State       framechannel.ChannelState
	Terminal    LifecycleTerminalState
	Cause       LifecycleCause
	Dropped     uint64
}

LifecycleTrace is deliberately enum-like and excludes provider error text or frame content. ChannelID and OperationID remain stable for the channel lifetime so concurrent admission and closure decisions can be reconstructed safely.

func (LifecycleTrace) DiagnosticRecord added in v0.1.2

func (v LifecycleTrace) DiagnosticRecord() diag.Record

type LifecycleTransition added in v0.1.2

type LifecycleTransition string
const (
	LifecycleTransitionSendAccepted           LifecycleTransition = "send_accepted"
	LifecycleTransitionSendRejected           LifecycleTransition = "send_rejected"
	LifecycleTransitionSendRetired            LifecycleTransition = "send_retired"
	LifecycleTransitionRemoteTerminalReserved LifecycleTransition = "remote_terminal_reserved"
	LifecycleTransitionTerminationPending     LifecycleTransition = "termination_pending"
	LifecycleTransitionClosedClean            LifecycleTransition = "closed_clean"
	LifecycleTransitionClosedFailed           LifecycleTransition = "closed_failed"
	LifecycleTransitionTraceDropped           LifecycleTransition = "trace_dropped"
)

func (LifecycleTransition) DiagnosticName added in v0.1.2

func (value LifecycleTransition) DiagnosticName() string

DiagnosticName belongs to the source vocabulary; recorders accept new values.

type SendCapacity added in v0.1.2

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

SendCapacity is injected by the application. Pion's BufferedAmount retains each charge after Send returns; returning from Send is not delivery completion. Lane windows and SCTP congestion control remain independent.

func NewSendCapacity added in v0.1.2

func NewSendCapacity() *SendCapacity

Jump to

Keyboard shortcuts

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