RTCPeerConnection: getSenders() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

The getSenders() method of the RTCPeerConnection interface returns an array of RTCRtpSender objects, each of which represents the RTP sender responsible for transmitting one track's data. A sender object provides methods and properties for examining and controlling the encoding and transmission of the track's data.

Syntax

js
getSenders()

Return value

An array of RTCRtpSender objects, one for each track on the connection. The array is empty if there are no RTP senders on the connection.

The order of the returned RTCRtpSender instances is not defined by the specification, and may change from one call to getSenders() to the next.

The array does not include senders associated with transceivers that have been stopped (following offer/answer).

Example

In this example, a setMuting() function is shown. This function takes as input an RTCPeerConnection, pc, and a Boolean, muting. The function gets the list of the peer connection's senders and iterates over every sender, setting the corresponding media track's enabled to the inverse of the specified muting.

js
function setMuting(pc, muting) {
  let senderList = pc.getSenders();

  senderList.forEach((sender) => {
    sender.track.enabled = !muting;
  });
}

Specifications

Specification
WebRTC: Real-Time Communication in Browsers
# dom-peerconnection-getsenders

Browser compatibility

BCD tables only load in the browser

See also