Fill in some of RTCPeerConnection, add signaller

This commit is contained in:
Manish Goregaokar 2019-01-26 11:11:40 -08:00
parent cc4fb3918d
commit e0d8de2714
3 changed files with 113 additions and 14 deletions

View file

@ -101,6 +101,7 @@ use servo_media::audio::graph::NodeId;
use servo_media::audio::panner_node::{DistanceModel, PanningModel}; use servo_media::audio::panner_node::{DistanceModel, PanningModel};
use servo_media::audio::param::ParamType; use servo_media::audio::param::ParamType;
use servo_media::player::Player; use servo_media::player::Player;
use servo_media::webrtc::WebRtcController;
use servo_media::Backend; use servo_media::Backend;
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl}; use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use smallvec::SmallVec; use smallvec::SmallVec;
@ -483,6 +484,7 @@ unsafe_no_jsmanaged_fields!(AudioContext<Backend>);
unsafe_no_jsmanaged_fields!(NodeId); unsafe_no_jsmanaged_fields!(NodeId);
unsafe_no_jsmanaged_fields!(AnalysisEngine, DistanceModel, PanningModel, ParamType); unsafe_no_jsmanaged_fields!(AnalysisEngine, DistanceModel, PanningModel, ParamType);
unsafe_no_jsmanaged_fields!(dyn Player); unsafe_no_jsmanaged_fields!(dyn Player);
unsafe_no_jsmanaged_fields!(WebRtcController);
unsafe_no_jsmanaged_fields!(Mutex<MediaFrameRenderer>); unsafe_no_jsmanaged_fields!(Mutex<MediaFrameRenderer>);
unsafe_no_jsmanaged_fields!(RenderApiSender); unsafe_no_jsmanaged_fields!(RenderApiSender);
unsafe_no_jsmanaged_fields!(ResourceFetchTiming); unsafe_no_jsmanaged_fields!(ResourceFetchTiming);

View file

