A
negotiationneeded
event is sent to the
RTCPeerConnection
when negotiation of the connection through the signaling channel is required.
This occurs both during the initial setup of the connection as well as any time a change to the communication environment requires reconfiguring the connection.
| 冒泡 | No |
|---|---|
| 可取消 | No |
| 接口 |
事件
|
| 事件处理程序特性 |
RTCPeerConnection.onnegotiationneeded
|
negotiationneeded
event is first dispatched to the
RTCPeerConnection
when media is first added to the connection. This starts the process of
ICE
negotiation by instructing your code to begin exchanging ICE candidates through the signaling server. See
Signaling transaction flow
in
Signaling and video calling
for a description of the signaling process that begins with a
negotiationneeded
事件。
In this example, we use
addEventListener()
to create an event handler for
negotiationneeded
. Its role is to create an
SDP
offer and send it through the signaling channel to the remote peer.
pc.addEventListener("negotiationneeded", ev => {
pc.createOffer()
.then(offer => return pc.setLocalDescription(offer))
.then(() => sendSignalingMessage({
type: "video-offer",
sdp: pc.localDescription
}))
.catch(err => {
/* handle error */
);
}, false);
After creating the offer, the local end is configured by calling
RTCPeerConnection.setLocalDescription()
; then a signaling message is created and sent to the remote peer through the signaling server, to share that offer with the other peer. The other peer should recognize this message and follow up by creating its own
RTCPeerConnection
, setting the remote description with
setRemoteDescription()
, and then creating an answer to send back to the offering peer.
You can also set an event handler for the
negotiationneeded
event by assigning the event handler function to the
RTCPeerConnection.onnegotiationneeded
特性:
pc.onnegotiationneeded = ev => {
pc.createOffer()
.then(offer => return pc.setLocalDescription(offer))
.then(() => sendSignalingMessage({
type: "video-offer",
sdp: pc.localDescription
}))
.catch(err => {
/* handle error */
);
};
For a more detailed example, see Starting negotiation in Signaling and video calling .
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'negotiationneeded' in that specification. |
候选推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
negotiationneeded
event
|
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 ? | Samsung Internet Android 6.0 |
完整支持
不支持
兼容性未知
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()
addstream
identityresult
negotiationneeded
removestream
signalingstatechange
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannel
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceCandidate
RTCIceTransport
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsEvent
RTCStatsReport
RTCTrackEvent