Skip to content

Commit 544bfa3

Browse files
authored
Add WebIDL items DisplayMediaStreamConstraints and getDisplayMedia (#2423)
1 parent ffa3e93 commit 544bfa3

File tree

6 files changed

+81
-0
lines changed

6 files changed

+81
-0
lines changed

crates/web-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ DeviceRotationRateInit = []
269269
DhKeyDeriveParams = []
270270
DirectionSetting = []
271271
Directory = []
272+
DisplayMediaStreamConstraints = []
272273
DisplayNameOptions = []
273274
DisplayNameResult = []
274275
DistanceModelType = []
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[wasm_bindgen]
5+
extern "C" {
6+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = DisplayMediaStreamConstraints)]
7+
#[derive(Debug, Clone, PartialEq, Eq)]
8+
#[doc = "The `DisplayMediaStreamConstraints` dictionary."]
9+
#[doc = ""]
10+
#[doc = "*This API requires the following crate features to be activated: `DisplayMediaStreamConstraints`*"]
11+
pub type DisplayMediaStreamConstraints;
12+
}
13+
impl DisplayMediaStreamConstraints {
14+
#[doc = "Construct a new `DisplayMediaStreamConstraints`."]
15+
#[doc = ""]
16+
#[doc = "*This API requires the following crate features to be activated: `DisplayMediaStreamConstraints`*"]
17+
pub fn new() -> Self {
18+
#[allow(unused_mut)]
19+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
20+
ret
21+
}
22+
#[doc = "Change the `audio` field of this object."]
23+
#[doc = ""]
24+
#[doc = "*This API requires the following crate features to be activated: `DisplayMediaStreamConstraints`*"]
25+
pub fn audio(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
26+
use wasm_bindgen::JsValue;
27+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("audio"), &JsValue::from(val));
28+
debug_assert!(
29+
r.is_ok(),
30+
"setting properties should never fail on our dictionary objects"
31+
);
32+
let _ = r;
33+
self
34+
}
35+
#[doc = "Change the `video` field of this object."]
36+
#[doc = ""]
37+
#[doc = "*This API requires the following crate features to be activated: `DisplayMediaStreamConstraints`*"]
38+
pub fn video(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
39+
use wasm_bindgen::JsValue;
40+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("video"), &JsValue::from(val));
41+
debug_assert!(
42+
r.is_ok(),
43+
"setting properties should never fail on our dictionary objects"
44+
);
45+
let _ = r;
46+
self
47+
}
48+
}

crates/web-sys/src/features/gen_MediaDevices.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ extern "C" {
3232
#[doc = ""]
3333
#[doc = "*This API requires the following crate features to be activated: `MediaDevices`*"]
3434
pub fn enumerate_devices(this: &MediaDevices) -> Result<::js_sys::Promise, JsValue>;
35+
# [wasm_bindgen (catch , method , structural , js_class = "MediaDevices" , js_name = getDisplayMedia)]
36+
#[doc = "The `getDisplayMedia()` method."]
37+
#[doc = ""]
38+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia)"]
39+
#[doc = ""]
40+
#[doc = "*This API requires the following crate features to be activated: `MediaDevices`*"]
41+
pub fn get_display_media(this: &MediaDevices) -> Result<::js_sys::Promise, JsValue>;
42+
#[cfg(feature = "DisplayMediaStreamConstraints")]
43+
# [wasm_bindgen (catch , method , structural , js_class = "MediaDevices" , js_name = getDisplayMedia)]
44+
#[doc = "The `getDisplayMedia()` method."]
45+
#[doc = ""]
46+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia)"]
47+
#[doc = ""]
48+
#[doc = "*This API requires the following crate features to be activated: `DisplayMediaStreamConstraints`, `MediaDevices`*"]
49+
pub fn get_display_media_with_constraints(
50+
this: &MediaDevices,
51+
constraints: &DisplayMediaStreamConstraints,
52+
) -> Result<::js_sys::Promise, JsValue>;
3553
#[cfg(feature = "MediaTrackSupportedConstraints")]
3654
# [wasm_bindgen (method , structural , js_class = "MediaDevices" , js_name = getSupportedConstraints)]
3755
#[doc = "The `getSupportedConstraints()` method."]

crates/web-sys/src/features/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,12 @@ mod gen_Directory;
14321432
#[cfg(feature = "Directory")]
14331433
pub use gen_Directory::*;
14341434

1435+
#[cfg(feature = "DisplayMediaStreamConstraints")]
1436+
#[allow(non_snake_case)]
1437+
mod gen_DisplayMediaStreamConstraints;
1438+
#[cfg(feature = "DisplayMediaStreamConstraints")]
1439+
pub use gen_DisplayMediaStreamConstraints::*;
1440+
14351441
#[cfg(feature = "DisplayNameOptions")]
14361442
#[allow(non_snake_case)]
14371443
mod gen_DisplayNameOptions;

crates/web-sys/webidls/enabled/MediaDevices.webidl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ interface MediaDevices : EventTarget {
2121

2222
[Throws, NeedsCallerType]
2323
Promise<MediaStream> getUserMedia(optional MediaStreamConstraints constraints);
24+
25+
[SecureContext, Pref="media.getdisplaymedia.enabled", Throws, NeedsCallerType]
26+
Promise<MediaStream> getDisplayMedia(optional DisplayMediaStreamConstraints constraints);
2427
};

crates/web-sys/webidls/enabled/MediaStream.webidl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ dictionary MediaStreamConstraints {
2323
DOMString? peerIdentity = null;
2424
};
2525

26+
dictionary DisplayMediaStreamConstraints {
27+
(boolean or MediaTrackConstraints) video = true;
28+
(boolean or MediaTrackConstraints) audio = false;
29+
};
30+
2631
[Exposed=Window,
2732
Constructor,
2833
Constructor (MediaStream stream),

0 commit comments

Comments
 (0)