webrtc

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: MIT Imports: 29 Imported by: 0

README

Pion WebRTC
Pion WebRTC

A Golang implementation of the WebRTC API


Build Status GoDoc Go Report Card Coverage Status Codacy Badge


See DESIGN.md for an overview of features and future goals.

Install

Currently Pion uses CGO and OpenSSL for DTLS. We are actively working on replacing it. For now you have to make sure to install a C compliler and the OpenSSL headers for your platform:

Ubuntu/Debian

sudo apt-get install libssl-dev

OSX

brew install openssl
export CPATH=`brew --prefix`/opt/openssl/include
export LIBRARY_PATH=`brew --prefix`/opt/openssl/lib
go get -u github.com/pions/webrtc

Fedora

sudo yum install openssl-devel

Windows

  1. Install mingw-w64
  2. Install pkg-config-lite
  3. Build (or install precompiled) openssl for mingw32-w64
  4. Set PKG_CONFIG_PATH to the directory containing openssl.pc (i.e. c:\mingw64\mingw64\lib\pkgconfig)

Usage

Check out the example applications to help you along your Pion WebRTC journey.

The Pion WebRTC API closely matches the JavaScript WebRTC API. Most existing documentation is therefore also usefull when working with Pion. Furthermore, our GoDoc is actively maintained.

Now go forth and build some awesome apps! Here are some ideas to get your creative juices flowing:

  • Send a video file to multiple browser in real time for perfectly synchronized movie watching.
  • Send a webcam on an embedded device to your browser with no additional server required!
  • Securely send data between two servers, without using pub/sub.
  • Record your webcam and do special effects server side.
  • Build a conferencing application that processes audio/video and make decisions off of it.

Roadmap

The library is in active development, please refer to the roadmap to track our major milestones.

Community

Pion has an active community on the Golang Slack. Sign up and join the #pion channel for discussions and support. You can also use Pion mailing list.

We are always looking to support your projects. Please reach out if you have something to build!

If you need commercial support or don't want to use public methods you can contact us at team@pion.ly

  • pions/turn: A simple extendable Golang TURN server
  • [WIP] pions/media-server: A Pion WebRTC powered media server, providing the building blocks for anything RTC.
  • [WIP] pions/dcnet: A package providing Golang net interfaces around Pion WebRTC data channels.

Contributing

Check out the contributing wiki to join the group of amazing people making this project possible:

License

MIT License - see LICENSE.md for full text

Documentation

Overview

Package webrtc implements the WebRTC 1.0 as defined in W3C WebRTC specification document.

Index

Constants

View Source
const (
	DefaultPayloadTypeOpus = 111
	DefaultPayloadTypeVP8  = 96
	DefaultPayloadTypeVP9  = 98
	DefaultPayloadTypeH264 = 100
)

PayloadTypes for the default codecs

View Source
const (
	Opus = "opus"
	VP8  = "VP8"
	VP9  = "VP9"
	H264 = "H264"
)

Names for the default codecs supported by pions-webrtc

View Source
const Unknown = iota

Unknown defines default public constant to use for "enum" like struct comparisons when no value was defined.

Variables

View Source
var (
	// ErrUnknownType indicates an error with Unknown info.
	ErrUnknownType = errors.New("unknown")

	// ErrConnectionClosed indicates an operation executed after connection
	// has already been closed.
	ErrConnectionClosed = errors.New("connection closed")

	// ErrCertificateExpired indicates that an x509 certificate has expired.
	ErrCertificateExpired = errors.New("x509Cert expired")

	// ErrNoTurnCredencials indicates that a TURN server URL was provided
	// without required credentials.
	ErrNoTurnCredencials = errors.New("turn server credentials required")

	// ErrTurnCredencials indicates that provided TURN credentials are partial
	// or malformed.
	ErrTurnCredencials = errors.New("invalid turn server credentials")

	// ErrExistingTrack indicates that a track already exists.
	ErrExistingTrack = errors.New("track aready exists")

	// ErrPrivateKeyType indicates that a particular private key encryption
	// chosen to generate a certificate is not supported.
	ErrPrivateKeyType = errors.New("private key type not supported")

	// ErrModifyingPeerIdentity indicates that an attempt to modify
	// PeerIdentity was made after RTCPeerConnection has been initialized.
	ErrModifyingPeerIdentity = errors.New("peerIdentity cannot be modified")

	// ErrModifyingCertificates indicates that an attempt to modify
	// Certificates was made after RTCPeerConnection has been initialized.
	ErrModifyingCertificates = errors.New("certificates cannot be modified")

	// ErrModifyingBundlePolicy indicates that an attempt to modify
	// BundlePolicy was made after RTCPeerConnection has been initialized.
	ErrModifyingBundlePolicy = errors.New("bundle policy cannot be modified")

	// ErrModifyingRtcpMuxPolicy indicates that an attempt to modify
	// RtcpMuxPolicy was made after RTCPeerConnection has been initialized.
	ErrModifyingRtcpMuxPolicy = errors.New("rtcp mux policy cannot be modified")

	// ErrModifyingIceCandidatePoolSize indicates that an attempt to modify
	// IceCandidatePoolSize was made after RTCPeerConnection has been initialized.
	ErrModifyingIceCandidatePoolSize = errors.New("ice candidate pool size cannot be modified")

	// ErrStringSizeLimit indicates that the character size limit of string is
	// exceeded. The limit is hardcoded to 65535 according to specifications.
	ErrStringSizeLimit = errors.New("data channel label exceeds size limit")

	// ErrMaxDataChannelID indicates that the maximum number ID that could be
	// specified for a data channel has been exceeded.
	ErrMaxDataChannelID = errors.New("maximum number ID for datachannel specified")

	// ErrNegotiatedWithoutID indicates that an attempt to create a data channel
	// was made while setting the negotiated option to true without providing
	// the negotiated channel ID.
	ErrNegotiatedWithoutID = errors.New("negotiated set without channel id")

	// ErrRetransmitsOrPacketLifeTime indicates that an attempt to create a data
	// channel was made with both options MaxPacketLifeTime and MaxRetransmits
	// set together. Such configuration is not supported by the specification
	// and is mutually exclusive.
	ErrRetransmitsOrPacketLifeTime = errors.New("both MaxPacketLifeTime and MaxRetransmits was set")
)
View Source
var DefaultMediaEngine = NewMediaEngine()

