这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
RTCPeerConnection.setConfiguration()
method sets the current configuration of the
RTCPeerConnection
based on the values included in the specified
RTCConfiguration
object. This lets you change the ICE servers used by the connection and which transport policies to use.
The most common use case for this method (and even then, probably not a very common use case) is to replace the set of ICE servers to be used. Two potential scenarios in which this might be done:
RTCPeerConnection
was instantiated without specifying any ICE servers. If, for example, the
RTCPeerConnection()
constructor was called with no parameters, you would have to then call
setConfiguration()
to add ICE servers before ICE negotiation could begin.
setConfiguration()
to switch to new regional ICE servers, then initiate an
ICE restart
.
You cannot change the identity information for a connection once it's already been set.
RTCPeerConnection.setConfiguration(configuration);
configuration
RTCConfiguration
object which provides the options to be set. The changes are not additive; instead, the new values completely replace the existing ones.
InvalidAccessError
configuration.iceServers
是
TURN
server, but complete login information is not provided (that is, either the
RTCIceServer.username
or
RTCIceServer.credentials
is missing). This prevents successful login to the server.
InvalidModificationError
configuration
includes changed identity information, but the connection already has identity information specified. This happens if
configuration.peerIdentity
or
configuration.certificates
is set and their values differ from the current configuration.
InvalidStateError
RTCPeerConnection
is closed.
SyntaxError
configuration.iceServers
list is invalid.
In this example, it has already been determined that ICE restart is needed, and that negotiation needs to be done using a different ICE server.
var restartConfig = { iceServers: [{
urls: "turn:asia.myturnserver.net",
username: "allie@oopcode.com",
credential: "topsecretpassword"
}]
};
myPeerConnection.setConfiguration(restartConfig);
myPeerConnection.createOffer({"iceRestart": true}).then(function(offer) {
return myPeerConnection.setLocalDescription(offer);
})
.then(function() {
// send the offer to the other peer using the signaling server
})
.catch(reportError);
First, a new
RTCConfiguration
is created,
restartConfig
, specifying the new ICE server and its credentials. This is then passed into
setConfiguration()
. ICE negotiation is restarted by calling
createOffer()
, specifying
true
as the value of the
iceRestart
option. From there, we handle the process as usual, by setting the local description to the returned offer and then sending that offer to the other peer.
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'setConfiguration()' in that specification. |
候选推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
setConfiguration
|
Chrome 48 | Edge ≤18 |
Firefox
不支持
No
注意事项
|
IE 不支持 No |
Opera
43
注意事项
|
Safari 11 | WebView Android 48 | Chrome Android 48 |
Firefox Android
不支持
No
注意事项
|
Opera Android
43
注意事项
|
Safari iOS Yes | 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()
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannel
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceCandidate
RTCIceTransport
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsEvent
RTCStatsReport
RTCTrackEvent