Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline RTCSessionDescriptionInit description #33963

Merged
merged 10 commits into from
Sep 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The parameters for the older form of `createAnswer()` are described below, to ai

### Return value

A {{jsxref("Promise")}} whose fulfillment handler is called with an object conforming to the {{domxref("RTCSessionDescriptionInit")}} dictionary which contains the SDP answer to be delivered to the other peer.
A {{jsxref("Promise")}} whose fulfillment handler is called with an object conforming to the [`RTCSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) dictionary which contains the SDP answer to be delivered to the other peer.

## Examples

Expand Down
6 changes: 3 additions & 3 deletions files/en-us/web/api/rtcpeerconnection/createoffer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The **`createOffer()`** method of the {{domxref("RTCPeerConnection")}} interface

The SDP offer includes information about any {{domxref("MediaStreamTrack")}} objects already attached to the WebRTC session, codec, and options supported by the browser, and any candidates already gathered by the {{Glossary("ICE")}} agent, for the purpose of being sent over the signaling channel to a potential peer to request a connection or to update the configuration of an existing connection.

The return value is a {{jsxref("Promise")}} which, when the offer has been created, is resolved with a {{domxref("RTCSessionDescription")}} object containing the newly-created offer.
The return value is a {{jsxref("Promise")}} which, when the offer has been created, is resolved with a [`RTCSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) dictionary containing the newly-created offer.

## Syntax

Expand Down Expand Up @@ -57,7 +57,7 @@ The parameters for the older form of `createOffer()` are described below, to aid

### Return value

