大网数据广告活动
Web 标准与前端开发

RTCSessionDescription: RTCSessionDescription() constructor

· 52CE 我爱测

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

WebRTC

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 RTCSessionDescription.type and RTCSessionDescription.sdp properties, so you don't have to instantiate an RTCSessionDescription yourself.

Syntax

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
        • : 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.

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

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。