-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best way to access unsupported WD API's from web_sys? #2136
Comments
Somebody (possibly you) has to add the WebIDL to the unstable folder, by following these directions. |
Thanks @Pauan I will take a look at adding the WebIDL. In the mean time I found the following workaround.
|
Hello guys :) When looking on documentation at https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API and at I was wondering if there was a plan to add it so we can make screenshot easily in Rust 😄 I do not understand the instructions there #2000 (comment) . It is a bit far from my skills right now. If there is no plan for it, how could I use it ? |
|
Well, I tried to make the change :
I did the commands and got : #![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = EventTarget , extends = :: js_sys :: Object , js_name = MediaDevices , typescript_type = "MediaDevices")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `MediaDevices` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaDevices`*"]
pub type MediaDevices;
# [wasm_bindgen (structural , method , getter , js_class = "MediaDevices" , js_name = ondevicechange)]
#[doc = "Getter for the `ondevicechange` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/ondevicechange)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaDevices`*"]
pub fn ondevicechange(this: &MediaDevices) -> Option<::js_sys::Function>;
# [wasm_bindgen (structural , method , setter , js_class = "MediaDevices" , js_name = ondevicechange)]
#[doc = "Setter for the `ondevicechange` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/ondevicechange)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaDevices`*"]
pub fn set_ondevicechange(this: &MediaDevices, value: Option<&::js_sys::Function>);
# [wasm_bindgen (catch , method , structural , js_class = "MediaDevices" , js_name = enumerateDevices)]
#[doc = "The `enumerateDevices()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices)"]
#[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 = "MediaTrackSupportedConstraints")]
# [wasm_bindgen (method , structural , js_class = "MediaDevices" , js_name = getSupportedConstraints)]
#[doc = "The `getSupportedConstraints()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getSupportedConstraints)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaDevices`, `MediaTrackSupportedConstraints`*"]
pub fn get_supported_constraints(this: &MediaDevices) -> MediaTrackSupportedConstraints;
# [wasm_bindgen (catch , method , structural , js_class = "MediaDevices" , js_name = getUserMedia)]
#[doc = "The `getUserMedia()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaDevices`*"]
pub fn get_user_media(this: &MediaDevices) -> Result<::js_sys::Promise, JsValue>;
#[cfg(feature = "MediaStreamConstraints")]
# [wasm_bindgen (catch , method , structural , js_class = "MediaDevices" , js_name = getUserMedia)]
#[doc = "The `getUserMedia()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaDevices`, `MediaStreamConstraints`*"]
pub fn get_user_media_with_constraints(
this: &MediaDevices,
constraints: &MediaStreamConstraints,
) -> Result<::js_sys::Promise, JsValue>;
}
I wrote a test in Now when I follow the instruction to run my test this way : https://rustwasm.github.io/docs/wasm-bindgen/contributing/web-sys/testing.html My computer gets out of Memory Ram, and So I use this command, but it said there is no test to run on root of
=>
use wasm_bindgen_test::*;
use web_sys::{HtmlMediaElement, MediaStream, MediaStreamConstraints, window};
use wasm_bindgen::JsValue;
#[wasm_bindgen_test]
fn test_get_display() {
let mut constraints = MediaStreamConstraints::new();
constraints.video(&JsValue::from(true));
let media_stream_promise : Result<MediaStream, JsValue> = window()
.navigator()
.media_devices()
.unwrap()
.get_display_media(constraints);
assert_eq!(media_stream_promise.is_ok(),true);
}
Is there something I am missing ? I did follow the instruction there https://rustwasm.github.io/docs/wasm-bindgen/contributing/web-sys/testing.html |
Thank you @MartinKavik for the help 😉 We can now share a screen and it works very nicely 😄 Should we close this issue maybe? I also have a new question now 😛 Should I open a new issue to ask more information about |
Summary
What is the best way to access an API that is not currently supported by web_sys. I am tying to access the Screen Capture API[1] which is still a working draft.
Additional Details
I am trying to use the screen capture API[1] which extends the MediaDevices[2] with the getDisplayMedia() function that returns a Promise similar to the way getUserMedia() works. As this is a working draft API I understand it should not be added to web_sys yet. What is the best way to access this API.
The text was updated successfully, but these errors were encountered: