Skip to content

Commit a5d2539

Browse files
authored
Implement RTCRtpSender.getCapabilities method (#3737)
1 parent cfe3dc2 commit a5d2539

8 files changed

+238
-0
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
### Added
77

8+
* Add bindings for `RTCRtpSender.getCapabilities(DOMString)` method, `RTCRtpCapabilities`, `RTCRtpCodecCapability` and `RTCRtpHeaderExtensionCapability`.
9+
[#3737](https://github.com/rustwasm/wasm-bindgen/pull/3737)
10+
811
* Add bindings for `UserActivation`.
912
[#3719](https://github.com/rustwasm/wasm-bindgen/pull/3719)
1013

crates/web-sys/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,12 @@ RtcPeerConnectionIceEventInit = []
10971097
RtcPeerConnectionState = []
10981098
RtcPriorityType = []
10991099
RtcRtcpParameters = []
1100+
RtcRtpCapabilities = []
1101+
RtcRtpCodecCapability = []
11001102
RtcRtpCodecParameters = []
11011103
RtcRtpContributingSource = []
11021104
RtcRtpEncodingParameters = []
1105+
RtcRtpHeaderExtensionCapability = []
11031106
RtcRtpHeaderExtensionParameters = []
11041107
RtcRtpParameters = []
11051108
RtcRtpReceiver = []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#![allow(unused_imports)]
2+
#![allow(clippy::all)]
3+
use super::*;
4+
use wasm_bindgen::prelude::*;
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = RTCRtpCapabilities)]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `RtcRtpCapabilities` dictionary."]
10+
#[doc = ""]
11+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCapabilities`*"]
12+
pub type RtcRtpCapabilities;
13+
}
14+
impl RtcRtpCapabilities {
15+
#[doc = "Construct a new `RtcRtpCapabilities`."]
16+
#[doc = ""]
17+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCapabilities`*"]
18+
pub fn new(
19+
codecs: &::wasm_bindgen::JsValue,
20+
header_extensions: &::wasm_bindgen::JsValue,
21+
) -> Self {
22+
#[allow(unused_mut)]
23+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
24+
ret.codecs(codecs);
25+
ret.header_extensions(header_extensions);
26+
ret
27+
}
28+
#[doc = "Change the `codecs` field of this object."]
29+
#[doc = ""]
30+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCapabilities`*"]
31+
pub fn codecs(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
32+
use wasm_bindgen::JsValue;
33+
let r =
34+
::js_sys::Reflect::set(self.as_ref(), &JsValue::from("codecs"), &JsValue::from(val));
35+
debug_assert!(
36+
r.is_ok(),
37+
"setting properties should never fail on our dictionary objects"
38+
);
39+
let _ = r;
40+
self
41+
}
42+
#[doc = "Change the `headerExtensions` field of this object."]
43+
#[doc = ""]
44+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCapabilities`*"]
45+
pub fn header_extensions(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
46+
use wasm_bindgen::JsValue;
47+
let r = ::js_sys::Reflect::set(
48+
self.as_ref(),
49+
&JsValue::from("headerExtensions"),
50+
&JsValue::from(val),
51+
);
52+
debug_assert!(
53+
r.is_ok(),
54+
"setting properties should never fail on our dictionary objects"
55+
);
56+
let _ = r;
57+
self
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#![allow(unused_imports)]
2+
#![allow(clippy::all)]
3+
use super::*;
4+
use wasm_bindgen::prelude::*;
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = RTCRtpCodecCapability)]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `RtcRtpCodecCapability` dictionary."]
10+
#[doc = ""]
11+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"]
12+
pub type RtcRtpCodecCapability;
13+
}
14+
impl RtcRtpCodecCapability {
15+
#[doc = "Construct a new `RtcRtpCodecCapability`."]
16+
#[doc = ""]
17+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"]
18+
pub fn new(clock_rate: u32, mime_type: &str) -> Self {
19+
#[allow(unused_mut)]
20+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
21+
ret.clock_rate(clock_rate);
22+
ret.mime_type(mime_type);
23+
ret
24+
}
25+
#[doc = "Change the `channels` field of this object."]
26+
#[doc = ""]
27+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"]
28+
pub fn channels(&mut self, val: u16) -> &mut Self {
29+
use wasm_bindgen::JsValue;
30+
let r = ::js_sys::Reflect::set(
31+
self.as_ref(),
32+
&JsValue::from("channels"),
33+
&JsValue::from(val),
34+
);
35+
debug_assert!(
36+
r.is_ok(),
37+
"setting properties should never fail on our dictionary objects"
38+
);
39+
let _ = r;
40+
self
41+
}
42+
#[doc = "Change the `clockRate` field of this object."]
43+
#[doc = ""]
44+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"]
45+
pub fn clock_rate(&mut self, val: u32) -> &mut Self {
46+
use wasm_bindgen::JsValue;
47+
let r = ::js_sys::Reflect::set(
48+
self.as_ref(),
49+
&JsValue::from("clockRate"),
50+
&JsValue::from(val),
51+
);
52+
debug_assert!(
53+
r.is_ok(),
54+
"setting properties should never fail on our dictionary objects"
55+
);
56+
let _ = r;
57+
self
58+
}
59+
#[doc = "Change the `mimeType` field of this object."]
60+
#[doc = ""]
61+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"]
62+
pub fn mime_type(&mut self, val: &str) -> &mut Self {
63+
use wasm_bindgen::JsValue;
64+
let r = ::js_sys::Reflect::set(
65+
self.as_ref(),
66+
&JsValue::from("mimeType"),
67+
&JsValue::from(val),
68+
);
69+
debug_assert!(
70+
r.is_ok(),
71+
"setting properties should never fail on our dictionary objects"
72+
);
73+
let _ = r;
74+
self
75+
}
76+
#[doc = "Change the `sdpFmtpLine` field of this object."]
77+
#[doc = ""]
78+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCodecCapability`*"]
79+
pub fn sdp_fmtp_line(&mut self, val: &str) -> &mut Self {
80+
use wasm_bindgen::JsValue;
81+
let r = ::js_sys::Reflect::set(
82+
self.as_ref(),
83+
&JsValue::from("sdpFmtpLine"),
84+
&JsValue::from(val),
85+
);
86+
debug_assert!(
87+
r.is_ok(),
88+
"setting properties should never fail on our dictionary objects"
89+
);
90+
let _ = r;
91+
self
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![allow(unused_imports)]
2+
#![allow(clippy::all)]
3+
use super::*;
4+
use wasm_bindgen::prelude::*;
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = RTCRtpHeaderExtensionCapability)]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `RtcRtpHeaderExtensionCapability` dictionary."]
10+
#[doc = ""]
11+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpHeaderExtensionCapability`*"]
12+
pub type RtcRtpHeaderExtensionCapability;
13+
}
14+
impl RtcRtpHeaderExtensionCapability {
15+
#[doc = "Construct a new `RtcRtpHeaderExtensionCapability`."]
16+
#[doc = ""]
17+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpHeaderExtensionCapability`*"]
18+
pub fn new(uri: &str) -> Self {
19+
#[allow(unused_mut)]
20+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
21+
ret.uri(uri);
22+
ret
23+
}
24+
#[doc = "Change the `uri` field of this object."]
25+
#[doc = ""]
26+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpHeaderExtensionCapability`*"]
27+
pub fn uri(&mut self, val: &str) -> &mut Self {
28+
use wasm_bindgen::JsValue;
29+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("uri"), &JsValue::from(val));
30+
debug_assert!(
31+
r.is_ok(),
32+
"setting properties should never fail on our dictionary objects"
33+
);
34+
let _ = r;
35+
self
36+
}
37+
}

