Configure STUN servers

This commit is contained in:
Manish Goregaokar 2019-01-28 19:35:50 -08:00
parent 2d8ac7825c
commit 7761243100

View file

@ -7,11 +7,12 @@ use crate::dom::bindings::codegen::Bindings::RTCIceCandidateBinding::RTCIceCandi
use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding; use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding;
use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::RTCPeerConnectionMethods; use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::RTCPeerConnectionMethods;
use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::{ use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::{
RTCAnswerOptions, RTCConfiguration, RTCOfferOptions, RTCAnswerOptions, RTCBundlePolicy, RTCConfiguration, RTCOfferOptions,
}; };
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{ use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
RTCSdpType, RTCSessionDescriptionInit, RTCSdpType, RTCSessionDescriptionInit,
}; };
use crate::dom::bindings::codegen::UnionTypes::StringOrStringSequence;
use crate::dom::bindings::error::Error; use crate::dom::bindings::error::Error;
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
@ -35,7 +36,7 @@ use dom_struct::dom_struct;
use servo_media::webrtc::MediaStream as BackendMediaStream; use servo_media::webrtc::MediaStream as BackendMediaStream;
use servo_media::webrtc::{ use servo_media::webrtc::{
IceCandidate, SdpType, SessionDescription, WebRtcController, WebRtcSignaller, BundlePolicy, IceCandidate, SdpType, SessionDescription, WebRtcController, WebRtcSignaller,
}; };
use servo_media::ServoMedia; use servo_media::ServoMedia;
@ -109,7 +110,7 @@ impl RTCPeerConnection {
} }
} }
pub fn new(global: &GlobalScope) -> DomRoot<RTCPeerConnection> { pub fn new(global: &GlobalScope, config: &RTCConfiguration) -> DomRoot<RTCPeerConnection> {
let this = reflect_dom_object( let this = reflect_dom_object(
Box::new(RTCPeerConnection::new_inherited()), Box::new(RTCPeerConnection::new_inherited()),
global, global,
@ -117,14 +118,34 @@ impl RTCPeerConnection {
); );
let signaller = this.make_signaller(); let signaller = this.make_signaller();
*this.controller.borrow_mut() = Some(ServoMedia::get().unwrap().create_webrtc(signaller)); *this.controller.borrow_mut() = Some(ServoMedia::get().unwrap().create_webrtc(signaller));
if let Some(ref servers) = config.iceServers {
if let Some(ref server) = servers.get(0) {
let server = match server.urls {
StringOrStringSequence::String(ref s) => Some(s.clone()),
StringOrStringSequence::StringSequence(ref s) => s.get(0).cloned(),
};
if let Some(server) = server {
let policy = match config.bundlePolicy {
RTCBundlePolicy::Balanced => BundlePolicy::Balanced,
RTCBundlePolicy::Max_compat => BundlePolicy::MaxCompat,
RTCBundlePolicy::Max_bundle => BundlePolicy::MaxBundle,
};
this.controller
.borrow()
.as_ref()
.unwrap()
.configure(server.to_string(), policy);
}
}
}
this this
} }
pub fn Constructor( pub fn Constructor(
window: &Window, window: &Window,
_config: &RTCConfiguration, config: &RTCConfiguration,
) -> Fallible<DomRoot<RTCPeerConnection>> { ) -> Fallible<DomRoot<RTCPeerConnection>> {
Ok(RTCPeerConnection::new(&window.global())) Ok(RTCPeerConnection::new(&window.global(), config))
} }
fn make_signaller(&self) -> Box<WebRtcSignaller> { fn make_signaller(&self) -> Box<WebRtcSignaller> {
@ -159,9 +180,7 @@ impl RTCPeerConnection {
None, None,
true, true,
); );
event event.upcast::<Event>().fire(self.upcast());
.upcast::<Event>()
.fire(self.upcast());
} }
fn on_negotiation_needed(&self) { fn on_negotiation_needed(&self) {
@ -174,9 +193,7 @@ impl RTCPeerConnection {
EventBubbles::DoesNotBubble, EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable, EventCancelable::NotCancelable,
); );
event event.upcast::<Event>().fire(self.upcast());
.upcast::<Event>()
.fire(self.upcast());
} }
fn create_offer(&self) { fn create_offer(&self) {