Skip to content

Commit 1d2d345

Browse files
authored
Fix ImageCapture API (#2347) (#2348)
* Fix ImageCapture API (#2347) * Move ImageCapture to unstable webidls
1 parent 45d2f2d commit 1d2d345

File tree

2 files changed

+62
-47
lines changed

2 files changed

+62
-47
lines changed
Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,86 @@
11
#![allow(unused_imports)]
22
use super::*;
33
use wasm_bindgen::prelude::*;
4+
#[cfg(web_sys_unstable_apis)]
45
#[wasm_bindgen]
56
extern "C" {
6-
# [wasm_bindgen (extends = EventTarget , extends = :: js_sys :: Object , js_name = ImageCapture , typescript_type = "ImageCapture")]
7+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ImageCapture , typescript_type = "ImageCapture")]
78
#[derive(Debug, Clone, PartialEq, Eq)]
89
#[doc = "The `ImageCapture` class."]
910
#[doc = ""]
1011
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture)"]
1112
#[doc = ""]
1213
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`*"]
14+
#[doc = ""]
15+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
16+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
1317
pub type ImageCapture;
14-
#[cfg(feature = "VideoStreamTrack")]
15-
# [wasm_bindgen (structural , method , getter , js_class = "ImageCapture" , js_name = videoStreamTrack)]
16-
#[doc = "Getter for the `videoStreamTrack` field of this object."]
18+
#[cfg(web_sys_unstable_apis)]
19+
#[cfg(feature = "MediaStreamTrack")]
20+
# [wasm_bindgen (structural , method , getter , js_class = "ImageCapture" , js_name = track)]
21+
#[doc = "Getter for the `track` field of this object."]
1722
#[doc = ""]
18-
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/videoStreamTrack)"]
23+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/track)"]
1924
#[doc = ""]
20-
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`, `VideoStreamTrack`*"]
21-
pub fn video_stream_track(this: &ImageCapture) -> VideoStreamTrack;
22-
# [wasm_bindgen (structural , method , getter , js_class = "ImageCapture" , js_name = onphoto)]
23-
#[doc = "Getter for the `onphoto` field of this object."]
25+
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`, `MediaStreamTrack`*"]
2426
#[doc = ""]
25-
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/onphoto)"]
27+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
28+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
29+
pub fn track(this: &ImageCapture) -> MediaStreamTrack;
30+
#[cfg(web_sys_unstable_apis)]
31+
#[cfg(feature = "MediaStreamTrack")]
32+
#[wasm_bindgen(catch, constructor, js_class = "ImageCapture")]
33+
#[doc = "The `new ImageCapture(..)` constructor, creating a new instance of `ImageCapture`."]
2634
#[doc = ""]
27-
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`*"]
28-
pub fn onphoto(this: &ImageCapture) -> Option<::js_sys::Function>;
29-
# [wasm_bindgen (structural , method , setter , js_class = "ImageCapture" , js_name = onphoto)]
30-
#[doc = "Setter for the `onphoto` field of this object."]
35+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/ImageCapture)"]
3136
#[doc = ""]
32-
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/onphoto)"]
37+
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`, `MediaStreamTrack`*"]
3338
#[doc = ""]
34-
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`*"]
35-
pub fn set_onphoto(this: &ImageCapture, value: Option<&::js_sys::Function>);
36-
# [wasm_bindgen (structural , method , getter , js_class = "ImageCapture" , js_name = onerror)]
37-
#[doc = "Getter for the `onerror` field of this object."]
39+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
40+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
41+
pub fn new(video_track: &MediaStreamTrack) -> Result<ImageCapture, JsValue>;
42+
#[cfg(web_sys_unstable_apis)]
43+
# [wasm_bindgen (method , structural , js_class = "ImageCapture" , js_name = getPhotoCapabilities)]
44+
#[doc = "The `getPhotoCapabilities()` method."]
3845
#[doc = ""]
39-
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/onerror)"]
46+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/getPhotoCapabilities)"]
4047
#[doc = ""]
4148
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`*"]
42-
pub fn onerror(this: &ImageCapture) -> Option<::js_sys::Function>;
43-
# [wasm_bindgen (structural , method , setter , js_class = "ImageCapture" , js_name = onerror)]
44-
#[doc = "Setter for the `onerror` field of this object."]
4549
#[doc = ""]
46-
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/onerror)"]
50+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
51+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
52+
pub fn get_photo_capabilities(this: &ImageCapture) -> ::js_sys::Promise;
53+
#[cfg(web_sys_unstable_apis)]
54+
# [wasm_bindgen (method , structural , js_class = "ImageCapture" , js_name = getPhotoSettings)]
55+
#[doc = "The `getPhotoSettings()` method."]
56+
#[doc = ""]
57+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/getPhotoSettings)"]
4758
#[doc = ""]
4859
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`*"]
49-
pub fn set_onerror(this: &ImageCapture, value: Option<&::js_sys::Function>);
50-
#[cfg(feature = "VideoStreamTrack")]
51-
#[wasm_bindgen(catch, constructor, js_class = "ImageCapture")]
52-
#[doc = "The `new ImageCapture(..)` constructor, creating a new instance of `ImageCapture`."]
5360
#[doc = ""]
54-
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/ImageCapture)"]
61+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
62+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
63+
pub fn get_photo_settings(this: &ImageCapture) -> ::js_sys::Promise;
64+
#[cfg(web_sys_unstable_apis)]
65+
# [wasm_bindgen (method , structural , js_class = "ImageCapture" , js_name = grabFrame)]
66+
#[doc = "The `grabFrame()` method."]
67+
#[doc = ""]
68+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/grabFrame)"]
5569
#[doc = ""]
56-
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`, `VideoStreamTrack`*"]
57-
pub fn new(track: &VideoStreamTrack) -> Result<ImageCapture, JsValue>;
58-
# [wasm_bindgen (catch , method , structural , js_class = "ImageCapture" , js_name = takePhoto)]
70+
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`*"]
71+
#[doc = ""]
72+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
73+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
74+
pub fn grab_frame(this: &ImageCapture) -> ::js_sys::Promise;
75+
#[cfg(web_sys_unstable_apis)]
76+
# [wasm_bindgen (method , structural , js_class = "ImageCapture" , js_name = takePhoto)]
5977
#[doc = "The `takePhoto()` method."]
6078
#[doc = ""]
6179
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/takePhoto)"]
6280
#[doc = ""]
6381
#[doc = "*This API requires the following crate features to be activated: `ImageCapture`*"]
64-
pub fn take_photo(this: &ImageCapture) -> Result<(), JsValue>;
82+
#[doc = ""]
83+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
84+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
85+
pub fn take_photo(this: &ImageCapture) -> ::js_sys::Promise;
6586
}

