--- title: RTCPeerConnection.currentLocalDescription slug: Web/API/RTCPeerConnection/currentLocalDescription tags: - API - SDP - WebRTC translation_of: Web/API/RTCPeerConnection/currentLocalDescription ---
{{WebRTCSidebar}}
只读属性 RTCPeerConnection.currentLocalDescription
返回一个 {{domxref("RTCSessionDescription")}} 对象,该对象描述了 自上次 {{domxref("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
,则调用 {{domxref("RTCPeerConnection.setLocalDescription()")}} 。这将会触发引发该值被设置的一系列事件。 如果希望详细了解策略与机制,查阅 {{SectionOnPage("/en-US/docs/Web/API/WebRTC_API/Connectivity", "Pending and current descriptions")}}。
与 {{domxref("RTCPeerConnection.localDescription")}} 不同, 这个值代表了当前连接的本地端的事实当前状态; localDescription
也许指明了一个当前正在切换中的连接的description。
sessionDescription = RTCPeerConnection.currentLocalDescription;
连接本地端的当前description描述,如果成功设置了一个。否则返回null。
本例子查看 currentLocalDescription
并且显示了包含 {{domxref("RTCSessionDescription")}} 对象的 type
与 sdp
字段的alert。
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 | Status | Comment |
---|---|---|
{{ SpecName('WebRTC 1.0', '#dom-peerconnection-currentlocaldesc', 'RTCPeerConnection.currentLocalDescription') }} | {{ Spec2('WebRTC 1.0') }} | Initial specification. |
{{Compat("api.RTCPeerConnection.currentLocalDescription")}}
The addition of currentLocalDescription
and {{domxref("RTCPeerConnection.pendingLocalDescription", "pendingLocalDescription")}} to the WebRTC spec is relatively recent. In browsers which don't support them, just use {{domxref("RTCPeerConnection.localDescription", "localDescription")}}.