RTCRtpSender

The sender that encodes and sends the media of a track.

class webrtc.interfaces.rtc_rtp_sender.RTCRtpSender(native_obj=None)

Encodes the media of a track and sends it to the remote peer, and controls how it’s sent.

Each webrtc.RTCRtpTransceiver of an webrtc.RTCPeerConnection has one.

See MDN: RTCRtpSender.

property track: MediaStreamTrack | None

The track being sent, or None if nothing is.

Change it with replace_track().

See MDN: RTCRtpSender/track.

Type:

webrtc.MediaStreamTrack, optional

property transport: RTCDtlsTransport | None

The transport the packets go over.

It’s None until there’s one. See MDN: RTCRtpSender/transport.

Type:

webrtc.RTCDtlsTransport, optional

property dtmf: RTCDTMFSender | None

Sends DTMF tones, or is None for a video sender.

See MDN: RTCRtpSender/dtmf.

Type:

webrtc.RTCDTMFSender, optional

property transform: RTCRtpScriptTransform | RTCRtpSFrameEncryptor | None

The frame transform.

It changes the encoded frames before they’re sent. With None, frames are sent as encoded. A transform serves one sender or receiver for its lifetime, so once attached it can’t be set elsewhere.

See MDN: RTCRtpSender/transform.

Raises:
Type:

webrtc.RTCRtpScriptTransform or webrtc.RTCRtpSFrameEncryptor, optional

get_parameters()

Returns the parameters the sender sends with.

To change them, modify the result and pass it to set_parameters(), which takes the last ones returned until it succeeds. A later task of the event loop gets new ones. Video encodings without scale_resolution_down_by get the effective value filled in.

See MDN: RTCRtpSender/getParameters.

Returns:

webrtc.RTCRtpSendParameters – The parameters, with a new transaction_id.

Return type:

RTCRtpSendParameters

async set_parameters(parameters, set_parameter_options=None)

Changes the encodings and the degradation preference the sender sends with.

See MDN: RTCRtpSender/setParameters.

Parameters:
Raises:
  • webrtc.InvalidStateError – If get_parameters() wasn’t called since parameters were last set, or the transceiver of the sender is stopped.

  • webrtc.InvalidModificationError – If the transaction_id, the codecs, the header extensions, the RTCP parameters, the number of encodings or their rid changed, the codec of an encoding isn’t negotiated, or encoding_options isn’t empty or one per encoding.

  • webrtc.InvalidRangeError – If a value is out of range, like scale_resolution_down_by below 1.

  • TypeError – If max_bitrate isn’t an unsigned 32-bit integer, or a video value isn’t a finite number.

async replace_track(with_track)

Replaces the track the sender sends, without renegotiating.

It runs in the operations chain of the connection, after the operations queued before it (like setting a description), and never before the calling code continues.

See MDN: RTCRtpSender/replaceTrack.

Parameters:

with_track (webrtc.MediaStreamTrack, optional) – The new track of the same kind, or None to stop sending.

Raises:
set_streams(*streams)

Sets the streams the remote peer puts the track of the sender in, from the next negotiation.

Repeated streams count once.

See MDN: RTCRtpSender/setStreams.

Parameters:

*streams (webrtc.MediaStream) – The streams. Pass none to put the track in no stream.

static get_capabilities(kind)

Returns the codecs and header extensions senders of a kind support.

See MDN: RTCRtpSender/getCapabilities_static.

Parameters:

kind (webrtc.MediaType) – Audio or video.

Returns:

webrtc.RTCRtpCapabilities, optional – The capabilities, or None for another kind.

Return type:

RTCRtpCapabilities | None

async get_stats()

Collects the stats of the sender and of the objects they refer to.

See MDN: RTCRtpSender/getStats.

Returns:

webrtc.RTCStatsReport – The stats.

Raises:

webrtc.InvalidStateError – If the connection is closed.

Return type:

RTCStatsReport