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

RTCPeerConnection.setRemoteDescription()

· 52CE 我爱测

`RTCPeerConnection.setRemoteDescription()`** 方法改变与连接相关的描述,该描述主要是描述有些关于连接的属性,例如对端使用的解码器。连接受此更改影响,并且必须能够支持旧的和新的描述。方法带三个参数,RTCSessionDescription 对象用于设置,然后是更改成功的回调方法,一个是更改失败的回调方法。

WebRTC

RTCPeerConnection.setRemoteDescription() 方法改变与连接相关的描述,该描述主要是描述有些关于连接的属性,例如对端使用的解码器。连接受此更改影响,并且必须能够支持旧的和新的描述。方法带三个参数,RTCSessionDescription 对象用于设置,然后是更改成功的回调方法,一个是更改失败的回调方法。

方法是异步的,不用等待设置完成,成功会调用成功回调方法,失败则会调用错误回调方法。

连接的 offer 通常来自于负责匹配的服务器所发送的数据。执行者应调用此方法设置远程描述,然后生成发送到对端计算机的 answer。

语法

aPromise = pc.setRemoteDescription(sessionDescription);

pc.setRemoteDescription(sessionDescription, successCallback, errorCallback);

这个方法没有返回值。

参数

  • sessionDescription
    • : Is a String is the description of the parameters to be applied to the remote session.
  • successCallback
    • : Is a Function without parameter which will be called when the description has been successfully set. At this point, one can send the offer to a remote server that can forward it to a remote client
  • errorCallback
    • : Is a RTCPeerConnectionErrorCallback which will be called if the description can't be set. It takes the following parameter:
      • errorInformation which is a String describing the reason why the description has not been set.

Example

var pc = new PeerConnection();
pc.setRemoteDescription(new RTCSessionDescription(offer), function () {
  pc.createAnswer(function (answer) {
    pc.setLocalDescription(answer, function () {
      // send the answer to the remote connection
    });
  });
});

规范

浏览器兼容性

参见

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

资料来源与适用范围

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

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

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