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

句法

pc = new RTCPeerConnection([configuration]);
					

参数

configuration 可选
RTCConfiguration dictionary providing options to configure the new connection.

RTCConfiguration dictionary

bundlePolicy 可选
Specifies how to handle negotiation of candidates when the remote peer is not compatible with the SDP BUNDLE standard . This must be one of the values from the enum RTCBundlePolicy . If this value isn't included in the dictionary, "balanced" is assumed.
certificates 可选
数组 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 below for additional information. 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 可选
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() 被调用。 Changing the size of the ICE candidate pool may trigger the beginning of ICE gathering.
iceServers 可选
An array of RTCIceServer 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.
iceTransportPolicy 可选
The current ICE transport policy; this must be one of the values from the RTCIceTransportPolicy enum. If this isn't specified, "all" is assumed.
peerIdentity 可选
DOMString which specifies the target peer identity for the RTCPeerConnection . If this value is set (it defaults to null ), RTCPeerConnection will not connect to a remote peer unless it can successfully authenticate with the given name.
rtcpMuxPolicy 可选
The RTCP mux policy to use when gathering ICE candidates, in order to support non-multiplexed RTCP. The value must be one of those from the RTCRtcpMuxPolicy enum 。默认为 "require" .

返回值

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

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection()' in that specification.
候选推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
RTCPeerConnection() 构造函数 Chrome 23
23
Before Chrome 63 the default value for the RTCConfiguration.rtcpMuxPolicy parameter was "negotiate"
Edge ≤18 Firefox 22 IE No Opera 43
43
Promise-based version.
不支持 37 — 43
Safari ? WebView Android Yes
Yes
Before Chrome 63 the default value for the RTCConfiguration.rtcpMuxPolicy parameter was "negotiate"
Chrome Android Yes
Yes
Before Chrome 63 the default value for the RTCConfiguration.rtcpMuxPolicy parameter was "negotiate"
Firefox Android 44 Opera Android 43
43
Promise-based version.
不支持 37 — 43
Safari iOS ? Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

见实现注意事项。

另请参阅

元数据

  • 最后修改:
  1. WebRTC API
  2. RTCPeerConnection
  3. 构造函数
    1. RTCPeerConnection()
  4. 特性
    1. canTrickleIceCandidates
    2. connectionState
    3. currentLocalDescription
    4. currentRemoteDescription
    5. getDefaultIceServers()
    6. iceConnectionState
    7. iceGatheringState
    8. localDescription
    9. onaddstream
    10. onconnectionstatechange
    11. ondatachannel
    12. onicecandidate
    13. oniceconnectionstatechange
    14. onicegatheringstatechange
    15. onidentityresult
    16. onidpassertionerror
    17. onidpvalidationerror
    18. onnegotiationneeded
    19. onpeeridentity
    20. onremovestream
    21. onsignalingstatechange
    22. ontrack
    23. peerIdentity
    24. pendingLocalDescription
    25. pendingRemoteDescription
    26. remoteDescription
    27. sctp
    28. signalingState
  5. 方法
    1. addIceCandidate()
    2. addStream()
    3. addTrack()
    4. close()
    5. createAnswer()
    6. createDataChannel()
    7. createOffer()
    8. generateCertificate()
    9. getConfiguration()
    10. getIdentityAssertion()
    11. getReceivers()
    12. getSenders()
    13. getStats()
    14. getStreamById()
    15. getTransceivers()
    16. removeStream()
    17. removeTrack()
    18. restartIce()
    19. setConfiguration()
    20. setIdentityProvider()
    21. setLocalDescription()
    22. setRemoteDescription()
  6. 事件
    1. addstream
    2. icecandidateerror
    3. identityresult
    4. negotiationneeded
    5. removestream
    6. signalingstatechange
  7. 继承:
    1. EventTarget
  8. Related pages for WebRTC
    1. MediaDevices.getUserMedia()
    2. Navigator.mediaDevices
    3. RTCCertificate
    4. RTCDTMFSender
    5. RTCDTMFToneChangeEvent
    6. RTCDataChannel
    7. RTCDataChannelEvent
    8. RTCDtlsTransport
    9. RTCErrorEvent
    10. RTCIceCandidate
    11. RTCIceTransport
    12. RTCPeerConnectionIceErrorEvent
    13. RTCPeerConnectionIceEvent
    14. RTCRtpReceiver
    15. RTCRtpSender
    16. RTCRtpTransceiver
    17. RTCSctpTransport
    18. RTCSessionDescription
    19. RTCStatsReport
    20. RTCTrackEvent

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1