MediaDevices: getSupportedConstraints() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Phương thức getSupportedConstraints() của giao diện MediaDevices trả về một đối tượng dựa trên dictionary MediaTrackSupportedConstraints, trong đó mỗi trường thành viên chỉ định một trong các thuộc tính có thể ràng buộc mà user agent hiểu được.

Cú pháp

js
getSupportedConstraints()

Tham số

Không có.

Giá trị trả về

Một đối tượng mới dựa trên dictionary MediaTrackSupportedConstraints liệt kê các ràng buộc được user agent hỗ trợ. Vì chỉ những ràng buộc được user agent hỗ trợ mới được đưa vào danh sách, mỗi thuộc tính Boolean này có giá trị true.

Ví dụ

Ví dụ này xuất ra danh sách các ràng buộc được trình duyệt của bạn hỗ trợ.

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

for (const constraint of Object.keys(supportedConstraints)) {
  const elem = document.createElement("li");
  elem.appendChild(document.createElement("code")).textContent = constraint;
  constraintList.appendChild(elem);
}

Kết quả

Thông số kỹ thuật

Thông số kỹ thuật
Media Capture and Streams
# dom-mediadevices-getsupportedconstraints

Tương thích trình duyệt