crates/web-sys/webidls/enabled/ImageCapture.webidl renamed to crates/web-sys/webidls/unstable/ImageCapture.webidl

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@
1010
* W3C liability, trademark and document use rules apply.
1111
*/
1212

13-
[Pref="dom.imagecapture.enabled", Constructor(VideoStreamTrack track)]
14-
interface ImageCapture : EventTarget {
15-
// readonly attribute PhotoSettingsOptions photoSettingsOptions;
16-
readonly attribute VideoStreamTrack videoStreamTrack;
17-
attribute EventHandler onphoto;
18-
attribute EventHandler onerror;
19-
// attribute EventHandler onphotosettingschange;
20-
// attribute EventHandler onframegrab;
13+
[Pref="dom.imagecapture.enabled", Constructor(MediaStreamTrack videoTrack)]
14+
interface ImageCapture {
15+
Promise<Blob> takePhoto(optional PhotoSettings photoSettings);
16+
Promise<PhotoCapabilities> getPhotoCapabilities();
17+
Promise<PhotoSettings> getPhotoSettings();
2118

22-
// [Throws]
23-
// void setOptions (PhotoSettings? photoSettings);
24-
[Throws]
25-
void takePhoto();
26-
// [Throws]
27-
// void getFrame();
19+
Promise<ImageBitmap> grabFrame();
20+
21+
readonly attribute MediaStreamTrack track;
2822
};

0 commit comments

Comments
 (0)