Skip to content

Commit

Permalink
Add mediasession api (rustwasm#2926)
Browse files Browse the repository at this point in the history
* Added MediaSession API to web-sys

* Added WebIDL inclusion instructions to web-sys README
  • Loading branch information
rozbb authored and expenses committed Jun 14, 2022
1 parent ee0a1b5 commit e526546
Show file tree
Hide file tree
Showing 13 changed files with 864 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/web-sys/Cargo.toml
Expand Up @@ -737,6 +737,7 @@ MediaEncodingConfiguration = []
MediaEncodingType = []
MediaEncryptedEvent = ["Event"]
MediaError = []
MediaImage = []
MediaKeyError = ["Event"]
MediaKeyMessageEvent = ["Event"]
MediaKeyMessageEventInit = []
Expand All @@ -754,13 +755,20 @@ MediaKeys = []
MediaKeysPolicy = []
MediaKeysRequirement = []
MediaList = []
MediaMetadata = []
MediaMetadataInit = []
MediaPositionState = []
MediaQueryList = ["EventTarget"]
MediaQueryListEvent = ["Event"]
MediaQueryListEventInit = []
MediaRecorder = ["EventTarget"]
MediaRecorderErrorEvent = ["Event"]
MediaRecorderErrorEventInit = []
MediaRecorderOptions = []
MediaSession = []
MediaSessionAction = []
MediaSessionActionDetails = []
MediaSessionPlaybackState = []
MediaSource = ["EventTarget"]
MediaSourceEndOfStreamError = []
MediaSourceEnum = []
Expand Down
18 changes: 18 additions & 0 deletions crates/web-sys/README.md
Expand Up @@ -14,3 +14,21 @@ found in `crates/web-sys/Cargo.toml`, but the rule of thumb for `web-sys` is
that each type has its own cargo feature (named after the type). Using an API
requires enabling the features for all types used in the API, and APIs should
mention in the documentation what features they require.

## How to add an interface

If you don't see a particular web API in `web-sys`, here is how to add it.

1. Copy the WebIDL specification of the API and place it in a new file in the
`webidls/unstable` folder. You can often find the IDL by going to the MDN
docs page for the API, scrolling to the bottom, clicking the
"Specifications" link, and scrolling to the bottom of the specification
page. For example, the bottom of the [MDN
docs](https://developer.mozilla.org/en-US/docs/Web/API/MediaSession) on the
MediaSession API takes you to the
[spec](https://w3c.github.io/mediasession/#the-mediasession-interface). The
[very bottom](https://w3c.github.io/mediasession/#idl-index) of _that_ page
is the IDL.
2. Run `cargo run --release --package wasm-bindgen-webidl -- webidls src/features`
3. Copy the contents of `features` into the `[features]` section of `Cargo.toml`
4. Run `git add .` to add all the generated files into git.
82 changes: 82 additions & 0 deletions crates/web-sys/src/features/gen_MediaImage.rs
@@ -0,0 +1,82 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = MediaImage)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `MediaImage` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaImage`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type MediaImage;
}
#[cfg(web_sys_unstable_apis)]
impl MediaImage {
#[doc = "Construct a new `MediaImage`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaImage`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new(src: &str) -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret.src(src);
ret
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `sizes` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaImage`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn sizes(&mut self, val: &str) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("sizes"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `src` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaImage`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn src(&mut self, val: &str) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("src"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `type` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaImage`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn type_(&mut self, val: &str) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("type"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
129 changes: 129 additions & 0 deletions crates/web-sys/src/features/gen_MediaMetadata.rs
@@ -0,0 +1,129 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = MediaMetadata , typescript_type = "MediaMetadata")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `MediaMetadata` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type MediaMetadata;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "MediaMetadata" , js_name = title)]
#[doc = "Getter for the `title` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata/title)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn title(this: &MediaMetadata) -> String;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , setter , js_class = "MediaMetadata" , js_name = title)]
#[doc = "Setter for the `title` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata/title)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn set_title(this: &MediaMetadata, value: &str);
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "MediaMetadata" , js_name = artist)]
#[doc = "Getter for the `artist` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata/artist)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn artist(this: &MediaMetadata) -> String;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , setter , js_class = "MediaMetadata" , js_name = artist)]
#[doc = "Setter for the `artist` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata/artist)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn set_artist(this: &MediaMetadata, value: &str);
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "MediaMetadata" , js_name = album)]
#[doc = "Getter for the `album` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata/album)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn album(this: &MediaMetadata) -> String;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , setter , js_class = "MediaMetadata" , js_name = album)]
#[doc = "Setter for the `album` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata/album)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn set_album(this: &MediaMetadata, value: &str);
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "MediaMetadata" , js_name = artwork)]
#[doc = "Getter for the `artwork` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata/artwork)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn artwork(this: &MediaMetadata) -> ::js_sys::Array;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , setter , js_class = "MediaMetadata" , js_name = artwork)]
#[doc = "Setter for the `artwork` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata/artwork)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn set_artwork(this: &MediaMetadata, value: &::wasm_bindgen::JsValue);
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen(catch, constructor, js_class = "MediaMetadata")]
#[doc = "The `new MediaMetadata(..)` constructor, creating a new instance of `MediaMetadata`."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata/MediaMetadata)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new() -> Result<MediaMetadata, JsValue>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "MediaMetadataInit")]
#[wasm_bindgen(catch, constructor, js_class = "MediaMetadata")]
#[doc = "The `new MediaMetadata(..)` constructor, creating a new instance of `MediaMetadata`."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata/MediaMetadata)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadata`, `MediaMetadataInit`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new_with_init(init: &MediaMetadataInit) -> Result<MediaMetadata, JsValue>;
}
109 changes: 109 additions & 0 deletions crates/web-sys/src/features/gen_MediaMetadataInit.rs
@@ -0,0 +1,109 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = MediaMetadataInit)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `MediaMetadataInit` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadataInit`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type MediaMetadataInit;
}
#[cfg(web_sys_unstable_apis)]
impl MediaMetadataInit {
#[doc = "Construct a new `MediaMetadataInit`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadataInit`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new() -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `album` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadataInit`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn album(&mut self, val: &str) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("album"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `artist` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadataInit`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn artist(&mut self, val: &str) -> &mut Self {
use wasm_bindgen::JsValue;
let r =
::js_sys::Reflect::set(self.as_ref(), &JsValue::from("artist"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `artwork` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadataInit`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn artwork(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(
self.as_ref(),
&JsValue::from("artwork"),
&JsValue::from(val),
);
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `title` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `MediaMetadataInit`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn title(&mut self, val: &str) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("title"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
#[cfg(web_sys_unstable_apis)]
impl Default for MediaMetadataInit {
fn default() -> Self {
Self::new()
}
}

0 comments on commit e526546

Please sign in to comment.