RTCPeerConnection: RTCPeerConnection() constructor

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.

* Some parts of this feature may have varying levels of support.

The RTCPeerConnection() constructor returns a newly-created RTCPeerConnection, which represents a connection between the local device and a remote peer.

Syntax

js
new RTCPeerConnection()
new RTCPeerConnection(configuration)

Parameters

configuration Optional

An object providing options to configure the new connection:

bundlePolicy Optional

Specifies how to handle negotiation of candidates when the remote peer is not compatible with the SDP BUNDLE standard. If the remote endpoint is BUNDLE-aware, all media tracks and data channels are bundled onto a single transport at the completion of negotiation, regardless of policy used, and any superfluous transports that were created initially are closed at that point.

In technical terms, a BUNDLE lets all media flow between two peers flow across a single 5-tuple; that is, from a single IP and port on one peer to a single IP and port on the other peer, using the same transport protocol.

This must be one of the following string values, if not balanced is assumed:

"balanced"

The ICE agent initially creates one RTCDtlsTransport for each type of content added: audio, video, and data channels. If the remote endpoint is not BUNDLE-aware, then each of these DTLS transports handles all the communication for one type of data.

"max-compat"

The ICE agent initially creates one RTCDtlsTransport per media track and a separate one for data channels. If the remote endpoint is not BUNDLE-aware, everything is negotiated on these separate DTLS transports.

"max-bundle"

The ICE agent initially creates only a single RTCDtlsTransport to carry all of the RTCPeerConnection's data. If the remote endpoint is not BUNDLE-aware, then only a single track will be negotiated and the rest ignored.

certificates Optional

An Array of objects of type RTCCertificate which are used by the connection for authentication. If this property isn't specified, a set of certificates is generated automatically for each RTCPeerConnection instance. Although only one certificate is used by a given connection, providing certificates for multiple algorithms may improve the odds of successfully connecting in some circumstances. See Using certificates for further information.

Note: This configuration option cannot be changed after it is first specified; once the certificates have been set, this property is ignored in future calls to RTCPeerConnection.setConfiguration().

iceCandidatePoolSize Optional

An unsigned 16-bit integer value which specifies the size of the prefetched ICE candidate pool. The default value is 0 (meaning no candidate prefetching will occur). You may find in some cases that connections can be established more quickly by allowing the ICE agent to start fetching ICE candidates before you start trying to connect, so that they're already available for inspection when RTCPeerConnection.setLocalDescription() is called.

Note: Changing the size of the ICE candidate pool may trigger the beginning of ICE gathering.

iceServers Optional

An array of objects, each describing one server which may be used by the ICE agent; these are typically STUN and/or TURN servers. If this isn't specified, the connection attempt will be made with no STUN or TURN server available, which limits the connection to local peers. Each object may have the following properties:

credential Optional

The credential to use when logging into the server. This is only used if the object represents a TURN server.

credentialType Optional

If the object represents a TURN server, this attribute specifies what kind of credential is to be used when connecting. The default is "password".

urls

This required property is either a single string or an array of strings, each specifying a URL which can be used to connect to the server.

username Optional

If the object represents a TURN server, then this is the username to use during the authentication.

iceTransportPolicy Optional

A string representing the current ICE transport policy. Possible values are:

"all"

All ICE candidates will be considered. This is the default value.

"public"

Only ICE candidates with public IP addresses will be considered.

"relay"

Only ICE candidates whose IP addresses are being relayed, such as those being passed through a TURN server, will be considered.

peerIdentity Optional

A string which specifies the target peer identity for the RTCPeerConnection. If this value is set (it defaults to null), the RTCPeerConnection will not connect to a remote peer unless it can successfully authenticate with the given name.

rtcpMuxPolicy Optional

A string which specifies the RTCP mux policy to use when gathering ICE candidates, in order to support non-multiplexed RTCP. Possible values are:

"negotiate"

Instructs the ICE agent to gather both RTP and RTCP candidates. If the remote peer can multiplex RTCP, then RTCP candidates are multiplexed atop the corresponding RTP candidates. Otherwise, both the RTP and RTCP candidates are returned, separately.

"require"

Tells the ICE agent to gather ICE candidates for only RTP, and to multiplex RTCP atop them. If the remote peer doesn't support RTCP multiplexing, then session negotiation fails. This is the default value.

Return value

A newly-created RTCPeerConnection object, configured as described by configuration, if specified; otherwise, configured to appropriate basic defaults.

Using certificates

When you wish to provide your own certificates for use by an RTCPeerConnection instead of having the RTCPeerConnection generate them automatically, you do so by calling the static RTCPeerConnection.generateCertificate() function.