DefaultMediaEngine is the default MediaEngine used by RTCPeerConnections

Functions

func RegisterCodec

func RegisterCodec(codec *RTCRtpCodec)

RegisterCodec is used to register a codec with the DefaultMediaEngine

func RegisterDefaultCodecs

func RegisterDefaultCodecs()

RegisterDefaultCodecs is a helper that registers the default codecs supported by pions-webrtc

Types

type MediaEngine

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

MediaEngine defines the codecs supported by a RTCPeerConnection

func NewMediaEngine

func NewMediaEngine() *MediaEngine

NewMediaEngine creates a new MediaEngine

func (*MediaEngine) RegisterCodec

func (m *MediaEngine) RegisterCodec(codec *RTCRtpCodec) uint8

RegisterCodec registers a codec to a media engine

type RTCAnswerOptions

type RTCAnswerOptions struct {
	RTCOfferAnswerOptions
}

RTCAnswerOptions structure describes the options used to control the answer creation process.

type RTCBundlePolicy

type RTCBundlePolicy int

RTCBundlePolicy affects which media tracks are negotiated if the remote endpoint is not bundle-aware, and what ICE candidates are gathered. If the remote endpoint is bundle-aware, all media tracks and data channels are bundled onto the same transport.

const (
	// RTCBundlePolicyBalanced indicates to gather ICE candidates for each
	// media type in use (audio, video, and data). If the remote endpoint is
	// not bundle-aware, negotiate only one audio and video track on separate
	// transports.
	RTCBundlePolicyBalanced RTCBundlePolicy = iota + 1

	// RTCBundlePolicyMaxCompat indicates to gather ICE candidates for each
	// track. If the remote endpoint is not bundle-aware, negotiate all media
	// tracks on separate transports.
	RTCBundlePolicyMaxCompat

	// RTCBundlePolicyMaxBundle indicates to gather ICE candidates for only
	// one track. If the remote endpoint is not bundle-aware, negotiate only
	// one media track.
	RTCBundlePolicyMaxBundle
)

func (RTCBundlePolicy) String

func (t RTCBundlePolicy) String() string

type RTCCertificate

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

RTCCertificate represents a x509Cert used to authenticate WebRTC communications.

func GenerateCertificate

func GenerateCertificate(secretKey crypto.PrivateKey) (*RTCCertificate, error)

GenerateCertificate causes the creation of an X.509 certificate and corresponding private key.

func NewRTCCertificate

func NewRTCCertificate(key crypto.PrivateKey, tpl x509.Certificate) (*RTCCertificate, error)

NewRTCCertificate generates a new x509 compliant RTCCertificate to be used by DTLS for encrypting data sent over the wire. This method differs from GenerateCertificate by allowing to specify a template x509.Certificate to be used in order to define certificate parameters.

func (RTCCertificate) Equals

func (c RTCCertificate) Equals(o RTCCertificate) bool

Equals determines if two certificates are identical by comparing both the secretKeys and x509Certificates.

func (RTCCertificate) Expires

func (c RTCCertificate) Expires() time.Time

Expires returns the timestamp after which this certificate is no longer valid.

func (RTCCertificate) GetFingerprints

func (c RTCCertificate) GetFingerprints()

GetFingerprints returns the list of certificate fingerprints, one of which is computed with the digest algorithm used in the certificate signature.

type RTCConfiguration

type RTCConfiguration struct {
	// IceServers defines a slice describing servers available to be used by
	// ICE, such as STUN and TURN servers.
	IceServers []RTCIceServer

	// IceTransportPolicy indicates which candidates the IceAgent is allowed
	// to use.
	IceTransportPolicy RTCIceTransportPolicy

	// BundlePolicy indicates which media-bundling policy to use when gathering
	// ICE candidates.
	BundlePolicy RTCBundlePolicy

	// RtcpMuxPolicy indicates which rtcp-mux policy to use when gathering ICE
	// candidates.
	RtcpMuxPolicy RTCRtcpMuxPolicy

	// PeerIdentity sets the target peer identity for the RTCPeerConnection.
	// The RTCPeerConnection will not establish a connection to a remote peer
	// unless it can be successfully authenticated with the provided name.
	PeerIdentity string

	// Certificates describes a set of certificates that the RTCPeerConnection
	// uses to authenticate. Valid values for this parameter are created
	// through calls to the GenerateCertificate function. Although any given
	// DTLS connection will use only one certificate, this attribute allows the
	// caller to provide multiple certificates that support different
	// algorithms. The final certificate will be selected based on the DTLS
	// handshake, which establishes which certificates are allowed. The
	// RTCPeerConnection implementation selects which of the certificates is
	// used for a given connection; how certificates are selected is outside
	// the scope of this specification. If this value is absent, then a default
	// set of certificates is generated for each RTCPeerConnection instance.
	Certificates []RTCCertificate

	// IceCandidatePoolSize describes the size of the prefetched ICE pool.
	IceCandidatePoolSize uint8
}

RTCConfiguration defines a set of parameters to configure how the peer-to-peer communication via RTCPeerConnection is established or re-established.

type RTCDataChannel

