aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/rtcpeerconnection/removestream/index.html
blob: 1f842f3a8340509f8dc38c1605f0ccb40904ad62 (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
---
title: RTCPeerConnection.removeStream()
slug: Web/API/RTCPeerConnection/removeStream
translation_of: Web/API/RTCPeerConnection/removeStream
---
<p>{{APIRef("WebRTC")}}{{SeeCompatTable}}</p>

<p><code><strong>RTCPeerConnection.removeStream()</strong></code> 方法用来移除本地音频或视频的 {{domxref("媒体流")}} 。 如果已经发生交互,远程主机可能需要使用一个新的媒体流。</p>

<p>{{domxref("RTCPeerConnection.signalingState", "signalingState")}} 的值为<code>"closed"时,将抛出</code><code>InvalidStateError异常。当</code>  {{domxref("RTCPeerConnection.signalingState", "signalingState")}} 值为<code>"stable"时,</code> 将触发{{domxref("RTCPeerConnection")}}的 {{event("negotiationneeded")}} 事件。</p>

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

<pre class="syntaxbox"><code><em>pc</em>.removeStream(<em>mediaStream</em>);
</code></pre>

<p>
 <i>此方法没有返回值。</i>
</p>

<h3 id="Example" name="Example">参数</h3>

<dl>
 <dt><em>mediaStream</em></dt>
 <dd>{{domxref("MediaStream")}} 类型的表示要移除的媒体流</dd>
</dl>

<h2 id="Example" name="Example">例子</h2>

<pre class="brush: js">var pc, videoStream;
navigator.getUserMedia({video: true}, function(stream) {
  pc = new RTCPeerConnection();
  videoStream = stream;
  pc.addStream(stream);
}
document.getElementById("closeButton").addEventListener("click", function(event) {
  pc.removeStream(videoStream);
  pc.close();
}, false);</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-removeStream-void-MediaStream-stream', 'RTCPeerConnection.removeStream()') }}</td>
   <td>{{ Spec2('WebRTC 1.0') }}</td>
   <td>Initial specification.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

{{Compat("api.RTCPeerConnection.removeStream")}}

<h2 id="扩展阅读">扩展阅读</h2>

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