aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/rtcpeerconnection/setremotedescription/index.html
blob: 9e8db040bc6f6ee9d7b8445a84228286df7e255f (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
119
120
121
122
123
124
125
126
127
---
title: RTCPeerConnection.setRemoteDescription()
slug: Web/API/RTCPeerConnection/setRemoteDescription
translation_of: Web/API/RTCPeerConnection/setRemoteDescription
---
<p>{{APIRef("WebRTC")}}{{SeeCompatTable}}</p>

<p><code><strong>RTCPeerConnection.setRemoteDescription()</strong></code> 方法改变与连接相关的描述,该描述主要是描述有些关于连接的属性,例如对端使用的解码器。 连接受此更改影响,并且必须能够支持旧的和新的描述。 方法带三个参数,{{domxref("RTCSessionDescription")}} 对象用于设置,然后是更改成功的回调方法,一个是更改失败的回调方法。</p>

<p>方法是异步的,不用等待设置完成,成功会调用成功回调方法,失败则会调用错误回调方法。</p>

<p>连接的offer通常来自于负责匹配的服务器所发送的数据。执行者应调用此方法设置远程描述,然后生成发送到对端计算机的answer。</p>

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

<pre>aPromise = pc.setRemoteDescription(<em>sessionDescription</em>);

<code><em>pc</em>.setRemoteDescription(<em>sessionDescription</em>, <em>successCallback</em>, <em>errorCallback</em>);
</code></pre>

<p><em>这个方法没有返回值。</em></p>

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

<dl>
 <dt><em>sessionDescription</em></dt>
 <dd>Is a {{domxref("DOMString")}} is the description of the parameters to be applied to the remote session.</dd>
 <dt><em>successCallback</em></dt>
 <dd>Is a <code>Function</code> without parameter which will be called when the description has been successfully set. At this point, one can send the offer to a remote server that can forward it to a remote client</dd>
 <dt><em>errorCallback</em></dt>
 <dd>Is a <code>RTCPeerConnectionErrorCallback</code> which will be called if the description can't be set. It takes the following parameter:
 <ul>
  <li><em>errorInformation </em>which is a {{domxref("DOMString")}} describing the reason why the description has not been set.</li>
 </ul>
 </dd>
</dl>

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

<pre class="brush: js">var pc = new PeerConnection();
pc.setRemoteDescription( new RTCSessionDescription( offer ), function() {
   pc.createAnswer( function( answer ) {
     pc.setLocalDescription( answer, function() {
       // send the answer to the remote connection
    })
  })
});
</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 1.0', '#widl-RTCPeerConnection-setRemoteDescription-void-RTCSessionDescription-description-VoidFunction-successCallback-RTCPeerConnectionErrorCallback-failureCallback', 'RTCPeerConnection.setRemoteDescription()') }}</td>
   <td>{{ Spec2('WebRTC 1.0') }}</td>
   <td>Initial specification.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</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="See_also">See also</h2>

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