API Reference

WebRTC

class aiortc.RTCPeerConnection(configuration=None)

The RTCPeerConnection interface represents a WebRTC connection between the local computer and a remote peer.

Parameters

configuration (Optional[RTCConfiguration]) – An optional RTCConfiguration.

property localDescription

An RTCSessionDescription describing the session for the local end of the connection.

Return type

RTCSessionDescription

property remoteDescription

An RTCSessionDescription describing the session for the remote end of the connection.

Return type

RTCSessionDescription

property sctp

An RTCSctpTransport describing the SCTP transport being used for datachannels or None.

Return type

Optional[RTCSctpTransport]

addTrack(track)

Add a MediaStreamTrack to the set of media tracks which will be transmitted to the remote peer.

Return type

RTCRtpSender

addTransceiver(trackOrKind, direction='sendrecv')

Add a new RTCRtpTransceiver.

Return type

RTCRtpTransceiver

createDataChannel(label, maxPacketLifeTime=None, maxRetransmits=None, ordered=True, protocol='', negotiated=False, id=None)

Create a data channel with the given label.

Return type

RTCDataChannel

getReceivers()

Returns the list of RTCRtpReceiver objects that are currently attached to the connection.

Return type

List[RTCRtpReceiver]

getSenders()

Returns the list of RTCRtpSender objects that are currently attached to the connection.

Return type

List[RTCRtpSender]

getTransceivers()

Returns the list of RTCRtpTransceiver objects that are currently attached to the connection.

Return type

List[RTCRtpTransceiver]

class aiortc.RTCSessionDescription(sdp, type)

The RTCSessionDescription dictionary describes one end of a connection and how it’s configured.

class aiortc.RTCConfiguration(iceServers=None)

The RTCConfiguration dictionary is used to provide configuration options for an RTCPeerConnection.

iceServers: Optional[List[aiortc.rtcconfiguration.RTCIceServer]] = None

A list of RTCIceServer objects to configure STUN / TURN servers.

Interactive Connectivity Establishment (ICE)

class aiortc.RTCIceCandidate(component, foundation, ip, port, priority, protocol, type, relatedAddress=None, relatedPort=None, sdpMid=None, sdpMLineIndex=None, tcpType=None)

The RTCIceCandidate interface represents a candidate Interactive Connectivity Establishment (ICE) configuration which may be used to establish an RTCPeerConnection.

class aiortc.RTCIceGatherer(iceServers=None)

The RTCIceGatherer interface gathers local host, server reflexive and relay candidates, as well as enabling the retrieval of local Interactive Connectivity Establishment (ICE) parameters which can be exchanged in signaling.

property state

The current state of the ICE gatherer.

Return type

str

classmethod getDefaultIceServers()

Return the list of default RTCIceServer.

Return type

List[RTCIceServer]

getLocalCandidates()

Retrieve the list of valid local candidates associated with the ICE gatherer.

Return type

List[RTCIceCandidate]

getLocalParameters()

Retrieve the ICE parameters of the ICE gatherer.

Return type

RTCIceParameters

class aiortc.RTCIceTransport(gatherer)

The RTCIceTransport interface allows an application access to information about the Interactive Connectivity Establishment (ICE) transport over which packets are sent and received.

Parameters

gatherer (RTCIceGatherer) – An RTCIceGatherer.

property iceGatherer

The ICE gatherer passed in the constructor.

Return type

RTCIceGatherer

property role

The current role of the ICE transport.

Either ‘controlling’ or ‘controlled’.

Return type

str

property state

The current state of the ICE transport.

Return type

str

getRemoteCandidates()

Retrieve the list of candidates associated with the remote RTCIceTransport.

Return type

List[RTCIceCandidate]

class aiortc.RTCIceParameters(usernameFragment=None, password=None, iceLite=False)

The RTCIceParameters dictionary includes the ICE username fragment and password and other ICE-related parameters.

usernameFragment: Optional[str] = None

ICE username fragment.

password: Optional[str] = None

ICE password.

class aiortc.RTCIceServer(urls, username=None, credential=None, credentialType='password')

The RTCIceServer dictionary defines how to connect to a single STUN or TURN server. It includes both the URL and the necessary credentials, if any, to connect to the server.

urls: str = None

This required property is either a single string or a list of strings, each specifying a URL which can be used to connect to the server.

username: Optional[str] = None

The username to use during authentication (for TURN only).

credential: Optional[str] = None

