RTCPeerConnection
接口的
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.
RTCPeerConnection.onnegotiationneeded = eventHandler;
This should be set to a function you provide which is passed a single parameter: an
事件
object containing the
negotiationneeded
event. There's no additional information provided in the event; anything you need, you can get by examining the
特性对于
RTCPeerConnection
.
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.
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.onnegotiationneeded' in that specification. |
候选推荐 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
onnegotiationneeded
|
Chrome 24 | Edge 15 | Firefox 22 | IE No |
Opera
43
|
Safari 11 | WebView Android Yes | Chrome Android Yes | Firefox Android 44 |
Opera Android
43
|
Safari iOS Yes | Samsung Internet Android 6.0 |
完整支持
不支持
见实现注意事项。
negotiationneeded
event and its type,
事件
.
RTCPeerConnection
canTrickleIceCandidates
connectionState
currentLocalDescription
currentRemoteDescription
getDefaultIceServers()
iceConnectionState
iceGatheringState
localDescription
onaddstream
onconnectionstatechange
ondatachannel
onicecandidate
oniceconnectionstatechange
onicegatheringstatechange
onidentityresult
onidpassertionerror
onidpvalidationerror
onnegotiationneeded
onpeeridentity
onremovestream
onsignalingstatechange
ontrack
peerIdentity
pendingLocalDescription
pendingRemoteDescription
remoteDescription
sctp
signalingState
addIceCandidate()
addStream()
addTrack()
close()
createAnswer()
createDataChannel()
createOffer()
generateCertificate()
getConfiguration()
getIdentityAssertion()
getReceivers()
getSenders()
getStats()
getStreamById()
getTransceivers()
removeStream()
removeTrack()
restartIce()
setConfiguration()
setIdentityProvider()
setLocalDescription()
setRemoteDescription()
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannel
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceCandidate
RTCIceTransport
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsEvent
RTCStatsReport
RTCTrackEvent