type RTCDataChannel struct {
	sync.RWMutex

	// Transport represents the associated underlying data transport that is
	// used to transport actual data to the other peer.
	Transport *RTCSctpTransport

	// Label represents a label that can be used to distinguish this
	// RTCDataChannel object from other RTCDataChannel objects. Scripts are
	// allowed to create multiple RTCDataChannel objects with the same label.
	Label string

	// Ordered represents if the RTCDataChannel is ordered, and false if
	// out-of-order delivery is allowed.
	Ordered bool

	// MaxPacketLifeTime represents the length of the time window (msec) during
	// which transmissions and retransmissions may occur in unreliable mode.
	MaxPacketLifeTime *uint16

	// MaxRetransmits represents the maximum number of retransmissions that are
	// attempted in unreliable mode.
	MaxRetransmits *uint16

	// Protocol represents the name of the sub-protocol used with this
	// RTCDataChannel.
	Protocol string

	// Negotiated represents whether this RTCDataChannel was negotiated by the
	// application (true), or not (false).
	Negotiated bool

	// ID represents the ID for this RTCDataChannel. The value is initially
	// null, which is what will be returned if the ID was not provided at
	// channel creation time, and the DTLS role of the SCTP transport has not
	// yet been negotiated. Otherwise, it will return the ID that was either
	// selected by the script or generated. After the ID is set to a non-null
	// value, it will not change.
	ID *uint16

	// Priority represents the priority for this RTCDataChannel. The priority is
	// assigned at channel creation time.
	Priority RTCPriorityType

	// ReadyState represents the state of the RTCDataChannel object.
	ReadyState RTCDataChannelState

	// BufferedAmount represents the number of bytes of application data
	// (UTF-8 text and binary data) that have been queued using send(). Even
	// though the data transmission can occur in parallel, the returned value
	// MUST NOT be decreased before the current task yielded back to the event
	// loop to prevent race conditions. The value does not include framing
	// overhead incurred by the protocol, or buffering done by the operating
	// system or network hardware. The value of BufferedAmount slot will only
	// increase with each call to the send() method as long as the ReadyState is
	// open; however, BufferedAmount does not reset to zero once the channel
	// closes.
	BufferedAmount uint64

	// BufferedAmountLowThreshold represents the threshold at which the
	// bufferedAmount is considered to be low. When the bufferedAmount decreases
	// from above this threshold to equal or below it, the bufferedamountlow
	// event fires. BufferedAmountLowThreshold is initially zero on each new
	// RTCDataChannel, but the application may change its value at any time.
	BufferedAmountLowThreshold uint64

	// Onmessage designates an event handler which is invoked on a message
	// arrival over the sctp transport from a remote peer.
	//
	// Deprecated: use OnMessage instead.
	Onmessage func(datachannel.Payload)

	// OnMessage designates an event handler which is invoked on a message
	// arrival over the sctp transport from a remote peer.
	OnMessage func(datachannel.Payload)

	// OnOpen designates an event handler which is invoked when
	// the underlying data transport has been established (or re-established).
	OnOpen func()
	// contains filtered or unexported fields
}

RTCDataChannel represents a WebRTC DataChannel The RTCDataChannel interface represents a network channel which can be used for bidirectional peer-to-peer transfers of arbitrary data

func (*RTCDataChannel) Send

Send sends the passed message to the DataChannel peer

type RTCDataChannelInit

type RTCDataChannelInit struct {
	// Ordered indicates if data is allowed to be delivered out of order. The
	// default value of true, guarantees that data will be delivered in order.
	Ordered *bool

	// MaxPacketLifeTime limits the time (in milliseconds) during which the
	// channel will transmit or retransmit data if not acknowledged. This value
	// may be clamped if it exceeds the maximum value supported.
	MaxPacketLifeTime *uint16

	// MaxRetransmits limits the number of times a channel will retransmit data
	// if not successfully delivered. This value may be clamped if it exceeds
	// the maximum value supported.
	MaxRetransmits *uint16

	// Protocol describes the subprotocol name used for this channel.
	Protocol *string

	// Negotiated describes if the data channel is created by the local peer or
	// the remote peer. The default value of false tells the user agent to
	// announce the channel in-band and instruct the other peer to dispatch a
	// corresponding RTCDataChannel. If set to true, it is up to the application
	// to negotiate the channel and create an RTCDataChannel with the same id
	// at the other peer.
	Negotiated *bool

	// ID overrides the default selection of ID for this channel.
	ID *uint16

	// Priority describes the priority of this channel.
	Priority *RTCPriorityType
}

RTCDataChannelInit can be used to configure properties of the underlying channel such as data reliability.

type RTCDataChannelState

type RTCDataChannelState int

RTCDataChannelState indicates the state of a data channel.

const (
	// RTCDataChannelStateConnecting indicates that the data channel is being
	// established. This is the initial state of RTCDataChannel, whether created
	// with CreateDataChannel, or dispatched as a part of an RTCDataChannelEvent.
	RTCDataChannelStateConnecting RTCDataChannelState = iota + 1

	// RTCDataChannelStateOpen indicates that the underlying data transport is
	// established and communication is possible.
	RTCDataChannelStateOpen

	// RTCDataChannelStateClosing indicates that the procedure to close down the
	// underlying data transport has started.
	RTCDataChannelStateClosing

	// RTCDataChannelStateClosed indicates that the underlying data transport
	// has been closed or could not be established.
	RTCDataChannelStateClosed
)

func (RTCDataChannelState) String

func (t RTCDataChannelState) String() string

type RTCDtlsFingerprint

type RTCDtlsFingerprint struct {
	// Algorithm specifies one of the the hash function algorithms defined in
	// the 'Hash function Textual Names' registry.
	Algorithm string

	// Value specifies the value of the certificate fingerprint in lowercase
	// hex string as expressed utilizing the syntax of 'fingerprint' in
	// https://tools.ietf.org/html/rfc4572#section-5.
	Value string
}

RTCDtlsFingerprint specifies the hash function algorithm and certificate fingerprint as described in https://tools.ietf.org/html/rfc4572.

type RTCDtlsTransport

type RTCDtlsTransport struct {
}

RTCDtlsTransport allows an application access to information about the DTLS transport over which RTP and RTCP packets are sent and received by RTCRtpSender and RTCRtpReceiver, as well other data such as SCTP packets sent and received by data channels.

type RTCDtlsTransportState

type RTCDtlsTransportState int

RTCDtlsTransportState indicates the dtsl transport establishment state.

