--- title: RTCPeerConnection.currentLocalDescription slug: Web/API/RTCPeerConnection/currentLocalDescription tags: - API - SDP - WebRTC translation_of: Web/API/RTCPeerConnection/currentLocalDescription --- <p>{{WebRTCSidebar}}</p> <p>只读属性 <code><strong>RTCPeerConnection.currentLocalDescription</strong></code> 返回一个 {{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候选人的列表。</p> <p>若想改变 <code>currentLocalDescription</code> ,则调用 {{domxref("RTCPeerConnection.setLocalDescription()")}} 。这将会触发引发该值被设置的一系列事件。 如果希望详细了解策略与机制,查阅 {{SectionOnPage("/en-US/docs/Web/API/WebRTC_API/Connectivity", "Pending and current descriptions")}}。</p> <div class="note"> <p>与 {{domxref("RTCPeerConnection.localDescription")}} 不同, 这个值代表了当前连接的本地端的事实当前状态; <code>localDescription</code> 也许指明了一个当前正在切换中的连接的description。</p> </div> <h2 id="语法">语法</h2> <pre class="syntaxbox notranslate"><em>sessionDescription</em> = <em>RTCPeerConnection</em>.currentLocalDescription;</pre> <h3 id="返回值">返回值</h3> <p>连接本地端的当前description描述,如果成功设置了一个。否则返回null。</p> <h2 id="例子">例子</h2> <p>本例子查看 <code>currentLocalDescription</code> 并且显示了包含 {{domxref("RTCSessionDescription")}} 对象的 <code>type</code> 与 <code>sdp</code> 字段的alert。</p> <pre class="brush: js notranslate">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."); } </pre> <h2 id="参数类别">参数类别</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td>{{ SpecName('WebRTC 1.0', '#dom-peerconnection-currentlocaldesc', 'RTCPeerConnection.currentLocalDescription') }}</td> <td>{{ Spec2('WebRTC 1.0') }}</td> <td>Initial specification.</td> </tr> </tbody> </table> <h2 id="浏览器兼容性">浏览器兼容性</h2> <p>{{Compat("api.RTCPeerConnection.currentLocalDescription")}}</p> <div class="note"> <p>The addition of <code>currentLocalDescription</code> 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")}}.</p> </div> <h2 id="参阅">参阅</h2> <ul> <li>{{domxref("RTCPeerConnection.setLocalDescription()")}}, {{domxref("RTCPeerConnection.pendingLocalDescription")}}, {{domxref("RTCPeerConnection.localDescription")}}</li> <li>{{domxref("RTCPeerConnection.setRemoteDescription()")}}, {{domxref("RTCPeerConnection.remoteDescription")}}, {{domxref("RTCPeerConnection.pendingRemoteDescription")}}, {{domxref("RTCPeerConnection.currentRemoteDescription")}}</li> <li><a href="/en-US/docs/Web/Guide/API/WebRTC">WebRTC</a></li> </ul>