WebRTC (Web Real-Time Communication) is a technology which enables Web applications and sites to capture and optionally stream audio and/or video media, as well as to exchange arbitrary data between browsers without requiring an intermediary. The set of standards that comprise WebRTC makes it possible to share data and perform teleconferencing peer-to-peer, without requiring that the user install plug-ins or any other third-party software.
WebRTC consists of several interrelated APIs and protocols which work together to achieve this. The documentation you'll find here will help you understand the fundamentals of WebRTC, how to set up and use both data and media connections, and more.
Because implementations of WebRTC are still evolving, and because each browser has different levels of support for codecs and WebRTC features, you should strongly consider making use of the Adapter.js library provided by Google before you begin to write your code.
Adapter.js uses shims and polyfills to smooth over the differences among the WebRTC implementations across the environments supporting it. Adapter.js also handles prefixes and other naming differences to make the entire WebRTC development process easier, with more broadly compatible results. The library is also available as an NPM package .
To learn more about Adapter.js, see Improving compatibility using WebRTC adapter.js .
WebRTC serves multiple purposes; together with the Media Capture and Streams API , they provide powerful multimedia capabilities to the Web, including support for audio and video conferencing, file exchange, screen sharing, identity management, and interfacing with legacy telephone systems including support for sending DTMF (touch-tone dialing) signals. Connections between peers can be made without requiring any special drivers or plug-ins, and can often be made without any intermediary servers.
Connections between two peers are represented by the
RTCPeerConnection
interface. Once a connection has been established and opened using
RTCPeerConnection
, media streams (
MediaStream
s) and/or data channels (
RTCDataChannel
s) can be added to the connection.
Media streams can consist of any number of tracks of media information; tracks, which are represented by objects based on the
MediaStreamTrack
interface, may contain one of a number of types of media data, including audio, video, and text (such as subtitles or even chapter names). Most streams consist of at least one audio track and likely also a video track, and can be used to send and receive both live media or stored media information (such as a streamed movie).
You can also use the connection between two peers to exchange arbitrary binary data using the
RTCDataChannel
interface. This can be used for back-channel information, metadata exchange, game status packets, file transfers, or even as a primary channel for data transfer.
more details and links to relevant guides and tutorials needed
Because WebRTC provides interfaces that work together to accomplish a variety of tasks, we have divided up the reference by category. Please see the sidebar for an alphabetical list.
These interfaces, dictionaries, and types are used to set up, open, and manage WebRTC connections. Included are interfaces representing peer media connections, data channels, and interfaces used when exchanging information on the capabilities of each peer in order to select the best possible configuration for a two-way media connection.
RTCPeerConnection
Represents a WebRTC connection between the local computer and a remote peer. It is used to handle efficient streaming of data between the two peers.
RTCDataChannel
Represents a bi-directional data channel between two peers of a connection.
RTCDataChannelEvent
RTCDataChannel
到
RTCPeerConnection
. The only event sent with this interface is
datachannel
.
RTCSessionDescription
RTCSessionDescription
consists of a description
type
indicating which part of the offer/answer negotiation process it describes and of the
SDP
descriptor of the session.
RTCStatsReport
RTCPeerConnection.getStats()
. Details about using WebRTC statistics can be found in
WebRTC Statistics API
.
RTCIceCandidate
RTCPeerConnection
.
RTCIceTransport
RTCPeerConnectionIceEvent
RTCPeerConnection
. Only one event is of this type:
icecandidate
.
RTCRtpSender
MediaStreamTrack
在
RTCPeerConnection
.
RTCRtpReceiver
MediaStreamTrack
在
RTCPeerConnection
.
RTCTrackEvent
track
event, which indicates that an
RTCRtpReceiver
object was added to the
RTCPeerConnection
object, indicating that a new incoming
MediaStreamTrack
was created and added to the
RTCPeerConnection
.
RTCSctpTransport
RTCPeerConnection
's data channels are sent and received.
RTCConfiguration
RTCPeerConnection
.
RTCIceServer
RTCRtpContributingSource
Contains information about a given contributing source (CSRC) including the most recent time a packet that the source contributed was played out.
bufferedamountlow
bufferedAmount
property—has decreased to be at or below the channel's minimum buffered data size, as specified by
bufferedAmountLowThreshold
.
close
closed
state. Its underlying data transport is completely closed at this point. You can be notified
before
closing completes by watching for the
closing
event instead.
closing
RTCDataChannel
has transitioned to the
closing
state, indicating that it will be closed soon. You can detect the completion of the closing process by watching for the
close
事件。
connectionstatechange
connectionState
, has changed.
datachannel
RTCDataChannel
is available following the remote peer opening a new data channel. This event's type is
RTCDataChannelEvent
.
error
RTCErrorEvent
indicating that an error occurred on the data channel.
error
RTCErrorEvent
indicating that an error occurred on the
RTCDtlsTransport
. This error will be either
dtls-failure
or
fingerprint-failure
.
gatheringstatechange
RTCIceTransport
's gathering state has changed.
icecandidate
RTCPeerConnectionIceEvent
which is sent whenever the local device has identified a new ICE candidate which needs to be added to the local peer by calling
setLocalDescription()
.
icecandidateerror
RTCPeerConnectionIceErrorEvent
indicating that an error has occurred while gathering ICE candidates.
iceconnectionstatechange
RTCPeerConnection
when its ICE connection's state—found in the
iceconnectionstate
property—changes.
icegatheringstatechange
RTCPeerConnection
when its ICE gathering state—found in the
icegatheringstate
property—changes.
message
MessageEvent
.
negotiationneeded
RTCPeerConnection
that it needs to perform session negotiation by calling
createOffer()
followed by
setLocalDescription()
.
open
RTCDataChannel
has been successfully opened or re-opened.
selectedcandidatepairchange
RTCIceTransport
on which the event is fired.
track
track
event, of type
RTCTrackevent
is sent to an
RTCPeerConnection
when a new track is added to the connection following the successful negotiation of the media's streaming.
signalingstatechange
signalingstate
has changed. This happens as a result of a call to either
setLocalDescription()
or
setRemoteDescription()
.
statechange
RTCDtlsTransport
已改变。
statechange
RTCIceTransport
已改变。
statechange
RTCSctpTransport
已改变。
RTCSctpTransportState
RTCSctpTransport
实例。
RTCSessionDescriptionCallback
RTCPeerConnection
object when requesting it to create offers or answers.
These APIs are used to manage user identity and security, in order to authenticate the user for a connection.
RTCIdentityProvider
Enables a user agent is able to request that an identity assertion be generated or validated.
RTCIdentityAssertion
null
. Once set it can't be changed.
RTCIdentityProviderRegistrar
Registers an identity provider (idP).
RTCIdentityEvent
RTCPeerConnection
. The only event sent with this type is
identityresult
.
RTCIdentityErrorEvent
RTCPeerConnection
. Two events are sent with this type:
idpassertionerror
and
idpvalidationerror
.
RTCCertificate
RTCPeerConnection
uses to authenticate.
These interfaces and events are related to interactivity with Public-Switched Telephone Networks (PTSNs). They're primarily used to send tone dialing sounds—or packets representing those tones—across the network to the remote peer.
RTCDTMFSender
RTCPeerConnection
.
RTCDTMFToneChangeEvent
tonechange
event to indicate that a DTMF tone has either begun or ended. This event does not bubble (except where otherwise stated) and is not cancelable (except where otherwise stated).
tonechange
RTCDTMFSender
's
toneBuffer
has been sent and the buffer is now empty. The event's type is
RTCDTMFToneChangeEvent
.
This article introduces the protocols on top of which the WebRTC API is built.
A guide to how WebRTC connections work and how the various protocols and interfaces can be used together to build powerful communication apps.
WebRTC lets you build peer-to-peer communication of arbitrary data, audio, or video—or any combination thereof—into a browser application. In this article, we'll look at the lifetime of a WebRTC session, from establishing the connection all the way through closing the connection when it's no longer needed.
A tutorial and example which turns a WebSocket-based chat system created for a previous example and adds support for opening video calls among participants. The chat server's WebSocket connection is used for WebRTC signaling.
A guide to the codecs which WebRTC requires browsers to support as well as the optional ones supported by various popular browsers. Included is a guide to help you choose the best codecs for your needs.
RTCDataChannel
to exchange arbitrary data between two peers.
RTCDTMFSender
interface. This guide shows how to do so.
This article shows how to use WebRTC to access the camera on a computer or mobile phone with WebRTC support and take a photo with it.
RTCDataChannel
interface is a feature which lets you open a channel between two peers over which you may send and receive arbitrary data. The API is intentionally similar to the
WebSocket API
, so that the same programming model can be used for each.
| 规范 | 状态 | 注释 |
|---|---|---|
| WebRTC 1.0: Real-time Communication Between Browsers | 候选推荐 | The initial definition of the API of WebRTC. |
| 媒体捕获和流 | 候选推荐 | The initial definition of the object conveying the stream of media content. |
| Media Capture from DOM Elements | 工作草案 | The initial definition on how to obtain stream of content from DOM Elements |
In additions to these specifications defining the API needed to use WebRTC, there are several protocols, listed under resources .
MediaDevices
MediaStreamEvent
MediaStreamConstraints
MediaStreamTrack
MessageEvent
MediaStream
RTCPeerConnection
RTCSessionDescription
RTCIceCandidate
RTCPeerConnectionIceEvent
RTCPeerConnectionIceErrorEvent
RTCCertificate
RTCRtpSender
RTCRtpReceiver
RTCRtpTransceiver
RTCDtlsTransport
RTCIceTransport
RTCTrackEvent
RTCSctpTransport
RTCDataChannel
RTCDataChannelEvent
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCStatsReport
RTCErrorEvent
RTCDTMFSender
:
tonechange
RTCDataChannel
:
bufferedamountlow
RTCDataChannel
:
close
RTCDataChannel
:
closing
RTCDataChannel
:
error
RTCDataChannel
:
message
RTCDataChannel
:
open
RTCDtlsTransport
:
error
RTCDtlsTransport
:
statechange
RTCIceTransport
:
error
RTCIceTransport
:
gatheringstatechange
RTCIceTransport
:
selectedcandidatepairchange
RTCIceTransport
:
statechange
RTCPeerConnection
:
connectionstatechange
RTCPeerConnection
:
datachannel
RTCPeerConnection
:
icecandidate
RTCPeerConnection
:
icecandidateerror
RTCPeerConnection
:
iceconnectionstatechange
RTCPeerConnection
:
icegatheringstatechange
RTCPeerConnection
:
negotiationneeded
RTCPeerConnection
:
signalingstatechange
RTCPeerConnection
:
track
RTCSctpTransport
:
error