大网数据广告活动
Web 标准与前端开发

RTCPeerConnection: getConfiguration() method

· 52CE 我爱测

The **`getConfiguration()`** method of the RTCPeerConnection interface returns an object which indicates the current configuration of the RTCPeerConnection on which the method is called.

WebRTC

The getConfiguration() method of the RTCPeerConnection interface returns an object which indicates the current configuration of the RTCPeerConnection on which the method is called.

The returned configuration is the last configuration applied via RTCPeerConnection.setConfiguration, or if setConfiguration() hasn't been called, the configuration the RTCPeerConnection was constructed with. The configuration includes a list of the ICE servers used by the connection, information about transport policies, and identity information.

Syntax

getConfiguration()

Parameters

None.

Return value

An object describing the RTCPeerConnection's current configuration. See RTCPeerConnection() for more information on what options are allowed.

Examples

This example adds a new certificate to an active connection if it doesn't already have one in use.

let configuration = myPeerConnection.getConfiguration();

if (configuration.certificates?.length === 0) {
  RTCPeerConnection.generateCertificate({
    name: "RSASSA-PKCS1-v1_5",
    hash: "SHA-256",
    modulusLength: 2048,
    publicExponent: new Uint8Array([1, 0, 1]),
  }).then((cert) => {
    configuration.certificates = [cert];
    myPeerConnection.setConfiguration(configuration);
  });
}

This example fetches the current configuration of the RTCPeerConnection, then looks to see if it has any certificates set by examining whether or not (a) the configuration has a value for certificates, and (b) whether its length is zero.

If it's determined that there are no certificates in place, RTCPeerConnection.generateCertificate_static is called to create a new certificate; we provide a fulfillment handler which adds a new array containing the one newly-created certificate to the current configuration and passes it to RTCPeerConnection.setConfiguration to add the certificate to the connection.

Specifications

Browser compatibility

See also

  • RTCPeerConnection.setConfiguration()
  • RTCPeerConnection.RTCPeerConnection
  • RTCPeerConnection

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。