A {{jsxref("Promise")}} whose fulfillment handler will receive an object conforming to the [RTCSessionDescriptionInit](/en-US/docs/Web/API/RTCSessionDescription/RTCSessionDescription#rtcsessiondescriptioninit) dictionary which contains the SDP describing the generated offer.
A {{jsxref("Promise")}} whose fulfillment handler will receive an object conforming to the [`RTCSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) dictionary which contains the SDP describing the generated offer.
That received offer should be delivered through the signaling server to a remote peer.

### Exceptions
Expand Down Expand Up @@ -98,7 +98,7 @@ myPeerConnection
});
```

In this code, the offer is created, and once successful, the local end of the {{domxref("RTCPeerConnection")}} is configured to match by passing the offer (which is represented using an object conforming to [RTCSessionDescriptionInit](/en-US/docs/Web/API/RTCSessionDescription/RTCSessionDescription#rtcsessiondescriptioninit)) into {{domxref("RTCPeerConnection.setLocalDescription", "setLocalDescription()")}}.
In this code, the offer is created, and once successful, the local end of the {{domxref("RTCPeerConnection")}} is configured to match by passing the offer (which is represented using an object conforming to [`RTCSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) into {{domxref("RTCPeerConnection.setLocalDescription", "setLocalDescription()")}}.
Once that's done, the offer is sent to the remote system over the signaling channel; in this case, by using a custom function called `sendToServer()`.
The implementation of the signaling server is independent from the WebRTC specification, so it doesn't matter how the offer is sent as long as both the caller and potential receiver are using the same one.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ setLocalDescription(sessionDescription, successCallback, errorCallback) // depre
### Parameters

- `sessionDescription` {{optional_inline}}
- : An {{domxref("RTCSessionDescriptionInit")}} or {{domxref("RTCSessionDescription")}} which specifies the configuration to be applied to the local end of the connection.
- : An [`RTCLocalSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) or {{domxref("RTCSessionDescription")}} which specifies the configuration to be applied to the local end of the connection.
If the description is omitted, the WebRTC runtime tries to automatically do the right thing.

### Return value
Expand All @@ -47,7 +47,7 @@ Otherwise, `setLocalDescription()` creates an answer, which becomes the new loca

#### Type of the description parameter

The description is of type `RTCSessionDescriptionInit`, which is a serialized version of a {{domxref("RTCSessionDescription")}} browser object. They're interchangeable:
The description is of type `RTCLocalSessionDescriptionInit`, which is a serialized version of a {{domxref("RTCSessionDescription")}} browser object. They're interchangeable:

```js
myPeerConnection
Expand Down Expand Up @@ -90,7 +90,7 @@ When using the deprecated callback-based version of `setLocalDescription()`, the
- `InvalidStateError` {{domxref("DOMException")}} {{deprecated_inline}}
- : Thrown if the connection's {{domxref("RTCPeerConnection.signalingState", "signalingState")}} is `"closed"`, indicating that the connection is not currently open, so negotiation cannot take place.
- `InvalidSessionDescriptionError` {{domxref("DOMException")}} {{deprecated_inline}}
- : Thrown if the {{domxref("RTCSessionDescription")}} specified by the `sessionDescription` parameter is invalid.
- : Thrown if the [`RTCLocalSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) specified by the `sessionDescription` parameter is invalid.

## Examples

Expand Down Expand Up @@ -140,3 +140,4 @@ called `signalRemotePeer()`.
## See also

- [WebRTC API](/en-US/docs/Web/API/WebRTC_API)
- {{domxref("RTCSessionDescription")}}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ setRemoteDescription(sessionDescription)
### Parameters

- `sessionDescription`
- : An {{domxref("RTCSessionDescriptionInit")}} or {{domxref("RTCSessionDescription")}} which specifies the remote peer's current offer or answer.
- : An [`RTCSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) or {{domxref("RTCSessionDescription")}} which specifies the remote peer's current offer or answer.
This value is an offer or answer received from the remote peer through your implementation of

The `sessionDescription` parameter is technically of type `RTCSessionDescriptionInit`, but because {{domxref("RTCSessionDescription")}} serializes to be indistinguishable from `RTCSessionDescriptionInit`, you can also pass in an `RTCSessionDescription`.
Expand Down Expand Up @@ -124,7 +124,7 @@ When using the deprecated callback-based version of `setRemoteDescription()`, th
- `InvalidStateError` {{deprecated_inline}}
- : The connection's {{domxref("RTCPeerConnection.signalingState", "signalingState")}} is `"closed"`, indicating that the connection is not currently open, so negotiation cannot take place.
- `InvalidSessionDescriptionError` {{deprecated_inline}}
- : The {{domxref("RTCSessionDescription")}} specified by the `sessionDescription` parameter is invalid.
- : The [`RTCSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) specified by the `sessionDescription` parameter is invalid.

## Examples

Expand Down Expand Up @@ -169,3 +169,4 @@ When our promise fulfillment handler is called, indicating that this has been do
- {{domxref("RTCPeerConnection.remoteDescription")}},
{{domxref("RTCPeerConnection.pendingRemoteDescription")}},
{{domxref("RTCPeerConnection.currentRemoteDescription")}}
- {{domxref("RTCSessionDescription")}}
40 changes: 38 additions & 2 deletions files/en-us/web/api/rtcsessiondescription/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _The `RTCSessionDescription` interface doesn't inherit any properties._
_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.
- : This constructor returns a new `RTCSessionDescription`. The parameter is a [`RTCSessionDescriptionInit`](#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.

Expand All @@ -36,7 +36,7 @@ signalingChannel.onmessage = (evt) => {
if (!pc) start(false);

const message = JSON.parse(evt.data);
if (message.sdp) {
if (message.type && message.sdp) {
pc.setRemoteDescription(
new RTCSessionDescription(message),
() => {
Expand All @@ -57,6 +57,42 @@ signalingChannel.onmessage = (evt) => {
};
```

## RTCSessionDescriptionInit

`RTCSessionDescriptionInit` is a dictionary that holds same properties to `RTCSessionDescription`. It's used as an argument for the {{domxref("RTCPeerConnection.setLocalDescription")}}, and {{domxref("RTCPeerConnection.setRemoteDescription")}} methods, and a return value from the {{domxref("RTCPeerConnection.createOffer")}}, and {{domxref("RTCPeerConnection.createAnswer")}} methods.

The `RTCSessionDescriptionInit` dictionary has the following properties:

- `type` (required): A string indicating the type of the session description.
- `sdp`: A string containing the SDP describing the session. If sdp is not provided, it defaults to an empty string. If `type` is `"rollback"`, `sdp` must be null or an empty string.

For `setLocalDescription`, Web Specification uses `RTCLocalSessionDescriptionInit` dictionary, which is a subset of `RTCSessionDescriptionInit`. It has the same properties, but the `type` property is optional (explained in more detail in the [Implicit description in RTCPeerConnection.setLocalDescription()](/en-US/docs/Web/API/RTCPeerConnection/setLocalDescription#implicit_description)).

For using in `setLocalDescription` and `setRemoteDescription` methods, creating an `RTCSessionDescription` also works, but it's not necessary. Some older examples may use this method, but such usage has no advantage over passing a dictionary directly to the method.

```js
signalingChannel.onmessage = (evt) => {
if (!pc) start(false);

const message = JSON.parse(evt.data);
if (message.type && message.sdp) {
// This line is changed not to use RTCSessionDescription constructor
pc.setRemoteDescription(message).then(() => {
// 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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ specified object.
> **Note:** This constructor has been deprecated because
> {{domxref("RTCPeerConnection.setLocalDescription()")}} and other methods which take
> SDP as input now directly accept an object conforming to the
> `RTCSessionDescriptionInit` dictionary, so you don't have to instantiate an
> [`RTCSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) dictionary, so you don't have to instantiate an
> `RTCSessionDescription` yourself.

## Syntax
Expand All @@ -31,7 +31,7 @@ new RTCSessionDescription(options)
- `options` {{optional_inline}}

- : An object providing the default values for the session description; the object
conforms to the `RTCSessionDescriptionInit` dictionary. That dictionary has
conforms to the [`RTCSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) dictionary. That dictionary has
the following properties:

- `type`
Expand All @@ -45,7 +45,7 @@ This example uses the constructor to convert an SDP offer into an
`RTCSessionDescription` object.

> **Note:** This is no longer necessary, however;
> {{domxref("RTCPeerConnection.setLocalDescription()")}} and other methods which take
> [`RTCSessionDescriptionInit`](/en-US/docs/Web/API/RTCSessionDescription#rtcsessiondescriptioninit) and other methods which take
Josh-Cena marked this conversation as resolved.
Show resolved Hide resolved
> SDP as input now directly accept an object conforming to the
> `RTCSessionDescriptionInit` dictionary, so you don't have to instantiate an
> `RTCSessionDescription` yourself.
Expand Down