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.
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 document is not complete. It is subject to major changes and, while early experimentations are 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:
As the specification matures, the group hopes to strike the right balance between a low-level API that would enable interested parties to tweak potentially complex system parameters, and a more high-level API that Web developers can use without a priori technical knowledge about real-time communications.
There are a number of facets to video-conferencing in HTML covered by this specification:
video
or
audio
elements.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. This object may be extended to also 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 MUST 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 PeerConnection
object (later described in
this document) will take as input the data received from a remote peer.
Similarly, a 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
PeerConnection
object.
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
PeerConnection
, 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).
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 PeerConnection
. If this
happens for the reason exemplified, or for any other reason than the
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.
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]].
A track in a MediaStream
, received with a
PeerConnection
, MUST have its
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 PeerConnection
, all
MediaStreamTrack
objects in the resulting
MediaStream
are muted until media data can be read
from the RTP source.
The AudioMediaStreamTrack
is a specialization of
of a normal MediaStreamTrack
that only carries audio
and is extended to have the capability to send and/or receive DTMF
codes.
The canInsertDTMF
attribute MUST indicate if the
AudioMediaStreamTrack
is capable of sending
DTMF.
When a AudioMediaStreamTrack
object’s 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.
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.
A PeerConnection
allows two users to communicate
directly, browser-to-browser. Communications are coordinated via a
signaling channel provided by script in the page via the server, e.g. using
XMLHttpRequest
.
Calling new PeerConnection(configuration,
<<<<<<< HEAD
signalingCallback)
creates a
=======
signalingCallback, constraints) creates a
>>>>>>> master
PeerConnection
object.
The configuration string gives the address of a STUN or TURN server to use to establish the connection. [[!STUN]] [[!TURN]]
The allowed formats for this string are:
TYPE 203.0.113.2:3478
"Indicates a specific IP address and port for the server.
TYPE relay.example.net:3478
"Indicates a specific host and port for the server; the user agent will look up the IP address in DNS.
TYPE example.net
"Indicates a specific domain for the server; the user agent will look up the IP address and port in DNS.
The "TYPE
" is one of:
STUN
STUNS
TURN
TURNS
The signalingCallback argument is a method that will be
invoked when the user agent needs to send a message to the other host over
the signaling channel. When the callback is invoked, convey its first
argument (a string) to the other peer using whatever method is being used
by the Web application to relay signaling messages. (Messages returned from
the other peer are provided back to the user agent using the processSignalingMessage()
method.)
A PeerConnection
object has an associated PeerConnection
signaling
callback, a PeerConnection
ICE Agent,
a PeerConnection
readiness state and an SDP Agent.
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). Steps in the synchronous section are marked with ⌛.
Let serverConfiguration be the constructor’s first argument.
Let signalingCallback be the constructor’s second argument.
Let connection be a newly created
PeerConnection
object.
Create an ICE Agent and let connection’s PeerConnection
ICE Agent
be that ICE Agent. [[!ICE]]
If serverConfiguration contains a U+000A LINE FEED (LF) character or a U+000D CARRIAGE RETURN (CR) character (or both), remove all characters from serverConfiguration after the first such character.
Split serverConfiguration on spaces to obtain configuration components.
If configuration components has two or more components, and the first component is a case-sensitive match for one of the following strings:
STUN
"STUNS
"TURN
"TURNS
"...then run the following substeps:
Let server type be STUN if the first component of
configuration components is 'STUN
' or
'STUNS
', and TURN otherwise (the first component of
configuration components is "TURN
" or
"TURNS
").
Let secure be true if the first component of
configuration components is
"STUNS
" or "TURNS
", and false
otherwise.
Let host be the contents of the second component of configuration components up to the character before the first U+003A COLON character (:), if any, or the entire string otherwise.
Let port be the contents of the second component of configuration components from the character after the first U+003A COLON character (:) up to the end, if any, or the empty string otherwise.
Configure the PeerConnection
ICE
Agent’s STUN or TURN server as follows:
If the given IP address, host name, domain name, or port are invalid, then the user agent MUST act as if no STUN or TURN server is configured.
Let the connection’s PeerConnection
signaling callback be signalingCallback.
Set connection’s PeerConnection
readiness
state to NEW
(0).
Set connection’s PeerConnection
ice
state to NEW
(0).
Set connection’s PeerConnection
sdp
state to NEW
(0).
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. (Steps in synchronous sections are marked with ⌛.)
⌛ If the ice state is set to NEW, it MUST queue a task to start gathering ICE address and set the ice state to ICE_GATHERING.
⌛ Once the ICE address gathering is complete, if there are any streams in localStreams, the SDP Agent will send the initial the SDP offer. The initial SDP offer MUST contain both the ICE candidate information as well as the SDP to represent the media descriptions for all the streams in localStreams.
During the lifetime of the peerConnection object, the following procedures are followed:
If a local media stream has been added and an SDP offer needs to be sent, and the ICE state is not NEW or ICE_GATHERING, and the SDP Agent state is NEW or SDP_IDLE, then send and queue a task to send an SDP offer and change the SPD state to SDP Waiting.
If an SDP offer has been received, and the SDP state is NEW or SDP_IDLE, pass the ICE candidates from the SDP offer to the ICE Agent and change it state to ICE_CHECKING. Construct an appropriate SDP answer, update the remote streams, queue a task to send the SDP offer, and set the SDPAgent state to SDP_IDLE.
At the point the sdpState changes from NEW to some other state, the readyState changes to NEGOTIATING.
If the ICE Agent finds a candidates that froms a valid connection, the ICE state is changed to ICE_CONNECTED
If the ICE Agent finishes checking all candidates, if a connection has been found, the ice state is changed to ICE_COMPLETED and if not connection has been found it is changed to ICE_FAILED.
If the iceState is ICE_CONNECTED or ICE_COMPLETED and the SDP stat is SDP_IDLE, the readyState is set to ACTIVE.
If the iceState is ICE_FAILED, a task is queued to calls the close method.
The close method will cause the system to wait until the sdpStat is SDP_IDLE then it will send an SDP offer terminating all media and change the readyState to CLOSING as well as stop all ICE process and change the iceState to ICE_CLOSED. Once an SDP anser to this offer is received, the readyState will be changed to CLOSED.
User agents MAY negotiate any codec and any resolution, bitrate, or
other quality metric. User agents are encouraged to initially negotiate for
the native resolution of the 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.
All SDP media descriptions for streams represented by
MediaStream
objects MUST include a label attribute
("a=label:
") whose value is the value of the
MediaStream
object’s label
attribute. [[!SDP]] [[!SDPLABEL]]
PeerConnection
s MUST not
generate any candidates for media streams whose media descriptions do not
have a label attribute ("a=label:
"). [[!ICE]] [[!SDP]]
[[!SDPLABEL]]
When a user agent has reached the point in the media negotiation where a
MediaStream
can be created to represent incoming
components, the user agent MUST run the following steps:
Let connection be the PeerConnection
expecting this media.
Create a MediaStream
object to represent the
media stream. Set its label
attribute to the value of the
SDP Label attribute for that component’s media stream.
Run the following steps for each component in the media stream.
Create a MediaStreamTrack
object
track to represent the component.
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 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 thas 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 (its port has been set
to zero in a media description sent on the signaling channel), the user
agent MUST follow these steps:
Let connection be the PeerConnection
associated with the stream being removed.
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 a PeerConnection
object is consuming a MediaStream
and a track is
added to one of the stream’s MediaStreaMtrackList
objects, by, e.g., the add()
method being invoked, the
PeerConnection
object MUST add a media component for
that track the next time the user agent provides a stable state. The user agent
MUST also remove a media component in same way.
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.
When a message is relayed from the remote peer over the signaling
channel is received by the Web application, pass it to the user agent
by calling the processSignalingMessage()
method.
The order of messages is important. Passing messages to the user agent in a different order than they were generated by the remote peer’s user agent can prevent a successful connection from being established or degrade the connection’s quality if one is established.
When the processSignalingMessage()
method is invoked, the
user agent MUST run the following steps:
Let message be the method’s argument.
Let connection be the
PeerConnection
object on which the method was
invoked.
If connection’s PeerConnection
readiness state is CLOSED
(3), throw an
INVALID_STATE_ERR
exception.
If the first four characters of message are not
"SDP
" followed by a U+000A LINE FEED (LF) character,
then abort these steps. (This indicates an error in the signaling
channel implementation. User agents MAY report such errors to
their developer consoles to aid debugging.)
Future extensions to the
PeerConnection
interface might use other
prefix values to implement additional features.
Let sdp be the string consisting of all but the first four characters of message.
Pass the sdp to the PeerConnection
SDP
Agent as a subsequent offer or answer, to be interpreted as
appropriate given the current state of the SDP Agent.
[[!ICE]]
When a PeerConnection
ICE Agent
forms a connection to the the far side and enters the state
ICE_CONNECTED, the user agent MUST queue a task that sets the
PeerConnection
object’s PeerConnection
readiness state to ACTIVE
(2) and then
fires a simple event named
open
at the
PeerConnection
object.
close()
method has been
invoked.close()
method has been invoked.The readyState
attribute MUST return the
PeerConnection
object’s PeerConnection
readiness state, represented by a number from the following
list:
PeerConnection
. NEW
(0)PeerConnection
. NEGOTIATING
(1)PeerConnection
. ACTIVE
(2)PeerConnection
. CLOSING
(4)PeerConnection
object is terminating
all media and is in the process of closing the Ice Agent and SDP
Agent.PeerConnection
. CLOSED
(3)The iceState
attribute
MUST return the state of the PeerConnection
ICE Agent
ICE state, represented by a number from the following list:
PeerConnection
. NEW
(0)PeerConnection
. ICE_GATHERING
(0x100)PeerConnection
. ICE_WAITING
(0x200)PeerConnection
. ICE_CHECKING
(0x300)PeerConnection
. ICE_CONNECTED
(0x400)PeerConnection
. ICE_COMPLETED
(0x500)PeerConnection
. ICE_FAILED
(0x600)PeerConnection
. ICE_CLOSED
(0x700)The sdpState
attribute
MUST return the state of the PeerConnection
SDP Agent , represented
by a number from the following list:
PeerConnection
. NEW
(0)PeerConnection
. SDP_IDLE
(0x1000)PeerConnection
. SDP_WAITING
(0x2000)PeerConnection
. SDP_GLARE
(0x3000)Creates a new DataChannel
object with the
given label. The DataChannelInit
dictionary can
be used to configure properties of underlying channel such as
data reliability. A corresponding
DataChannel
object is dispatched at the other
peer if the channel setup was successful.
When the createDataChannel()
method is invoked, the user agent MUST run the following steps.
If the PeerConnection
object’s PeerConnection
readiness state is CLOSED
(3), throw an
INVALID_STATE_ERR
exception.
Let channel be a newly created
DataChannel
object.
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.
datachannel
, MUST be
supported by all objects implementing the
PeerConnection
interface.Attempts to starting sending the given stream to the remote peer. The format for the MediaStreamHints objects is currently undefined by the specification.
When the other peer starts sending a stream in this manner, an
addstream
event is fired at
the PeerConnection
object.
When the addStream()
method is invoked, the user agent MUST
run the following steps:
Let stream be the method’s first argument.
Let hints be the method’s second argument.
If the PeerConnection
object’s PeerConnection
readiness state is CLOSED
(3), throw an
INVALID_STATE_ERR
exception.
If stream is already in the
PeerConnection
object’s localStreams
object, then abort these steps.
Add stream to the end of the
PeerConnection
object’s localStreams
object.
Return from the method.
Parse the hints provided by the application and apply them to the MediaStream, if possible.
Have the PeerConnection
add a media stream
for stream the next time the user agent provides a stable state. Any
other pending stream additions and removals MUST be processed at
the same time.
Stops sending the given stream to the remote peer.
When the other peer stops sending a stream in this manner, a
removestream
event is
fired at the PeerConnection
object.
When the removeStream()
method is invoked, the user agent MUST
run the following steps:
Let stream be the method’s argument.
If the PeerConnection
object’s PeerConnection
readiness state is CLOSED
(3), throw an
INVALID_STATE_ERR
exception.
If stream is not in the
PeerConnection
object’s localStreams
object, then abort these steps.
Remove stream from the
PeerConnection
object’s localStreams
object.
Return from the method.
Have the PeerConnection
remove the media
stream for stream the next time the user agent
provides a stable
state. Any other pending stream additions and removals
MUST be processed at the same time.
Returns a live array containing the streams that the user agent is
currently attempting to transmit to the remote peer (those that were
added with addStream()
).
Specifically, it MUST return the read-only
MediaStream
array that the attribute was set to
when the PeerConnection
’s constructor ran.
Returns a live array containing the streams that the user agent is currently receiving from the remote peer.
Specifically, it MUST return the read-only
MediaStream
array that the attribute was set to
when the PeerConnection
’s constructor ran.
This array is updated when addstream
and removestream
events are
fired.
When the close()
method is invoked, the user agent MUST run
the following steps:
If the PeerConnection
object’s 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).
The localStreams
and
remoteStreams
objects
remain in the state they were in when the object was closed.
connecting
, MUST be
supported by all objects implementing the
PeerConnection
interface.open
, MUST be supported by all
objects implementing the PeerConnection
interface.open
, MUST be supported by all
objects implementing the PeerConnection
interface.
It is called any time the readyState, iceState, or sdpState
changes.addstream
, MUST be supported
by all objects implementing the PeerConnection
interface.removestream
, MUST be
supported by all objects implementing the
PeerConnection
interface.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" if the PeerConnection a video stream has been added no "false" otherwise.
In some cases, a PeerConenction may wish to receive video but it is not going to send any video. The PeerConenction 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 it's 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".
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 "true" and "false". The default is a non mandatory "false".
This constraints indicat4es if the ICE engine is restricted to 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.
TODO items - need to register with IANA. Need to have error on constructor if not possible to resolve them.
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.
// the first argument describes the STUN/TURN server configuration var local = new PeerConnection('TURNS example.net', sendSignalingChannel); local.signalingChannel(...); // if we have a message from the other side, pass it along here // (aLocalStream is some LocalMediaStream object) local.addStream(aLocalStream); // start sending video function sendSignalingChannel(message) { ... // send message to the other side via the signaling channel } function receiveSignalingChannel (message) { // call this whenever we get a message on the signaling channel local.signalingChannel(message); } local.onaddstream = function (event) { // (videoElement is some <video> element) videoElement.src = URL.createObjectURL(event.stream); };
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 DataChannel
interface represents a
bi-directional data channel between two peers. A
DataChannel
is created via a factory method on a
PeerConnection
object. The corresponding
DataChannel
object is then dispatched at the other
peer if the channel setup was successful.
Each DataChannel
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, is configured by the peer taking the initiative
to create the channel. The receiving 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.
A DataChannel
created with createDataChannel()
MUST initially be in the CONNECTING
(0) state. If the
DataChannel
object’s underlying data transport
is successfully set up, the user agent MUST announce the 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 PeerConnection
object’s
PeerConnection
readiness state is CLOSED
(3), abort these
steps.
Let channel be the DataChannel
object to be announced.
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 PeerConnection
object’s
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
DataChannel
object.
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 PeerConnection
object.
When the process of tearing down a
DataChannel
object’s underlying data
transport is initiated, the user agent MUST run the following
steps:
If the associated PeerConnection
object’s
PeerConnection
readiness state is CLOSED
(3), abort these
steps.
Let channel be the DataChannel
object which is about to be closed.
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.
The DataChannel.label
attribute represents a label that can be used to distinguish this
DataChannel
object from other
DataChannel
objects. The attribute MUST return
the value to which it was set when the
DataChannel
object was created.
The DataChannel.reliable
attribute returns true if the DataChannel
is
reliable, and false otherwise. The attribute MUST return the value to
which it was set when the DataChannel
was
created.
The user agent is attempting to establish the underlying data
transport. This is the initial state of a
DataChannel
object created with createDataChannel()
.
The underlying data transport is established and
communication is possible. This is the initial state of a
DataChannel
object dispatched as a part of a
DataChannelEvent
.
The process of closing down the underlying data transport has started.
The underlying data transport has been closed or could not be established.
The 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.
FIXME: align behavior with WebSocket API
open
, MUST be supported by all
objects implementing the DataChannel
interface.error
, MUST be supported by all
objects implementing the DataChannel
interface.close
, MUST be supported by all
objects implementing the DataChannel
interface.Closes the DataChannel
. It may be called
regardless if the DataChannel
object was created
by this peer or the remote peer.
When the close()
method is called, the
user agent MUST initiate the
process of tearing down the DataChannel
object’s
underlying data transport.
message
, MUST be supported by
all objects implementing the DataChannel
interface.FIXME: align behavior with WebSocket API
FIXME: align behavior with WebSocket API
FIXME: align behavior with WebSocket API
FIXME: align behavior with WebSocket API
This 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 PeerConnection
objects
created from the constructor whose global object is that
Window
object.
The addtrack
and
removetrack
events
use the MediaStreamTrackEvent
interface.
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
MediaStreamTrackEvent
interface with the
track
attribute set to track, MUST be created and dispatched at the
given target.
The track
attribute
represents the MediaStreamTrack
object associated
with the event.
-
The addstream
and removestream
events use the
MediaStreamEvent
interface.
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 MediaStreamEvent
interface with the
stream
attribute
set to stream, MUST be created and dispatched at the
given target.
The stream
attribute
represents the MediaStream
object associated with
the event.
-
The datachannel
event use the
DataChannelEvent
interface.
Firing a datachannel event named
e with a DataChannel
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
DataChannelEvent
interface with the channel
attribute set to
channel, MUST be created and dispatched at the given
target.
The channel
attribute
represents the DataChannel
object associated with
the event.
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 |
MediaStreamTrackEvent |
A new MediaStreamTrack has been added to this
list. |
removetrack |
MediaStreamTrackEvent |
A MediaStreamTrack has been removed from this
list. |
The following events fire on PeerConnection
objects:
Event name | Interface | Fired when... |
---|---|---|
connecting |
Event |
The ICE Agent has begun negotiating with the peer. This can
happen multiple times during the lifetime of the
PeerConnection object. |
open |
Event |
The ICE Agent has finished negotiating with the peer. |
datachannel_ |
DataChannelEvent |
The other peer successfully created a new
DataChannel object. |
addstream |
MediaStreamEvent |
A new stream has been added to the remoteStreams
array. |
removestream |
MediaStreamEvent |
A stream has been removed from the remoteStreams
array. |
The following events fire on DataChannel
objects:
Event name | Interface | Fired when... |
---|---|---|
open |
Event |
The DataChannel object’s underlying data
transport has been established (or re-established).
|
error |
Event |
- |
close |
Event |
The DataChannel object’s underlying data
transport has was closed.
|
message |
MessageEvent |
A message was successfully received. |
IANA is requested to register the constraints defined in Constraints Section as specified in [[!RTCWEB-CONSTRAINTS]].
This registration is for community review and will be submitted to the IESG for review, approval, and registration with IANA.
This format is used for encoding UDP packets transmitted by potentially hostile Web page content via a trusted user agent to a destination selected by a potentially hostile remote server. To prevent this mechanism from being abused for cross-protocol attacks, all the data in these packets is masked so as to appear to be random noise. The intent of this masking is to reduce the potential attack scenarios to those already possible previously.
However, this feature still allows random data to be sent to destinations that might not normally have been able to receive them, such as to hosts within the victim’s intranet. If a service within such an intranet cannot handle receiving UDP packets containing random noise, it might be vulnerable to attack from this feature.
Fragment identifiers cannot be used with application/html-peer-connection-data
as URLs cannot be used to identify streams that use this format.
This section will be removed before publication.
Need a way to indicate the type of the SDP when passing SDP strings.
The editors wish to thank the Working Group chairs, Harald Alvestrand and Stefan Håkansson, for their support.