blob: 6717c46b3d0324c76d3c3c45ef8294f97fe1301b (
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
|
---
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>
{{Compat("api.RTCPeerConnection.setRemoteDescription")}}
<h2 id="See_also">See also</h2>
<ul>
<li><a href="/en-US/docs/Web/Guide/API/WebRTC">WebRTC</a></li>
</ul>
|