const (
	// RTCDtlsTransportStateNew indicates that DTLS has not started negotiating
	// yet.
	RTCDtlsTransportStateNew RTCDtlsTransportState = iota + 1

	// RTCDtlsTransportStateConnecting indicates that DTLS is in the process of
	// negotiating a secure connection and verifying the remote fingerprint.
	RTCDtlsTransportStateConnecting

	// RTCDtlsTransportStateConnected indicates that DTLS has completed
	// negotiation of a secure connection and verified the remote fingerprint.
	RTCDtlsTransportStateConnected

	// RTCDtlsTransportStateClosed indicates that the transport has been closed
	// intentionally as the result of receipt of a close_notify alert, or
	// calling close().
	RTCDtlsTransportStateClosed

	// RTCDtlsTransportStateFailed indicates that the transport has failed as
	// the result of an error (such as receipt of an error alert or failure to
	// validate the remote fingerprint).
	RTCDtlsTransportStateFailed
)

func (RTCDtlsTransportState) String

func (t RTCDtlsTransportState) String() string

type RTCIceCandidateType

type RTCIceCandidateType int

RTCIceCandidateType represents the type of the ICE candidate used.

const (
	// RTCIceCandidateTypeHost indicates that the candidate is of Host type as
	// described in https://tools.ietf.org/html/rfc8445#section-5.1.1.1. A
	// candidate obtained by binding to a specific port from an IP address on
	// the host. This includes IP addresses on physical interfaces and logical
	// ones, such as ones obtained through VPNs.
	RTCIceCandidateTypeHost RTCIceCandidateType = iota + 1

	// RTCIceCandidateTypeSrflx indicates the the candidate is of Server
	// Reflexive type as described
	// https://tools.ietf.org/html/rfc8445#section-5.1.1.2. A candidate type
	// whose IP address and port are a binding allocated by a NAT for an ICE
	// agent after it sends a packet through the NAT to a server, such as a
	// STUN server.
	RTCIceCandidateTypeSrflx

	// RTCIceCandidateTypePrflx indicates that the candidate is of Peer
	// Reflexive type. A candidate type whose IP address and port are a binding
	// allocated by a NAT for an ICE agent after it sends a packet through the
	// NAT to its peer.
	RTCIceCandidateTypePrflx

	// RTCIceCandidateTypeRelay indicates the the candidate is of Relay type as
	// described in https://tools.ietf.org/html/rfc8445#section-5.1.1.2. A
	// candidate type obtained from a relay server, such as a TURN server.
	RTCIceCandidateTypeRelay
)

func (RTCIceCandidateType) String

func (t RTCIceCandidateType) String() string

type RTCIceComponent

type RTCIceComponent int

RTCIceComponent describes if the ice transport is used for RTP (or RTCP multiplexing).

const (
	// RTCIceComponentRtp indicates that the ICE Transport is used for RTP (or
	// RTCP multiplexing), as defined in
	// https://tools.ietf.org/html/rfc5245#section-4.1.1.1. Protocols
	// multiplexed with RTP (e.g. data channel) share its component ID. This
	// represents the component-id value 1 when encoded in candidate-attribute.
	RTCIceComponentRtp RTCIceComponent = iota + 1

	// RTCIceComponentRtcp indicates that the ICE Transport is used for RTCP as
	// defined by https://tools.ietf.org/html/rfc5245#section-4.1.1.1. This
	// represents the component-id value 2 when encoded in candidate-attribute.
	RTCIceComponentRtcp
)

func (RTCIceComponent) String

func (t RTCIceComponent) String() string

type RTCIceConnectionState

type RTCIceConnectionState int

RTCIceConnectionState indicates signaling state of the Ice Connection.

const (
	// RTCIceConnectionStateNew indicates that any of the RTCIceTransports are
	// in the "new" state and none of them are in the "checking", "disconnected"
	// or "failed" state, or all RTCIceTransports are in the "closed" state, or
	// there are no transports.
	RTCIceConnectionStateNew RTCIceConnectionState = iota + 1

	// RTCIceConnectionStateChecking indicates that any of the RTCIceTransports
	// are in the "checking" state and none of them are in the "disconnected"
	// or "failed" state.
	RTCIceConnectionStateChecking

	// RTCIceConnectionStateConnected indicates that all RTCIceTransports are
	// in the "connected", "completed" or "closed" state and at least one of
	// them is in the "connected" state.
	RTCIceConnectionStateConnected

	// RTCIceConnectionStateCompleted indicates that all RTCIceTransports are
	// in the "completed" or "closed" state and at least one of them is in the
	// "completed" state.
	RTCIceConnectionStateCompleted

	// RTCIceConnectionStateDisconnected indicates that any of the
	// RTCIceTransports are in the "disconnected" state and none of them are
	// in the "failed" state.
	RTCIceConnectionStateDisconnected

	// RTCIceConnectionStateFailed indicates that any of the RTCIceTransports
	// are in the "failed" state.
	RTCIceConnectionStateFailed

	// RTCIceConnectionStateClosed indicates that the RTCPeerConnection's
	// isClosed is true.
	RTCIceConnectionStateClosed
)

func (RTCIceConnectionState) String

func (c RTCIceConnectionState) String() string

type RTCIceCredentialType

type RTCIceCredentialType int

RTCIceCredentialType indicates the type of credentials used to connect to an ICE server.

const (
	// RTCIceCredentialTypePassword describes username and pasword based
	// credentials as described in https://tools.ietf.org/html/rfc5389.
	RTCIceCredentialTypePassword RTCIceCredentialType = iota + 1

	// RTCIceCredentialTypeOauth describes token based credential as described
	// in https://tools.ietf.org/html/rfc7635.
	RTCIceCredentialTypeOauth
)

func (RTCIceCredentialType) String

func (t RTCIceCredentialType) String() string

type RTCIceGatheringState

type RTCIceGatheringState int

RTCIceGatheringState describes the state of the candidate gathering process.

const (
	// RTCIceGatheringStateNew indicates that any of the RTCIceTransports are
	// in the "new" gathering state and none of the transports are in the
	// "gathering" state, or there are no transports.
	RTCIceGatheringStateNew RTCIceGatheringState = iota + 1

	// RTCIceGatheringStateGathering indicates that any of the RTCIceTransports
	// are in the "gathering" state.
	RTCIceGatheringStateGathering

	// RTCIceGatheringStateComplete indicates that at least one RTCIceTransport
	// exists, and all RTCIceTransports are in the "completed" gathering state.
	RTCIceGatheringStateComplete
)

