RTCPeerConnection.onnegotiationneeded - Web APIs 编辑

The RTCPeerConnection interface's onnegotiationneeded property is an EventListener which specifies a function which is called to handle the negotiationneeded event when it occurs on an RTCPeerConnection instance. This event is fired when a change has occurred which requires session negotiation. This negotiation should be carried out as the offerer, because some session changes cannot be negotiated as the answerer.

Most commonly, the negotiationneeded event is fired after a send track is added to the RTCPeerConnection. If the session is modified in a manner that requires negotiation while a negotiation is already in progress, no negotiationneeded event will fire until negotiation completes, and only then if negotiation is still needed.

Syntax

RTCPeerConnection.onnegotiationneeded = eventHandler;

Value

This should be set to a function you provide which is passed a single parameter: an Event object containing the negotiationneeded event. There's no additional information provided in the event; anything you need, you can get by examining the properties of the RTCPeerConnection.

Example

This example, derived from the example in Signaling and video calling, establishes a handler for negotiationneeded events to handle creating an offer, configuring the local end of the connection, and sending the offer to the remote peer.

pc.onnegotiationneeded = function() {
  pc.createOffer().then(function(offer) {
    return pc.setLocalDescription(offer);
  })
  .then(function() {
      // Send the offer to the remote peer through the signaling server
    });
  })
  .catch(reportError);
}

First, it creates the offer by calling createOffer(). When that succeeds, the offer is passed into setLocalDescription() to set the local description for the connection. Once that's succeeded in turn, the offer can be sent to the signaling server for delivery to the remote peer.

Specifications

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

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:75 次

字数:4760

最后编辑:6 年前

编辑次数:0 次

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