RTCPeerConnection.onicecandidate - Web APIs 编辑

The RTCPeerConnection property onicecandidate property is an EventHandler which specifies a function to be called when the icecandidate event occurs on an RTCPeerConnection instance. This happens whenever the local ICE agent needs to deliver a message to the other peer through the signaling server. This lets the ICE agent perform negotiation with the remote peer without the browser itself needing to know any specifics about the technology being used for signaling; implement this method to use whatever messaging technology you choose to send the ICE candidate to the remote peer.

Syntax

rtcPeerConnection.onicecandidate = eventHandler;

Value

This should be set to a function which you provide that accepts as input an RTCPeerConnectionIceEvent object representing the icecandidate event. The function should deliver the ICE candidate, whose SDP can be found in the event's candidate property, to the remote peer through the signaling server.

If the event's candidate property is null, ICE gathering has finished. This message should not be sent to the remote peer. When this happens, the connection's iceGatheringState has also changed to complete. You don't need to watch for this explicitly; instead, if you need to sense the end of signaling, you should watch for a icegatheringstatechange event indicating that the ICE negotiation has transitioned to the complete state.

Example

The example below, which is based on the code from the article Signaling and video calling, sets up a handler for icecandidate events to send the candidates to the remote peer.

pc.onicecandidate = function(event) {
  if (event.candidate) {
    // Send the candidate to the remote peer
  } else {
    // All ICE candidates have been sent
  }
}

Notice that the end of negotiation is detected here when the event's candidate property is null.

Specifications

SpecificationStatusComment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.onicecandidate' in that specification.
Candidate RecommendationInitial specification.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:46 次

字数:4752

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文