func (RTCIceGatheringState) String

func (t RTCIceGatheringState) String() string

type RTCIceProtocol

type RTCIceProtocol int

RTCIceProtocol indicates the transport protocol type that is used in the ice.URL structure.

const (
	// RTCIceProtocolUDP indicates the URL uses a UDP transport.
	RTCIceProtocolUDP RTCIceProtocol = iota + 1

	// RTCIceProtocolTCP indicates the URL uses a TCP transport.
	RTCIceProtocolTCP
)

func (RTCIceProtocol) String

func (t RTCIceProtocol) String() string

type RTCIceRole

type RTCIceRole int

RTCIceRole describes the role ice.Agent is playing in selecting the preferred the candidate pair.

const (
	// RTCIceRoleControlling indicates that the ICE agent that is responsible
	// for selecting the final choice of candidate pairs and signaling them
	// through STUN and an updated offer, if needed. In any session, one agent
	// is always controlling. The other is the controlled agent.
	RTCIceRoleControlling RTCIceRole = iota + 1

	// RTCIceRoleControlled indicates that an ICE agent that waits for the
	// controlling agent to select the final choice of candidate pairs.
	RTCIceRoleControlled
)

func (RTCIceRole) String

func (t RTCIceRole) String() string

type RTCIceServer

type RTCIceServer struct {
	URLs           []string
	Username       string
	Credential     interface{}
	CredentialType RTCIceCredentialType
}

RTCIceServer describes a single STUN and TURN server that can be used by the IceAgent to establish a connection with a peer.

type RTCIceTransport

type RTCIceTransport struct {
}

RTCIceTransport allows an application access to information about the ICE transport over which packets are sent and received.

type RTCIceTransportPolicy

type RTCIceTransportPolicy int

RTCIceTransportPolicy defines the ICE candidate policy surface the permitted candidates. Only these candidates are used for connectivity checks.

const (
	// RTCIceTransportPolicyRelay indicates only media relay candidates such
	// as candidates passing through a TURN server are used.
	RTCIceTransportPolicyRelay RTCIceTransportPolicy = iota + 1

	// RTCIceTransportPolicyAll indicates any type of candidate is used.
	RTCIceTransportPolicyAll
)

func (RTCIceTransportPolicy) String

func (t RTCIceTransportPolicy) String() string

type RTCOAuthCredential

type RTCOAuthCredential struct {
	// MacKey is a base64-url encoded format. It is used in STUN message
	// integrity hash calculation.
	MacKey string

	// AccessToken is a base64-encoded format. This is an encrypted
	// self-contained token that is opaque to the application.
	AccessToken string
}

RTCOAuthCredential represents OAuth credential information which is used by the STUN/TURN client to connect to an ICE server as defined in https://tools.ietf.org/html/rfc7635. Note that the kid parameter is not located in RTCOAuthCredential, but in RTCIceServer's username member.

type RTCOfferAnswerOptions

type RTCOfferAnswerOptions struct {
	// VoiceActivityDetection allows the application to provide information
	// about whether it wishes voice detection feature to be enabled or disabled.
	VoiceActivityDetection bool
}

RTCOfferAnswerOptions is a base structure which describes the options that can be used to control the offer/answer creation process.

type RTCOfferOptions

type RTCOfferOptions struct {
	RTCOfferAnswerOptions

	// IceRestart forces the underlying ice gathering process to be restarted.
	// When this value is true, the generated description will have ICE
	// credentials that are different from the current credentials
	IceRestart bool
}

RTCOfferOptions structure describes the options used to control the offer creation process

type RTCPeerConnection

type RTCPeerConnection struct {
	sync.RWMutex

	// CurrentLocalDescription represents the local description that was
	// successfully negotiated the last time the RTCPeerConnection transitioned
	// into the stable state plus any local candidates that have been generated
	// by the IceAgent since the offer or answer was created.
	CurrentLocalDescription *RTCSessionDescription

	// PendingLocalDescription represents a local description that is in the
	// process of being negotiated plus any local candidates that have been
	// generated by the IceAgent since the offer or answer was created. If the
	// RTCPeerConnection is in the stable state, the value is null.
	PendingLocalDescription *RTCSessionDescription

	// CurrentRemoteDescription represents the last remote description that was
	// successfully negotiated the last time the RTCPeerConnection transitioned
	// into the stable state plus any remote candidates that have been supplied
	// via AddIceCandidate() since the offer or answer was created.
	CurrentRemoteDescription *RTCSessionDescription

	// PendingRemoteDescription represents a remote description that is in the
	// process of being negotiated, complete with any remote candidates that
	// have been supplied via AddIceCandidate() since the offer or answer was
	// created. If the RTCPeerConnection is in the stable state, the value is
	// null.
	PendingRemoteDescription *RTCSessionDescription

	// SignalingState attribute returns the signaling state of the
	// RTCPeerConnection instance.
	SignalingState RTCSignalingState

	// IceGatheringState attribute returns the ICE gathering state of the
	// RTCPeerConnection instance.
	IceGatheringState RTCIceGatheringState // FIXME NOT-USED

	// IceConnectionState attribute returns the ICE connection state of the
	// RTCPeerConnection instance.
	// IceConnectionState RTCIceConnectionState  // FIXME SWAP-FOR-THIS
	IceConnectionState ice.ConnectionState // FIXME REMOVE

	// ConnectionState attribute returns the connection state of the
	// RTCPeerConnection instance.
	ConnectionState RTCPeerConnectionState

	// OnIceConnectionStateChange designates an event handler which is called
	// when an ice connection state is changed.
	OnICEConnectionStateChange func(ice.ConnectionState)

	// OnTrack designates an event handler which is called when remote track
	// arrives from a remote peer.
	OnTrack func(*RTCTrack)

	// OnDataChannel designates an event handler which is invoked when a data
	// channel message arrives from a remote peer.
	OnDataChannel func(*RTCDataChannel)
	// contains filtered or unexported fields
}