crates/web-sys/src/features/gen_RtcRtpSender.rs

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ extern "C" {
2828
#[doc = ""]
2929
#[doc = "*This API requires the following crate features to be activated: `RtcRtpSender`, `RtcdtmfSender`*"]
3030
pub fn dtmf(this: &RtcRtpSender) -> Option<RtcdtmfSender>;
31+
#[cfg(feature = "RtcRtpCapabilities")]
32+
# [wasm_bindgen (static_method_of = RtcRtpSender , js_class = "RTCRtpSender" , js_name = getCapabilities)]
33+
#[doc = "The `getCapabilities()` method."]
34+
#[doc = ""]
35+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/getCapabilities)"]
36+
#[doc = ""]
37+
#[doc = "*This API requires the following crate features to be activated: `RtcRtpCapabilities`, `RtcRtpSender`*"]
38+
pub fn get_capabilities(kind: &str) -> Option<RtcRtpCapabilities>;
3139
#[cfg(feature = "RtcRtpParameters")]
3240
# [wasm_bindgen (method , structural , js_class = "RTCRtpSender" , js_name = getParameters)]
3341
#[doc = "The `getParameters()` method."]

crates/web-sys/src/features/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -6394,6 +6394,18 @@ mod gen_RtcRtcpParameters;
63946394
#[cfg(feature = "RtcRtcpParameters")]
63956395
pub use gen_RtcRtcpParameters::*;
63966396

