From a5d2539314e0392c87a4d3203e99cf4888050fc0 Mon Sep 17 00:00:00 2001 From: logist322 <53333039+logist322@users.noreply.github.com> Date: Fri, 8 Dec 2023 23:49:42 +0100 Subject: [PATCH] Implement `RTCRtpSender.getCapabilities` method (#3737) --- CHANGELOG.md | 3 + crates/web-sys/Cargo.toml | 3 + .../src/features/gen_RtcRtpCapabilities.rs | 59 ++++++++++++ .../src/features/gen_RtcRtpCodecCapability.rs | 93 +++++++++++++++++++ .../gen_RtcRtpHeaderExtensionCapability.rs | 37 ++++++++ .../web-sys/src/features/gen_RtcRtpSender.rs | 8 ++ crates/web-sys/src/features/mod.rs | 18 ++++ .../webidls/enabled/RTCRtpSender.webidl | 17 ++++ 8 files changed, 238 insertions(+) create mode 100644 crates/web-sys/src/features/gen_RtcRtpCapabilities.rs create mode 100644 crates/web-sys/src/features/gen_RtcRtpCodecCapability.rs create mode 100644 crates/web-sys/src/features/gen_RtcRtpHeaderExtensionCapability.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a246ee6f2f..f83e91261fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Added +* Add bindings for `RTCRtpSender.getCapabilities(DOMString)` method, `RTCRtpCapabilities`, `RTCRtpCodecCapability` and `RTCRtpHeaderExtensionCapability`. + [#3737](https://github.com/rustwasm/wasm-bindgen/pull/3737) + * Add bindings for `UserActivation`. [#3719](https://github.com/rustwasm/wasm-bindgen/pull/3719) diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index baa3d3529c6..3879e8b7255 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -1097,9 +1097,12 @@ RtcPeerConnectionIceEventInit = [] RtcPeerConnectionState = [] RtcPriorityType = [] RtcRtcpParameters = [] +RtcRtpCapabilities = [] +RtcRtpCodecCapability = [] RtcRtpCodecParameters = [] RtcRtpContributingSource = [] RtcRtpEncodingParameters = [] +RtcRtpHeaderExtensionCapability = [] RtcRtpHeaderExtensionParameters = [] RtcRtpParameters = [] RtcRtpReceiver = [] diff --git a/crates/web-sys/src/features/gen_RtcRtpCapabilities.rs b/crates/web-sys/src/features/gen_RtcRtpCapabilities.rs new file mode 100644 index 00000000000..872d90d0bd6 --- /dev/null +++ b/crates/web-sys/src/features/gen_RtcRtpCapabilities.rs @@ -0,0 +1,59 @@ +#![allow(unused_imports)] +#![allow(clippy::all)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = RTCRtpCapabilities)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `RtcRtpCapabilities` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCapabilities`*"] + pub type RtcRtpCapabilities; +} +impl RtcRtpCapabilities { + #[doc = "Construct a new `RtcRtpCapabilities`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCapabilities`*"] + pub fn new( + codecs: &::wasm_bindgen::JsValue, + header_extensions: &::wasm_bindgen::JsValue, + ) -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret.codecs(codecs); + ret.header_extensions(header_extensions); + ret + } + #[doc = "Change the `codecs` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCapabilities`*"] + pub fn codecs(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { + use wasm_bindgen::JsValue; + let r = + ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("codecs"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `headerExtensions` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCapabilities`*"] + pub fn header_extensions(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("headerExtensions"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } +} diff --git a/crates/web-sys/src/features/gen_RtcRtpCodecCapability.rs b/crates/web-sys/src/features/gen_RtcRtpCodecCapability.rs new file mode 100644 index 00000000000..1b8730d70b9 --- /dev/null +++ b/crates/web-sys/src/features/gen_RtcRtpCodecCapability.rs @@ -0,0 +1,93 @@ +#![allow(unused_imports)] +#![allow(clippy::all)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = RTCRtpCodecCapability)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `RtcRtpCodecCapability` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"] + pub type RtcRtpCodecCapability; +} +impl RtcRtpCodecCapability { + #[doc = "Construct a new `RtcRtpCodecCapability`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"] + pub fn new(clock_rate: u32, mime_type: &str) -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret.clock_rate(clock_rate); + ret.mime_type(mime_type); + ret + } + #[doc = "Change the `channels` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"] + pub fn channels(&mut self, val: u16) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("channels"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `clockRate` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"] + pub fn clock_rate(&mut self, val: u32) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("clockRate"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `mimeType` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"] + pub fn mime_type(&mut self, val: &str) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("mimeType"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `sdpFmtpLine` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"] + pub fn sdp_fmtp_line(&mut self, val: &str) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("sdpFmtpLine"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } +} diff --git a/crates/web-sys/src/features/gen_RtcRtpHeaderExtensionCapability.rs b/crates/web-sys/src/features/gen_RtcRtpHeaderExtensionCapability.rs new file mode 100644 index 00000000000..de9ec55990f --- /dev/null +++ b/crates/web-sys/src/features/gen_RtcRtpHeaderExtensionCapability.rs @@ -0,0 +1,37 @@ +#![allow(unused_imports)] +#![allow(clippy::all)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = RTCRtpHeaderExtensionCapability)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `RtcRtpHeaderExtensionCapability` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpHeaderExtensionCapability`*"] + pub type RtcRtpHeaderExtensionCapability; +} +impl RtcRtpHeaderExtensionCapability { + #[doc = "Construct a new `RtcRtpHeaderExtensionCapability`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpHeaderExtensionCapability`*"] + pub fn new(uri: &str) -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret.uri(uri); + ret + } + #[doc = "Change the `uri` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpHeaderExtensionCapability`*"] + pub fn uri(&mut self, val: &str) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("uri"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } +} diff --git a/crates/web-sys/src/features/gen_RtcRtpSender.rs b/crates/web-sys/src/features/gen_RtcRtpSender.rs index 714521c0d3e..8cdd9d5d66b 100644 --- a/crates/web-sys/src/features/gen_RtcRtpSender.rs +++ b/crates/web-sys/src/features/gen_RtcRtpSender.rs @@ -28,6 +28,14 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `RtcRtpSender`, `RtcdtmfSender`*"] pub fn dtmf(this: &RtcRtpSender) -> Option; + #[cfg(feature = "RtcRtpCapabilities")] + # [wasm_bindgen (static_method_of = RtcRtpSender , js_class = "RTCRtpSender" , js_name = getCapabilities)] + #[doc = "The `getCapabilities()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/getCapabilities)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `RtcRtpCapabilities`, `RtcRtpSender`*"] + pub fn get_capabilities(kind: &str) -> Option; #[cfg(feature = "RtcRtpParameters")] # [wasm_bindgen (method , structural , js_class = "RTCRtpSender" , js_name = getParameters)] #[doc = "The `getParameters()` method."] diff --git a/crates/web-sys/src/features/mod.rs b/crates/web-sys/src/features/mod.rs index 8333053be51..93d5a0a8aa9 100644 --- a/crates/web-sys/src/features/mod.rs +++ b/crates/web-sys/src/features/mod.rs @@ -6394,6 +6394,18 @@ mod gen_RtcRtcpParameters; #[cfg(feature = "RtcRtcpParameters")] pub use gen_RtcRtcpParameters::*; +#[cfg(feature = "RtcRtpCapabilities")] +#[allow(non_snake_case)] +mod gen_RtcRtpCapabilities; +#[cfg(feature = "RtcRtpCapabilities")] +pub use gen_RtcRtpCapabilities::*; + +#[cfg(feature = "RtcRtpCodecCapability")] +#[allow(non_snake_case)] +mod gen_RtcRtpCodecCapability; +#[cfg(feature = "RtcRtpCodecCapability")] +pub use gen_RtcRtpCodecCapability::*; + #[cfg(feature = "RtcRtpCodecParameters")] #[allow(non_snake_case)] mod gen_RtcRtpCodecParameters; @@ -6412,6 +6424,12 @@ mod gen_RtcRtpEncodingParameters; #[cfg(feature = "RtcRtpEncodingParameters")] pub use gen_RtcRtpEncodingParameters::*; +#[cfg(feature = "RtcRtpHeaderExtensionCapability")] +#[allow(non_snake_case)] +mod gen_RtcRtpHeaderExtensionCapability; +#[cfg(feature = "RtcRtpHeaderExtensionCapability")] +pub use gen_RtcRtpHeaderExtensionCapability::*; + #[cfg(feature = "RtcRtpHeaderExtensionParameters")] #[allow(non_snake_case)] mod gen_RtcRtpHeaderExtensionParameters; diff --git a/crates/web-sys/webidls/enabled/RTCRtpSender.webidl b/crates/web-sys/webidls/enabled/RTCRtpSender.webidl index 3b1c49c7bc2..fffb4ca175a 100644 --- a/crates/web-sys/webidls/enabled/RTCRtpSender.webidl +++ b/crates/web-sys/webidls/enabled/RTCRtpSender.webidl @@ -66,6 +66,22 @@ dictionary RTCRtpParameters { sequence codecs; }; +dictionary RTCRtpCodecCapability { + required DOMString mimeType; + required unsigned long clockRate; + unsigned short channels; + DOMString sdpFmtpLine; +}; + +dictionary RTCRtpHeaderExtensionCapability { + required DOMString uri; +}; + +dictionary RTCRtpCapabilities { + required sequence codecs; + required sequence headerExtensions; +}; + [Pref="media.peerconnection.enabled", JSImplementation="@mozilla.org/dom/rtpsender;1"] interface RTCRtpSender { @@ -74,6 +90,7 @@ interface RTCRtpSender { RTCRtpParameters getParameters(); Promise replaceTrack(MediaStreamTrack? withTrack); Promise getStats(); + static RTCRtpCapabilities? getCapabilities(DOMString kind); [Pref="media.peerconnection.dtmf.enabled"] readonly attribute RTCDTMFSender? dtmf; // Ugh, can't use a ChromeOnly attribute sequence...