Skip to content
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

Add WebIDLs for experimental AudioContext sinkId, setSinkId #3433

Merged
merged 3 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# `wasm-bindgen` Change Log
--------------------------------------------------------------------------------

## [Unreleased](https://github.com/rustwasm/wasm-bindgen/compare/0.2.87...main)

### Added

* Extend `AudioContext` with unstable features supporting audio sink configuration.
[#3433](https://github.com/rustwasm/wasm-bindgen/pull/3433)

## [0.2.87](https://github.com/rustwasm/wasm-bindgen/compare/0.2.86...0.2.87)

Released 2023-06-12.
Expand Down
4 changes: 4 additions & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ AudioBufferSourceNode = ["AudioNode", "AudioScheduledSourceNode", "EventTarget"]
AudioBufferSourceOptions = []
AudioConfiguration = []
AudioContext = ["BaseAudioContext", "EventTarget"]
AudioContextLatencyCategory = []
AudioContextOptions = []
AudioContextState = []
AudioData = []
Expand All @@ -90,6 +91,9 @@ AudioParamMap = []
AudioProcessingEvent = ["Event"]
AudioSampleFormat = []
AudioScheduledSourceNode = ["AudioNode", "EventTarget"]
AudioSinkInfo = []
AudioSinkOptions = []
AudioSinkType = []
AudioStreamTrack = ["EventTarget", "MediaStreamTrack"]
AudioTrack = []
AudioTrackList = ["EventTarget"]
Expand Down
59 changes: 59 additions & 0 deletions crates/web-sys/src/features/gen_AudioContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@ extern "C" {
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioContext`*"]
pub type AudioContext;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "AudioContext" , js_name = sinkId)]
#[doc = "Getter for the `sinkId` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/sinkId)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioContext`*"]
#[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 sink_id(this: &AudioContext) -> ::wasm_bindgen::JsValue;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "AudioContext" , js_name = onsinkchange)]
#[doc = "Getter for the `onsinkchange` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/onsinkchange)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioContext`*"]
#[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 onsinkchange(this: &AudioContext) -> Option<::js_sys::Function>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , setter , js_class = "AudioContext" , js_name = onsinkchange)]
#[doc = "Setter for the `onsinkchange` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/onsinkchange)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioContext`*"]
#[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_onsinkchange(this: &AudioContext, value: Option<&::js_sys::Function>);
#[cfg(feature = "AudioDestinationNode")]
# [wasm_bindgen (structural , method , getter , js_class = "AudioContext" , js_name = destination)]
#[doc = "Getter for the `destination` field of this object."]
Expand Down Expand Up @@ -128,6 +161,32 @@ extern "C" {
this: &AudioContext,
media_stream: &MediaStream,
) -> Result<MediaStreamAudioSourceNode, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "AudioContext" , js_name = setSinkId)]
#[doc = "The `setSinkId()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/setSinkId)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioContext`*"]
#[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_sink_id_with_str(this: &AudioContext, sink_id: &str) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "AudioSinkOptions")]
# [wasm_bindgen (method , structural , js_class = "AudioContext" , js_name = setSinkId)]
#[doc = "The `setSinkId()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/setSinkId)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioContext`, `AudioSinkOptions`*"]
#[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_sink_id_with_audio_sink_options(
this: &AudioContext,
sink_id: &AudioSinkOptions,
) -> ::js_sys::Promise;
# [wasm_bindgen (catch , method , structural , js_class = "AudioContext" , js_name = suspend)]
#[doc = "The `suspend()` method."]
#[doc = ""]
Expand Down
13 changes: 13 additions & 0 deletions crates/web-sys/src/features/gen_AudioContextLatencyCategory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[doc = "The `AudioContextLatencyCategory` enum."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioContextLatencyCategory`*"]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AudioContextLatencyCategory {
Balanced = "balanced",
Interactive = "interactive",
Playback = "playback",
}
35 changes: 35 additions & 0 deletions crates/web-sys/src/features/gen_AudioContextOptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ impl AudioContextOptions {
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[doc = "Change the `latencyHint` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioContextOptions`*"]
pub fn latency_hint(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(
self.as_ref(),
&JsValue::from("latencyHint"),
&JsValue::from(val),
);
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[doc = "Change the `sampleRate` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioContextOptions`*"]
Expand All @@ -37,6 +54,24 @@ impl AudioContextOptions {
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `sinkId` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioContextOptions`*"]
#[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 sink_id(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
use wasm_bindgen::JsValue;
let r =
::js_sys::Reflect::set(self.as_ref(), &JsValue::from("sinkId"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
impl Default for AudioContextOptions {
fn default() -> Self {
Expand Down
31 changes: 31 additions & 0 deletions crates/web-sys/src/features/gen_AudioSinkInfo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = AudioSinkInfo , typescript_type = "AudioSinkInfo")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `AudioSinkInfo` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioSinkInfo)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioSinkInfo`*"]
#[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 AudioSinkInfo;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "AudioSinkType")]
# [wasm_bindgen (structural , method , getter , js_class = "AudioSinkInfo" , js_name = type)]
#[doc = "Getter for the `type` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioSinkInfo/type)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioSinkInfo`, `AudioSinkType`*"]
#[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_(this: &AudioSinkInfo) -> AudioSinkType;
}
51 changes: 51 additions & 0 deletions crates/web-sys/src/features/gen_AudioSinkOptions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = AudioSinkOptions)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `AudioSinkOptions` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioSinkOptions`*"]
#[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 AudioSinkOptions;
}
#[cfg(web_sys_unstable_apis)]
impl AudioSinkOptions {
#[cfg(feature = "AudioSinkType")]
#[doc = "Construct a new `AudioSinkOptions`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioSinkOptions`, `AudioSinkType`*"]
#[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(type_: AudioSinkType) -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret.type_(type_);
ret
}
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "AudioSinkType")]
#[doc = "Change the `type` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioSinkOptions`, `AudioSinkType`*"]
#[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: AudioSinkType) -> &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
}
}
15 changes: 15 additions & 0 deletions crates/web-sys/src/features/gen_AudioSinkType.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
#[doc = "The `AudioSinkType` enum."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AudioSinkType`*"]
#[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)*"]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AudioSinkType {
None = "none",
}
24 changes: 24 additions & 0 deletions crates/web-sys/src/features/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ mod gen_AudioContext;
#[cfg(feature = "AudioContext")]
pub use gen_AudioContext::*;