@ -2,8 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::RTCIceCandidateBinding::{self, RTCIceCandidateMethods};
use crate::dom::bindings::codegen::Bindings::RTCIceCandidateBinding::RTCIceCandidateInit; use crate::dom::bindings::codegen::Bindings::RTCIceCandidateBinding::RTCIceCandidateInit;
use crate::dom::bindings::codegen::Bindings::RTCIceCandidateBinding::{
self, RTCIceCandidateMethods,
};
use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::reflect_dom_object; use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::{DomObject, Reflector}; use crate::dom::bindings::reflector::{DomObject, Reflector};
@ -23,18 +25,35 @@ pub struct RTCIceCandidate {
} }
impl RTCIceCandidate { impl RTCIceCandidate {
pub fn new_inherited(candidate: DOMString, sdp_m_id: Option<DOMString>, pub fn new_inherited(
sdp_m_line_index: Option<u16>, username_fragment: Option<DOMString>) -> RTCIceCandidate { candidate: DOMString,
sdp_m_id: Option<DOMString>,
sdp_m_line_index: Option<u16>,
username_fragment: Option<DOMString>,
) -> RTCIceCandidate {
RTCIceCandidate { RTCIceCandidate {
reflector: Reflector::new(), reflector: Reflector::new(),
candidate, sdp_m_id, sdp_m_line_index, username_fragment candidate,
sdp_m_id,
sdp_m_line_index,
username_fragment,
} }
} }
pub fn new(global: &GlobalScope, candidate: DOMString, sdp_m_id: Option<DOMString>, pub fn new(
sdp_m_line_index: Option<u16>, username_fragment: Option<DOMString>) -> DomRoot<RTCIceCandidate> { global: &GlobalScope,
candidate: DOMString,
sdp_m_id: Option<DOMString>,
sdp_m_line_index: Option<u16>,
username_fragment: Option<DOMString>,
) -> DomRoot<RTCIceCandidate> {
reflect_dom_object( reflect_dom_object(
Box::new(RTCIceCandidate::new_inherited(candidate, sdp_m_id, sdp_m_line_index, username_fragment)), Box::new(RTCIceCandidate::new_inherited(
candidate,
sdp_m_id,
sdp_m_line_index,
username_fragment,
)),
global, global,
RTCIceCandidateBinding::Wrap, RTCIceCandidateBinding::Wrap,
) )
@ -45,15 +64,20 @@ impl RTCIceCandidate {
config: &RTCIceCandidateInit, config: &RTCIceCandidateInit,
) -> Fallible<DomRoot<RTCIceCandidate>> { ) -> Fallible<DomRoot<RTCIceCandidate>> {
if config.sdpMid.is_none() && config.sdpMLineIndex.is_none() { if config.sdpMid.is_none() && config.sdpMLineIndex.is_none() {
return Err(Error::Type(format!("one of sdpMid and sdpMLineIndex must be set"))); return Err(Error::Type(format!(
"one of sdpMid and sdpMLineIndex must be set"
)));
} }
Ok(RTCIceCandidate::new(&window.global(), config.candidate.clone(), Ok(RTCIceCandidate::new(
config.sdpMid.clone(), config.sdpMLineIndex, &window.global(),
config.usernameFragment.clone())) config.candidate.clone(),
config.sdpMid.clone(),
config.sdpMLineIndex,
config.usernameFragment.clone(),
))
} }
} }
impl RTCIceCandidateMethods for RTCIceCandidate { impl RTCIceCandidateMethods for RTCIceCandidate {
/// https://www.w3.org/TR/webrtc/#dom-rtcicecandidate-candidate /// https://www.w3.org/TR/webrtc/#dom-rtcicecandidate-candidate
fn Candidate(&self) -> DOMString { fn Candidate(&self) -> DOMString {

View file

@ -2,35 +2,86 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding; use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding;
use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::RTCConfiguration; use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::RTCConfiguration;
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::refcounted::Trusted;
use crate::dom::bindings::reflector::reflect_dom_object; use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::DomObject; use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::eventtarget::EventTarget; use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::task::TaskCanceller;
use crate::task_source::networking::NetworkingTaskSource;
use crate::task_source::TaskSource;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use servo_media::webrtc::MediaStream as BackendMediaStream;
use servo_media::webrtc::{IceCandidate, WebRtcController, WebRtcSignaller};
use servo_media::ServoMedia;
#[dom_struct] #[dom_struct]
pub struct RTCPeerConnection { pub struct RTCPeerConnection {
eventtarget: EventTarget, eventtarget: EventTarget,
#[ignore_malloc_size_of = "defined in servo-media"]
controller: DomRefCell<Option<WebRtcController>>,
}
struct RTCSignaller {
trusted: Trusted<RTCPeerConnection>,
task_source: NetworkingTaskSource,
canceller: TaskCanceller,
}
impl WebRtcSignaller for RTCSignaller {
fn on_ice_candidate(&self, _: &WebRtcController, candidate: IceCandidate) {
let this = self.trusted.clone();
let _ = self.task_source.queue_with_canceller(
task!(on_ice_candidate: move || {
let this = this.root();
this.on_ice_candidate(candidate);
}),
&self.canceller,
);
}
fn on_negotiation_needed(&self, _: &WebRtcController) {
let this = self.trusted.clone();
let _ = self.task_source.queue_with_canceller(
task!(on_negotiation_needed: move || {
let this = this.root();
this.on_negotiation_needed();
}),
&self.canceller,
);
}
fn on_add_stream(&self, _: Box<BackendMediaStream>) {}
fn close(&self) {
// do nothing
}
} }
impl RTCPeerConnection { impl RTCPeerConnection {
pub fn new_inherited() -> RTCPeerConnection { pub fn new_inherited() -> RTCPeerConnection {
RTCPeerConnection { RTCPeerConnection {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
controller: DomRefCell::new(None),
} }
} }
pub fn new(global: &GlobalScope) -> DomRoot<RTCPeerConnection> { pub fn new(global: &GlobalScope) -> DomRoot<RTCPeerConnection> {
reflect_dom_object( let this = reflect_dom_object(
Box::new(RTCPeerConnection::new_inherited()), Box::new(RTCPeerConnection::new_inherited()),
global, global,
RTCPeerConnectionBinding::Wrap, RTCPeerConnectionBinding::Wrap,
) );
let signaller = this.make_signaller();
*this.controller.borrow_mut() = Some(ServoMedia::get().unwrap().create_webrtc(signaller));
this
} }
pub fn Constructor( pub fn Constructor(
@ -39,4 +90,26 @@ impl RTCPeerConnection {
) -> Fallible<DomRoot<RTCPeerConnection>> { ) -> Fallible<DomRoot<RTCPeerConnection>> {
Ok(RTCPeerConnection::new(&window.global())) Ok(RTCPeerConnection::new(&window.global()))
} }
fn make_signaller(&self) -> Box<WebRtcSignaller> {
let trusted = Trusted::new(self);
let (task_source, canceller) = self
.global()
.as_window()
.task_manager()
.networking_task_source_with_canceller();
Box::new(RTCSignaller {
trusted,
task_source,
canceller,
})
}
fn on_ice_candidate(&self, _candidate: IceCandidate) {
// todo
}
fn on_negotiation_needed(&self) {
// todo
}
} }