The certificates property's value cannot be changed once it's first specified. If it's included in the configuration passed into a call to a connection's setConfiguration(), it is ignored.

This attribute supports providing multiple certificates because even though a given DTLS connection uses only one certificate, providing multiple certificates allows support for multiple encryption algorithms. The implementation of RTCPeerConnection will choose which certificate to use based on the algorithms it and the remote peer support, as determined during DTLS handshake.

If you don't provide certificates, new ones are generated automatically. One obvious benefit to providing your own is identity key continuity—if you use the same certificate for subsequent calls, the remote peer can tell you're the same caller. This also avoids the cost of generating new keys.

Specifications

Specification
WebRTC: Real-Time Communication in Browsers
# dom-peerconnection

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
RTCPeerConnection() constructor
Chrome – Full support
Chrome 23 (Release date: 2012-11-06)
prefix
prefix Implemented with the vendor prefix: webkit
Chrome – Full support
Chrome 56 (Release date: 2017-01-25)
footnote
footnote Before Chrome 63, the default value for the configuration.rtcpMuxPolicy parameter is "negotiate" instead of "required".
Edge – Full support
Edge 15 (Release date: 2017-04-05)
prefix
prefix Implemented with the vendor prefix: webkit
Edge – Full support
Edge 15 (Release date: 2017-04-05)
footnote Full support
Firefox – Full support
Firefox 22 (Release date: 2013-06-25)
prefix
prefix Implemented with the vendor prefix: moz
Firefox – Full support
Firefox 44 (Release date: 2016-01-26)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
prefix
prefix Implemented with the vendor prefix: webkit
Opera – Full support
Opera 43 (Release date: 2017-02-07)
footnote
footnote Before Opera 50, the default value for the configuration.rtcpMuxPolicy parameter is "negotiate" instead of "required".
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
prefix
prefix Implemented with the vendor prefix: webkit
Chrome Android – Full support
Chrome Android 56 (Release date: 2017-02-01)
footnote
footnote Before Chrome Android 63, the default value for the configuration.rtcpMuxPolicy parameter is "negotiate" instead of "required".
Firefox for Android – Full support
Firefox for Android 24 (Release date: 2013-09-17)
prefix
prefix Implemented with the vendor prefix: moz
Firefox for Android – Full support
Firefox for Android 44 (Release date: 2016-01-26)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
prefix
prefix Implemented with the vendor prefix: webkit
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote
footnote Before Opera Android 46, the default value for the configuration.rtcpMuxPolicy parameter is "negotiate" instead of "required".
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
prefix
prefix Implemented with the vendor prefix: webkit
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote
footnote Before Samsung Internet 8.0, the default value for the configuration.rtcpMuxPolicy parameter is "negotiate" instead of "required".
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
prefix
prefix Implemented with the vendor prefix: webkit
WebView Android – Full support
WebView Android 56 (Release date: 2017-02-01)
footnote
footnote Before WebView Android 63, the default value for the configuration.rtcpMuxPolicy parameter is "negotiate" instead of "required".
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
configuration.bundlePolicy parameter
Chrome – Full support
Chrome 42 (Release date: 2015-04-14)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 42 (Release date: 2015-11-03)
footnote Full support
Opera – Full support
Opera 29 (Release date: 2015-04-28)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 42 (Release date: 2015-04-15)
footnote Full support
Firefox for Android – Full support
Firefox for Android 42 (Release date: 2015-11-03)
footnote Full support
Opera Android – Full support
Opera Android 29 (Release date: 2015-04-28)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 42 (Release date: 2015-04-15)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
configuration.certificates parameter
Chrome – Full support
Chrome 49 (Release date: 2016-03-02)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 42 (Release date: 2015-11-03)
footnote Full support
Opera – Full support
Opera 36 (Release date: 2016-03-15)
footnote Full support
Safari – Full support
Safari 12.1 (Release date: 2019-03-25)
footnote Full support
Chrome Android – Full support
Chrome Android 49 (Release date: 2016-03-09)
footnote Full support
Firefox for Android – Full support
Firefox for Android 42 (Release date: 2015-11-03)
footnote Full support
Opera Android – Full support
Opera Android 36 (Release date: 2016-03-31)
footnote Full support
Safari on iOS – Full support
Safari on iOS 12.2 (Release date: 2019-03-25)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 49 (Release date: 2016-03-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 12.2 (Release date: 2019-03-25)
footnote Full support
configuration.iceCandidatePoolSize parameter
Chrome – Full support
Chrome 59 (Release date: 2017-06-05)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 46 (Release date: 2017-06-22)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 59 (Release date: 2017-06-06)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 44 (Release date: 2017-12-11)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 59 (Release date: 2017-06-06)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
configuration.iceServers parameter
Chrome – Full support
Chrome 45 (Release date: 2015-09-01)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 22 (Release date: 2013-06-25)
footnote Full support
Opera – Full support
Opera 32 (Release date: 2015-09-15)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 45 (Release date: 2015-09-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 24 (Release date: 2013-09-17)
footnote Full support
Opera Android – Full support
Opera Android 32 (Release date: 2015-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 45 (Release date: 2015-09-01)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
configuration.iceServers.credentialType parameter
Deprecated Non-standard
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 47 (Release date: 2016-06-07)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – Full support
Firefox for Android 47 (Release date: 2016-06-07)
footnote Full support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
configuration.iceServers.credential parameter
Chrome – Full support
Chrome 45 (Release date: 2015-09-01)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 22 (Release date: 2013-06-25)
footnote Full support
Opera – Full support
Opera 32 (Release date: 2015-09-15)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 45 (Release date: 2015-09-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 24 (Release date: 2013-09-17)
footnote Full support
Opera Android – Full support
Opera Android 32 (Release date: 2015-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
configuration.iceServers.url parameter
Deprecated
Chrome – Full support
Chrome 45 (Release date: 2015-09-01)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 22 (Release date: 2013-06-25)
footnote Full support
Opera – Full support
Opera 32 (Release date: 2015-09-15)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 45 (Release date: 2015-09-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 24 (Release date: 2013-09-17)
footnote Full support
Opera Android – Full support
Opera Android 32 (Release date: 2015-09-23)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
configuration.iceServers.urls parameter
Chrome – Full support
Chrome 45 (Release date: 2015-09-01)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 37 (Release date: 2015-03-31)
footnote Full support
Opera – Full support
Opera 32 (Release date: 2015-09-15)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 45 (Release date: 2015-09-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 37 (Release date: 2015-03-31)
footnote Full support
Opera Android – Full support
Opera Android 32 (Release date: 2015-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
configuration.iceServers.username parameter
Chrome – Full support
Chrome 45 (Release date: 2015-09-01)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 23 (Release date: 2013-08-06)
footnote Full support
Opera – Full support
Opera 32 (Release date: 2015-09-15)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 45 (Release date: 2015-09-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 24 (Release date: 2013-09-17)
footnote Full support
Opera Android – Full support
Opera Android 32 (Release date: 2015-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
configuration.iceTransportPolicy parameter
Chrome – Full support
Chrome 38 (Release date: 2014-10-07)
altname
altname Alternate name: iceTransports
Chrome – Full support
Chrome 56 (Release date: 2017-01-25)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
altname
altname Alternate name: iceTransports
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 42 (Release date: 2015-11-03)
footnote Full support
Opera – Full support
Opera 25 (Release date: 2014-10-15)
altname
altname Alternate name: iceTransports
Opera – Full support
Opera 43 (Release date: 2017-02-07)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 38 (Release date: 2014-10-08)
altname
altname Alternate name: iceTransports
Chrome Android – Full support
Chrome Android 56 (Release date: 2017-02-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 42 (Release date: 2015-11-03)
footnote Full support
Opera Android – Full support
Opera Android 44 (Release date: 2017-12-11)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 3 (Release date: 2015-04-10)
altname
altname Alternate name: iceTransports
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 38 (Release date: 2014-10-08)
altname
altname Alternate name: iceTransports
WebView Android – Full support
WebView Android 56 (Release date: 2017-02-01)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
configuration.peerIdentity parameter
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 32 (Release date: 2014-09-02)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – Full support
Firefox for Android 32 (Release date: 2014-09-02)
footnote Full support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
configuration.rtcpMuxPolicy parameter
Chrome – Full support
Chrome 57 (Release date: 2017-03-09)
footnote
footnote Default for rtcpMuxPolicy is require
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote Default for rtcpMuxPolicy is require
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 44 (Release date: 2017-03-21)
footnote
footnote Default for rtcpMuxPolicy is require
Safari – Full support
Safari 12.1 (Release date: 2019-03-25)
footnote Full support
Chrome Android – Full support
Chrome Android 57 (Release date: 2017-03-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 44 (Release date: 2017-12-11)
footnote Full support
Safari on iOS – Full support
Safari on iOS 12.2 (Release date: 2019-03-25)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 57 (Release date: 2017-03-16)
footnote Full support
WebView on iOS – Full support
WebView on iOS 12.2 (Release date: 2019-03-25)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.
Uses a non-standard name
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also