#[cfg(feature = "AudioContextLatencyCategory")]
#[allow(non_snake_case)]
mod gen_AudioContextLatencyCategory;
#[cfg(feature = "AudioContextLatencyCategory")]
pub use gen_AudioContextLatencyCategory::*;

#[cfg(feature = "AudioContextOptions")]
#[allow(non_snake_case)]
mod gen_AudioContextOptions;
Expand Down Expand Up @@ -352,6 +358,24 @@ mod gen_AudioScheduledSourceNode;
#[cfg(feature = "AudioScheduledSourceNode")]
pub use gen_AudioScheduledSourceNode::*;

#[cfg(feature = "AudioSinkInfo")]
#[allow(non_snake_case)]
mod gen_AudioSinkInfo;
#[cfg(feature = "AudioSinkInfo")]
pub use gen_AudioSinkInfo::*;

#[cfg(feature = "AudioSinkOptions")]
#[allow(non_snake_case)]
mod gen_AudioSinkOptions;
#[cfg(feature = "AudioSinkOptions")]
pub use gen_AudioSinkOptions::*;

#[cfg(feature = "AudioSinkType")]
#[allow(non_snake_case)]
mod gen_AudioSinkType;
#[cfg(feature = "AudioSinkType")]
pub use gen_AudioSinkType::*;

#[cfg(feature = "AudioStreamTrack")]
#[allow(non_snake_case)]
mod gen_AudioStreamTrack;
Expand Down
9 changes: 8 additions & 1 deletion crates/web-sys/webidls/enabled/AudioContext.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
* liability, trademark and document use rules apply.
*/

enum AudioContextLatencyCategory {
"balanced",
"interactive",
"playback"
};

dictionary AudioContextOptions {
float sampleRate = 0;
(AudioContextLatencyCategory or double) latencyHint = "interactive";
float sampleRate = 0;
};

[Pref="dom.webaudio.enabled",
Expand Down
18 changes: 18 additions & 0 deletions crates/web-sys/webidls/unstable/AudioContext.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
enum AudioSinkType {
"none"
};

dictionary AudioSinkOptions {
required AudioSinkType type;
};

partial dictionary AudioContextOptions {
(DOMString or AudioSinkOptions) sinkId;
};

partial interface AudioContext {
[SecureContext] readonly attribute (DOMString or AudioSinkInfo) sinkId;

[SecureContext] Promise<undefined> setSinkId ((DOMString or AudioSinkOptions) sinkId);
attribute EventHandler onsinkchange;
};
4 changes: 4 additions & 0 deletions crates/web-sys/webidls/unstable/AudioSinkInfo.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Exposed=Window]
interface AudioSinkInfo {
readonly attribute AudioSinkType type;
};