static function
RTCRtpSender.getCapabilities()
返回
RTCRtpCapabilities
object describing the codecs and capabilities supported by the
RTCRtpSender
.
You can, similarly, obtain the capabilities of
RTCRtpReceiver
s by calling the static function
RTCRtpReceiver.getCapabilities()
.
let rtpCapabilities = RTCRtpSender.getCapabilities(kind);
kind
DOMString
indicating the type of media for which you wish to get the sender's capability to receive. All browsers support the primary media kinds:
audio
and
视频
.
RTCRtpCapabilities
object stating what capabilities the browser has for sending the specified media kind over an
RTCPeerConnection
. If the browser doesn't have any support for the given media kind, the returned value is
null
.
As a static function, this is always called using the form:
capabilities = RTCRtpSender.getCapabilities("audio");
The returned set of capabilities is the most optimistic possible list. It is entirely possible that certain combinations of options may fail to work when you actually try to use them.
调用
RTCRtpSender.getCapabilities()
doesn't prime the browser in any way to handle media. Nothing is loaded, fetched, or otherwise prepared. It's simply a means of determining what might be usable before starting to try to access media.
Because the set of capabilities available tend to be stable for a length of time (people don't install and uninstall codecs and the like very often), the media capabilities can in whole or in part provide a cross-origin method for identifying a user. For that reason, in privacy-sensitive contexts, the browser may choose to obscure the capabilities; this might be done, for example, by leaving out rarely-used codec configurations.
The function below returns a Boolean indicating whether or not the device supports sending H.264 video on an
RTCRtpSender
.
由于
RTCRtpSender.getCapabilities()
actually only indicates
probable
support, H.264 support might still fail even after getting a positive response from this function.
function canSendH264() {
let capabilities = RTCRtpSender.getCapabilities("video");
capabilities.codecs.forEach((codec) => {
if (codec.mimeType === "video/H264") {
return true;
}
});
return false;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCRtpSender.getCapabilities()' in that specification. |
候选推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
getCapabilities()
|
Chrome Yes | Edge 12 | Firefox ? | IE 不支持 No | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android ? | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
完整支持
不支持
兼容性未知
RTCPeerConnection
RTCSessionDescription
RTCIceCandidate
RTCPeerConnectionIceEvent
RTCPeerConnectionIceErrorEvent
RTCCertificate
RTCRtpSender
RTCRtpReceiver
RTCRtpTransceiver
RTCDtlsTransport
RTCIceTransport
RTCTrackEvent
RTCSctpTransport
RTCDataChannel
RTCDataChannelEvent
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCStatsReport
RTCErrorEvent
RTCDTMFSender
:
tonechange
RTCDataChannel
:
bufferedamountlow
RTCDataChannel
:
close
RTCDataChannel
:
closing
RTCDataChannel
:
error
RTCDataChannel
:
message
RTCDataChannel
:
open
RTCDtlsTransport
:
error
RTCDtlsTransport
:
statechange
RTCIceTransport
:
error
RTCIceTransport
:
gatheringstatechange
RTCIceTransport
:
selectedcandidatepairchange
RTCIceTransport
:
statechange
RTCPeerConnection
:
connectionstatechange
RTCPeerConnection
:
datachannel
RTCPeerConnection
:
icecandidate
RTCPeerConnection
:
icecandidateerror
RTCPeerConnection
:
iceconnectionstatechange
RTCPeerConnection
:
icegatheringstatechange
RTCPeerConnection
:
negotiationneeded
RTCPeerConnection
:
signalingstatechange
RTCPeerConnection
:
track
RTCSctpTransport
:
error