RTCPeerConnection: getConfiguration() 方法
RTCPeerConnection 介面的 getConfiguration() 方法會返回一個物件,該物件指示呼叫該方法的 RTCPeerConnection 的當前配置。
返回的配置是最後透過 setConfiguration() 應用的配置,如果尚未呼叫 setConfiguration(),則是在構造 RTCPeerConnection 時使用的配置。配置包括連線使用的 ICE 伺服器列表、有關傳輸策略的資訊以及身份資訊。
語法
js
getConfiguration()
引數
無。
返回值
一個描述 RTCPeerConnection 當前配置的物件。有關允許的選項的更多資訊,請參閱 RTCPeerConnection()。
示例
此示例在連線尚未配置證書時,向活動連線新增一個新證書。
js
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);
});
}
此示例會獲取 RTCPeerConnection 的當前配置,然後透過檢查配置是否具有 certificates 屬性以及該屬性的長度是否為零來判斷它是否已設定任何證書。
如果確定沒有設定證書,則呼叫 RTCPeerConnection.generateCertificate() 來建立一個新證書;我們提供一個 fulfillment handler,該 handler 將包含新建立的證書的陣列新增到當前配置中,並將其傳遞給 setConfiguration() 以將證書新增到連線。
規範
| 規範 |
|---|
| WebRTC:瀏覽器中的即時通訊 # dom-rtcpeerconnection-getconfiguration |
瀏覽器相容性
載入中…