MediaDevices: getSupportedConstraints() メソッド

getSupportedConstraints()MediaDevices インターフェイスのメソッドで、 MediaTrackSupportedConstraints 辞書に基づくオブジェクトを返却し、そのそれぞれのメンバーフィールドは、ユーザーエージェントが理解する制約可能なプロパティの 1 つを指定します。

構文

js
getSupportedConstraints()

引数

なし。

返値

MediaTrackSupportedConstraints 辞書に基づく新しいオブジェクトです。このオブジェクトはユーザーエージェントが扱うことができるメディア制約の一覧を含みます。この一覧に含まれているものは、ユーザーエージェントが取り扱えるものだけなので、全ての論理型のプロパティは true の値になっています。

この例は、実行中のブラウザーで対応している制約の一覧を出力するものです。

js
const constraintList = document.querySelector("#constraintList");
const supportedConstraints = navigator.mediaDevices.getSupportedConstraints();

for (const constraint of Object.keys(supportedConstraints)) {
  const elem = document.createElement("li");
  elem.innerHTML = `<code>${constraint}</code>`;
  constraintList.appendChild(elem);
}

結果

仕様書

Specification
Media Capture and Streams
# dom-mediadevices-getsupportedconstraints

ブラウザーの互換性

BCD tables only load in the browser