RTCRtpTransceiver

The pair of a sender and a receiver that share a media section of the SDP.

class webrtc.interfaces.rtc_rtp_transceiver.RTCRtpTransceiver(native_obj=None)

A sender and a receiver that share one media section of the SDP, with its direction and codecs.

Created by webrtc.RTCPeerConnection.add_transceiver(), webrtc.RTCPeerConnection.add_track() and remote offers, and listed by webrtc.RTCPeerConnection.get_transceivers(). See MDN: RTCRtpTransceiver.

property mid: str | None

The media ID (a=mid) of the media section of the transceiver.

None until a description with the section is set. See MDN: RTCRtpTransceiver/mid.

Type:

str, optional

property receiver: RTCRtpReceiver

Receives and decodes the media of the transceiver. It’s always the same object.

See MDN: RTCRtpTransceiver/receiver.

Type:

webrtc.RTCRtpReceiver

property sender: RTCRtpSender

Encodes and sends the media of the transceiver. It’s always the same object.

See MDN: RTCRtpTransceiver/sender.

Type:

webrtc.RTCRtpSender

property stopped: bool

Whether the transceiver was stopped, by stop() or by a negotiation.

See MDN: RTCRtpTransceiver/stopped.

Type:

bool

property direction: RTCRtpTransceiverDirection

The preferred direction, which the next negotiation offers.

It can be set with a member or its value. A change leads to a negotiationneeded event, and the negotiated direction is current_direction. Setting it on a stopped transceiver raises webrtc.InvalidStateError. Setting it to stopped raises TypeError, so use stop() for that. See MDN: RTCRtpTransceiver/direction.

Type:

webrtc.RTCRtpTransceiverDirection

property current_direction: RTCRtpTransceiverDirection | None

The direction of the last negotiation.

None until the transceiver is negotiated. See MDN: RTCRtpTransceiver/currentDirection.

Type:

webrtc.RTCRtpTransceiverDirection, optional

stop()

Stops the transceiver for good. Its sender stops sending and the track of its receiver ends.

The next negotiation removes its media section. See MDN: RTCRtpTransceiver/stop.

Raises:

webrtc.InvalidStateError – If the connection is closed.

set_codec_preferences(codecs)

Sets the codecs to negotiate, in order of preference, from the next negotiation.

Codecs are matched to the supported ones by MIME type, clock rate, channels and SDP format parameters. See MDN: RTCRtpTransceiver/setCodecPreferences.

Parameters:

codecs (list of webrtc.RTCRtpCodec) – Codecs from the capabilities of webrtc.RTCRtpSender.get_capabilities() or webrtc.RTCRtpReceiver.get_capabilities() for the kind of the transceiver. An empty list restores the default preferences.

Raises:

webrtc.InvalidModificationError – If a codec isn’t supported, or only resiliency codecs (like RTX or FEC) are given.

get_header_extensions_to_negotiate()

Returns the header extensions offered or accepted in the next negotiation.

Returns:

list of webrtc.RTCRtpHeaderExtensionCapability – The extensions and the direction each one is negotiated in. The ones that aren’t negotiated have webrtc.RTCRtpTransceiverDirection.stopped.

Return type:

list[RTCRtpHeaderExtensionCapability]

set_header_extensions_to_negotiate(extensions)

Changes the directions the header extensions are negotiated in, from the next negotiation.

Parameters:

extensions (list of webrtc.RTCRtpHeaderExtensionCapability) – The list get_header_extensions_to_negotiate() returns, with directions changed.

Raises:
get_negotiated_header_extensions()

Returns the header extensions negotiated last, and their directions.

Returns:

list of webrtc.RTCRtpHeaderExtensionCapability – Every extension that can be negotiated. The ones that weren’t negotiated have webrtc.RTCRtpTransceiverDirection.stopped.

Return type:

list[RTCRtpHeaderExtensionCapability]