The credential to use during authentication (for TURN only).

Datagram Transport Layer Security (DTLS)

class aiortc.RTCCertificate(key, cert)

The RTCCertificate interface enables the certificates used by an RTCDtlsTransport.

To generate a certificate and the corresponding private key use generateCertificate().

property expires

The date and time after which the certificate will be considered invalid.

Return type

datetime

getFingerprints()

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

Return type

List[RTCDtlsFingerprint]

classmethod generateCertificate()

Create and return an X.509 certificate and corresponding private key.

Return type

RTCCertificate

class aiortc.RTCDtlsTransport(transport, certificates)

The RTCDtlsTransport object includes information relating to Datagram Transport Layer Security (DTLS) transport.

Parameters
  • transport (RTCIceTransport) – An RTCIceTransport.

  • certificates (List[RTCCertificate]) – A list of RTCCertificate (only one is allowed currently).

property state

The current state of the DTLS transport.

One of ‘new’, ‘connecting’, ‘connected’, ‘closed’ or ‘failed’.

Return type

str

property transport

The associated RTCIceTransport instance.

getLocalParameters()

Get the local parameters of the DTLS transport.

Return type

RTCDtlsParameters

class aiortc.RTCDtlsParameters(fingerprints=<factory>, role='auto')

The RTCDtlsParameters dictionary includes information relating to DTLS configuration.

fingerprints: List[RTCDtlsFingerprint] = None

List of RTCDtlsFingerprint, one fingerprint for each certificate.

role: str = 'auto'

The DTLS role, with a default of auto.

class aiortc.RTCDtlsFingerprint(algorithm, value)

The RTCDtlsFingerprint dictionary includes the hash function algorithm and certificate fingerprint.

algorithm: str = None

The hash function name, for instance ‘sha-256’.

value: str = None

The fingerprint value.

Real-time Transport Protocol (RTP)

class aiortc.RTCRtpReceiver(kind, transport)

The RTCRtpReceiver interface manages the reception and decoding of data for a MediaStreamTrack.

Parameters
  • kind (str) – The kind of media (‘audio’ or ‘video’).

  • transport (RTCDtlsTransport) – An RTCDtlsTransport.

property track

The MediaStreamTrack which is being handled by the receiver.

Return type

MediaStreamTrack

property transport

The RTCDtlsTransport over which the media for the receiver’s track is received.

Return type

RTCDtlsTransport

classmethod getCapabilities(kind)

Returns the most optimistic view of the system’s capabilities for receiving media of the given kind.

Return type

RTCRtpCapabilities

getSynchronizationSources()

Returns a RTCRtpSynchronizationSource for each unique SSRC identifier received in the last 10 seconds.

Return type

List[RTCRtpSynchronizationSource]

class aiortc.RTCRtpSender(trackOrKind, transport)

The RTCRtpSender interface provides the ability to control and obtain details about how a particular MediaStreamTrack is encoded and sent to a remote peer.

Parameters
  • trackOrKind (Union[MediaStreamTrack, str]) – Either a MediaStreamTrack instance or a media kind (‘audio’ or ‘video’).

  • transport – An RTCDtlsTransport.

property track

The MediaStreamTrack which is being handled by the sender.

Return type

MediaStreamTrack

property transport

The RTCDtlsTransport over which media data for the track is transmitted.

classmethod getCapabilities(kind)

Returns the most optimistic view of the system’s capabilities for sending media of the given kind.

Return type

RTCRtpCapabilities

class aiortc.RTCRtpTransceiver(kind, receiver, sender, direction='sendrecv')

The RTCRtpTransceiver interface describes a permanent pairing of an RTCRtpSender and an RTCRtpReceiver, along with some shared state.

property currentDirection

The currently negotiated direction of the transceiver.

One of ‘sendrecv’, ‘sendonly’, ‘recvonly’, ‘inactive’ or None.

Return type

Optional[str]

property direction

The preferred direction of the transceiver, which will be used in RTCPeerConnection.createOffer() and RTCPeerConnection.createAnswer().

One of ‘sendrecv’, ‘sendonly’, ‘recvonly’ or ‘inactive’.

Return type

str

property receiver

The RTCRtpReceiver that handles receiving and decoding incoming media.

Return type

RTCRtpReceiver

property sender

The RTCRtpSender responsible for encoding and sending data to the remote peer.

Return type

RTCRtpSender

setCodecPreferences(codecs)

Override the default codec preferences.

