Skip to content

Commit 9178231

Browse files
committed
impl OptionFromWasmAbi and OptionIntoWasmAbi for ImportEnum, enable RTCRtpTransceiver.webidl, add add rtc_rtp_transceiver_direction test
1 parent e075d04 commit 9178231

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

crates/backend/src/codegen.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,18 @@ impl ToTokens for ast::ImportEnum {
844844
}
845845
}
846846

847+
#[allow(clippy::all)]
848+
impl ::wasm_bindgen::convert::OptionIntoWasmAbi for #name {
849+
#[inline]
850+
fn none() -> Self::Abi { Object::none() }
851+
}
852+
853+
#[allow(clippy::all)]
854+
impl ::wasm_bindgen::convert::OptionFromWasmAbi for #name {
855+
#[inline]
856+
fn is_none(abi: &Self::Abi) -> bool { Object::is_none(abi) }
857+
}
858+
847859
#[allow(clippy::all)]
848860
impl From<#name> for ::wasm_bindgen::JsValue {
849861
fn from(obj: #name) -> ::wasm_bindgen::JsValue {

crates/web-sys/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,9 @@ RtcRtpSender = []
814814
RtcRtpSourceEntry = []
815815
RtcRtpSourceEntryType = []
816816
RtcRtpSynchronizationSource = []
817+
RtcRtpTransceiver = []
818+
RtcRtpTransceiverDirection = []
819+
RtcRtpTransceiverInit = []
817820
RtcRtxParameters = []
818821
RtcSdpType = []
819822
RtcSessionDescription = []
@@ -826,6 +829,7 @@ RtcStatsReport = []
826829
RtcStatsReportInternal = []
827830
RtcStatsType = []
828831
RtcTrackEvent = []
832+
RtcTrackEventInit = []
829833
RtcTransportStats = []
830834
RtcdtmfSender = []
831835
RtcdtmfToneChangeEvent = []

crates/web-sys/tests/wasm/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub mod pre_element;
4848
pub mod progress_element;
4949
pub mod quote_element;
5050
pub mod response;
51+
pub mod rtc_rtp_transceiver_direction;
5152
pub mod script_element;
5253
pub mod select_element;
5354
pub mod slot_element;
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
use wasm_bindgen::{prelude::*, JsCast};
2+
use wasm_bindgen_futures::JsFuture;
3+
use wasm_bindgen_test::*;
4+
5+
use futures::Future;
6+
7+
use web_sys::{
8+
RtcPeerConnection, RtcRtpTransceiver, RtcRtpTransceiverDirection, RtcRtpTransceiverInit,
9+
RtcSessionDescriptionInit,
10+
};
11+
12+
13+
#[wasm_bindgen(inline_js = "export function is_unified_avail() { return Object.keys(RTCRtpTransceiver.prototype).indexOf('currentDirection')>-1; }")]
14+
extern "C" {
15+
/// Available in FF since forever, in Chrome since 72, in Safari since 12.1
16+
fn is_unified_avail() -> bool;
17+
}
18+
19+
#[wasm_bindgen_test(async)]
20+
fn rtc_rtp_transceiver_direction() -> impl Future<Item = (), Error = JsValue> {
21+
22+
if !is_unified_avail(){
23+
Ok(())
24+
}
25+
26+
let mut tr_init: RtcRtpTransceiverInit = RtcRtpTransceiverInit::new();
27+
28+
let pc1: RtcPeerConnection = RtcPeerConnection::new().unwrap();
29+
30+
let tr1: RtcRtpTransceiver = pc1.add_transceiver_with_str_and_init(
31+
"audio",
32+
tr_init.direction(RtcRtpTransceiverDirection::Sendonly),
33+
);
34+
assert_eq!(tr1.direction(), RtcRtpTransceiverDirection::Sendonly);
35+
assert_eq!(tr1.current_direction(), None);
36+
37+
let pc2: RtcPeerConnection = RtcPeerConnection::new().unwrap();
38+
39+
exchange_sdps(pc1, pc2).and_then(move |(_, p2)| {
40+
assert_eq!(tr1.direction(), RtcRtpTransceiverDirection::Sendonly);
41+
assert_eq!(
42+
tr1.current_direction(),
43+
Some(RtcRtpTransceiverDirection::Sendonly)
44+
);
45+
46+
let tr2: RtcRtpTransceiver = js_sys::try_iter(&p2.get_transceivers())
47+
.unwrap()
48+
.unwrap()
49+
.next()
50+
.unwrap()
51+
.unwrap()
52+
.unchecked_into();
53+
54+
assert_eq!(tr2.direction(), RtcRtpTransceiverDirection::Recvonly);
55+
assert_eq!(
56+
tr2.current_direction(),
57+
Some(RtcRtpTransceiverDirection::Recvonly)
58+
);
59+
60+
Ok(())
61+
})
62+
}
63+
64+
fn exchange_sdps(
65+
p1: RtcPeerConnection,
66+
p2: RtcPeerConnection,
67+
) -> impl Future<Item = (RtcPeerConnection, RtcPeerConnection), Error = JsValue> {
68+
JsFuture::from(p1.create_offer())
69+
.and_then(move |offer| {
70+
let offer = offer.unchecked_into::<RtcSessionDescriptionInit>();
71+
JsFuture::from(p1.set_local_description(&offer)).join4(
72+
JsFuture::from(p2.set_remote_description(&offer)),
73+
Ok(p1),
74+
Ok(p2),
75+
)
76+
})
77+
.and_then(|(_, _, p1, p2)| JsFuture::from(p2.create_answer()).join3(Ok(p1), Ok(p2)))
78+
.and_then(|(answer, p1, p2)| {
79+
let answer = answer.unchecked_into::<RtcSessionDescriptionInit>();
80+
JsFuture::from(p2.set_local_description(&answer)).join4(
81+
JsFuture::from(p1.set_remote_description(&answer)),
82+
Ok(p1),
83+
Ok(p2),
84+
)
85+
})
86+
.and_then(|(_, _, p1, p2)| Ok((p1, p2)))
87+
}

0 commit comments

Comments
 (0)