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-2014 W3C® (MIT, ERCIM, Keio, Beihang), 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 ECMAScript APIs in WebIDL to allow media to be sent to and received from another browser or device implementing the appropriate set of real-time protocols. 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 was published by the Web Real-Time Communications Working Group as a Working Group Note. If you wish to make comments regarding this document, please send them to public-webrtc@w3.org (subscribe, archives). All comments are welcome.
Publication as a Working Group Note 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.
This document is governed by the 1 August 2014 W3C Process Document.
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 [GETUSERMEDIA]developed by the Media Capture Task Force. An overview of the system can be found in [RTCWEB-OVERVIEW] and [RTCWEB-SECURITY].
The EventHandler
interface represents a callback used for event handlers as defined in
[HTML5].
The concepts queue a task and fires a simple event are defined in [HTML5].
The terms event, event handlers and event handler event types are defined in [HTML5].
The terms MediaStream, MediaStreamTrack, Constraints, and Consumer are defined in [GETUSERMEDIA].
The RTP media API lets a web application send and receive MediaStreamTracks over a peer-to-peer connection. Tracks, when added to a PeerConnection, result in signaling; when this signaling is forwarded to a remote peer, it causes corresponding tracks to be created on the remote side.
The actual encoding and transmission of MediaStreamTracks is managed through objects called RTCRtpSenders. Similarly, the reception and decoding of MediaStreamTracks is managed through objects called RTCRtpReceivers.
A
object contains a
set of RTCRtpSenders, representing tracks to
be sent, and a set of RTCRtpReceivers,
representing tracks that are to be received on this
RTCPeerConnection
object. Both of these sets are
initialized to empty sets when the
RTCPeerConnection
object is created.RTCPeerConnection
The RTP media API extends the
interface as described below.RTCPeerConnection
partial interface RTCPeerConnection {
sequence<RTCRtpSender
> getSenders ();
sequence<RTCRtpReceiver
> getReceivers ();
RTCRtpSender
addTrack (MediaStreamTrack track, MediaStream... streams);
void removeTrack (RTCRtpSender
sender);
attribute EventHandler onaddtrack;
};
onaddtrack
of type EventHandler, This event handler, of event handler event type addtrack
, MUST be supported
by all objects implementing the
interface. It is called any time a RTCPeerConnection
MediaStreamTrack
is added
by the remote peer. This will be fired only as a result of
setRemoteDescription
. onaddtrack happens as early as
possible after the setRemoteDescription
. This callback
does not wait for a given media track to be accepted or rejected via
SDP negotiation.
addTrack
Adds a new track to the RTCPeerConnection, and indicate that it is contained in the specified MediaStreams.
When the addTrack()
method is invoked, the user agent MUST
run the following steps:
Let connection be the
object on which the
RTCPeerConnection
MediaStreamTrack
, track, is to be
added.
If connection's RTCPeerConnection
signalingState is closed
, throw an
InvalidStateError
exception and abort these
steps.
If an RTCRtpSender for track already exists in connection's set of senders, then abort these steps.
Create a new RTCRtpSender for track, add it to connection's set of senders, and return it to the caller.
A track could have contents that are inaccessible to the application. This can be due to being marked with a peerIdentity option or anything that would make a track CORS cross-origin. These tracks can be supplied to the addTrack method, and have an RTCRtpSender created for them, but content MUST NOT be transmitted, though tracks marked with peerIdentity can be transmitted if they meet the requirements for sending (see isolated streams and RTCPeerConnection).
All other tracks that are not accessible to the application MUST NOT be sent to the peer, with silence (audio), black frames (video) or equivalently absent content being sent in place of track content.
Note that this property can change over time.
If connection's RTCPeerConnection
signalingState is stable
, then fire a negotiationneeded event at
connection.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
track | MediaStreamTrack | ✘ | ✘ | |
streams | MediaStream | ✘ | ✘ |
RTCRtpSender
getReceivers
Returns a sequence of
objects
representing the RTP receivers that are currently attached to this
RTCRtpReceiver
object.RTCPeerConnection
The getReceivers()
method MUST return a new sequence that represents a snapshot of all
the
objects in this
RTCRtpReceiver
object's set of receivers. The conversion from
the receivers set to the sequence, to be returned, is user agent
defined and the order does not have to stable between calls.RTCPeerConnection
sequence<RTCRtpReceiver
>
getSenders
Returns a sequence of
objects
representing the RTP senders that are currently attached to this
RTCRtpSender
object.RTCPeerConnection
The getSenders()
method MUST return a new sequence that represents a snapshot of all
the RTCRtpSenders
objects in this
object's set of senders. The conversion from the
senders set to the sequence, to be returned, is user agent defined
and the order does not have to stable between calls.RTCPeerConnection
sequence<RTCRtpSender
>
removeTrack
Removes sender, and its associated MediaStreamTrack, from the
.RTCPeerConnection
When the other peer stops sending a track in this manner, a
ended
event is
fired at the MediaStreamTrack
object.
When the removeTrack()
method is invoked, the user agent
MUST run the following steps:
Let connection be the
object on which the
RTCPeerConnection
, sender, is to be
removed.RTCRtpSender
If connection's RTCPeerConnection
signalingState is closed
, throw an
InvalidStateError
exception.
If sender is not in connection's set of senders, then abort these steps.
Remove sender from connection's set of senders.
If connection's RTCPeerConnection
signalingState is stable
, then fire a negotiationneeded event at
connection.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
sender |
| ✘ | ✘ |
void
The RTCRtpSender
interface allows an application to control how a given
MediaStreamTrack
is encoded and transmitted to a remote peer.
When attributes on an RTCRtpSender
are modified, the encoding is either
changed appropriately, or a negotiation is triggered to signal the new encoding
parameters to the other side.
interface RTCRtpSender {
readonly attribute MediaStreamTrack track;
};
track
of type MediaStreamTrack, readonly The RTCRtpSender.track
attribute is the track that is immutably associated with this
object.RTCRtpSender
The RTCRtpReceiver
interface allows an application to control the receipt
of a MediaStreamTrack
. When attributes on an RTCRtpReceiver
are modified, a negotiation is triggered to signal the changes regarding what the application
wants to receive to the other side.
interface RTCRtpReceiver {
readonly attribute MediaStreamTrack track;
};
track
of type MediaStreamTrack, readonly The RTCRtpReceiver.track
attribute is the track that is immutably associated with this
object.RTCRtpReceiver
The onaddtrack
event uses the
interface.RTCAddTrackEvent
Firing an
RTCAddTrackEvent event named e with an
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
RTCAddTrackEvent
track
attribute
set to track, MUST be created and dispatched at the
given target.
dictionary RTCAddTrackEventInit : EventInit {
RTCRtpReceiver
receiver;
MediaStreamTrack track;
sequence<MediaStream> streams;
};
[ Constructor (DOMString type, RTCAddTrackEventInit
eventInitDict)]
interface RTCAddTrackEvent : Event {
readonly attribute RTCRtpReceiver
receiver;
readonly attribute MediaStreamTrack track;
sequence<MediaStream> getStreams ();
};
RTCAddTrackEvent
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
type | DOMString | ✘ | ✘ | |
eventInitDict |
| ✘ | ✘ |
receiver
of type RTCRtpReceiver
, readonly The receiver
attribute
represents the
object associated with
the event.RTCRtpReceiver
track
of type MediaStreamTrack, readonly The track
attribute
represents the MediaStreamTrack
object that is
associated with the
identified by
RTCRtpReceiver
receiver
.
getStreams
Returns a sequence of MediaStream
objects
representing the MediaStream
s that this event's
track
is a part of.
sequence<MediaStream>
RTCAddTrackEventInit
Membersreceiver
of type RTCRtpReceiver
TODO
streams
of type sequence<MediaStream>TODO
track
of type MediaStreamTrackTODO
This section is non-normative.
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.
var signalingChannel = new SignalingChannel(); var configuration = { "iceServers": [{ "url": "stun:stun.example.org" }] }; var pc; // call start() to initiate function start() { pc = new RTCPeerConnection(configuration); // send any ice candidates to the other peer pc.onicecandidate = function (evt) { if (evt.candidate) signalingChannel.send(JSON.stringify({ "candidate": evt.candidate })); }; // let the "negotiationneeded" event trigger offer generation pc.onnegotiationneeded = function () { pc.createOffer(localDescCreated, logError); } // once remote video track arrives, show it in the remote video element pc.onaddtrack = function (evt) { if (evt.track.kind === "video") remoteView.srcObject = evt.getStreams()[0]; }; // get a local stream, show it in a self-view and add it to be sent navigator.mediaDevices.getUserMedia({ "audio": true, "video": true }, function (stream) { selfView.srcObject = stream; if (stream.getAudioTracks().length > 0) pc.addTrack(stream.getAudioTracks()[0], stream); if (stream.getVideoTracks().length > 0) pc.addTrack(stream.getVideoTracks()[0], stream); }, logError); } function localDescCreated(desc) { pc.setLocalDescription(desc, function () { signalingChannel.send(JSON.stringify({ "sdp": pc.localDescription })); }, logError); } signalingChannel.onmessage = function (evt) { if (!pc) start(); var message = JSON.parse(evt.data); if (message.sdp) pc.setRemoteDescription(new RTCSessionDescription(message.sdp), function () { // if we received an offer, we need to answer if (pc.remoteDescription.type == "offer") pc.createAnswer(localDescCreated, logError); }, logError); else pc.addIceCandidate(new RTCIceCandidate(message.candidate), function () {}, logError); }; function logError(error) { log(error.name + ": " + error.message); }
The editors wish to thank the Working Group chairs and Team Contact, Harald Alvestrand, Stefan Håkansson and Dominique Hazaël-Massieux, for their support. Substantial text in this specification was provided by many people including Martin Thomson, Harald Alvestrand, Justin Uberti, and Eric Rescorla.