只读 RTCPeerConnection property peerIdentity returns a JavaScript Promise that resolves to an RTCIdentityAssertion which contains a DOMString identifying the remote peer. Once this promise resolves successfully, the resulting identity is the target peer identity and cannot change for the duration of the connection.

句法

 var identity = rtcPeerConnection.peerIdentity;
					

A JavaScript Promise which resolves to an RTCIdentityAssertion that describes the remote peer's identity.

If an error occcurs while attempting to validate an incoming identity assertion (that is, the information describing a peer's identity), the promise is rejected. If there isn't already a target peer identity, peerIdentity is set to a newly created promise and the process begins again, until the process succeeds or no further attempts to authenticate occur.

注意: The promise returned by setRemoteDescription() cannot resolve until any target peer identity that's been set is validated. If the identity hasn't been validated yet, the promise returned by setRemoteDescription() will be rejected. If there's no target peer identity, setRemoteDescription() doesn't need to wait for validation to occur before it resolves.

范例

In this example, a function, getIdentityAssertion() , is created which asynchronously waits for the peer's identity to be verified, then returns the identity to the caller. If an error occurs and the promise is rejected, this logs the error to the console and returns null to the caller.

let pc = new RTCPeerConnection();
/* ... */
async function getIdentityAssertion(pc) {
  try {
    const identity = await pc.peerIdentity;
    return identity;
  } catch(err) {
    console.log("Error identifying remote peer: ", err);
    return null;
  }
}
					

规范

规范 状态 注释
Identity for WebRTC 候选推荐 最初的规范。

浏览器兼容性

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
peerIdentity Chrome No Edge ≤18 — 79 Firefox 22 IE No Opera 43
43
Promise-based version.
不支持 37 — 43
Safari ? WebView Android No Chrome Android No Firefox Android 44 Opera Android 43
43
Promise-based version.
不支持 37 — 43
Safari iOS ? Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

见实现注意事项。

另请参阅

元数据

  • 最后修改: