API Reference¶
WebRTC¶
- class aiortc.RTCPeerConnection(configuration=None)¶
The
RTCPeerConnectioninterface represents a WebRTC connection between the local computer and a remote peer.
- Parameters:
configuration (
Optional[RTCConfiguration]) – An optionalRTCConfiguration.
- property connectionState: str¶
The current connection state.
Possible values: “connected”, “connecting”, “closed”, “failed”, “new”.
When the state changes, the “connectionstatechange” event is fired.
- property iceConnectionState: str¶
The current ICE connection state.
Possible values: “checking”, “completed”, “closed”, “failed”, “new”.
When the state changes, the “iceconnectionstatechange” event is fired.
- property iceGatheringState: str¶
The current ICE gathering state.
Possible values: “complete”, “gathering”, “new”.
When the state changes, the “icegatheringstatechange” event is fired.
- property localDescription: RTCSessionDescription¶
An
RTCSessionDescriptiondescribing the session for the local end of the connection.
- property remoteDescription: RTCSessionDescription¶
An
RTCSessionDescriptiondescribing the session for the remote end of the connection.
- property sctp: RTCSctpTransport | None¶
An
RTCSctpTransportdescribing the SCTP transport being used for datachannels or None.
- property signalingState: str¶
The current signaling state.
Possible values: “closed”, “have-local-offer”, “have-remote-offer”, “stable”.
When the state changes, the “signalingstatechange” event is fired.
- await addIceCandidate(candidate)¶
Add a new
RTCIceCandidatereceived from the remote peer.The specified candidate must have a value for either sdpMid or sdpMLineIndex.
- Parameters:
candidate (
Optional[RTCIceCandidate]) – The new remote candidate or None to signal end-of-candidates.- Return type:
- addTrack(track)¶
Add a
MediaStreamTrackto the set of media tracks which will be transmitted to the remote peer.
- Return type:
- addTransceiver(trackOrKind, direction='sendrecv')¶
Add a new
RTCRtpTransceiver.
- Return type:
- await createAnswer()¶
Create an SDP answer to an offer received from a remote peer during the offer/answer negotiation of a WebRTC connection.
- Return type:
- createDataChannel(label, maxPacketLifeTime=None, maxRetransmits=None, ordered=True, protocol='', negotiated=False, id=None)¶
Create a data channel with the given label.
- Return type:
- await createOffer()¶
Create an SDP offer for the purpose of starting a new WebRTC connection to a remote peer.
- Return type:
- getReceivers()¶
Returns the list of
RTCRtpReceiverobjects that are currently attached to the connection.
- Return type:
- getSenders()¶
Returns the list of
RTCRtpSenderobjects that are currently attached to the connection.
- Return type:
- await getStats()¶
Returns statistics for the connection.
- Return type:
- getTransceivers()¶
Returns the list of
RTCRtpTransceiverobjects that are currently attached to the connection.
- Return type:
- await setLocalDescription(sessionDescription=None)¶
Change the local description associated with the connection.
- Parameters:
sessionDescription (
Optional[RTCSessionDescription]) – AnRTCSessionDescriptiongenerated bycreateOffer()orcreateAnswer()or None to implicitly create an offer or create an answer, as needed.- Return type:
- await setRemoteDescription(sessionDescription)¶
Changes the remote description associated with the connection.
- Parameters:
sessionDescription (
RTCSessionDescription) – AnRTCSessionDescriptioncreated from information received over the signaling channel.- Return type:
- class aiortc.RTCSessionDescription(sdp, type)¶
The
RTCSessionDescriptiondictionary describes one end of a connection and how it’s configured.
- class aiortc.RTCBundlePolicy¶
The
RTCBundlePolicyaffects which media tracks are negotiated if the remote endpoint is not bundle-aware, and what ICE candidates are gathered.See https://w3c.github.io/webrtc-pc/#rtcbundlepolicy-enum
- BALANCED = 'balanced'¶
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.
- MAX_COMPAT = 'max-compat'¶
Gather ICE candidates for each track. If the remote endpoint is not bundle-aware, negotiate all media tracks on separate transports.
- MAX_BUNDLE = 'max-bundle'¶
Gather ICE candidates for only one track. If the remote endpoint is not bundle-aware, negotiate only one media track.
- class aiortc.RTCConfiguration(iceServers=None, bundlePolicy=RTCBundlePolicy.BALANCED)¶
The
RTCConfigurationdictionary is used to provide configuration options for anRTCPeerConnection.
- iceServers:
Optional[list[RTCIceServer]] = None¶A list of
RTCIceServerobjects to configure STUN / TURN servers.
- bundlePolicy:
RTCBundlePolicy= 'balanced'¶The media-bundling policy to use when gathering ICE candidates.
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
RTCIceCandidateinterface represents a candidate Interactive Connectivity Establishment (ICE) configuration which may be used to establish an RTCPeerConnection.
- class aiortc.RTCIceGatherer(iceServers=None, local_username=None, local_password=None)¶
The
RTCIceGathererinterface 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.
- classmethod getDefaultIceServers()¶
Return the list of default
RTCIceServer.
- Return type:
- getLocalCandidates()¶
Retrieve the list of valid local candidates associated with the ICE gatherer.
- Return type:
- getLocalParameters()¶
Retrieve the ICE parameters of the ICE gatherer.
- Return type:
- class aiortc.RTCIceTransport(gatherer)¶
The
RTCIceTransportinterface allows an application access to information about the Interactive Connectivity Establishment (ICE) transport over which packets are sent and received.
- Parameters:
gatherer (
RTCIceGatherer) – AnRTCIceGatherer.
- property iceGatherer: RTCIceGatherer¶
The ICE gatherer passed in the constructor.
- await addRemoteCandidate(candidate)¶
Add a remote candidate.
- Parameters:
candidate (
Optional[RTCIceCandidate]) – The new candidate or None to signal end of candidates.- Return type:
- getRemoteCandidates()¶
Retrieve the list of candidates associated with the remote
RTCIceTransport.
- Return type:
- await start(remoteParameters)¶
Initiate connectivity checks.
- Parameters:
remoteParameters (
RTCIceParameters) – TheRTCIceParametersassociated with the remoteRTCIceTransport.- Return type:
- await stop()¶
Irreversibly stop the
RTCIceTransport.
- Return type:
- class aiortc.RTCIceParameters(usernameFragment=None, password=None, iceLite=False)¶
The
RTCIceParametersdictionary includes the ICE username fragment and password and other ICE-related parameters.
- class aiortc.RTCIceServer(urls, username=None, credential=None, credentialType='password')¶
The
RTCIceServerdictionary 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.
Datagram Transport Layer Security (DTLS)¶
- class aiortc.RTCCertificate(key, cert)¶
The
RTCCertificateinterface enables the certificates used by anRTCDtlsTransport.To generate a certificate and the corresponding private key use
generateCertificate().
- property expires: datetime¶
The date and time after which the certificate will be considered invalid.
- getFingerprints()¶
Returns the list of certificate fingerprints, one of which is computed with the digest algorithm used in the certificate signature.
- Return type:
- classmethod generateCertificate()¶
Create and return an X.509 certificate and corresponding private key.
- Return type:
- class aiortc.RTCDtlsTransport(transport, certificates)¶
The
RTCDtlsTransportobject includes information relating to Datagram Transport Layer Security (DTLS) transport.
- Parameters:
transport (
RTCIceTransport) – AnRTCIceTransport.certificates (
list[RTCCertificate]) – A list ofRTCCertificate(only one is allowed currently).
- property state: str¶
The current state of the DTLS transport.
One of ‘new’, ‘connecting’, ‘connected’, ‘closed’ or ‘failed’.
- property transport: RTCIceTransport¶
The associated
RTCIceTransportinstance.
- getLocalParameters()¶
Get the local parameters of the DTLS transport.
- Return type:
- await start(remoteParameters)¶
Start DTLS transport negotiation with the parameters of the remote DTLS transport.
- Parameters:
remoteParameters (
RTCDtlsParameters) – AnRTCDtlsParameters.- Return type:
- class aiortc.RTCDtlsParameters(fingerprints=<factory>, role='auto')¶
The
RTCDtlsParametersdictionary includes information relating to DTLS configuration.
- fingerprints:
list[RTCDtlsFingerprint]¶List of
RTCDtlsFingerprint, one fingerprint for each certificate.
Real-time Transport Protocol (RTP)¶
- class aiortc.RTCRtpReceiver(kind, transport)¶
The
RTCRtpReceiverinterface manages the reception and decoding of data for aMediaStreamTrack.
- Parameters:
kind (
str) – The kind of media (‘audio’ or ‘video’).transport (
RTCDtlsTransport) – AnRTCDtlsTransport.
- property track: MediaStreamTrack¶
The
MediaStreamTrackwhich is being handled by the receiver.
- property transport: RTCDtlsTransport¶
The
RTCDtlsTransportover which the media for the receiver’s track is received.
- classmethod getCapabilities(kind)¶
Returns the most optimistic view of the system’s capabilities for receiving media of the given kind.
- Return type:
- await getStats()¶
Returns statistics about the RTP receiver.
- Return type:
- getSynchronizationSources()¶
Returns a
RTCRtpSynchronizationSourcefor each unique SSRC identifier received in the last 10 seconds.
- Return type:
- await receive(parameters)¶
Attempt to set the parameters controlling the receiving of media.
- Parameters:
parameters (
RTCRtpReceiveParameters) – TheRTCRtpParametersfor the receiver.- Return type:
- class aiortc.RTCRtpSender(trackOrKind, transport)¶
The
RTCRtpSenderinterface provides the ability to control and obtain details about how a particularMediaStreamTrackis encoded and sent to a remote peer.
- Parameters:
trackOrKind (
Union[MediaStreamTrack,str]) – Either aMediaStreamTrackinstance or a media kind (‘audio’ or ‘video’).transport (
RTCDtlsTransport) – AnRTCDtlsTransport.
- property track: MediaStreamTrack¶
The
MediaStreamTrackwhich is being handled by the sender.
- property transport: RTCDtlsTransport¶
The
RTCDtlsTransportover 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:
- await getStats()¶
Returns statistics about the RTP sender.
- Return type:
- await send(parameters)¶
Attempt to set the parameters controlling the sending of media.
- Parameters:
parameters (
RTCRtpSendParameters) – TheRTCRtpSendParametersfor the sender.- Return type:
- class aiortc.RTCRtpTransceiver(kind, receiver, sender, direction='sendrecv')¶
The RTCRtpTransceiver interface describes a permanent pairing of an
RTCRtpSenderand anRTCRtpReceiver, along with some shared state.
- property currentDirection: str | None¶
The currently negotiated direction of the transceiver.
One of ‘sendrecv’, ‘sendonly’, ‘recvonly’, ‘inactive’ or None.
- property direction: str¶
The preferred direction of the transceiver, which will be used in
RTCPeerConnection.createOffer()andRTCPeerConnection.createAnswer().One of ‘sendrecv’, ‘sendonly’, ‘recvonly’ or ‘inactive’.
- property receiver: RTCRtpReceiver¶
The
RTCRtpReceiverthat handles receiving and decoding incoming media.
- property sender: RTCRtpSender¶
The
RTCRtpSenderresponsible for encoding and sending data to the remote peer.
- setCodecPreferences(codecs)¶
Override the default codec preferences.
See
RTCRtpSender.getCapabilities()andRTCRtpReceiver.getCapabilities()for the supported codecs.
- Parameters:
codecs (
list[RTCRtpCodecCapability]) – A list ofRTCRtpCodecCapability, in decreasing order of preference. If empty, restores the default preferences.- Return type:
- await stop()¶
Permanently stops the
RTCRtpTransceiver.
- Return type:
- class aiortc.RTCRtpSynchronizationSource(timestamp, source)¶
The
RTCRtpSynchronizationSourcedictionary contains information about a synchronization source (SSRC).
- class aiortc.RTCRtpCapabilities(codecs=<factory>, headerExtensions=<factory>)¶
The
RTCRtpCapabilitiesdictionary provides information about support codecs and header extensions.
- codecs:
list[RTCRtpCodecCapability]¶A list of
RTCRtpCodecCapability.
- headerExtensions:
list[RTCRtpHeaderExtensionCapability]¶A list of
RTCRtpHeaderExtensionCapability.
- class aiortc.RTCRtpCodecCapability(mimeType, clockRate, channels=None, parameters=<factory>)¶
The
RTCRtpCodecCapabilitydictionary provides information on codec capabilities.
- class aiortc.RTCRtpHeaderExtensionCapability(uri)¶
The
RTCRtpHeaderExtensionCapabilitydictionary provides information on a supported header extension.
- class aiortc.RTCRtpParameters(codecs=<factory>, headerExtensions=<factory>, muxId='', rtcp=<factory>)¶
The
RTCRtpParametersdictionary describes the configuration of anRTCRtpReceiveror anRTCRtpSender.
- codecs:
list[RTCRtpCodecParameters]¶A list of
RTCRtpCodecParametersto send or receive.
- rtcp:
RTCRtcpParameters¶Parameters to configure RTCP.
- class aiortc.RTCRtpCodecParameters(mimeType, clockRate, channels=None, payloadType=None, rtcpFeedback=<factory>, parameters=<factory>)¶
The
RTCRtpCodecParametersdictionary provides information on codec settings.
- class aiortc.RTCRtcpParameters(cname=None, mux=False, ssrc=None)¶
The
RTCRtcpParametersdictionary provides information on RTCP settings.
Stream Control Transmission Protocol (SCTP)¶
- class aiortc.RTCSctpTransport(transport, port=5000)¶
The
RTCSctpTransportinterface includes information relating to Stream Control Transmission Protocol (SCTP) transport.
- Parameters:
transport (
RTCDtlsTransport) – AnRTCDtlsTransport.
- property maxChannels: int | None¶
The maximum number of
RTCDataChannelthat can be used simultaneously.
- property transport: RTCDtlsTransport¶
The
RTCDtlsTransportover which SCTP data is transmitted.
- classmethod getCapabilities()¶
Retrieve the capabilities of the transport.
- Return type:
- class State(value)¶
- class aiortc.RTCSctpCapabilities(maxMessageSize)¶
The
RTCSctpCapabilitiesdictionary provides information about the capabilities of theRTCSctpTransport.
Data channels¶
- class aiortc.RTCDataChannel(transport, parameters, send_open=True)¶
The
RTCDataChannelinterface represents a network channel which can be used for bidirectional peer-to-peer transfers of arbitrary data.
- Parameters:
transport (
RTCSctpTransport) – AnRTCSctpTransport.parameters (
RTCDataChannelParameters) – AnRTCDataChannelParameters.
- property bufferedAmount: int¶
The number of bytes of data currently queued to be sent over the data channel.
- property bufferedAmountLowThreshold: int¶
The number of bytes of buffered outgoing data that is considered “low”.
- property label: str¶
A name describing the data channel.
These labels are not required to be unique.
- property ordered: bool¶
Indicates whether or not the data channel guarantees in-order delivery of messages.
- property maxPacketLifeTime: int | None¶
The maximum time in milliseconds during which transmissions are attempted.
- property transport: RTCSctpTransport¶
The
RTCSctpTransportover which data is transmitted.
- class aiortc.RTCDataChannelParameters(label='', maxPacketLifeTime=None, maxRetransmits=None, ordered=True, protocol='', negotiated=False, id=None)¶
The
RTCDataChannelParametersdictionary describes the configuration of anRTCDataChannel.
- maxPacketLifeTime:
Optional[int] = None¶The maximum time in milliseconds during which transmissions are attempted.
Media¶
- class aiortc.MediaStreamTrack¶
A single media track within a stream.
- abstractmethod await recv()¶
Receive the next
AudioFrame,VideoFrameorPacket
Statistics¶
- class aiortc.RTCStatsReport¶
Provides statistics data about WebRTC connections as returned by the
RTCPeerConnection.getStats(),RTCRtpReceiver.getStats()andRTCRtpSender.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
RTCInboundRtpStreamStatsdictionary represents the measurement metrics for the incoming RTP media stream.
- class aiortc.RTCOutboundRtpStreamStats(timestamp, type, id, ssrc, kind, transportId, packetsSent, bytesSent, trackId)¶
The
RTCOutboundRtpStreamStatsdictionary represents the measurement metrics for the outgoing RTP stream.
- class aiortc.RTCRemoteInboundRtpStreamStats(timestamp, type, id, ssrc, kind, transportId, packetsReceived, packetsLost, jitter, roundTripTime, fractionLost)¶
The
RTCRemoteInboundRtpStreamStatsdictionary 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
RTCRemoteOutboundRtpStreamStatsdictionary 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)
- iceRole:
str¶The current value of
RTCIceTransport.role.
- dtlsState:
str¶The current value of
RTCDtlsTransport.state.