blob: 65e2a48084fcbe115e158ca90fa1e08b541a81ad (
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
73
74
75
76
77
78
79
80
81
82
83
84
|
---
title: 'RTCPeerConnection: icecandidate event'
slug: Web/API/RTCPeerConnection/icecandidate_event
translation_of: Web/API/RTCPeerConnection/icecandidate_event
original_slug: Web/Events/icecandidate
---
<p>{{SeeCompatTable}}</p>
<p>当 {{domxref("RTCPeerConnection")}}通过{{domxref("RTCPeerConnection.setLocalDescription()")}}方法更改本地描述之后,该{{domxref("RTCPeerConnection")}}会抛出<strong><code>icecandidate</code></strong>事件。该事件的监听器需要将更改后的描述信息传送给远端{{domxref("RTCPeerConnection")}},以更新远端的备选源。</p>
<h2 id="使用指南">使用指南</h2>
<p><code>icecandidate</code> 的类型为 {{domxref("RTCPeerIceCandidateEvent")}}, 在以下三种情况下会触发该事件:</p>
<h3 id="分享新的源">分享新的源</h3>
<p><code>触发icecandidate</code>事件的首要原因:当获得新的源之后,需要将该源的信息发送给远端信号服务器,并分发至其他端的{{domxref("RTCPeerConnection")}}。其他{{domxref("RTCPeerConnection")}}通过{{domxref("RTCPeerConnection.addIceCandidate", "addIceCandidate()")}}方法将新{{domxref("RTCPeerCandidateIceEvent.candidate", "candidate")}} 中携带的信息,将新的源描述信息添加进它的备选池中;</p>
<pre>rtcPeerConnection.onicecandidate = (event) => {
if (event.candidate) {
sendCandidateToRemotePeer(event.candidate)
}
}
</pre>
<h2 id="概述">概述</h2>
<dl>
<dt style="float: left; text-align: right; width: 120px;">规范</dt>
<dd style="margin: 0 0 0 120px;">{{ SpecName('WebRTC 1.0', '#event-mediastream-icecandidate', 'icecandidate') }}</dd>
<dt style="float: left; text-align: right; width: 120px;">接口</dt>
<dd style="margin: 0 0 0 120px;">{{domxref("RTCPeerConnectionIceEvent")}}</dd>
<dt style="float: left; text-align: right; width: 120px;">事件冒泡</dt>
<dd style="margin: 0 0 0 120px;">否</dd>
<dt style="float: left; text-align: right; width: 120px;">能否取消默认</dt>
<dd style="margin: 0 0 0 120px;">否</dd>
<dt style="float: left; text-align: right; width: 120px;">事件目标</dt>
<dd style="margin: 0 0 0 120px;">{{domxref("RTCPeerConnection")}}</dd>
<dt style="float: left; text-align: right; width: 120px;">默认行为</dt>
<dd style="margin: 0 0 0 120px;">无</dd>
</dl>
<h2 id="属性">属性</h2>
<p><em>属性继承自{{domxref("RTCPeerConnectionIceEvent")}}.</em></p>
<h2 id="方法">方法</h2>
<p><em>方法继承自 {{domxref("RTCPeerConnectionIceEvent")}}.</em></p>
<h2 id="相关事件">相关事件</h2>
<ul>
<li><em>无</em></li>
</ul>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">注释</th>
</tr>
<tr>
<td>{{ SpecName('WebRTC 1.0', '#event-mediastream-icecandidate', 'icecandidate') }}</td>
<td>{{Spec2('WebRTC 1.0')}}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="兼容性">兼容性</h2>
{{Compat("api.RTCPeerConnection.icecandidate_event")}}
<h2 id="参阅">参阅</h2>
<ul>
<li><a href="/en-US/docs/Web/Guide/API/WebRTC" title="/en-US/docs/CSS/Using_CSS_animations">WebRTC</a></li>
</ul>
|