Initial Author of this Specification was Ian Hickson, Google Inc., with the following copyright statement:
© Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and Opera Software ASA. You are granted a license to use, reproduce and create derivative works of this document.
All subsequent changes since 26 July 2011 done by the W3C WebRTC Working Group are under the following Copyright:
© 2011-2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. Document use rules apply.
For the entire publication on the W3C site the liability and trademark rules apply.
This document defines a set of APIs to represent streaming media, including audio and video, in JavaScript, to allow media to be sent over the network to another browser or device implementing the appropriate set of real-time protocols, and media received from another browser or device to be processed and displayed locally. This specification is being developed in conjunction with a protocol specification developed by the IETF RTCWEB group and an API specification to get access to local media devices developed by the Media Capture Task Force.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document is not complete. It is subject to major changes and, while early experimentation is encouraged, it is therefore not intended for implementation. The API is based on preliminary work done in the WHATWG. The Web Real-Time Communications Working Group expects this specification to evolve significantly based on:
This document was published by the Web Real-Time Communications Working Group as an Editor's Draft. If you wish to make comments regarding this document, please send them to public-webrtc@w3.org (subscribe, archives). All feedback is welcome.
Publication as an Editor's Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words must, must not, required, should, should not, recommended, may, and optional in this specification are to be interpreted as described in [RFC2119].
Implementations that use ECMAScript to implement the APIs defined in this specification must implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [WEBIDL], as this specification uses that specification and terminology.
This section is non-normative.
There are a number of facets to video-conferencing in HTML covered by this specification:
This document defines the APIs used for these features. This specification is being developed in conjunction with a protocol specification developed by the IETF RTCWEB group and an API specification to get access to local media devices developed by the Media Capture Task Force.
The MediaStream
interface, as defined in the
[GETUSERMEDIA] specification, typically represents a stream of data
of audio and/or video. A MediaStream
may be extended to represent a
stream that either comes from or is sent to a remote node (and not
just the local camera, for instance). The extensions required to
enable this capability on the MediaStream
object will be
described in this document.
A MediaStream
as defined in [GETUSERMEDIA] may
contain zero or more MediaStreamTrack
objects. A
MediaStreamTrack
sent to another peer will appear as one
and only one MediaStreamTrack
to the recipient.
Channels are the smallest unit considered in the
MediaStream
specification. Channels are intended to be
encoded together for transmission as, for instance, an RTP payload
type. All of the channels that a codec needs to encode jointly must be
in the same MediaStreamTrack
and the codecs should be
able to encode, or discard, all the channels in the track.
The concepts of an input and output to a given
MediaStream
apply in the case of MediaStream
objects transmitted over the network as well. A
MediaStream
created by a
object (later described in this document) will take as input
the data received from a remote peer. Similarly, a
PeerConnection
MediaStream
from a local source, for instance a camera
via [GETUSERMEDIA] will have an output that represents what is
transmitted to a remote peer if the object is used with a
object.PeerConnection
The concept of duplicating MediaStream
objects as
described in [GETUSERMEDIA] is also applicable here. This feature
can be used, for instance, in a video-conferencing scenario to display
the local video from the user’s camera and microphone in a local
monitor, while only transmitting the audio to the remote peer (e.g. in
response to the user using a "video mute" feature). Combining tracks
from different
MediaStream
objects into a new
MediaStream
is useful in certain cases.
In this section, we only specify aspects of the the
following objects that are relevant when used along with a
PeerConnection
. Please refer to the original definitions
of the objects in the [GETUSERMEDIA] document for general
information on using MediaStream
and
MediaStreamTrack
both in and outside the context of
PeerConnection
.
The label
attribute specified in
MediaStream
returns a label that is unique to this
stream, so that streams can be recognized after they are sent
through the
PeerConnection
API.
When a
MediaStream
is created to represent a stream obtained from a remote
peer, the label
attribute is initialized from
information provided by the remote source.
The label of a
MediaStream
object is unique to the source of the stream, but that
does not mean it is not possible to end up with duplicates. For
example, a locally generated stream could be sent from one user to
a remote peer using
, and then sent back to the original user in the same
manner, in which case the original user will have multiple streams
with the same label (the locally-generated one and the one
received from the remote peer).PeerConnection
A new media component may be associated with an existing
MediaStream
. This happens, e.g., on the A-side when the B-side adds
a new
MediaStreamTrack
object to one of the track lists of a
MediaStream
that is being sent over a
. If this happens for the reason exemplified, or for any
other reason than the PeerConnection
add()
[GETUSERMEDIA] method
being invoked locally on a
MediaStreamTrackList
or tracks are being added as the stream is created (i.e.
the stream is initialized with tracks), the user agent must run
the following steps:
Create a
MediaStreamTrack
object track to represent the new media
component.
If track’s
kind
attribute equals "audio
", add it to the
MediaStream
object’s
audioTracks
MediaStreamTrackList
object. [[OPEN ISSUE: Is there a way to generalize this
so that if we add a "smell" track this continues to work.]]
If track’s
kind
attribute equals "video
", add it to the
MediaStream
object’s
videoTracks
MediaStreamTrackList
object.
Fire a track event named
addtrack
with the newly created track at the
MediaStreamTrackList
object.
An existing media component may also be disassociated from a
MediaStream
. If this happens for any other reason than the
remove()
[GETUSERMEDIA] method being invoked
locally on a
MediaStreamTrackList
or the stream is being destroyed, the user agent must
run the following steps:
Let track be the
MediaStreamTrack
object representing the media component about to be
removed.
Remove track from the
MediaStreamTrackList
object.
Fire a track event named
removetrack
with track at the
MediaStreamTrackList
object.
The event source for the onended
event in the
networked case is the PeerConnection
object.
A MediaStreamTrack
object’s reference to its
MediaStream
in the non-local media source case (an RTP
source, as is the case for a MediaStream
received over
a PeerConnection
) is always strong.
When a track belongs to a
MediaStream
that comes from a remote peer and the remote peer has
permanently stopped sending data the ended
event must
be fired on the track, as specified in [GETUSERMEDIA].
[[ OPEN ISSUE: How do you know when it has stopped? This seems like
an SDP question, not a media-levelquestion.]]
A track in a
MediaStream
, received with a
, must have its PeerConnection
readyState
attribute
[GETUSERMEDIA] set to
MUTED
(1) until media data arrives.
In addition, a MediaStreamTrack
has its
readyState
set to MUTED
on the B-side if
the A-side disables the corresponding
MediaStreamTrack
in the
MediaStream
that is being sent. When the addstream event triggers on a
, all PeerConnection
MediaStreamTrack
objects in the resulting
MediaStream
are muted until media data can be read from the RTP
source.
[[ OPEN ISSUE: How do you know when it has been disabled? This seems like
an SDP question, not a media-levelquestion.]]
The
is a specialization of of a normal AudioMediaStreamTrack
MediaStreamTrack
that only carries audio and is extended to have the
capability to send and/or receive DTMF codes.
interface AudioMediaStreamTrack : MediaStreamTrack {
readonly attribute boolean canInsertDTMF;
void insertDTMF (DOMString tones, optional long duration);
};
canInsertDTMF
of type boolean, readonlyThe
canInsertDTMF
attribute must indicate if the
is capable of sending DTMF.AudioMediaStreamTrack
insertDTMF
When a
object’s
AudioMediaStreamTrack
insertDTMF()
method is invoked, the user agent must queue a task that
that sends the DTMF tones.
The tone parameters is treated as a series of characters. The characters 0 to 9, A to D, #, and * generated the associated DTMF tones. The characters a to d are equivalent to A to D. The character , indicates a an delay of 2 seconds before processing the next character in the tones parameter. Unrecognized characters are ignored.
The duration parameters indicates the duration in ms to play the each DTMF passed in the tones parameters. The duration can not be more than 6000 or less than 70. The default duration is 100 ms for each tone. The gap between tones must be at least 50 ms but should be as short as possible. [[OPEN ISSUE: How are invalid values handled?]]
If insertDTMF is called on the same object while an existing task for this object is generate DTMF is still running, the previous task is canceled. Calling insertDTMF with an empty tones parameter can be used to cancel any tones currently being send.
Editor Note: We need to add a callback that is set on the object that is called after the tones are sent. This is needed to allow the application to know when it can send new tones without canceling the tones that are currently being sent.
Editor Note: It seems we would want a callback or event for incoming tones. The proposal sent to the list had them played as audio to the speaker but I don’t see how that is useful.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
tones | DOMString | ✘ | ✘ | |
duration | long | ✘ | ✔ |
void
A
allows two users to communicate directly, browser to browser.
Communications are coordinated via a signaling channel which is provided
by unspecified means, but generally by a script in the page via the server,
e.g. using PeerConnection
XMLHttpRequest
.
Calling new
creates a PeerConnection
(configuration
)
object.PeerConnection
The configuration has the information to find and access the [STUN] and [TURN] servers. There may be multiple servers of each type and any TURN server also acts as a STUN server.
A PeerConnection object has an associated ICE Agent, PeerConnection state, and ICE State. These are initialized when the object is created.
When the
PeerConnection()
constructor is invoked, the user agent must run the following
steps. This algorithm has a synchronous section (which is triggered as
part of the event loop algorithm).
Create an ICE Agent and let connection’s PeerConnection
ICE
Agent be that ICE Agent and provide it the STUN and TURN servers
from the configuration array. The [ICE] will proceed with
gathering as soon as the IceTransports constraint is not set to
"none". At this point the ICE Agent does not know how many
ICE components it needs (and hence the number of candidates to
gather) but it can make a reasonable
assumption and as the PeerConnection object gets more information,
it can adjust the number of components.
Set connection’s PeerConnection
readiness state to
"new"
.
Set connection’s PeerConnection
ice state to
"new"
.
Let connection’s
localStreams
attribute be an empty read-only
MediaStream
array.
Let connection’s
remoteStreams
attribute be an empty read-only
MediaStream
array.
Return connection, but continue these steps asynchronously.
Await a stable state. The synchronous section consists of the remaining steps of this algorithm.
During the lifetime of the PeerConnection object, the following procedures are followed:
If the ice state is "new" and the IceTransports constraint is not set to "none", it must queue a task to start gathering ICE address and set the ice state to "gathering".
If the ICE Agent has found one or more candidate pairs for any MediaTrack that forms a valid connection, the ICE state is changed to "connected".
When the ICE Agent finishes checking all candidate pairs, if at least one connection has been found for some MediaTrack, the iceState is changed to "completed" and if no connection has been found for any MediaTrack, the iceState is changed to "failed". [[OPEN ISSUE: Note that this means that if I was able to negotiate audio but not video via ICE, then iceState == "completed". Is this really what is desired?]]
If the iceState is "connected" or "completed" and both the local and remote session descriptions are set, the peerState is set to "active".
If the iceState is "failed", a task is queued to calls the close method. Open Issue: CJ - this seems wrong to me.
User agents negotiate the codec resolution, bitrate, and other media
parameters. User agents are encouraged to initially negotiate for the
maximum resolution of a video stream. For streams that are then rendered
(using a video
element), user agents are encouraged to
renegotiate for a resolution that matches the rendered display size.
Starting with the native resolution means that if the
Web application notifies its peer of the native resolution as it starts
sending data, and the peer prepares its video
element
accordingly, there will be no need for a renegotiation once the stream
is flowing.
The word "components" in this context refers to an RTP media flow and does not have anything to do with how [ICE] uses the term "component".
When a user agent has reached the point where a
MediaStream
can be created to represent incoming components, the user
agent must run the following steps:
Let connection be the
expecting this media.PeerConnection
Create a
MediaStream
object to represent the media stream.
[[OPEN ISSUE: What if one already exists?]]
Run the following steps for each component in the media stream.
Create a
MediaStreamTrack
object track to represent the
component.
[[EDITORIAL: Can we just reference 3.2.1.2 here?]]
If track's
kind
attribute equals "audio
", add it to the
MediaStream
object's
audioTracks
MediaStreamTrackList
object.
If track's
kind
attribute equals "video
", add it to the
MediaStream
object's
videoTracks
MediaStreamTrackList
object.
The creation of new incoming MediaStream
s may be
triggered either by SDP negotiation or by the receipt of
media on a given flow.
The internal order in the
MediaStreamTrackList
objects on the receiving side should reflect the order on
the sending side. One way to enforce this is to specify the order in
the SDP.
Queue a task to run the following substeps:
If the connection’s PeerConnection
readiness state is
CLOSED
(3), abort these steps.
Add the newly created
MediaStream
object to the end of connection’s
remoteStreams
array.
Fire a stream event named
addstream
with the newly created
MediaStream
object at the connection object.
When a user agent has negotiated media for a component that belongs
to a media stream that is already represented by an existing
MediaStream
object, the user agent must associate the component with that
MediaStream
object.
When a
PeerConnection
finds that a stream from the remote peer has been removed
, the user agent must follow these steps:
Let connection be the
associated with the stream being removed.PeerConnection
Let stream be the
MediaStream
object that represents the media stream being removed, if
any. If there isn't one, then abort these steps.
By definition, stream is now finished.
A task is thus queued to update stream and fire an event.
Queue a task to run the following substeps:
If the connection’s PeerConnection
readiness state is
CLOSED
(3), abort these steps.
Remove stream from connection’s
remoteStreams
array.
Fire a stream event named
removestream
with stream at the
connection object.
The task source for the tasks listed in this section is the networking task source.
If something in the browser changes that causes the
object to need to initiate a new session descipriton
negotiation, an PeerConnection
renegotiationneeded
event is fired at the
object. PeerConnection
In particular, if a
object is consuming a PeerConnection
MediaStream
and a track is added to one of the stream's
MediaStreamTrackList
objects, by, e.g., the
add()
method being invoked, the
object must fire the "renegotiationneeded" event. Removal
of media components must also trigger "renegotianneeded".PeerConnection
To prevent network sniffing from allowing a fourth party to establish a connection to a peer using the information sent out-of-band to the other peer and thus spoofing the client, the configuration information should always be transmitted using an encrypted connection.
The general operation of the PeerConnection is described in [RTCWEB-JSEP].
The SdpType enums serve as arguments to setLocalDescription and setRemoteDescription. They provide information as to how the SDP should be handled.
enum SdpType { "offer", "pranswer", "answer" }
"offer"
An SdpType of "offer" indicates that a description should be treated as an [SDP] offer.
"pranswer"
An SdpType of "pranswer" indicates that a description should be treated as an [SDP] answer, but not a final answer. A description used as a SDP "pranswer" may be applied as a response to a SDP offer, or an update to a previously sent SDP "pranswer".
"answer"
An SdpType of "answer" indicates that a description should be treated as an [SDP] final answer, and the offer-answer exchange should be considered complete. A description used as a SDP answer may be applied as a response to a SDP offer, or an update to a previously send SDP "pranswer".
The
SessionDescription()
constructor takes one argument, description,
whose content is used to construct the new
object. This class is a future extensible carrier
for for the data contained in it and does not perform any
substantive processing. SessionDescription
[Constructor (DOMString description)]
interface SessionDescription {
attribute SdpType type;
attribute DOMString sdp;
stringifier DOMString ();
};
DOMString
Objects that implement the
interface must stringify as [SDP]. SessionDescription
stringifier
callback SessionDescriptionCallback = void (SessionDescription sdp)
callback PeerConnectionErrorCallback = void (DOMString errorInformation)
TODO: Open Issue: should this be defined as event like NavigatorUserMediaErrorCallback in getusermedia
enum PeerState { "new" "opening", "active", "closing", "closed" }
"new"
"opening"
"active"
"closing"
PeerConnection
object is terminating all media and is in the process of
closing the connection.
"closed"
enum IceState { "new" "gathering", "waiting", "checking", "connected", "completed","failed", "closed" }
"new"
"gathering"
"waiting"
"checking"
"connected"
"completed"
"failed"
"closed"
The
IceCandidate()
constructor takes one argument, candidate, whose
content is used to construct the new
IceCandidate
object. This class is a future extensible carrier
for for the data contained in it and does not perform any
substantive processing.
[Constructor (DOMString candidate)]
interface IceCandidate {
attribute DOMString candidate;
stringifier DOMString ();
};
candidate
of type DOMStringDOMString
Objects that implement the
IceCandidate
interface must stringify as the candidate-attribute as defined in section
15.1 of [ICE].
stringifier
callback IceCandidateCallback = void (IceCandidate candidate)
Open Issue: choose option 1 or option 2 for IceServers Type.
interface IceServers {
attribute DOMString servers[][];
};
servers[][]
of type DOMStringThe IceServers type is an array of pairs where each pair is defined as an array. Each pair provides the information to reach and use one STUN or TURN server. The first element in each pair is a stun or turn URIs as defined in [STUN-URI] and [TURN-URI]. If the first element of the pair is TURN URI, then the second element of the pair is the credential to use with that TURN server.
In network topologies with multiple layers of NATs, it is desirable to have a STUN servers between every layer of NATs in addition to the TURN servers to minimize the number peer to peer network latency.
An example configuration object is:
{ servers:[ ["stun:stun.example.net"] ,
["turn:user@turn.example.org","myPassword"] ]}
Open Issue: choose option 1 or option 2 for IceServers Type.
interface IceServers {
attribute DOMString servers[];
};
servers[]
of type DOMStringThe IceServers type is an array of strings where each string provides the URL and credentials for a server. Each string is either a the URL to reach a STUN server ad defined in [STUN-URI] or is the URL of a TURN server as defined in [TURN-URI] followed by a single space and then the rest of the string is the credential used to access that server. Note the credential may contains spaces.
In network topologies with multiple layers of NATs, it is desirable to have a STUN servers between every layer of NATs in addition to the TURN servers to minimize the number peer to peer network latency.
An example configuration object is:
{ servers:[ "stun:stun.example.net" ,
"turn:user@turn.example.org myPassword" ]}
Open Issue: should we collapse some of these functions a single "processRemoteSignal" method?
[Constructor (IceServers configuration, optional MediaConstraints constraints)]
interface PeerConnection {
void createOffer (SessionDescriptionCallback successCallback, optional PeerConnectionErrorCallback failureCallback, optional MediaConstraints constraints);
void createAnswer (SessionDescription
offer, SessionDescriptionCallback successCallback, optional PeerConnectionErrorCallback failureCallback, optional MediaConstraints constraints, optional Boolean createProvisionalAnswer=false);
void setLocalDescription (SdpType action, SessionDescription
description);
readonly attribute SessionDescription
localDescription;
void setRemoteDescription (SdpType action, SessionDescription
description);
readonly attribute SessionDescription
remoteDescription;
readonly attribute PeerState readyState;
void updateIce (optional IceServers
configuration, optional MediaConstraints constraints, optional Boolean restart=false);
void addIceCandidate (IceCandidate
candidate);
readonly attribute IceState iceState;
readonly attribute MediaStream[] localStreams;
readonly attribute MediaStream[] remoteStreams;
DataChannel
createDataChannel ([TreatNullAs=EmptyString] DOMString? label, optional DataChannelInit
? dataChannelDict);
attribute Function? ondatachannel;
void addStream (MediaStream stream, optional MediaConstraints constraints);
void removeStream (MediaStream stream);
void close ();
attribute Function? onrenegotationneeded;
attribute Function? onicecandidate;
attribute Function? onconnecting;
attribute Function? onopen;
attribute Function? onstatechange;
attribute Function? onaddstream;
attribute Function? onremovestream;
attribute Function? onicechange;
};
iceState
of type IceState, readonlyThe
iceState
attribute must return the state of the PeerConnection
ICE
Agent ICE state.
localDescription
of type SessionDescription
, readonlyThe localDescription method returns a copy of the SessionDescription that was most recently passed to setLocalDescription, plus any local candidates that have been generated by the ICE Agent since then.
A null object will be returned if the local description has not yet been set.
localStreams
of type array of MediaStream, readonlyReturns a live array containing the local streams (those that
were added with
addStream()
).
onaddstream
of type Function, nullable
addstream
, must be supported by all objects implementing the
PeerConnection
interface. Open Issue: It seems like this even handler
needs to be fired when the first of two things happens - the
remote side sends signaling indicating a media will be sent, or
the side that sent an offer start receiving media in reply to that
offer. onconnecting
of type Function, nullable
connecting
, must be supported by all objects implementing the
PeerConnection
interface.ondatachannel
of type Function, nullable
datachannel
, must be supported by all objects implementing the
PeerConnection
interface.onicecandidate
of type Function, nullable
onicecandidate
, must be supported by all objects implementing the
PeerConnection
interface. It is called any time there is a new ICE
candiate can be added to the a previos offer or answer. onicechange
of type Function, nullable
icechange
, must be supported by all objects implementing the
PeerConnection
interface. It is called any time the iceState
changes.onopen
of type Function, nullable
open
, must be supported by all objects implementing the
PeerConnection
interface.onremovestream
of type Function, nullable
removestream
, must be supported by all objects implementing the
PeerConnection
interface.onrenegotationneeded
of type Function, nullable
renegotiationneeded
, must be supported by all objects implementing the
PeerConnection
interface.
Open Issue: Need to sort out which things should be Function and
which should be a Callback.
onstatechange
of type Function, nullable
statechange
, must be supported by all objects implementing the
PeerConnection
interface. It is called any time the readyState changes.
readyState
of type PeerState, readonlyThe
readyState
attribute must return the
object's PeerConnection
PeerConnection
readiness state.
remoteDescription
of type SessionDescription
, readonlyThe remoteDescription method returns a copy of the current remote the SessionDescription that was most recently passed to setRemoteDescription, plus any remote candidates that have been supplied via addIceCandidate since then.
A null object will be returned if the remote description has not yet been set.
remoteStreams
of type array of MediaStream, readonlyReturns a live array containing the streams that the remote streams. (those that were added by the remote side).
This array is updated when
addstream
and
removestream
events are fired.
addIceCandidate
The addIceCandidate method provides a remote candidate to the ICE Agent, which will be added to the remote description. Connectivity checks will be sent to the new candidates as long as the "IceTransports" constraint is not set to "none". This call will result in a change to the state of the ICE Agent, and may result in a change to media state if it results in different connectivity being established.
A TBD exception will be thrown if candidate parameter is malformed.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
candidate |
| ✘ | ✘ |
void
addStream
Adds a new stream to the PeerConnection.
When the
addStream()
method is invoked, the user agent must run the
following steps:
If the
object's PeerConnection
PeerConnection
readiness state is
CLOSED
(3), throw an INVALID_STATE_ERR
exception.
If stream is already in the
object's PeerConnection
localStreams
object, then abort these steps.
Add stream to the end of the
object's PeerConnection
localStreams
object.
Parse the constraints provided by the application and apply them to the MediaStream, if possible. NOTE - need to deal with throwing an exception here.
Fire a renegotiationneeded event. [[OPEN ISSUE: Should this fire if the PeerConnection is in "new"?]]
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
stream | MediaStream | ✘ | ✘ | |
constraints | MediaConstraints | ✘ | ✔ |
void
close
When the
close()
method is invoked, the user agent must run the
following steps:
If the
object's PeerConnection
PeerConnection
readiness state is
CLOSED
(3), throw an INVALID_STATE_ERR
exception.
Destroy the PeerConnection
ICE Agent, abruptly ending any active ICE processing and
any active streaming, and releasing any relevant resources
(e.g. TURN permissions).
Set the object's PeerConnection
readiness state to
CLOSED
(3).
void
createAnswer
The createAnswer method generates a [SDP] answer with the supported configuration for the session that is compatible with the parameters supplied in offer. Like createOffer, the returned blob contains descriptions of the local MediaStreams attached to this PeerConnection, the codec/RTP/RTCP options negotiated for this session, and any candidates that have been gathered by the ICE Agent. The constraints parameter may be supplied to provide additional control over the generated answer.
As an answer, the generated SDP will contain a specific configuration that, along with the offer, specifies how the media plane should be established. The generation of the SDP must follow the appropriate process for generating an answer or provisional answer.
Session descriptions generated by createAnswer must be immediately usable by setLocalDescription without generating an error if setLocalDescription is called from the successCallback function. Like createOffer, the returned description should reflect the current state of the system. The session descriptions must remain usable by setLocalDescription without causing an error until at least the end of the successCallback function. Calling this method is is needed to get the ICE user name fragment and password. Provisional offers, as described in [RTCWEB-JSEP], are created if and only if the createProvisionalOffer flag is true.
The failureCallback will be called if the system can not generate an appropriate answer given the offer.
A TBD exception is thrown if the constraints parameter is malformed.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
offer |
| ✘ | ✘ | |
successCallback | SessionDescriptionCallback | ✘ | ✘ | |
failureCallback | PeerConnectionErrorCallback | ✘ | ✔ | |
constraints | MediaConstraints | ✘ | ✔ | |
createProvisionalAnswer=false | Boolean | ✘ | ✔ |
void
createDataChannel
Creates a new
object with the given label. The DataChannel
dictionary can be used to configure properties of
underlying channel such as
data reliability.
A corresponding DataChannelInit
object is dispatched at the other peer if the channel
setup was successful.DataChannel
When the
createDataChannel()
method is invoked, the user agent must run the
following steps.
If the
object’s PeerConnection
PeerConnection
readiness state is
CLOSED
(3), throw an INVALID_STATE_ERR
exception.
Let channel be a newly created
object.DataChannel
Initialize channel’s
label
attribute to the value of the first argument.
Initialize channel’s
reliable
attribute to true.
If the second argument is present and it contains a
reliable
dictionary member, then set channel’s
reliable
attribute to the dictionary member value.
Return channel and continue these steps in the background.
Create channel’s associated underlying data transport.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
label | DOMString | ✔ | ✘ | |
dataChannelDict |
| ✔ | ✔ |
DataChannel
createOffer
The createOffer method generates a blob of SDP that contains a RFC offer with the supported configurations for the session, including descriptions of the local MediaStreams attached to this PeerConnection, the codec/RTP/RTCP options supported by this implementation, and any candidates that have been gathered by the ICE Agent. The constraints parameter may be supplied to provide additional control over the offer generated.
As an offer, the generated SDP will contain the full set of capabilities supported by the session (as opposed to an answer, which will include only a specific negotiated subset to use); for each SDP line, the generation of the SDP must follow the appropriate process for generating an offer. In the event createOffer is called after the session is established, createOffer will generate an offer that is compatible with the current session, incorporating any changes that have been made to the session since the last complete offer-answer exchange, such as addition or removal of streams. If no changes have been made, the offer will be include the capabilities of the current local description as well as any additional capabilities that could be negotiated in an updated offer.
Session descriptions generated by createOffer must be immediately usable by setLocalDescription without causing an error as long as setLocalDiscription is called within the successCallback function. If a system has limited resources (e.g. a finite number of decoders), createOffer needs to return an offer that reflects the current state of the system, so that setLocalDescription will succeed when it attempts to acquire those resources. The session descriptions must remain usable by setLocalDescription without causing an error until at least end of the successCallback function. Calling this method is needed to get the ICE user name fragment and password.
The failureCallback will be called if the system can not generate an appropriate offer given the state of the PeerConnection.
A TBD exception is thrown if the constraints parameter is malformed. [[ OPEN ISSUE: How are errors reported? ]]
To Do: Discuss privacy aspects of this from a finger printing point of view - it's probably around as bad as access to a canvas :-)
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
successCallback | SessionDescriptionCallback | ✘ | ✘ | |
failureCallback | PeerConnectionErrorCallback | ✘ | ✔ | |
constraints | MediaConstraints | ✘ | ✔ |
void
removeStream
Removes the given stream from the localStream array in the PeerConnection and fires 'renegotiationneeded.
When the other peer stops sending a stream in this manner, a
removestream
event is fired at the
object.PeerConnection
When the
removeStream()
method is invoked, the user agent must run the
following steps:
If the
object's PeerConnection
PeerConnection
readiness state is
CLOSED
(3), throw an INVALID_STATE_ERR
exception.
If stream is not in the
object's PeerConnection
localStreams
object, then abort these steps. TODO: Do we need
an exception here?
Remove stream from the
object's PeerConnection
localStreams
object.
Fire a renegotiationneeded event.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
stream | MediaStream | ✘ | ✘ |
void
setLocalDescription
The setLocalDescription method instructs the PeerConnection to apply the supplied [SDP] description as the local offer or answer. The type parameter indicates whether the description should be processed as an offer, provisional answer, or final answer. [[OPEN ISSUE: The type appears as both the "action" argument and in the struct. That is redundant and just sort of crazy. We need to pick one.]]
This API changes the local media state. In order to successfully handle scenarios where the application wants to offer to change from one media format to a different, incompatible format, the PeerConnection must be able to simultaneously support use of both the old and new local descriptions (e.g. support codecs that exist in both descriptions) until a final answer is received, at which point the PeerConnection can fully adopt the new local description, or roll back to the old description if the remote side denied the change.
Open issues: how to indicate to roll back?
To Do: specify what parts of the SDP can be changed between the createOffer and setLocalDescription
Changes to the state of media transmission will occur when a final answer is successfully applied.
A TBD exception is thrown if sdp is invalid. A TBD exception is thrown if there are insufficient local resources to apply the sdp.
Open Issues: for setLocal and setRemote, discuss how to return erro codes and if they need to be asynchronous.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
action | SdpType | ✘ | ✘ | |
description |
| ✘ | ✘ |
void
setRemoteDescription
The setRemoteDescription method instructs the PeerConnection to apply the supplied [SDP] in the description. As in setLocalDescription, the action parameter indicates how the blob should be processed. This API changes the local media state.
Changes to the state of media transmission will occur when a final answer is successfully applied.
A TBD exception is thrown if the sdp parameter is invalid. A TBD exception is thrown if there are insufficient local resources to apply the SDP.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
action | SdpType | ✘ | ✘ | |
description |
| ✘ | ✘ |
void
updateIce
The updateIce method restarts or updates the ICE Agent process of gathering local candidates and pinging remote candidates. If there is a mandatory constraint called "IceTransports" it will control which how the ICE engine can act. This can be used to limit the use to TURN candidates by a callee to avoid leaking location information prior to the call being accepted.
This call may result in a change to the state of the ICE Agent, and may result in a change to media state if it results in connectivity being established.
If the restart parameter is set to true, the ICE state machine discards all candidates it has gathered, allocates new ports for the host candidates, and restarts ICE as if there had been no previos ICE session. Applications can use this to reset all ICE negotiation when something has gone terribly wrong.
A TBD exception will be thrown if constraints parameter is malformed.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
configuration |
| ✘ | ✔ | |
constraints | MediaConstraints | ✘ | ✔ | |
restart=false | Boolean | ✘ | ✔ |
void
PeerConnection
implements EventTarget;
IANA is requested to register the constraints defined in Constraints Section as specified in [RTCWEB-CONSTRAINTS].
TOOD: Need to change the naming and declaration of these constraints to match the constraints draft once that is a bit further along. The names here now are likely not quite right but they serve as a place holder. [[OPEN ISSUE: there are multiple ways to add constraints. How are multiple values reconciled?]]
The following new constraints are defined that can be used with a PeerConnection object:
This is a enum type constraint that can take the values "true" and "false". The default is a non mandatory "true" for a PeerConnection object that has a video stream at the point in time when the constraints are being evaluated and is non mandatory "false" otherwise.
In some cases, a PeerConnection may wish to receive video but it is not going to send any video. The PeerConnection needs to know if it should signal to the remote side if it wishes to receive video or not. This constraints allows an application to indicate its preferences for receiving video when creating an offer.
This is a enum type constraint that can take the values "true" and "false". The default is a non mandatory "true".
In some cases, a PeerConnection may wish to receive audio but it is not going to send any audio. The PeerConnection needs to know if it should signal to the remote side if it wishes to receive audio. This constraints allows an application to indicate its preferences for receiving audio when creating an offer.
This is a enum type constraint that can take the values "true" and "false". The default is a non mandatory "true".
Many codecs and system are capable of detecting "silence" and changing there behavior in this case by doing things such as not transmitting any media. In many cases, such as when dealing with sounds other than spoken voice or emergency calling, it is desirable to be able to turn off this behavior. This constraints allows the application to provide information about if it wishes this type of processing enable or disabled.
This is a enum type constraint that can take the values "none", "relay", and "all". The default is a non mandatory "all".
This constraints indicates which candidates the ICE engine is restricted use. The value "none" means the ICE engine must not send or receive any packets at this point. The value "relay" indicates the ICE engine must only using media relay candidates such as candidates passing through a TURN server. This can be used to reduce leakage of IP addresses in certain use cases. The value of "all" indicates all values can be used.
TODO items - need to register with IANA.
When two peers decide they are going to set up a connection to each other, they both go through these steps. The STUN/TURN server configuration describes a server they can use to get things like their public IP address or to set up NAT traversal. They also have to send data for the signaling channel to each other using the same out-of-band mechanism they used to establish that they were going to communicate in the first place.
NOTE: TODO - This code does not match the API yet and might have a few other problems.
var signalingChannel = createSignalingChannel(); var pc; // set up the call, get access to local media, and establish connectivity function start(isCaller) { // Create a PeerConnection and hook up the IceCallback pc = new PeerConnection("", function (candidate) { signalingChannel.send(JSON.stringify({ "type": "candidate", "sdp": candidate })); }); // get the local stream and show it in the local video element navigator.getUserMedia({"audio": true, "video": true}, function (stream) { selfView.src = URL.createObjectURL(stream); pc.addStream(stream); var type; if (isCaller) { pc.createOffer(gotDescription); type = "offer"; } else { pc.createAnswer(pc.remoteDescription, gotDescription); type = "answer"; } function gotDescription(desc) { pc.setLocalDescription(type, desc); signalingChannel.send(JSON.stringify({ "type": type, "sdp": desc })); } }); // once remote stream arrives, show it in the remote video element pc.onaddstream = function (evt) { remoteView.src = URL.createObjectURL(evt.stream); }; } signalingChannel.onmessage = function (evt) { var msg = JSON.parse(evt.data); var sdp = SessionDescription(msg.sdp) switch (msg.type) { case "offer": // create the PeerConnection start(false); // feed the received offer into the PeerConnection pc.setRemoteDescription(msg.type,SessionDescription(msg.sdp)); break; case "answer": pc.setRemoteDescription(msg.type,SessionDescription(msg.sdp)); break; case "candidate": pc.addIceCandidate(IceCandidate(msg.sdp)); break; } };
This example shows the more comples functionality.
TODO
The Peer-to-peer Data API lets a web application send and receive generic application data peer-to-peer.
Open issues (this should not be considered as a complete list of open issues)
The
interface represents a bi-directional data channel between
two peers. A DataChannel
is created via a factory method on a DataChannel
object. The corresponding PeerConnection
object is then dispatched at the other peer if the channel
setup was successful.DataChannel
Each
has an associated underlying data transport that
is used to transport actual data to the other peer. The transport
properties of the underlying data transport, such as
reliability mode, are configured by the peer taking the initiative to
create the channel. The other peer cannot change any transport
properties of a offered data channel. The actual wire protocol between
the peers is out of the scope for this specification.
Open Issues: this needs to explain how the configuration state
is passed between the peers.
Open Issues: this type of design where one side can pick anything and the
other side much support everything has proven to make future upgrades
very difficult. DataChannel
A
created with DataChannel
createDataChannel()
must initially be in the
CONNECTING
(0) state. If the
object’s underlying data transport is successfully
set up, the user agent must announce the
DataChannel
DataChannel
as open.
When the user agent is to announce a DataChannel
as
open, the user agent must queue a task to run the following
steps:
If the associated
object’s PeerConnection
PeerConnection
readiness state is
CLOSED
(3), abort these steps.
Let channel be the
object to be announced.DataChannel
Set channel’s
readyState
attribute to
OPEN
(1).
Fire a simple event named
open
at channel.
When an underlying data transport has been established, the user agent, of the peer that did not initiate the creation process must queue a task to run the following steps:
If the associated
object’s PeerConnection
PeerConnection
readiness state is
CLOSED
(3), abort these steps.
Let configuration be an information bundle with key-value pairs, received from the other peer as a part of the process to establish the underlying data channel.
Let channel be a newly created
object.DataChannel
Initialize channel’s
label
attribute to value that corresponds to the
"label
" key in configuration.
Initialize channel’s
reliable
attribute to true.
If configuration contains a key named
"reliable
", set channel’s
reliable
attribute to the corresponding value.
Set channel’s
readyState
attribute to
OPEN
(1).
Fire a datachannel event named
datachannel
with channel at the
object.PeerConnection
When the process of tearing down
a
object’s underlying data transport is
initiated, the user agent must run the following steps:DataChannel
If the associated
object’s PeerConnection
PeerConnection
readiness state is
CLOSED
(3), abort these steps.
Let channel be the
object which is about to be closed.DataChannel
If channel’s
readyState
is
CLOSING
(2) or
CLOSED
(3), then abort these steps.
Set channel’s
readyState
attribute to
CLOSING
(2).
Queue a task to run the following steps:
Close channel’s underlying data transport.
Set channel’s
readyState
attribute to
CLOSED
(3).
Fire a simple event named
close
at channel.
interface DataChannel {
readonly attribute DOMString label;
readonly attribute boolean reliable;
const unsigned short CONNECTING = 0;
const unsigned short OPEN = 1;
const unsigned short CLOSING = 2;
const unsigned short CLOSED = 3;
readonly attribute unsigned short readyState;
readonly attribute unsigned long bufferedAmount;
[TreatNonCallableAsNull]
attribute Function? onopen;
[TreatNonCallableAsNull]
attribute Function? onerror;
[TreatNonCallableAsNull]
attribute Function? onclose;
void close ();
[TreatNonCallableAsNull]
attribute Function? onmessage;
attribute DOMString binaryType;
void send (DOMString data);
void send (ArrayBuffer data);
void send (Blob data);
};
binaryType
of type DOMStringFIXME: align behavior with WebSocket API
bufferedAmount
of type unsigned long, readonlyFIXME: align behavior with WebSocket API
label
of type DOMString, readonlyThe
DataChannel.label
attribute represents a label that can be used to
distinguish this
object from other DataChannel
objects. The attribute must return the value to which it
was set when the DataChannel
object was created.DataChannel
onclose
of type Function, nullable
close
, must be supported by all objects implementing the
DataChannel
interface.onerror
of type Function, nullable
error
, must be supported by all objects implementing the
DataChannel
interface.onmessage
of type Function, nullable
message
, must be supported by all objects implementing the
DataChannel
interface.onopen
of type Function, nullable
open
, must be supported by all objects implementing the
DataChannel
interface.readyState
of type unsigned short, readonlyThe
DataChannel.readyState
attribute represents the state of the
DataChannel
object. It must return the value to which
the user agent last set it (as defined by the processing model
algorithms). The attribute can have the following values:
CONNECTING, OPEN, CLOSING or
CLOSED.
reliable
of type boolean, readonlyThe
DataChannel.reliable
attribute returns true if the
is reliable, and false otherwise. The attribute must
return the value to which it was set when the DataChannel
was created.DataChannel
close
Closes the
. It may be called regardless if the DataChannel
object was created by this peer or the remote peer.DataChannel
When the
close()
method is called, the user agent must initiate the process of tearing down
the DataChannel
object’s underlying data
transport.
void
send
FIXME: align behavior with WebSocket API
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
data | DOMString | ✘ | ✘ |
void
send
FIXME: align behavior with WebSocket API
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
data | ArrayBuffer | ✘ | ✘ |
void
send
FIXME: align behavior with WebSocket API
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
data | Blob | ✘ | ✘ |
void
CLOSED
of type unsigned shortThe underlying data transport has been closed or could not be established.
CLOSING
of type unsigned shortThe process of closing down the underlying data transport has started.
CONNECTING
of type unsigned shortThe user agent is attempting to establish the underlying
data transport. This is the initial state of a
object created with DataChannel
createDataChannel()
.
OPEN
of type unsigned shortTODO - theses constants need to be changed to an enum.
The underlying data transport is established and
communication is possible. This is the initial state of a
object dispatched as a part of a DataChannel
.DataChannelEvent
dictionary DataChannelInit {
boolean reliable;
};
DataChannelInit
Membersreliable
of type booleanThis simple example shows how to create a DataChannel, register an event listener to handle incoming data, and how to send a message.
var chan = peerConn.createDataChannel("mylabel"); chan.onmessage = function (evt) { // use evt.data }; chan.send("hello");
This simple example shows how to register an event listener to handle the case when a remote peer creates a new DataChannel.
peerConn.ondatachannel = function (evt) { var chan = evt.channel; chan.onmessage = function (evt) { // use evt.data }; chan.onclose = function () { // remote side closed the data channel }; };>
A Window
object has a strong reference to any
objects created from the constructor whose global object is
that PeerConnection
Window
object.
Several of the PeerConnection events use the
interface.PeerConnectionEvent
Firing a PeerConnectionEvent event named
e with a
peer means that an event with the name
e, which does not bubble (except where otherwise stated)
and is not cancelable (except where otherwise stated), and which uses
the PeerConnection
interface with the PeerConnectionEvent
peer
attribute set to the PeerConnectio object, must be created and
dispatched at the given target.
[Constructor(DOMString type, PeerConnectionEventInit eventInitDict)]
interface PeerConnectionEvent : Event {
readonly attribute PeerConnection
peer;
};
dictionary PeerConnectionEventInit : EventInit {
PeerConnection
peer;
};
peer
of type PeerConnection
, readonlyThe
peer
attribute represents the
object associated with the event.PeerConnection
PeerConnectionEventInit
Memberspeer
of type PeerConnection
The onicecandidate
event of the PeerConnection uses the
interface.PeerConnectionIceEvent
Firing a PeerConnectionIceEvent event named
e with a
peer means that an event with the name
e, which does not bubble (except where otherwise stated)
and is not cancelable (except where otherwise stated), and which uses
the PeerConnection
PeerConnectionIceEvent
interface with the peer
attribute set to the PeerConnection object, and the
candidate
attribute set to the new ICE candiate
must be created and
dispatched at the given target.
[Constructor(DOMString type, PeerConnectionIceEventInit eventInitDict)]
interface PeerConnectionIceEvent : Event {
readonly attribute PeerConnection
peer;
readonly attribute IceCandidate
candidate;
};
candidate
of type IceCandidate
, readonlyThe
candidate
attribute is the
IceCandidate
object with the new ICE candiate that caused the event.
peer
of type PeerConnection
, readonlyThe
peer
attribute represents the
object associated with the event.PeerConnection
dictionary PeerConnectionEventIceInit : EventInit {
PeerConnection
peer;
IceCandidate
candidate;
};
PeerConnectionEventIceInit
Memberscandidate
of type IceCandidate
peer
of type PeerConnection
The
addtrack
and
removetrack
events use the
interface.MediaStreamTrackEvent
Firing a track event named
e with a
MediaStreamTrack
track means that an event with the name
e, which does not bubble (except where otherwise stated)
and is not cancelable (except where otherwise stated), and which uses
the
interface with the MediaStreamTrackEvent
track
attribute set to track, must be created and
dispatched at the given target.
[Constructor(DOMString type, MediaStreamTrackEventInit eventInitDict)]
interface MediaStreamTrackEvent : Event {
readonly attribute MediaStreamTrack track;
};
dictionary MediaStreamTrackEventInit : EventInit {
readonly MediaStreamTrack? track;
};
track
of type MediaStreamTrack, readonlyThe
track
attribute represents the
MediaStreamTrack
object associated with the event.
MediaStreamTrackEventInit
Memberstrack
of type readonly MediaStreamTrack, nullableThe
addstream
and
removestream
events use the
interface.MediaStreamEvent
Firing a
stream event named e with a
MediaStream
stream means that an event with the name
e, which does not bubble (except where otherwise stated)
and is not cancelable (except where otherwise stated), and which uses
the
interface with the MediaStreamEvent
stream
attribute set to stream, must be created
and dispatched at the given target.
[Constructor(DOMString type, MediaStreamEventInit eventInitDict)]
interface MediaStreamEvent : Event {
readonly attribute MediaStream? stream;
};
dictionary MediaStreamEventInit : EventInit {
MediaStream stream;
};
stream
of type MediaStream, readonly, nullableThe
stream
attribute represents the
MediaStream
object associated with the event.
MediaStreamEventInit
Membersstream
of type MediaStreamThe
datachannel
event use the
interface.DataChannelEvent
Firing a datachannel event named
e with a
channel means that an event with the name
e, which does not bubble (except where otherwise stated)
and is not cancelable (except where otherwise stated), and which uses
the DataChannel
interface with the DataChannelEvent
channel
attribute set to channel, must be created and
dispatched at the given target.
[Constructor(DOMString type, DataChannelEventInit eventInitDict)]
interface DataChannelEvent : Event {
readonly attribute DataChannel
channel;
};
dictionary DataChannelEventInit : EventInit {
DataChannel
channel;
};
channel
of type DataChannel
, readonlyThe
channel
attribute represents the
object associated with the event.DataChannel
DataChannelEventInit
Memberschannel
of type DataChannel
This section is non-normative.
The following event fires on
MediaStream
objects:
Event name | Interface | Fired when... |
---|---|---|
ended
|
Event
|
The
MediaStream
finished as a result of all tracks in the
MediaStream
ending. |
The following event fires on
MediaStreamTrack
objects:
Event name | Interface | Fired when... |
---|---|---|
muted
|
Event
|
The
MediaStreamTrack
object's source is temporarily unable to provide
data. |
unmuted
|
Event
|
The
MediaStreamTrack
object's source is live again after having been
temporarily unable to provide data. |
ended
|
Event
|
The
MediaStreamTrack
object's source will no longer provide any data, either
because the user revoked the permissions, or because the source
device has been ejected, or because the remote peer stopped
sending data, or because the
stop()
method was invoked. |
The following event fires on
MediaStreamTrackList
objects:
Event name | Interface | Fired when... |
---|---|---|
addtrack
|
|
A new
MediaStreamTrack
has been added to this list. |
removetrack
|
|
A
MediaStreamTrack
has been removed from this list. |
The following event fires on
objects:DataChannel
Event name | Interface | Fired when... |
---|---|---|
open
|
Event
|
The object’s underlying data
transport has been established (or re-established). |
MessageEvent
|
Event
|
A message was successfully received. TODO: Ref where MessageEvent is defined? |
error
|
Event
|
TODO. |
close
|
Event
|
The object’s underlying data
transport has was closed. |
The following events fire on
objects:PeerConnection
Event name | Interface | Fired when... |
---|---|---|
connecting
|
Event
|
TODO |
open
|
Event
|
TODO |
addstream
|
|
A new stream has been added to the
remoteStreams
array. |
removestream
|
|
A stream has been removed from the
remoteStreams
array. |
renegotiationneeded
|
|
The browser wishes to inform the application that session negotiation needs to be redone at some point in the near future. Open Issue: should this be moved to "Negotiation Needed" instead of "Re-Negotiation Needed"? |
statechange
|
|
TODO |
icechange
|
|
TODO |
icecandidate
|
|
TODO |
This section will be removed before publication.
The editors wish to thank the Working Group chairs, Harald Alvestrand and Stefan Håkansson, for their support.