static function RTCRtpReceiver.getCapabilities() 返回 RTCRtpCapabilities object describing the codecs and capabilities supported by RTCRtpReceiver s on the current device.

You can, similarly, obtain the capabilities of RTCRtpSender s by calling the static function RTCRtpSender.getCapabilities() .

句法

let rtpCapabilities = RTCRtpReceiver.getCapabilities(kind);
					

参数

kind
DOMString indicating the type of media for which you wish to get the device's capability to receive. All browsers support the primary media kinds: audio and 视频 .

返回值

RTCRtpCapabilities object stating what capabilities the browser has for receiving 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 = RTCRtpReceiver.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.

调用 RTCRtpReceiver.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 receiving H.264 video on a WebRTC connection.

由于 RTCRtpReceiver.getCapabilities() actually only indicates probable support, attempting to receive H.264 video might still fail even after getting a positive response from this function.

function canReceiveH264() {
  let capabilities = RTCRtpReceiver.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 'RTCRtpReceiver.getCapabilities()' in that specification.
候选推荐

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getCapabilities Chrome 59 Edge 12 Firefox Yes IE 不支持 No Opera 46 Safari ? WebView Android 59 Chrome Android 59 Firefox Android Yes Opera Android 43 Safari iOS ? Samsung Internet Android 7.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

元数据

  • 最后修改: