RTCSessionDescription: RTCSessionDescription() constructor

Deprecated

Avoid using this feature in new projects. This feature may be a candidate for removal from web standards or browsers.

The RTCSessionDescription() constructor creates a new RTCSessionDescription with its properties initialized as described in the specified object.

Note: This constructor has been deprecated because RTCPeerConnection.setLocalDescription() and other methods which take SDP as input now directly accept an object containing the type and sdp properties, so you don't have to instantiate an RTCSessionDescription yourself.

Syntax

js
new RTCSessionDescription(options)

Values

options

An object providing the default values for the session description. It should contain the following properties:

type

Required. A string which is used to set the type property of the new RTCSessionDescription object. Must be one of the valid RTCSessionDescription.type values.

sdp Optional

A string containing a SDP message describing the session. This value is an empty string ("") by default and may not be null.

Example

This example uses the constructor to convert an SDP offer into an RTCSessionDescription object.

Note: This is no longer necessary, however; RTCPeerConnection.setLocalDescription() and other methods which take SDP as input now directly accept plain objects, so you don't have to instantiate an RTCSessionDescription yourself.

js
navigator.getUserMedia({ video: true }, (stream) => {
  pc.onaddstream({ stream });
  // Adding a local stream won't trigger the onaddstream callback
  pc.addStream(stream);

  pc.createOffer((offer) => {
    pc.setLocalDescription(
      new RTCSessionDescription(offer),
      () => {
        // send the offer to a server to be forwarded to the friend you're calling.
      },
      error,
    );
  }, error);
});

Specifications

Specification
WebRTC: Real-Time Communication in Browsers
# dom-sessiondescription

Browser compatibility

See also