WebRTC 1.0: Real-time Communication Between Browsers
W3C Working Draft 27 October 2011
- This version:
- http://www.w3.org/TR/2011/WD-webrtc-20111027/
- Latest published version:
- http://www.w3.org/TR/webrtc/
- Latest editor's draft:
- http://dev.w3.org/2011/webrtc/editor/webrtc.html
- Previous version:
- none
- Editors:
- Adam Bergkvist, Ericsson
- Daniel C. Burnett, Voxeo
- Cullen Jennings, Cisco
- Anant Narayanan, Mozilla
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 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.
Abstract
This document defines a set of APIs that allow local media, including audio and video, to be requested from a platform, 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.
Status of This Document
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 a First Public Working Draft and 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:
- The outcomes of ongoing exchanges in the companion RTCWEB group at IETF to define the set of protocols that, together with this document, will enable real-time communications in Web browsers.
- Privacy issues that arise when exposing local capabilities and local streams.
- Technical discussions within the group, on the data channel in particular.
- Experience gained through early experimentations.
- Feedback received from other groups and individuals.
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.
This document was published by the Web Real-Time Communications Working Group as a Working Draft. This document is intended to become a W3C Recommendation. 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 a Working 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.
1. Introduction
This section is non-normative.
There are a number of facets to video-conferencing in HTML:
- Getting a multimedia stream (video, audio, or both) from local devices (video cameras, microphones, Web cams) or from prerecorded files provided by the user.
- Recording such streams locally.
- Connecting to remote peers using NAT-traversal technologies such as ICE, STUN, and TURN.
- Sending the locally-produced streams to remote peers and receiving streams from remote peers.
- Displaying such streams (both the locally-produced ones and the remotely-obtained
ones) locally using the
videooraudioelements. - Sending arbitrary data to remote peers.
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.
2. Obtaining local multimedia content
2.2 Examples
A voice chat feature in a game could attempt to get access to the user's microphone by calling the API as follows:
<script>
navigator.getUserMedia('audio', gotAudio);
function gotAudio(stream) {
// ... use 'stream' ...
}
</script>
A video-conferencing system would ask for both audio and video:
<script>
function beginCall() {
navigator.getUserMedia('audio,video user', gotStream);
}
function gotStream(stream) {
// ... use 'stream' ...
}
</script>
3. Stream API
3.1 Introduction
The MediaStream interface is used to
represent streams of media data, typically (but not necessarily) of audio and/or video
content, e.g. from a local camera or a remote site. The data from a MediaStream object does not necessarily have a canonical
binary form; for example, it could just be "the video currently coming from the user's
video camera". This allows user agents to manipulate media streams in whatever fashion
is most suitable on the user's platform.
Each MediaStream object can represent zero
or more tracks, in particular audio and video tracks. Tracks can contain multiple
channels of parallel data; for example a single audio track could have nine channels of
audio data to represent a 7.2 surround sound audio track.
Each track represented by a MediaStream
object has a corresponding MediaStreamTrack object.
A MediaStream object has an input and an
output. The input depends on how the object was created: a LocalMediaStream object generated by a getUserMedia() call, for instance, might take
its input from the user's local camera, while a MediaStream created by a PeerConnection object will take as input the data received
from a remote peer. The output of the object controls how the object is used, e.g. what
is saved if the object is written to a file, what is displayed if the object is used in
a video element, or indeed what is transmitted to a remote peer if the
object is used with a PeerConnection
object.
Each track in a MediaStream object can be
disabled, meaning that it is muted in the object's output. All tracks are initially
enabled.
A MediaStream can be
finished,
indicating that its inputs have forever stopped providing data. When a MediaStream object is finished, all its tracks are muted
regardless of whether they are enabled or disabled.
The output of a MediaStream object must
correspond to the tracks in its input. Muted audio tracks must be replaced with
silence. Muted video tracks must be replaced with blackness.
A new MediaStream object can be created
from a list of MediaStreamTrack objects
using the MediaStream()
constructor. The list of MediaStreamTrack
objects can be the track list of another stream, a subset of the track list of
a stream or a composition of MediaStreamTrack
objects from different MediaStream objects.

