From e7de1cdb8f749d76cf2e873704d7c3cc101cb19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kav=C3=ADk?= Date: Mon, 18 Jan 2021 21:04:23 +0100 Subject: [PATCH] Add WebIDL items DisplayMediaStreamConstraints and getDisplayMedia --- crates/web-sys/Cargo.toml | 1 + .../gen_DisplayMediaStreamConstraints.rs | 48 +++++++++++++++++++ .../web-sys/src/features/gen_MediaDevices.rs | 18 +++++++ crates/web-sys/src/features/mod.rs | 6 +++ .../webidls/enabled/MediaDevices.webidl | 3 ++ .../webidls/enabled/MediaStream.webidl | 5 ++ 6 files changed, 81 insertions(+) create mode 100644 crates/web-sys/src/features/gen_DisplayMediaStreamConstraints.rs diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index 38786a1e6c8..456c5268e17 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -269,6 +269,7 @@ DeviceRotationRateInit = [] DhKeyDeriveParams = [] DirectionSetting = [] Directory = [] +DisplayMediaStreamConstraints = [] DisplayNameOptions = [] DisplayNameResult = [] DistanceModelType = [] diff --git a/crates/web-sys/src/features/gen_DisplayMediaStreamConstraints.rs b/crates/web-sys/src/features/gen_DisplayMediaStreamConstraints.rs new file mode 100644 index 00000000000..f040288f42e --- /dev/null +++ b/crates/web-sys/src/features/gen_DisplayMediaStreamConstraints.rs @@ -0,0 +1,48 @@ +#![allow(unused_imports)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = DisplayMediaStreamConstraints)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `DisplayMediaStreamConstraints` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `DisplayMediaStreamConstraints`*"] + pub type DisplayMediaStreamConstraints; +} +impl DisplayMediaStreamConstraints { + #[doc = "Construct a new `DisplayMediaStreamConstraints`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `DisplayMediaStreamConstraints`*"] + pub fn new() -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret + } + #[doc = "Change the `audio` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `DisplayMediaStreamConstraints`*"] + pub fn audio(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("audio"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `video` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `DisplayMediaStreamConstraints`*"] + pub fn video(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("video"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } +} diff --git a/crates/web-sys/src/features/gen_MediaDevices.rs b/crates/web-sys/src/features/gen_MediaDevices.rs index ad0338c7c72..d8a76c67fe4 100644 --- a/crates/web-sys/src/features/gen_MediaDevices.rs +++ b/crates/web-sys/src/features/gen_MediaDevices.rs @@ -32,6 +32,24 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `MediaDevices`*"] pub fn enumerate_devices(this: &MediaDevices) -> Result<::js_sys::Promise, JsValue>; + # [wasm_bindgen (catch , method , structural , js_class = "MediaDevices" , js_name = getDisplayMedia)] + #[doc = "The `getDisplayMedia()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `MediaDevices`*"] + pub fn get_display_media(this: &MediaDevices) -> Result<::js_sys::Promise, JsValue>; + #[cfg(feature = "DisplayMediaStreamConstraints")] + # [wasm_bindgen (catch , method , structural , js_class = "MediaDevices" , js_name = getDisplayMedia)] + #[doc = "The `getDisplayMedia()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `DisplayMediaStreamConstraints`, `MediaDevices`*"] + pub fn get_display_media_with_constraints( + this: &MediaDevices, + constraints: &DisplayMediaStreamConstraints, + ) -> Result<::js_sys::Promise, JsValue>; #[cfg(feature = "MediaTrackSupportedConstraints")] # [wasm_bindgen (method , structural , js_class = "MediaDevices" , js_name = getSupportedConstraints)] #[doc = "The `getSupportedConstraints()` method."] diff --git a/crates/web-sys/src/features/mod.rs b/crates/web-sys/src/features/mod.rs index 8611ff5a3d2..f7e2fd20cf8 100644 --- a/crates/web-sys/src/features/mod.rs +++ b/crates/web-sys/src/features/mod.rs @@ -1432,6 +1432,12 @@ mod gen_Directory; #[cfg(feature = "Directory")] pub use gen_Directory::*; +#[cfg(feature = "DisplayMediaStreamConstraints")] +#[allow(non_snake_case)] +mod gen_DisplayMediaStreamConstraints; +#[cfg(feature = "DisplayMediaStreamConstraints")] +pub use gen_DisplayMediaStreamConstraints::*; + #[cfg(feature = "DisplayNameOptions")] #[allow(non_snake_case)] mod gen_DisplayNameOptions; diff --git a/crates/web-sys/webidls/enabled/MediaDevices.webidl b/crates/web-sys/webidls/enabled/MediaDevices.webidl index a71aa05c1a3..8e157a2e03f 100644 --- a/crates/web-sys/webidls/enabled/MediaDevices.webidl +++ b/crates/web-sys/webidls/enabled/MediaDevices.webidl @@ -21,4 +21,7 @@ interface MediaDevices : EventTarget { [Throws, NeedsCallerType] Promise getUserMedia(optional MediaStreamConstraints constraints); + + [SecureContext, Pref="media.getdisplaymedia.enabled", Throws, NeedsCallerType] + Promise getDisplayMedia(optional DisplayMediaStreamConstraints constraints); }; diff --git a/crates/web-sys/webidls/enabled/MediaStream.webidl b/crates/web-sys/webidls/enabled/MediaStream.webidl index 71d24527e3a..edc8791a6d8 100644 --- a/crates/web-sys/webidls/enabled/MediaStream.webidl +++ b/crates/web-sys/webidls/enabled/MediaStream.webidl @@ -23,6 +23,11 @@ dictionary MediaStreamConstraints { DOMString? peerIdentity = null; }; +dictionary DisplayMediaStreamConstraints { + (boolean or MediaTrackConstraints) video = true; + (boolean or MediaTrackConstraints) audio = false; +}; + [Exposed=Window, Constructor, Constructor (MediaStream stream),