See RTCRtpSender.getCapabilities() and RTCRtpReceiver.getCapabilities() for the supported codecs.

Parameters

codecs (List[RTCRtpCodecCapability]) – A list of RTCRtpCodecCapability, in decreasing order of preference. If empty, restores the default preferences.

Return type

None

class aiortc.RTCRtpSynchronizationSource(timestamp, source)

The RTCRtpSynchronizationSource dictionary contains information about a synchronization source (SSRC).

timestamp: datetime.datetime = None

The timestamp associated with this source.

source: int = None

The SSRC identifier associated with this source.

class aiortc.RTCRtpCapabilities(codecs=<factory>, headerExtensions=<factory>)

The RTCRtpCapabilities dictionary provides information about support codecs and header extensions.

codecs: List[RTCRtpCodecCapability] = None

A list of RTCRtpCodecCapability.

headerExtensions: List[RTCRtpHeaderExtensionCapability] = None

A list of RTCRtpHeaderExtensionCapability.

class aiortc.RTCRtpCodecCapability(mimeType, clockRate, channels=None, parameters=<factory>)

The RTCRtpCodecCapability dictionary provides information on codec capabilities.

mimeType: str = None

The codec MIME media type/subtype, for instance ‘audio/PCMU’.

clockRate: int = None

The codec clock rate expressed in Hertz.

channels: Optional[int] = None

The number of channels supported (e.g. two for stereo).

parameters: OrderedDict = None

Codec-specific parameters available for signaling.

class aiortc.RTCRtpHeaderExtensionCapability(uri)

The RTCRtpHeaderExtensionCapability dictionary provides information on a supported header extension.

uri: str = None

The URI of the RTP header extension.

class aiortc.RTCRtpParameters(codecs=<factory>, headerExtensions=<factory>, muxId='', rtcp=<factory>)

The RTCRtpParameters dictionary describes the configuration of an RTCRtpReceiver or an RTCRtpSender.

codecs: List[RTCRtpCodecParameters] = None

A list of RTCRtpCodecParameters to send or receive.

headerExtensions: List[RTCRtpHeaderExtensionParameters] = None

A list of RTCRtpHeaderExtensionParameters.

muxId: str = ''

The muxId assigned to the RTP stream, if any, empty string if unset.

rtcp: RTCRtcpParameters = None

Parameters to configure RTCP.

class aiortc.RTCRtpCodecParameters(mimeType, clockRate, channels=None, payloadType=None, rtcpFeedback=<factory>, parameters=<factory>)

The RTCRtpCodecParameters dictionary provides information on codec settings.

mimeType: str = None

The codec MIME media type/subtype, for instance ‘audio/PCMU’.

clockRate: int = None

The codec clock rate expressed in Hertz.

channels: Optional[int] = None

The number of channels supported (e.g. two for stereo).

payloadType: Optional[int] = None

The value that goes in the RTP Payload Type Field.

rtcpFeedback: List['RTCRtcpFeedback'] = None

Transport layer and codec-specific feedback messages for this codec.

parameters: OrderedDict = None

Codec-specific parameters available for signaling.

class aiortc.RTCRtcpParameters(cname=None, mux=False, ssrc=None)

The RTCRtcpParameters dictionary provides information on RTCP settings.

cname: Optional[str] = None

The Canonical Name (CNAME) used by RTCP.

mux: bool = False

Whether RTP and RTCP are multiplexed.

ssrc: Optional[int] = None

The Synchronization Source identifier.

Stream Control Transmission Protocol (SCTP)

class aiortc.RTCSctpTransport(transport, port=5000)

The RTCSctpTransport interface includes information relating to Stream Control Transmission Protocol (SCTP) transport.

Parameters

transport (RTCDtlsTransport) – An RTCDtlsTransport.

property maxChannels

The maximum number of :class:`RTCDataChannel`s that can be used simultaneously.

Return type

Optional[int]

property port

The local SCTP port number used for data channels.

Return type

int

property state

The current state of the SCTP transport.

Return type

str

property transport

The RTCDtlsTransport over which SCTP data is transmitted.

classmethod getCapabilities()

Retrieve the capabilities of the transport.

Return type

RTCSctpCapabilities

class State

An enumeration.

class aiortc.RTCSctpCapabilities(maxMessageSize)

The RTCSctpCapabilities dictionary provides information about the capabilities of the RTCSctpTransport.

maxMessageSize: int = None

The maximum size of data that the implementation can send or 0 if the implementation can handle messages of any size.

