impl OptionFromWasmAbi and OptionIntoWasmAbi for ImportEnum, enable RTCRtpTransceiver.webidl, add add rtc_rtp_transceiver_direction test

This commit is contained in:
alexlapa 2019-03-14 12:15:02 -06:00
parent e075d0492d
commit 9178231b60
5 changed files with 104 additions and 0 deletions

View File

@ -844,6 +844,18 @@ impl ToTokens for ast::ImportEnum {
}
}
#[allow(clippy::all)]
impl ::wasm_bindgen::convert::OptionIntoWasmAbi for #name {
#[inline]
fn none() -> Self::Abi { Object::none() }
}
#[allow(clippy::all)]
impl ::wasm_bindgen::convert::OptionFromWasmAbi for #name {
#[inline]
fn is_none(abi: &Self::Abi) -> bool { Object::is_none(abi) }
}
#[allow(clippy::all)]
impl From<#name> for ::wasm_bindgen::JsValue {
fn from(obj: #name) -> ::wasm_bindgen::JsValue {

View File

@ -814,6 +814,9 @@ RtcRtpSender = []
RtcRtpSourceEntry = []
RtcRtpSourceEntryType = []
RtcRtpSynchronizationSource = []
RtcRtpTransceiver = []
RtcRtpTransceiverDirection = []
RtcRtpTransceiverInit = []
RtcRtxParameters = []
RtcSdpType = []
RtcSessionDescription = []
@ -826,6 +829,7 @@ RtcStatsReport = []
RtcStatsReportInternal = []
RtcStatsType = []
RtcTrackEvent = []
RtcTrackEventInit = []
RtcTransportStats = []
RtcdtmfSender = []
RtcdtmfToneChangeEvent = []

View File

@ -48,6 +48,7 @@ pub mod pre_element;
pub mod progress_element;
pub mod quote_element;
pub mod response;
pub mod rtc_rtp_transceiver_direction;
pub mod script_element;
pub mod select_element;
pub mod slot_element;

View File

@ -0,0 +1,87 @@
use wasm_bindgen::{prelude::*, JsCast};
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen_test::*;
use futures::Future;
use web_sys::{
RtcPeerConnection, RtcRtpTransceiver, RtcRtpTransceiverDirection, RtcRtpTransceiverInit,
RtcSessionDescriptionInit,
};
#[wasm_bindgen(inline_js = "export function is_unified_avail() { return Object.keys(RTCRtpTransceiver.prototype).indexOf('currentDirection')>-1; }")]
extern "C" {
/// Available in FF since forever, in Chrome since 72, in Safari since 12.1
fn is_unified_avail() -> bool;
}
#[wasm_bindgen_test(async)]
fn rtc_rtp_transceiver_direction() -> impl Future<Item = (), Error = JsValue> {
if !is_unified_avail(){
Ok(())
}
let mut tr_init: RtcRtpTransceiverInit = RtcRtpTransceiverInit::new();
let pc1: RtcPeerConnection = RtcPeerConnection::new().unwrap();
let tr1: RtcRtpTransceiver = pc1.add_transceiver_with_str_and_init(
"audio",
tr_init.direction(RtcRtpTransceiverDirection::Sendonly),
);
assert_eq!(tr1.direction(), RtcRtpTransceiverDirection::Sendonly);
assert_eq!(tr1.current_direction(), None);
let pc2: RtcPeerConnection = RtcPeerConnection::new().unwrap();
exchange_sdps(pc1, pc2).and_then(move |(_, p2)| {
assert_eq!(tr1.direction(), RtcRtpTransceiverDirection::Sendonly);
assert_eq!(
tr1.current_direction(),
Some(RtcRtpTransceiverDirection::Sendonly)
);
let tr2: RtcRtpTransceiver = js_sys::try_iter(&p2.get_transceivers())
.unwrap()
.unwrap()
.next()
.unwrap()
.unwrap()
.unchecked_into();
assert_eq!(tr2.direction(), RtcRtpTransceiverDirection::Recvonly);
assert_eq!(
tr2.current_direction(),
Some(RtcRtpTransceiverDirection::Recvonly)
);
Ok(())
})
}
fn exchange_sdps(
p1: RtcPeerConnection,
p2: RtcPeerConnection,
) -> impl Future<Item = (RtcPeerConnection, RtcPeerConnection), Error = JsValue> {
JsFuture::from(p1.create_offer())
.and_then(move |offer| {
let offer = offer.unchecked_into::<RtcSessionDescriptionInit>();
JsFuture::from(p1.set_local_description(&offer)).join4(
JsFuture::from(p2.set_remote_description(&offer)),
Ok(p1),
Ok(p2),
)
})
.and_then(|(_, _, p1, p2)| JsFuture::from(p2.create_answer()).join3(Ok(p1), Ok(p2)))
.and_then(|(answer, p1, p2)| {
let answer = answer.unchecked_into::<RtcSessionDescriptionInit>();
JsFuture::from(p2.set_local_description(&answer)).join4(
JsFuture::from(p1.set_remote_description(&answer)),
Ok(p1),
Ok(p2),
)
})
.and_then(|(_, _, p1, p2)| Ok((p1, p2)))
}