6397+
#[cfg(feature = "RtcRtpCapabilities")]
6398+
#[allow(non_snake_case)]
6399+
mod gen_RtcRtpCapabilities;
6400+
#[cfg(feature = "RtcRtpCapabilities")]
6401+
pub use gen_RtcRtpCapabilities::*;
6402+
6403+
#[cfg(feature = "RtcRtpCodecCapability")]
6404+
#[allow(non_snake_case)]
6405+
mod gen_RtcRtpCodecCapability;
6406+
#[cfg(feature = "RtcRtpCodecCapability")]
6407+
pub use gen_RtcRtpCodecCapability::*;
6408+
63976409
#[cfg(feature = "RtcRtpCodecParameters")]
63986410
#[allow(non_snake_case)]
63996411
mod gen_RtcRtpCodecParameters;
@@ -6412,6 +6424,12 @@ mod gen_RtcRtpEncodingParameters;
64126424
#[cfg(feature = "RtcRtpEncodingParameters")]
64136425
pub use gen_RtcRtpEncodingParameters::*;
64146426

6427+
#[cfg(feature = "RtcRtpHeaderExtensionCapability")]
6428+
#[allow(non_snake_case)]
6429+
mod gen_RtcRtpHeaderExtensionCapability;
6430+
#[cfg(feature = "RtcRtpHeaderExtensionCapability")]
6431+
pub use gen_RtcRtpHeaderExtensionCapability::*;
6432+
64156433
#[cfg(feature = "RtcRtpHeaderExtensionParameters")]
64166434
#[allow(non_snake_case)]
64176435
mod gen_RtcRtpHeaderExtensionParameters;

crates/web-sys/webidls/enabled/RTCRtpSender.webidl

+17
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ dictionary RTCRtpParameters {
6666
sequence<RTCRtpCodecParameters> codecs;
6767
};
6868

69+
dictionary RTCRtpCodecCapability {
70+
required DOMString mimeType;
71+
required unsigned long clockRate;
72+
unsigned short channels;
73+
DOMString sdpFmtpLine;
74+
};
75+
76+
dictionary RTCRtpHeaderExtensionCapability {
77+
required DOMString uri;
78+
};
79+
80+
dictionary RTCRtpCapabilities {
81+
required sequence<RTCRtpCodecCapability> codecs;
82+
required sequence<RTCRtpHeaderExtensionCapability> headerExtensions;
83+
};
84+
6985
[Pref="media.peerconnection.enabled",
7086
JSImplementation="@mozilla.org/dom/rtpsender;1"]
7187
interface RTCRtpSender {
@@ -74,6 +90,7 @@ interface RTCRtpSender {
7490
RTCRtpParameters getParameters();
7591
Promise<undefined> replaceTrack(MediaStreamTrack? withTrack);
7692
Promise<RTCStatsReport> getStats();
93+
static RTCRtpCapabilities? getCapabilities(DOMString kind);
7794
[Pref="media.peerconnection.dtmf.enabled"]
7895
readonly attribute RTCDTMFSender? dtmf;
7996
// Ugh, can't use a ChromeOnly attribute sequence<MediaStream>...

0 commit comments

Comments
 (0)