The ability to duplicate a MediaStream, i.e.
create a new MediaStream object from the track
list of an existing stream, allows for greater control since separate
MediaStream instances can be manipulated and consumed
individually. This 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 makes it
possible to, e.g., record selected tracks from a conversation involving several
MediaStream objects with a single
MediaStreamRecorder.
The LocalMediaStream interface is used
when the user agent is generating the stream's data (e.g. from a camera or streaming it
from a local video file). It allows authors to control individual tracks during the
generation of the content, e.g. to allow the user to temporarily disable a local camera
during a video-conference chat.
When a LocalMediaStream object is being
generated from a local file (as opposed to a live audio/video source), the user agent
should stream the data from the file in real time, not all at once. This reduces the
ease with which pages can distinguish live video from pre-recorded video, which can
help protect the user's privacy.
3.2 Interface definitions
3.2.5 BlobCallback
[Callback=FunctionOnly, NoInterfaceObject]
interface BlobCallback {
void handleEvent (Blob blob);
};
3.2.5.1 Methods
handleEvent- Def TBD
Parameter Type Nullable Optional Description blob Blob✘ ✘ No exceptions.
3.2.6 URL
Note that the following is actually only a partial interface, but ReSpec does not yet support that.
interface URL {
static DOMString createObjectURL (MediaStream stream);
};
3.2.6.1 Methods
createObjectURL-
Mints a Blob URL to refer to the given
MediaStream.When the
createObjectURL()method is called with aMediaStreamargument, the user agent must return a unique Blob URL for the givenMediaStream. [FILE-API]For audio and video streams, the data exposed on that stream must be in a format supported by the user agent for use in
audioandvideoelements.A Blob URL is the same as what the File API specification calls a Blob URI, except that anything in the definition of that feature that refers to
FileandBlobobjects is hereby extended to also apply toMediaStreamandLocalMediaStreamobjects.Parameter Type Nullable Optional Description stream MediaStream✘ ✘ No exceptions.
3.3 Examples
This sample code exposes a button. When clicked, the button is disabled and the user is prompted to offer a stream. The user can cause the button to be re-enabled by providing a stream (e.g. giving the page access to the local camera) and then disabling the stream (e.g. revoking that access).
<input type="button" value="Start" onclick="start()" id="startBtn">
<script>
var startBtn = document.getElementById('startBtn');
function start() {
navigator.getUserMedia('audio,video', gotStream);
startBtn.disabled = true;
}
function gotStream(stream) {
stream.onended = function () {
startBtn.disabled = false;
}
}
</script>
This example allows people to record a short audio message and upload it to the server. This example even shows rudimentary error handling.
<input type="button" value="⚫" onclick="msgRecord()" id="recBtn">
<input type="button" value="◼" onclick="msgStop()" id="stopBtn" disabled>
<p id="status">To start recording, press the ⚫ button.</p>
<script>
var recBtn = document.getElementById('recBtn');
var stopBtn = document.getElementById('stopBtn');
function report(s) {
document.getElementById('status').textContent = s;
}
function msgRecord() {
report('Attempting to access microphone...');
navigator.getUserMedia('audio', gotStream, noStream);
recBtn.disabled = true;
}
var msgStream, msgStreamRecorder;
function gotStream(stream) {
report('Recording... To stop, press to ◼ button.');
msgStream = stream;
msgStreamRecorder = stream.record();
stopBtn.disabled = false;
stream.onended = function () {
msgStop();
}
}
function msgStop() {
report('Creating file...');
stopBtn.disabled = true;
msgStream.onended = null;
msgStream.stop();
msgStreamRecorder.getRecordedData(msgSave);
}
function msgSave(blob) {
report('Uploading file...');
var x = new XMLHttpRequest();
x.open('POST', 'uploadMessage');
x.send(blob);
x.onload = function () {
report('Done! To record a new message, press the ⚫ button.');
recBtn.disabled = false;
};
x.onerror = function () {
report('Failed to upload message. To try recording a message again, press the ⚫ button.');
recBtn.disabled = false;
};
}
function noStream() {
report('Could not obtain access to your microphone. To try again, press the ⚫ button.');
recBtn.disabled = false;
}
</script>
This example allows people to take photos of themselves from the local video camera.
<article>
<style scoped>
video { transform: scaleX(-1); }
p { text-align: center; }
</style>
<h1>Snapshot Kiosk</h1>
<section id="splash">
<p id="errorMessage">Loading...</p>
</section>
<section id="app" hidden>
<p><video id="monitor" autoplay></video> <canvas id="photo"></canvas>
<p><input type=button value="📷" onclick="snapshot()">
</section>
<script>
navigator.getUserMedia('video user', gotStream, noStream);
var video = document.getElementById('monitor');
var canvas = document.getElementById('photo');
function gotStream(stream) {
video.src = URL.getObjectURL(stream);
video.onerror = function () {
stream.stop();
};
stream.onended = noStream;
video.onloadedmetadata = function () {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
document.getElementById('splash').hidden = true;
document.getElementById('app').hidden = false;
};
}
function noStream() {
document.getElementById('errorMessage').textContent = 'No camera available.';
}
function snapshot() {
canvas.getContext('2d').drawImage(video, 0, 0);
}
</script>
</article>
4. Peer-to-peer connections
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,
signalingCallback)" creates a 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- Indicates a STUN server
STUNS- Indicates a STUN server that is to be contacted using a TLS session.
TURN- Indicates a TURN server
TURNS- Indicates a TURN server that is to be contacted using a TLS session.
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
PeerConnectionobject. -
Create an ICE Agent and let connection's
PeerConnectionICE 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
PeerConnectionICE Agent's STUN or TURN server as follows:- If server type is STUN, the server is a STUN server. Otherwise, server type is TURN and the server is a TURN server.
- If secure is true, the server is to be contacted using TLS-over-TCP, otherwise, it is to be contacted using UDP.
- The IP address, host name, or domain name of the server is host.
- The port to use is port. If this is the empty string, then only a domain name is configured (and the ICE Agent will use DNS SRV requests to determine the IP address and port).
- The long-term username for the STUN or TURN server is the ASCII serialization of the entry script's origin; the long-term password is the empty string.
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
PeerConnectionsignaling callback be signalingCallback. -
Set connection's
PeerConnectionreadiness state toNEW(0). -
Set connection's
PeerConnectionice state toNEW(0). -
Set connection's
PeerConnectionsdp state toNEW(0). -
Let connection's
localStreamsattribute be an empty read-onlyMediaStreamarray. [WEBIDL] -
Let connection's
remoteStreamsattribute be an empty read-onlyMediaStreamarray. [WEBIDL] -
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 ICEGATHERING.
-
⌛ 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 ICEGATHERING, and the SDP Agent state is NEW or SDPIDLE, 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 SDPIDLE, pass the ICE candidates from the SDP offer to the ICE Agent and change it state to ICECHECKING. Construct an appropriate SDP answer, update the remote streams, queue a task to send the SDP offer, and set the SDPAgent state to SDPIDLE.
-
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 ICECONNECTED
-
If the ICE Agent finishes checking all candidates, if a connection has been found, the ice state is changed to ICECOMPLETED and if not connection has been found it is changed to ICEFAILED.
-
If the iceState is ICECONNECTED or ICECOMPLETED and the SDP stat is SDPIDLE, the readyState is set to ACTIVE.
-
If the iceState is ICEFAILED, a task is queued to calls the close method.
-
The close method will cause the system to wait until the sdpStat is SDPIDLE 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]
PeerConnections 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 starts receiving media for a component and a candidate was
provided for that component by a PeerConnection, the user agent must follow these
steps:
-
Let connection be the
PeerConnectionexpecting this media. -
If there is already a
MediaStreamobject for the media stream to which this component belongs, then associate the component with that media stream and abort these steps. (Some media streams have multiple components; this API does not expose the role of these individual components in ICE.) -
Create a
MediaStreamobject to represent the media stream. Set itslabelattribute to the value of the SDP Label attribute for that component's media stream. -
Queue a task to run the following substeps:
-
If the connection's
PeerConnectionreadiness state isCLOSED(3), abort these steps. -
Add the newly created
MediaStreamobject to the end of connection'sremoteStreamsarray. -
Fire a stream event named
addstreamwith the newly createdMediaStreamobject at the connection 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
PeerConnectionassociated with the stream being removed. -
Let stream be the
MediaStreamobject 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
PeerConnectionreadiness state isCLOSED(3), abort these steps. -
Remove stream from connection's
remoteStreamsarray. -
Fire a stream event named
removestreamwith stream at the connection object.
-
The task source for the tasks listed in this section is the networking task source.
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.
4.1 PeerConnection
[Constructor (in DOMString configuration, in SignalingCallback signalingCallback)]
interface PeerConnection {
void processSignalingMessage (DOMString message);
const unsigned short NEW = 0;
const unsigned short NEGOTIATING = 1;
const unsigned short ACTIVE = 2;
const unsigned short CLOSING = 4;
const unsigned short CLOSED = 3;
readonly attribute unsigned short readyState;
const unsigned short ICE_GATHERING = 0x100;
const unsigned short ICE_WAITING = 0x200;
const unsigned short ICE_CHECKING = 0x300;
const unsigned short ICE_CONNECTED = 0x400;
const unsigned short ICE_COMPLETED = 0x500;
const unsigned short ICE_FAILED = 0x600;
const unsigned short ICE_CLOSED = 00x700;
readonly attribute unsigned short iceState;
const unsigned short SDP_IDLE = 0x1000;
const unsigned short SDP_WAITING = 0x2000;
const unsigned short SDP_GLARE = 0x3000;
readonly attribute unsigned short sdpState;
void addStream (MediaStream stream, MediaStreamHints hints);
void removeStream (MediaStream stream);
readonly attribute MediaStream[] localStreams;
readonly attribute MediaStream[] remoteStreams;
void close ();
attribute Function? onconnecting;
attribute Function? onopen;
attribute Function? onstatechange;
attribute Function? onaddstream;
attribute Function? onremovestream;
};
4.1.1 Attributes
iceStateof type unsigned short, readonly-
The
iceStateattribute must return the state of thePeerConnectionICE AgentPeerConnectionICE state, represented by a number from the following list:PeerConnection.NEW(0)- The object was just created, and no networking has yet occurred.
PeerConnection.ICE_GATHERING(0x100)- The ICE Agent is attempting to establish a gather addresses.
PeerConnection.ICE_WAITING(0x200)- The ICE Agent is waiting for candidates from the other side before it can start checking.
PeerConnection.ICE_CHECKING(0x300)- The ICE Agent is checking candidates but has not yet found a connection.
PeerConnection.ICE_CONNECTED(0x400)- The ICE Agent has found a connection but is still checking other candidates to see if there is a better connection.
PeerConnection.ICE_COMPLETED(0x500)- The ICE Agent has finished checking and found a connection.
PeerConnection.ICE_FAILED(0x600)- The ICE Agent is finished checking all candidates and failed to find a connection.
PeerConnection.ICE_CLOSED(0x700)- The ICE Agent has shut down and is no longer responding to STUN requests.
No exceptions.
localStreamsof type array ofMediaStream, readonly-
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
MediaStreamarray that the attribute was set to when thePeerConnection's constructor ran.No exceptions.
onaddstreamof type Function, nullable- This event handler, of event handler event
type
addstream, must be supported by all objects implementing thePeerConnectioninterface.No exceptions.
onconnectingof type Function, nullable- This event handler, of event handler event
type
connecting, must be supported by all objects implementing thePeerConnectioninterface.No exceptions.
onopenof type Function, nullable- This event handler, of event handler event
type
open, must be supported by all objects implementing thePeerConnectioninterface.No exceptions.
onremovestreamof type Function, nullable- This event handler, of event handler event
type
removestream, must be supported by all objects implementing thePeerConnectioninterface.No exceptions.
onstatechangeof type Function, nullable- This event handler, of event handler event
type
open, must be supported by all objects implementing thePeerConnectioninterface. It is called any time the readyState, iceState, or sdpState changes.No exceptions.
readyStateof type unsigned short, readonly-
The
readyStateattribute must return thePeerConnectionobject'sPeerConnectionreadiness state, represented by a number from the following list:PeerConnection.NEW(0)- The object was just created, and no networking has yet occurred.
PeerConnection.NEGOTIATING(1)- The user agent is attempting to establish an connection with the ICE Agent and to negotiate codecs with the SDP Agent.
PeerConnection.ACTIVE(2)- The ICE Agent has found a connection the SDP Agent has performed a round of codec negotiation. It is possible for whatever media was negotiated to flow.
PeerConnection.CLOSING(4)- The
PeerConnectionobject is terminating all media and is in the process of closing the Ice Agent and SDP Agent. PeerConnection.CLOSED(3)- The connection is closed.
No exceptions.
remoteStreamsof type array ofMediaStream, readonly-
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
MediaStreamarray that the attribute was set to when thePeerConnection's constructor ran.This array is updated when
addstreamandremovestreamevents are fired.No exceptions.
sdpStateof type unsigned short, readonly-
The
sdpStateattribute must return the state of thePeerConnectionSDP Agent , represented by a number from the following list:PeerConnection.NEW(0)- The object was just created, and no networking has yet occurred.
PeerConnection.SDP_IDLE(0x1000)- At least one SDP offer or answer has been exchange and the SDP Agent is ready to send an SDP offer or receive an SDP answer.
PeerConnection.SDP_WAITING(0x2000)- The SDP Agent has sent and offer and is waiting for a answer.
PeerConnection.SDP_GLARE(0x3000)- The SDP Agent received an offer while waiting for an answer and now much wait a rondom amount of time before retrying to send the offer.
No exceptions.
4.1.2 Methods
addStream-
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
addstreamevent is fired at thePeerConnectionobject.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
PeerConnectionobject'sPeerConnectionreadiness state isCLOSED(3), throw anINVALID_STATE_ERRexception. -
If stream is already in the
PeerConnectionobject'slocalStreamsobject, then abort these steps. -
Add stream to the end of the
PeerConnectionobject'slocalStreamsobject. -
Return from the method.
-
Parse the hints provided by the application and apply them to the MediaStream, if possible.
-
Have the
PeerConnectionadd 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.
No exceptions.
-
close-
When the
close()method is invoked, the user agent must run the following steps:-
If the
PeerConnectionobject'sPeerConnectionreadiness state isCLOSED(3), throw anINVALID_STATE_ERRexception. -
Destroy the
PeerConnectionICE Agent, abruptly ending any active ICE processing and any active streaming, and releasing any relevant resources (e.g. TURN permissions). -
Set the object's
PeerConnectionreadiness state toCLOSED(3).
The
localStreamsandremoteStreamsobjects remain in the state they were in when the object was closed.No parameters.
No exceptions.
-
processSignalingMessage-
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
PeerConnectionobject on which the method was invoked. -
If connection's
PeerConnectionreadiness state isCLOSED(3), throw anINVALID_STATE_ERRexception. -
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
PeerConnectioninterface 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
PeerConnectionSDP Agent as a subsequent offer or answer, to be interpreted as appropriate given the current state of the SDP Agent. [ICE]
When a
PeerConnectionICE Agent forms a connection to the the far side and enters the state ICECONNECTED, the user agent must queue a task that sets thePeerConnectionobject'sPeerConnectionreadiness state toACTIVE(2) and then fires a simple event namedopenat thePeerConnectionobject.Parameter Type Nullable Optional Description message DOMString✘ ✘ No exceptions.
-
removeStream-
Stops sending the given stream to the remote peer.
When the other peer stops sending a stream in this manner, a
removestreamevent is fired at thePeerConnectionobject.When the
removeStream()method is invoked, the user agent must run the following steps:-
Let stream be the method's argument.
-
If the
PeerConnectionobject'sPeerConnectionreadiness state isCLOSED(3), throw anINVALID_STATE_ERRexception. -
If stream is not in the
PeerConnectionobject'slocalStreamsobject, then abort these steps. -
Remove stream from the
PeerConnectionobject'slocalStreamsobject. -
Return from the method.
-
Have the
PeerConnectionremove 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.
Parameter Type Nullable Optional Description stream MediaStream✘ ✘ No exceptions.
-
4.1.3 Constants
ACTIVEof type unsigned short- A connection has been formed and if any media streams were successfully negotiated, any relevant media can be streaming.
CLOSEDof type unsigned short- The
close()method has been invoked. CLOSINGof type unsigned short- The object is starting to shut down after the
close()method has been invoked. ICE_CHECKINGof type unsigned short- The ICE Agent is checking candidates but has not yet found a connection that works.
ICE_CLOSEDof type unsigned short- The ICE Agent is terminating and will no longer repined to STUN connectivity checks.
ICE_COMPLETEDof type unsigned short- The ICE Agent has finished checking all candidates and a connection has been formed.
ICE_CONNECTEDof type unsigned short- The ICE Agent has found at least one candidate that works but is still checking.
ICE_FAILEDof type unsigned short- The ICE Agent has finished checking all candidates and no connection was worked.
ICE_GATHERINGof type unsigned short- The ICE Agent is gather addresses that can be used.
ICE_WAITINGof type unsigned short- THE ICE Agent has complete gathering addresses and is waiting for candidates to start checking.
NEGOTIATINGof type unsigned short- The peerConenction object is attempting to get to the point wehre media can flow.
NEWof type unsigned short- The object was just created and its ICE and SDP Agent have not yet been started.
SDP_GLAREof type unsigned short- Both side sent SDP offers at the same time and the SDP Agent is waiting to be able to retransmit the SDP offer.
SDP_IDLEof type unsigned short- A valid offer anser pair has been exchanged and the SDP Agent is waiting for the next SDP transaction.
SDP_WAITINGof type unsigned short- The SDP Agent has sent an SDP offer and is waiting for a response.
PeerConnection implements EventTarget;
4.2 SignalingCallback
[Callback=FunctionOnly, NoInterfaceObject]
interface SignalingCallback {
void handleEvent (DOMString message, PeerConnection source);
};
4.2.1 Methods
handleEvent- Def TBD
No exceptions.
4.3 Examples
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.getObjectURL(event.stream);
};
5. The data stream
Although progress is being made, there is currently not enough agreement on the data channel to write it up. This section will be filled in as rough consensus is reached.
6. Garbage collection
A Window object has a strong reference to any PeerConnection objects created from the constructor whose
global object is that Window object.
8. Event summary
This section is non-normative.
The following event fires on MediaStream
objects:
| Event name | Interface | Fired when... |
|---|---|---|
ended |
Event |
The MediaStream object will no longer
stream 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 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. |
message |
MessageEvent |
A data UDP media stream message (to be defined) was received. |
addstream |
MediaStreamEvent |
A new stream has been added to the remoteStreams array. |
removestream |
MediaStreamEvent |
A stream has been removed from the remoteStreams array. |
9. application/html-peer-connection-data
This registration is for community review and will be submitted to the IESG for review, approval, and registration with IANA.
- Type name:
- application
- Subtype name:
- html-peer-connection-data
- Required parameters:
- No required parameters
- Optional parameters:
- No optional parameters
- Encoding considerations:
- This MIME type defines a binary protocol format which uses UTF-8 for text encoding.
- Security considerations:
-
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.
- Interoperability considerations:
- Rules for processing both conforming and non-conforming content are defined in this specification.
- Published specification:
- This document is the relevant specification.
- Applications that use this media type:
- This type is only intended for use with SDP. [SDP]
- Additional information:
-
- Magic number(s):
- No sequence of bytes can uniquely identify data in this format, as all data in this format is intentionally masked to avoid cross-protocol attacks.
- File extension(s):
- This format is not for use with files.
- Macintosh file type code(s):
- This format is not for use with files.
- Person & email address to contact for further information:
- Daniel C. Burnett <dburnett@voxeo.com>
- Intended usage:
- Common
- Restrictions on usage:
- No restrictions apply.
- Author:
- Daniel C. Burnett <dburnett@voxeo.com>
- Change controller:
- W3C
Fragment identifiers cannot be used with application/html-peer-connection-data
as URLs cannot be used to identify streams that use this format.
A. Acknowledgements
The editors wish to thank the Working Group chairs, Harald Alvestrand and Stefan Håkansson, for their support.
B. References
B.2 Informative references
No informative references.