webrtcpeer

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package webrtcpeer contains the webrtc and Ceeblue's whep/whip-like http implementation for webRTC load test tool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeCallBackType

type ChangeCallBackType int

ChangeCallBackType represents the type of change in the PeerConnection.

const (
	// ChangeCallBackTypeStateChagne indicates that the state of the PeerConnection has changed.
	ChangeCallBackTypeStateChagne ChangeCallBackType = iota
	// ChangeCallBackTypeNewTrack indicates that a new track has been added to the PeerConnection.
	ChangeCallBackTypeNewTrack
)

type ChangeCallback

type ChangeCallback func(peer *PeerConnection, change ChangeCallBackType, data any)

ChangeCallback is a callback function that is called when the PeerConnection changes.

type Client

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

Client represents the WebRTC Client for creating PeerConnections Based on the Pion WebRTC API and Ceeblue's whep/whip-like http implementation.

func NewClient

func NewClient(config Configuration, callback ChangeCallback) (*Client, error)

NewClient creates a new WebRTC Client with the given configuration. It handles the creation of PeerConnections and the signaling over HTTP.

func (*Client) NewPeerConnection

func (a *Client) NewPeerConnection(ctx context.Context, endpoint string) (*PeerConnection, error)

NewPeerConnection creates a new PeerConnection and handles Ceeblue's whep/whip-like http implementation. If the endpoint uses ws:// or wss://, it will use WebSocket signaling instead.

type Configuration

type Configuration struct {
	ICEServers         []webrtc.ICEServer
	ICETransportPolicy webrtc.ICETransportPolicy
	LiteMode           bool
	VideoCodec         VideoCodec
	BufferDuration     time.Duration
	TargetResolution   int
	TargetCodec        string // Preferred codec (e.g., "H264", "VP8"), empty means default to H264 if resolution is set
}

Configuration represents the configuration of a PeerConnection.

type PeerConnection

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

PeerConnection represents a basic WebRTC peer connection. For simulation purposes, it holds the state of the connection. And how many RTP packets were received.

func (*PeerConnection) Close

func (p *PeerConnection) Close() error

Close closes the underlying PeerConnection.

func (*PeerConnection) GetOffer

func (p *PeerConnection) GetOffer() string

GetOffer returns the local SDP of the PeerConnection ALways is offer and includes the ICE candidates.

func (*PeerConnection) GetStatus

func (p *PeerConnection) GetStatus() PeerConnectionStatus

GetStatus returns the current status of the PeerConnection.

func (*PeerConnection) GetTracks

func (p *PeerConnection) GetTracks() []TrackInfo

GetTracks returns the info objects of the tracks in the PeerConnection.

func (*PeerConnection) SetAnswer

func (p *PeerConnection) SetAnswer(answer string) error

SetAnswer sets the remote SDP of the PeerConnection Should be the answer and includes the ICE candidates (if required / any).

type PeerConnectionStatus

type PeerConnectionStatus uint8

PeerConnectionStatus represents the status of a PeerConnection.

const (
	// PeerConnectionStatusNew indicates that the PeerConnection is new
	// Waiting for the SDP answer.
	PeerConnectionStatusNew PeerConnectionStatus = iota
	// PeerConnectionStatusConnecting indicates that the PeerConnection is connecting.
	PeerConnectionStatusConnecting
	// PeerConnectionStatusConnected indicates that the PeerConnection is connected.
	PeerConnectionStatusConnected
	// PeerConnectionStatusDisconnected indicates that the PeerConnection is disconnected.
	PeerConnectionStatusDisconnected
	// PeerConnectionStatusClosed indicates that the PeerConnection is closed.
	// This is the final state of the PeerConnection.
	PeerConnectionStatusClosed
)

func (PeerConnectionStatus) String

func (s PeerConnectionStatus) String() string

type TrackInfo

type TrackInfo interface {
	// MimeType returns the MIME type of the track.
	MimeType() string
	// Kind returns the kind of the track.
	Kind() webrtc.RTPCodecType
	// GetPacketsCount returns the number of RTP packets received by the track during its lifetime.
	GetPacketsCount() uint64
	// GetLostPacketsCount returns the number of RTP packets lost by the track during its lifetime.
	GetLostPacketsCount() uint64
	// GetBytesCount returns the number of bytes received by the track during its lifetime.
	GetBytesCount() uint64
	// IsClosed returns whether the track is closed.
	IsClosed() bool
}

TrackInfo represents the information of a media track in a PeerConnection.

type VideoCodec

type VideoCodec uint8

VideoCodec is the video codec to use in the PeerConnection.

const (
	// VideoCodecAuto Allow any video codec added by Pion default media engine.
	VideoCodecAuto VideoCodec = iota
	// VideoCodecVP8 Use VP8 video codec.
	VideoCodecVP8
	// VideoCodecH264 Use H264 video codec.
	VideoCodecH264
)

Jump to

Keyboard shortcuts

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