aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/rtcpeerconnection/removestream/index.html
blob: d8934b29c97017810259b7f35c625029040436cc (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
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>

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatVersionUnknown() }} [1]</td>
   <td>{{ CompatVersionUnknown }} [1]</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Though this property is not prefixed, the interface it belongs to is.</p>

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

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