Share via


RTCRtpReceiver object

[Some information relates to pre-released product which may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.]

Exposes information relating to the RTP receiver.

Microsoft Edgerequires kind to be set in the constructor so as to allow a newly constructed RTCRtpReceiver to be used with an audio or video tag immediately, rather than having to wait until receive() is called for the value of kind to be determined.

Overview

An RTCRtpReceiver instance is associated to a receiving MediaStreamTrack and provides RTC related methods to it. Microsoft Edge requires kind to be set in the constructor so as to allow a newly constructed RTCRtpReceiver to be used with an audio or video tag immediately, rather than having to wait until receive() is called for the value of kind to be determined.

Note  Edge Interop Note: The Microsoft Edge ORTC API implementation requires use of RTP/RTCP multiplexing with RTCDtlsTransport objects. Therefore only a single RTCDtlsTransport instance can be associated to an RTCRtpReceiver instance. RTP/RTCP non-mux is supported for RTCSrtpSdesTransport objects. Only a single RTCSrtpSdesTransport object is required to handle both RTP and RTCP.

 

Operation

A RTCRtpReceiver instance is constructed from an RTCDtlsTransport object or an RTCSrtpSdesTransport object. If an attempt is made to construct an RTCRtpReceiver object with transport.state or rtcpTransport.state "closed", throw an InvalidStateError exception.

Syntax

[Constructor(RTCTransport transport, DOMString kind)]
interface RTCRtpReceiver : RTCStatsProvider {
    readonly    attribute MediaStreamTrack? track;
    readonly    attribute RTCTransport      transport;
    void                               setTransport (RTCTransport transport);
    static RTCRtpCapabilities          getCapabilities (optional DOMString kind);
    sequence<RTCRtpContributingSource> getContributingSources ();
    void                               receive (RTCRtpParameters parameters);
    void                               stop ();
                attribute EventHandler?     onerror;
};

Members

The RTCRtpReceiver object has these types of members:

  • Methods
  • Properties

Methods

The RTCRtpReceiver object has these methods.

Method Description
getCapabilities

Obtain the receiver capabilities, based on kind.

getContributingSources

Retrieve the sequence of contributing sources.

receive

The associated parameters controlling the media to be received.

setTransport

Set the transport (either an RTCDtlsTransport or an RTCSrtpSdesTransport).

stop (RTCRtpReceiver)

Stops receiving the track on the wire.

 

Properties

The RTCRtpReceiver object has these properties.

Property Access type Description

onerror

Fires if an issue is found with the RTCRtpParameters object passed to receive()

track

Read-only

The associated MediaStreamTrack instance.

transport

Read-only

The associated transport (either an RTCDtlsTransport or an RTCSrtpSdesTransport) instance.

 

Standards information

Example

// Assume we already have a way to signal, a transport
// (RTCDtlsTransport), and audio and video tracks. This is an example
// of  how to offer them  and get back an answer with audio and
// video tracks, and begin sending and receiving them.
// The example assumes that RTP and RTCP are multiplexed. 
function myInitiate(mySignaller, transport, audioTrack, videoTrack) {
  var audioSender = new RTCRtpSender(audioTrack, transport);
  var videoSender = new RTCRtpSender(videoTrack, transport);
  var audioReceiver = new RTCRtpReceiver(transport, 'audio');
  var videoReceiver = new RTCRtpReceiver(transport, 'video');

// Retrieve the audio and video receiver capabilities
  var recvAudioCaps = RTCRtpReceiver.getCapabilities('audio');
  var recvVideoCaps = RTCRtpReceiver.getCapabilities('video');   
// Retrieve the audio and video sender capabilities
  var sendAudioCaps = RTCRtpSender.getCapabilities('audio'); 
  var sendVideoCaps = RTCRtpSender.getCapabilities('video'); 

  mySignaller.myOfferTracks({
    // The initiator offers its receiver and sender capabilities. 
    "recvAudioCaps": recvAudioCaps, 
    "recvVideoCaps": recvVideoCaps,
    "sendAudioCaps": sendAudioCaps,
    "sendVideoCaps": sendVideoCaps 
  }, function(answer) {
    // The responder answers with its receiver capabilities

    // Derive the send and receive parameters
    var audioSendParams = myCapsToSendParams(sendAudioCaps, answer.recvAudioCaps); 
    var videoSendParams = myCapsToSendParams(sendVideoCaps, answer.recvVideoCaps); 
    var audioRecvParams = myCapsToRecvParams(recvAudioCaps, answer.sendAudioCaps);
    var videoRecvParams = myCapsToRecvParams(recvVideoCaps, answer.sendVideoCaps); 
    audioSender.send(audioSendParams);
    videoSender.send(videoSendParams);
    audioReceiver.receive(audioRecvParams);
    videoReceiver.receive(videoRecvParams);

    // Now we can render/play
    // audioReceiver.track and videoReceiver.track.
  });
}

Example

// Assume we already have a way to signal, a transport (RTCDtlsTransport)
// and audio and video tracks. This is an example of how to answer an
// offer with audio and video tracks, and begin sending and receiving them. 
// The example assumes that RTP and RTCP are multiplexed. 
function myAccept(mySignaller, remote, transport, audioTrack, videoTrack) {
  var audioSender = new RTCRtpSender(audioTrack, transport);
  var videoSender = new RTCRtpSender(videoTrack, transport);
  var audioReceiver = new RTCRtpReceiver(transport, 'audio');
  var videoReceiver = new RTCRtpReceiver(transport, 'video');

// Retrieve the send and receive capabilities
  var recvAudioCaps = RTCRtpReceiver.getCapabilities('audio');
  var recvVideoCaps = RTCRtpReceiver.getCapabilities('video');
  var sendAudioCaps = RTCRtpSender.getCapabilities('audio'); 
  var sendVideoCaps = RTCRtpSender.getCapabilities('video'); 

  mySignaller.myAnswerTracks({
    "recvAudioCaps": recvAudioCaps,
    "recvVideoCaps": recvVideoCaps,
    "sendAudioCaps": sendAudioCaps,
    "sendVideoCaps": sendVideoCaps
  });

    // Derive the send and receive parameters using Javascript functions defined in Section 17.2.
    var audioSendParams = myCapsToSendParams(sendAudioCaps, remote.recvAudioCaps);
    var videoSendParams = myCapsToSendParams(sendVideoCaps, remote.recvVideoCaps);
    var audioRecvParams = myCapsToRecvParams(recvAudioCaps, remote.sendAudioCaps);
    var videoRecvParams = myCapsToRecvParams(recvVideoCaps, remote.sendVideoCaps);
    audioSender.send(audioSendParams);
    videoSender.send(videoSendParams);
    audioReceiver.receive(audioRecvParams);
    videoReceiver.receive(videoRecvParams);

  // Now we can render/play
  // audioReceiver.track and videoReceiver.track.
}