blob: a61e2f28c6ade788155f8c9dff4800a6b642c1df (
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
|
---
title: RTCPeerConnection.onaddstream
slug: Web/API/RTCPeerConnection/onaddstream
translation_of: Web/API/RTCPeerConnection/onaddstream
---
<p>{{APIRef("WebRTC")}}{{SeeCompatTable}}</p>
<p><code><strong>当类型为</strong></code>{{domxref("MediaStreamEvent")}}的{{event("addstream")}} 事件发生时,通过{{domxref("RTCPeerConnection")}}触发<code><strong>RTCPeerConnection.onaddstream</strong></code> 事件处理函数。当远程媒体流{{domxref("MediaStream")}} 添加到连接后发送事件。当{{domxref("RTCPeerConnection.setRemoteDescription()")}} 后此事件立即被调用而不需要等待SDP交换完成。</p>
<h2 id="语法">语法</h2>
<pre class="eval"><em>peerconnection</em>.onaddstream = <em>function</em>;
</pre>
<h3 id="值">值</h3>
<ul>
<li><code>function</code> 是用户自定义的一个函数,写法上不带 <code>()</code> 和任何参数,也可以是一个匿名函数,例如 <code>function(event) {...}</code>。事件处理函数通常有个event做参数,类型为 {{domxref("MediaStreamEvent")}}.</li>
</ul>
<h2 id="例子">例子</h2>
<pre class="brush: js">pc.onaddstream = function(ev) { alert("onaddstream event detected!"); };
</pre>
<h2 id="Specifications" name="Specifications">规范</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', '#widl-RTCPeerConnection-onaddstream', 'RTCPeerConnection.onaddstream') }}</td>
<td>{{ Spec2('WebRTC 1.0') }}</td>
<td>Initial specification.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
{{Compat("api.RTCPeerConnection.onaddstream")}}
<h2 id="扩展阅读">扩展阅读</h2>
<ul>
<li>The {{event("addstream")}} event and its type, {{domxref("MediaStreamEvent")}}.</li>
</ul>
|