RTCPeerConnection.currentLocalDescription

只读属性 RTCPeerConnection.currentLocalDescription 返回一个 RTCSessionDescription 对象,该对象描述了 自上次 RTCPeerConnection 完成协商与连接到远程端后,最近一次成功协商的连接的本地端。原文(describing the local end of the connection as it was most recently successfully negotiated since the last time the RTCPeerConnection finished negotiating and connecting to a remote peer)。也包括自 RTCSessionDescription 所代表的 offer 或 anwser 首次实例化以来,ICE 代理可能已经生成的任何 ICE 候选人的列表。

若想改变 currentLocalDescription ,则调用 RTCPeerConnection.setLocalDescription() (en-US) 。这将会触发引发该值被设置的一系列事件。如果希望详细了解策略与机制,查阅待定的和当前描述

备注:RTCPeerConnection.localDescription (en-US) 不同,这个值代表了当前连接的本地端的事实当前状态; localDescription 也许指明了一个当前正在切换中的连接的 description。

语法

sessionDescription = RTCPeerConnection.currentLocalDescription;

返回值

连接本地端的当前 description 描述,如果成功设置了一个。否则返回 null。

示例

本例子查看 currentLocalDescription 并且显示了包含 RTCSessionDescription 对象的 typesdp 字段的 alert。

js
var pc = new RTCPeerConnection();var sd = pc.currentLocalDescription;
if (sd) {
  alert("Local session: type='" +
        sd.type + "'; sdp description='" +
        sd.sdp + "'");
}
else {
  alert("No local session yet.");
}

规范

Specification
WebRTC: Real-Time Communication in Browsers
# dom-peerconnection-currentlocaldesc

浏览器兼容性

BCD tables only load in the browser

备注: The addition of currentLocalDescription and pendingLocalDescription (en-US) to the WebRTC spec is relatively recent. In browsers which don't support them, just use localDescription (en-US).

参见