RTCRtpReceiver.getCapabilities() static function - Web APIs 编辑

The static function RTCRtpReceiver.getCapabilities() returns an RTCRtpCapabilities object describing the codecs and capabilities supported by RTCRtpReceivers on the current device.

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

Syntax

let rtpCapabilities = RTCRtpReceiver.getCapabilities(kind);

Parameters

kind
A 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 video.

Return value

An 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.

Description

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.

Calling RTCRtpReceiver.getCapabilities() doesn't prime the browser in any way to handle media. Nothing is loaded, fetched, or otherwise prepared. It's 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.

Example

The function below returns a Boolean indicating whether or not the device supports receiving H.264 video on a WebRTC connection.

Since 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;
}

Specifications

SpecificationStatusComment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCRtpReceiver.getCapabilities()' in that specification.
Candidate Recommendation

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:121 次

字数:4451

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文