RTCPeerConnection represents a WebRTC connection that establishes a peer-to-peer communications with another RTCPeerConnection instance in a browser, or to another endpoint implementing the required protocols.

func New

func New(configuration RTCConfiguration) (*RTCPeerConnection, error)

New creates a new RTCPeerConfiguration with the provided configuration

func (*RTCPeerConnection) AddTrack

func (pc *RTCPeerConnection) AddTrack(track *RTCTrack) (*RTCRtpSender, error)

AddTrack adds a RTCTrack to the RTCPeerConnection

func (*RTCPeerConnection) Close

func (pc *RTCPeerConnection) Close() error

Close ends the RTCPeerConnection

func (*RTCPeerConnection) CreateAnswer

func (pc *RTCPeerConnection) CreateAnswer(options *RTCAnswerOptions) (RTCSessionDescription, error)

CreateAnswer starts the RTCPeerConnection and generates the localDescription

func (*RTCPeerConnection) CreateDataChannel

func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataChannelInit) (*RTCDataChannel, error)

CreateDataChannel creates a new RTCDataChannel object with the given label and optitional RTCDataChannelInit used to configure properties of the underlying channel such as data reliability.

func (*RTCPeerConnection) CreateOffer

func (pc *RTCPeerConnection) CreateOffer(options *RTCOfferOptions) (RTCSessionDescription, error)

CreateOffer starts the RTCPeerConnection and generates the localDescription

func (*RTCPeerConnection) GetConfiguration

func (pc *RTCPeerConnection) GetConfiguration() RTCConfiguration

GetConfiguration returns an RTCConfiguration object representing the current configuration of this RTCPeerConnection object. The returned object is a copy and direct mutation on it will not take affect until SetConfiguration has been called with RTCConfiguration passed as its only argument. https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-getconfiguration

func (*RTCPeerConnection) GetReceivers

func (pc *RTCPeerConnection) GetReceivers() []RTCRtpReceiver

GetReceivers returns the RTCRtpReceivers that are currently attached to this RTCPeerConnection

func (*RTCPeerConnection) GetSenders

func (pc *RTCPeerConnection) GetSenders() []RTCRtpSender

GetSenders returns the RTCRtpSender that are currently attached to this RTCPeerConnection

func (*RTCPeerConnection) GetTransceivers

func (pc *RTCPeerConnection) GetTransceivers() []RTCRtpTransceiver

GetTransceivers returns the RTCRtpTransceiver that are currently attached to this RTCPeerConnection

func (*RTCPeerConnection) LocalDescription

func (pc *RTCPeerConnection) LocalDescription() *RTCSessionDescription

LocalDescription returns PendingLocalDescription if it is not null and otherwise it returns CurrentLocalDescription. This property is used to determine if setLocalDescription has already been called. https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-localdescription

func (*RTCPeerConnection) NewRTCTrack

func (pc *RTCPeerConnection) NewRTCTrack(payloadType uint8, id, label string) (*RTCTrack, error)

NewRTCTrack is used to create a new RTCTrack

func (*RTCPeerConnection) RemoteDescription

func (pc *RTCPeerConnection) RemoteDescription() *RTCSessionDescription

RemoteDescription returns PendingRemoteDescription if it is not null and otherwise it returns CurrentRemoteDescription. This property is used to determine if setRemoteDescription has already been called. https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-remotedescription

func (*RTCPeerConnection) SendRTCP

func (pc *RTCPeerConnection) SendRTCP(pkt rtcp.Packet) error

SendRTCP sends a user provided RTCP packet to the connected peer If no peer is connected the packet is discarded

func (*RTCPeerConnection) SetConfiguration

func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) error

SetConfiguration updates the configuration of this RTCPeerConnection object.

func (*RTCPeerConnection) SetIdentityProvider

func (pc *RTCPeerConnection) SetIdentityProvider(provider string) error

SetIdentityProvider is used to configure an identity provider to generate identity assertions

func (*RTCPeerConnection) SetMediaEngine

func (pc *RTCPeerConnection) SetMediaEngine(m *MediaEngine)

SetMediaEngine allows overwriting the default media engine used by the RTCPeerConnection This enables RTCPeerConnection with support for different codecs

func (*RTCPeerConnection) SetRemoteDescription

func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) error

SetRemoteDescription sets the SessionDescription of the remote peer

type RTCPeerConnectionState

type RTCPeerConnectionState int

RTCPeerConnectionState indicates the state of the RTCPeerConnection.

const (
	// RTCPeerConnectionStateNew indicates that any of the RTCIceTransports or
	// RTCDtlsTransports are in the "new" state and none of the transports are
	// in the "connecting", "checking", "failed" or "disconnected" state, or
	// all transports are in the "closed" state, or there are no transports.
	RTCPeerConnectionStateNew RTCPeerConnectionState = iota + 1

	// RTCPeerConnectionStateConnecting indicates that any of the
	// RTCIceTransports or RTCDtlsTransports are in the "connecting" or
	// "checking" state and none of them is in the "failed" state.
	RTCPeerConnectionStateConnecting

	// RTCPeerConnectionStateConnected indicates that all RTCIceTransports and
	// RTCDtlsTransports are in the "connected", "completed" or "closed" state
	// and at least one of them is in the "connected" or "completed" state.
	RTCPeerConnectionStateConnected

	// RTCPeerConnectionStateDisconnected indicates that any of the
	// RTCIceTransports or RTCDtlsTransports are in the "disconnected" state
	// and none of them are in the "failed" or "connecting" or "checking" state.
	RTCPeerConnectionStateDisconnected

	// RTCPeerConnectionStateFailed indicates that any of the RTCIceTransports
	// or RTCDtlsTransports are in a "failed" state.
	RTCPeerConnectionStateFailed

	// RTCPeerConnectionStateClosed indicates the peer connection is closed
	// and the isClosed member variable of RTCPeerConnection is true.
	RTCPeerConnectionStateClosed
)

func (RTCPeerConnectionState) String

func (t RTCPeerConnectionState) String() string

type RTCPriorityType

type RTCPriorityType int

RTCPriorityType determines the priority type of a data channel.

