aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/rtcpeerconnection/peeridentity/index.html
blob: b1565ae67c2cf4486900653676e4476938f59486 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
title: RTCPeerConnection.peerIdentity
slug: Web/API/RTCPeerConnection/peerIdentity
translation_of: Web/API/RTCPeerConnection/peerIdentity
---
<p>{{APIRef("WebRTC")}}</p>

<p><span class="seoSummary">只读属性 {{domxref("RTCPeerConnection")}}  <code><strong>peerIdentity</strong></code> ,返回{{jsxref("Promise")}} 对象,成功时返回 {{domxref("RTCIdentityAssertion")}} ,该结构 {{domxref("DOMString")}} 标识了远端的ID。这个身份标识在连接过程中将不会改变(直到连接结束)</span>.</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"> var <em>identity</em> = <em>rtcPeerConnection</em>.peerIdentity;</pre>

<h3 id="Value">Value</h3>

<p>A JavaScript {{jsxref("Promise")}} which resolves to an {{domxref("RTCIdentityAssertion")}} that describes the remote peer's identity.</p>

<p>当验证远程的身份ID出错时,  promise 将返回拒绝. 如果目标节点身份不存在, <code>peerIdentity</code> 将被设为 一个promise对象,并重启验证过程(一个断言), 直到成功或者不再想继续。</p>

<div class="blockIndicator note">
<p><strong>注意:</strong> {{domxref("RTCPeerConnection.setRemoteDescription", "setRemoteDescription()")}} 返回的promise 将不会成功返回,除非目标节点身份信息可用。 如不可用,则<code>setRemoteDescription()</code> 将被拒绝. 若无目标节点ID, 就不不需要等<code>setRemoteDescription() </code>这个返回验证成功了.</p>
</div>

<h2 id="举个栗子">举个栗子</h2>

<p>In this example, a function, <code>getIdentityAssertion()</code>, is created which asynchronously waits for the peer's identity to be verified, then returns the identity to the caller. If an error occurs and the promise is rejected, this logs the error to the console and returns <code>null</code> to the caller.</p>

<pre>let pc = new RTCPeerConnection();

/* ... */

async function getIdentityAssertion(pc) {
  try {
    const identity = await pc.peerIdentity;
    return identity;
  } catch(err) {
    console.log("Error identifying remote peer: ", err);
    return null;
  }
}
</pre>

<h2 id="Specifications" name="Specifications">Specifications</h2>

<table class="standard-table" style="height: 49px; width: 1000px;">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('WebRTC Identity', '#dom-rtcpeerconnection-peeridentity') }}</td>
   <td>{{ Spec2('WebRTC Identity') }}</td>
   <td>Initial specification.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.RTCPeerConnection.peerIdentity")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/WebRTC_API">WebRTC API</a></li>
</ul>