RTCSessionDescription
RTCSessionDescription 接口描述了连接(或潜在连接)的一端及其配置方式。每个 RTCSessionDescription 包含一个描述 type(指示其在 offer/answer 协商过程中的作用)以及会话的 SDP 描述符。
两个对等方之间协商连接的过程涉及来回交换 RTCSessionDescription 对象,每个描述都建议发送者支持的一种连接配置选项组合。一旦两个对等方就连接配置达成一致,协商即完成。
构造函数
RTCSessionDescription()已弃用-
通过指定
type和sdp来创建一个新的RTCSessionDescription。所有接受RTCSessionDescription对象的函数也都接受具有相同属性的对象,因此您可以使用一个普通对象代替创建RTCSessionDescription实例。
实例属性
RTCSessionDescription 接口不继承任何属性。
RTCSessionDescription.type只读-
一个枚举,描述会话描述的类型。
RTCSessionDescription.sdp只读-
一个包含描述会话的 SDP 的字符串。
实例方法
RTCSessionDescription 不继承任何方法。
RTCSessionDescription.toJSON()-
返回对象的 JSON 描述。生成的 JSON 中包含
type和sdp这两个属性的值。
示例
js
signalingChannel.onmessage = (evt) => {
if (!pc) start(false);
const message = JSON.parse(evt.data);
if (message.type && message.sdp) {
pc.setRemoteDescription(
new RTCSessionDescription(message),
() => {
// if we received an offer, we need to answer
if (pc.remoteDescription.type === "offer") {
pc.createAnswer(localDescCreated, logError);
}
},
logError,
);
} else {
pc.addIceCandidate(
new RTCIceCandidate(message.candidate),
() => {},
logError,
);
}
};
规范
| 规范 |
|---|
| WebRTC:浏览器中的实时通信 # rtcsessiondescription-class |
浏览器兼容性
加载中…