const (
	// RTCPriorityTypeVeryLow corresponds to "below normal".
	RTCPriorityTypeVeryLow RTCPriorityType = iota + 1

	// RTCPriorityTypeLow corresponds to "normal".
	RTCPriorityTypeLow

	// RTCPriorityTypeMedium corresponds to "high".
	RTCPriorityTypeMedium

	// RTCPriorityTypeHigh corresponds to "extra high".
	RTCPriorityTypeHigh
)

func (RTCPriorityType) String

func (p RTCPriorityType) String() string

type RTCRtcpMuxPolicy

type RTCRtcpMuxPolicy int

RTCRtcpMuxPolicy affects what ICE candidates are gathered to support non-multiplexed RTCP.

const (
	// RTCRtcpMuxPolicyNegotiate indicates to gather ICE candidates for both
	// RTP and RTCP candidates. If the remote-endpoint is capable of
	// multiplexing RTCP, multiplex RTCP on the RTP candidates. If it is not,
	// use both the RTP and RTCP candidates separately.
	RTCRtcpMuxPolicyNegotiate RTCRtcpMuxPolicy = iota + 1

	// RTCRtcpMuxPolicyRequire indicates to gather ICE candidates only for
	// RTP and multiplex RTCP on the RTP candidates. If the remote endpoint is
	// not capable of rtcp-mux, session negotiation will fail.
	RTCRtcpMuxPolicyRequire
)

func (RTCRtcpMuxPolicy) String

func (t RTCRtcpMuxPolicy) String() string

type RTCRtpCapabilities

type RTCRtpCapabilities struct {
	Codecs           []RTCRtpCodecCapability
	HeaderExtensions []RTCRtpHeaderExtensionCapability
}

RTCRtpCapabilities represents the capabilities of a transceiver

type RTCRtpCodec

type RTCRtpCodec struct {
	RTCRtpCodecCapability
	Type        RTCRtpCodecType
	Name        string
	PayloadType uint8
	Payloader   rtp.Payloader
}

RTCRtpCodec represents a codec supported by the PeerConnection

func NewRTCRtpCodec

func NewRTCRtpCodec(
	codecType RTCRtpCodecType,
	name string,
	clockrate uint32,
	channels uint16,
	fmtp string,
	payloadType uint8,
	payloader rtp.Payloader,
) *RTCRtpCodec

NewRTCRtpCodec is used to define a new codec

func NewRTCRtpH264Codec

func NewRTCRtpH264Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec

NewRTCRtpH264Codec is a helper to create an H264 codec

func NewRTCRtpOpusCodec

func NewRTCRtpOpusCodec(payloadType uint8, clockrate uint32, channels uint16) *RTCRtpCodec

NewRTCRtpOpusCodec is a helper to create an Opus codec

func NewRTCRtpVP8Codec

func NewRTCRtpVP8Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec

NewRTCRtpVP8Codec is a helper to create an VP8 codec

func NewRTCRtpVP9Codec

func NewRTCRtpVP9Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec

NewRTCRtpVP9Codec is a helper to create an VP9 codec

type RTCRtpCodecCapability

type RTCRtpCodecCapability struct {
	MimeType    string
	ClockRate   uint32
	Channels    uint16
	SdpFmtpLine string
}

RTCRtpCodecCapability provides information about codec capabilities.

type RTCRtpCodecType

type RTCRtpCodecType int

RTCRtpCodecType determines the type of a codec

const (

	// RTCRtpCodecTypeAudio indicates this is an audio codec
	RTCRtpCodecTypeAudio RTCRtpCodecType = iota + 1

	// RTCRtpCodecTypeVideo indicates this is a video codec
	RTCRtpCodecTypeVideo
)

func (RTCRtpCodecType) String

func (t RTCRtpCodecType) String() string

type RTCRtpHeaderExtensionCapability

type RTCRtpHeaderExtensionCapability struct {
	URI string
}

RTCRtpHeaderExtensionCapability is used to define a RFC5285 RTP header extension supported by the codec.

type RTCRtpReceiver

type RTCRtpReceiver struct {
	Track *RTCTrack
}

RTCRtpReceiver allows an application to inspect the receipt of a RTCTrack

type RTCRtpSender

type RTCRtpSender struct {
	Track *RTCTrack
}

RTCRtpSender allows an application to control how a given RTCTrack is encoded and transmitted to a remote peer

type RTCRtpTransceiver

type RTCRtpTransceiver struct {
	Mid       string
	Sender    *RTCRtpSender
	Receiver  *RTCRtpReceiver
	Direction RTCRtpTransceiverDirection
	// contains filtered or unexported fields
}

RTCRtpTransceiver represents a combination of an RTCRtpSender and an RTCRtpReceiver that share a common mid.

func (*RTCRtpTransceiver) Stop

func (t *RTCRtpTransceiver) Stop() error

Stop irreversibly stops the RTCRtpTransceiver

type RTCRtpTransceiverDirection

type RTCRtpTransceiverDirection int

RTCRtpTransceiverDirection indicates the direction of the RTCRtpTransceiver.

const (
	// RTCRtpTransceiverDirectionSendrecv indicates the RTCRtpSender will offer
	// to send RTP and RTCRtpReceiver the will offer to receive RTP.
	RTCRtpTransceiverDirectionSendrecv RTCRtpTransceiverDirection = iota + 1

	// RTCRtpTransceiverDirectionSendonly indicates the RTCRtpSender will offer
	// to send RTP.
	RTCRtpTransceiverDirectionSendonly

	// RTCRtpTransceiverDirectionRecvonly indicates the RTCRtpReceiver the will
	// offer to receive RTP.
	RTCRtpTransceiverDirectionRecvonly

	// RTCRtpTransceiverDirectionInactive indicates the RTCRtpSender won't offer
	// to send RTP and RTCRtpReceiver the won't offer to receive RTP.
	RTCRtpTransceiverDirectionInactive
)

func NewRTCRtpTransceiverDirection

func NewRTCRtpTransceiverDirection(raw string) RTCRtpTransceiverDirection

NewRTCRtpTransceiverDirection defines a procedure for creating a new RTCRtpTransceiverDirection from a raw string naming the transceiver direction.

