/
index.md
71 lines (53 loc) · 2.64 KB
/
index.md
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
---
title: RTCSessionDescription
slug: Web/API/RTCSessionDescription
page-type: web-api-interface
browser-compat: api.RTCSessionDescription
---
{{APIRef("WebRTC")}}
The **`RTCSessionDescription`** interface describes one end of a connection—or potential connection—and how it's configured. Each `RTCSessionDescription` consists of a description {{domxref("RTCSessionDescription.type", "type")}} indicating which part of the offer/answer negotiation process it describes and of the {{Glossary("SDP")}} descriptor of the session.
The process of negotiating a connection between two peers involves exchanging `RTCSessionDescription` objects back and forth, with each description suggesting one combination of connection configuration options that the sender of the description supports. Once the two peers agree upon a configuration for the connection, negotiation is complete.
## Instance properties
_The `RTCSessionDescription` interface doesn't inherit any properties._
- {{domxref("RTCSessionDescription.type")}} {{ReadOnlyInline}}
- : An enum describing the session description's type.
- {{domxref("RTCSessionDescription.sdp")}} {{ReadOnlyInline}}
- : A string containing the {{Glossary("SDP")}} describing the session.
## Instance methods
_The `RTCSessionDescription` doesn't inherit any methods._
- {{domxref("RTCSessionDescription.RTCSessionDescription", "RTCSessionDescription()")}} {{deprecated_inline}}
- : This constructor returns a new `RTCSessionDescription`. The parameter is a `RTCSessionDescriptionInit` dictionary containing the values to assign the two properties.
- {{domxref("RTCSessionDescription.toJSON()")}}
- : Returns a {{Glossary("JSON")}} description of the object. The values of both properties, {{domxref("RTCSessionDescription.type", "type")}} and {{domxref("RTCSessionDescription.sdp", "sdp")}}, are contained in the generated JSON.
## Example
```js
signalingChannel.onmessage = (evt) => {
if (!pc) start(false);
const message = JSON.parse(evt.data);
if (message.sdp) {
pc.setRemoteDescription(
new RTCSessionDescription(message),
() => {
// if we received an offer, we need to answer
if (pc.remoteDescription.type === "offer") {
pc.createAnswer(localDescCreated, logError);
}
},
logError,
);
} else {
pc.addIceCandidate(
new RTCIceCandidate(message.candidate),
() => {},
logError,
);
}
};
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [WebRTC](/en-US/docs/Web/API/WebRTC_API)
- {{domxref("RTCPeerConnection.setLocalDescription()")}} and {{domxref("RTCPeerConnection.setRemoteDescription()")}}