Data channels

class aiortc.RTCDataChannel(transport, parameters, send_open=True)

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

Parameters
property bufferedAmount

The number of bytes of data currently queued to be sent over the data channel.

Return type

int

property bufferedAmountLowThreshold

The number of bytes of buffered outgoing data that is considered “low”.

Return type

int

property negotiated

Whether data channel was negotiated out-of-band.

Return type

bool

property id

An ID number which uniquely identifies the data channel.

Return type

Optional[int]

property label

A name describing the data channel.

These labels are not required to be unique.

Return type

str

property ordered

Indicates whether or not the data channel guarantees in-order delivery of messages.

Return type

bool

property maxPacketLifeTime

The maximum time in milliseconds during which transmissions are attempted.

Return type

Optional[int]

property maxRetransmits

“The maximum number of retransmissions that are attempted.

Return type

Optional[int]

property protocol

The name of the subprotocol in use.

Return type

str

property readyState

A string indicating the current state of the underlying data transport.

Return type

str

property transport

The RTCSctpTransport over which data is transmitted.

close()

Close the data channel.

Return type

None

send(data)

Send data across the data channel to the remote peer.

Return type

None

class aiortc.RTCDataChannelParameters(label='', maxPacketLifeTime=None, maxRetransmits=None, ordered=True, protocol='', negotiated=False, id=None)

The RTCDataChannelParameters dictionary describes the configuration of an RTCDataChannel.

label: str = ''

A name describing the data channel.

maxPacketLifeTime: Optional[int] = None

The maximum time in milliseconds during which transmissions are attempted.

maxRetransmits: Optional[int] = None

The maximum number of retransmissions that are attempted.

ordered: bool = True

Whether the data channel guarantees in-order delivery of messages.

protocol: str = ''

The name of the subprotocol in use.

negotiated: bool = False

Whether data channel will be negotiated out of-band, where both sides create data channel with an agreed-upon ID.

id: Optional[int] = None

An numeric ID for the channel; permitted values are 0-65534. If you don’t include this option, the user agent will select an ID for you. Must be set when negotiating out-of-band.

Media

class aiortc.MediaStreamTrack

A single media track within a stream.

property id

An automatically generated globally unique ID.

Return type

str

Statistics

class aiortc.RTCStatsReport

Provides statistics data about WebRTC connections as returned by the RTCPeerConnection.getStats(), RTCRtpReceiver.getStats() and RTCRtpSender.getStats() coroutines.

This object consists of a mapping of string identifiers to objects which are instances of:

class aiortc.RTCInboundRtpStreamStats(timestamp, type, id, ssrc, kind, transportId, packetsReceived, packetsLost, jitter)

The RTCInboundRtpStreamStats dictionary represents the measurement metrics for the incoming RTP media stream.

class aiortc.RTCOutboundRtpStreamStats(timestamp, type, id, ssrc, kind, transportId, packetsSent, bytesSent, trackId)

The RTCOutboundRtpStreamStats dictionary represents the measurement metrics for the outgoing RTP stream.

class aiortc.RTCRemoteInboundRtpStreamStats(timestamp, type, id, ssrc, kind, transportId, packetsReceived, packetsLost, jitter, roundTripTime, fractionLost)

The RTCRemoteInboundRtpStreamStats dictionary represents the remote endpoint’s measurement metrics for a particular incoming RTP stream.

class aiortc.RTCRemoteOutboundRtpStreamStats(timestamp, type, id, ssrc, kind, transportId, packetsSent, bytesSent, remoteTimestamp=None)

The RTCRemoteOutboundRtpStreamStats dictionary represents the remote endpoint’s measurement metrics for its outgoing RTP stream.

class aiortc.RTCTransportStats(timestamp, type, id, packetsSent, packetsReceived, bytesSent, bytesReceived, iceRole, dtlsState)

RTCTransportStats(timestamp: datetime.datetime, type: str, id: str, packetsSent: int, packetsReceived: int, bytesSent: int, bytesReceived: int, iceRole: str, dtlsState: str)

packetsSent: int = None

Total number of packets sent over this transport.

packetsReceived: int = None

Total number of packets received over this transport.

bytesSent: int = None

Total number of bytes sent over this transport.

bytesReceived: int = None

Total number of bytes received over this transport.

iceRole: str = None

The current value of RTCIceTransport.role.

dtlsState: str = None

The current value of RTCDtlsTransport.state.