func (RTCRtpTransceiverDirection) String

type RTCSample deprecated

type RTCSample = media.RTCSample

RTCSample contains media, and the amount of samples in it

Deprecated: use RTCSample from github.com/pions/webrtc/pkg/media instead

type RTCSctpTransport

type RTCSctpTransport struct {
	// Transport represents the transport over which all SCTP packets for data
	// channels will be sent and received.
	Transport *RTCDtlsTransport

	// State represents the current state of the SCTP transport.
	State RTCSctpTransportState

	// MaxMessageSize represents the maximum size of data that can be passed to
	// RTCDataChannel's send() method.
	MaxMessageSize float64

	// MaxChannels represents the maximum amount of RTCDataChannel's that can
	// be used simultaneously.
	MaxChannels *uint16
}

RTCSctpTransport provides details about the SCTP transport.

type RTCSctpTransportState

type RTCSctpTransportState int

RTCSctpTransportState indicates the state of the SCTP transport.

const (
	// RTCSctpTransportStateConnecting indicates the RTCSctpTransport is in the
	// process of negotiating an association. This is the initial state of the
	// SctpTransportState when an RTCSctpTransport is created.
	RTCSctpTransportStateConnecting RTCSctpTransportState = iota + 1

	// RTCSctpTransportStateConnected indicates the negotiation of an
	// association is completed.
	RTCSctpTransportStateConnected

	// RTCSctpTransportStateClosed indicates a SHUTDOWN or ABORT chunk is
	// received or when the SCTP association has been closed intentionally,
	// such as by closing the peer connection or applying a remote description
	// that rejects data or changes the SCTP port.
	RTCSctpTransportStateClosed
)

func (RTCSctpTransportState) String

func (s RTCSctpTransportState) String() string

type RTCSdpType

type RTCSdpType int

RTCSdpType describes the type of an RTCSessionDescription.

const (
	// RTCSdpTypeOffer indicates that a description MUST be treated as an SDP
	// offer.
	RTCSdpTypeOffer RTCSdpType = iota + 1

	// RTCSdpTypePranswer indicates that a description MUST be treated as an
	// SDP answer, but not a final answer. A description used as an SDP
	// pranswer may be applied as a response to an SDP offer, or an update to
	// a previously sent SDP pranswer.
	RTCSdpTypePranswer

	// RTCSdpTypeAnswer indicates that a description MUST be treated as an SDP
	// final answer, and the offer-answer exchange MUST be considered complete.
	// A description used as an SDP answer may be applied as a response to an
	// SDP offer or as an update to a previously sent SDP pranswer.
	RTCSdpTypeAnswer

	// RTCSdpTypeRollback indicates that a description MUST be treated as
	// canceling the current SDP negotiation and moving the SDP offer and
	// answer back to what it was in the previous stable state. Note the
	// local or remote SDP descriptions in the previous stable state could be
	// null if there has not yet been a successful offer-answer negotiation.
	RTCSdpTypeRollback
)

func (RTCSdpType) MarshalJSON

func (t RTCSdpType) MarshalJSON() ([]byte, error)

MarshalJSON enables JSON marshaling of a RTCSdpType

func (RTCSdpType) String

func (t RTCSdpType) String() string

func (*RTCSdpType) UnmarshalJSON

func (t *RTCSdpType) UnmarshalJSON(b []byte) error

UnmarshalJSON enables JSON unmarshaling of a RTCSdpType

type RTCSessionDescription

type RTCSessionDescription struct {
	Type RTCSdpType `json:"type"`
	Sdp  string     `json:"sdp"`
	// contains filtered or unexported fields
}

RTCSessionDescription is used to expose local and remote session descriptions.

type RTCSignalingState

type RTCSignalingState int

RTCSignalingState indicates the signaling state of the offer/answer process.

const (
	// RTCSignalingStateStable indicates there is no offer/answer exchange in
	// progress. This is also the initial state, in which case the local and
	// remote descriptions are nil.
	RTCSignalingStateStable RTCSignalingState = iota + 1

	// RTCSignalingStateHaveLocalOffer indicates that a local description, of
	// type "offer", has been successfully applied.
	RTCSignalingStateHaveLocalOffer

	// RTCSignalingStateHaveRemoteOffer indicates that a remote description, of
	// type "offer", has been successfully applied.
	RTCSignalingStateHaveRemoteOffer

	// RTCSignalingStateHaveLocalPranswer indicates that a remote description
	// of type "offer" has been successfully applied and a local description
	// of type "pranswer" has been successfully applied.
	RTCSignalingStateHaveLocalPranswer

	// RTCSignalingStateHaveRemotePranswer indicates that a local description
	// of type "offer" has been successfully applied and a remote description
	// of type "pranswer" has been successfully applied.
	RTCSignalingStateHaveRemotePranswer

	// RTCSignalingStateClosed indicates The RTCPeerConnection has been closed.
	RTCSignalingStateClosed
)

func (RTCSignalingState) String

func (t RTCSignalingState) String() string

type RTCTrack

type RTCTrack struct {
	ID          string
	PayloadType uint8
	Kind        RTCRtpCodecType
	Label       string
	Ssrc        uint32
	Codec       *RTCRtpCodec
	Packets     <-chan *rtp.Packet
	Samples     chan<- media.RTCSample
}

RTCTrack represents a track that is communicated

Directories

Path Synopsis
sfu
internal
sdp
pkg
ice
Package ice implements the Interactive Connectivity Establishment (ICE) protocol defined in rfc5245.
Package ice implements the Interactive Connectivity Establishment (ICE) protocol defined in rfc5245.
null
Package null is used to represent values where the 0 value is significant This pattern is common in ECMAScript, this allows us to maintain a matching API
Package null is used to represent values where the 0 value is significant This pattern is common in ECMAScript, this allows us to maintain a matching API
rtcerr
Package rtcerr implements the error wrappers defined throughout the WebRTC 1.0 specifications.
Package rtcerr implements the error wrappers defined throughout the WebRTC 1.0 specifications.
rtp

Jump to

Keyboard shortcuts

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