mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Add createAnswer
This commit is contained in:
parent
c156289a0c
commit
cfc235bad2
2 changed files with 58 additions and 8 deletions
|
@ -7,7 +7,7 @@ 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::{
|
||||||
RTCConfiguration, RTCOfferOptions,
|
RTCAnswerOptions, RTCConfiguration, RTCOfferOptions,
|
||||||
};
|
};
|
||||||
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
|
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
|
||||||
RTCSdpType, RTCSessionDescriptionInit,
|
RTCSdpType, RTCSessionDescriptionInit,
|
||||||
|
@ -46,11 +46,13 @@ pub struct RTCPeerConnection {
|
||||||
#[ignore_malloc_size_of = "defined in servo-media"]
|
#[ignore_malloc_size_of = "defined in servo-media"]
|
||||||
controller: DomRefCell<Option<WebRtcController>>,
|
controller: DomRefCell<Option<WebRtcController>>,
|
||||||
closed: Cell<bool>,
|
closed: Cell<bool>,
|
||||||
/// Helps track state changes between the time createOffer
|
/// Helps track state changes between the time createOffer/createAnswer
|
||||||
/// is called and resolved
|
/// is called and resolved
|
||||||
offer_generation: Cell<u32>,
|
offer_answer_generation: Cell<u32>,
|
||||||
#[ignore_malloc_size_of = "promises are hard"]
|
#[ignore_malloc_size_of = "promises are hard"]
|
||||||
offer_promises: DomRefCell<Vec<Rc<Promise>>>,
|
offer_promises: DomRefCell<Vec<Rc<Promise>>>,
|
||||||
|
#[ignore_malloc_size_of = "promises are hard"]
|
||||||
|
answer_promises: DomRefCell<Vec<Rc<Promise>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RTCSignaller {
|
struct RTCSignaller {
|
||||||
|
@ -95,8 +97,9 @@ impl RTCPeerConnection {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
controller: DomRefCell::new(None),
|
controller: DomRefCell::new(None),
|
||||||
closed: Cell::new(false),
|
closed: Cell::new(false),
|
||||||
offer_generation: Cell::new(0),
|
offer_answer_generation: Cell::new(0),
|
||||||
offer_promises: DomRefCell::new(vec![]),
|
offer_promises: DomRefCell::new(vec![]),
|
||||||
|
answer_promises: DomRefCell::new(vec![]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +174,7 @@ impl RTCPeerConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_offer(&self) {
|
fn create_offer(&self) {
|
||||||
let generation = self.offer_generation.get();
|
let generation = self.offer_answer_generation.get();
|
||||||
let (task_source, canceller) = self
|
let (task_source, canceller) = self
|
||||||
.global()
|
.global()
|
||||||
.as_window()
|
.as_window()
|
||||||
|
@ -183,7 +186,7 @@ impl RTCPeerConnection {
|
||||||
let _ = task_source.queue_with_canceller(
|
let _ = task_source.queue_with_canceller(
|
||||||
task!(offer_created: move || {
|
task!(offer_created: move || {
|
||||||
let this = this.root();
|
let this = this.root();
|
||||||
if this.offer_generation.get() != generation {
|
if this.offer_answer_generation.get() != generation {
|
||||||
// the state has changed since we last created the offer,
|
// the state has changed since we last created the offer,
|
||||||
// create a fresh one
|
// create a fresh one
|
||||||
this.create_offer();
|
this.create_offer();
|
||||||
|
@ -200,6 +203,41 @@ impl RTCPeerConnection {
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_answer(&self) {
|
||||||
|
let generation = self.offer_answer_generation.get();
|
||||||
|
let (task_source, canceller) = self
|
||||||
|
.global()
|
||||||
|
.as_window()
|
||||||
|
.task_manager()
|
||||||
|
.networking_task_source_with_canceller();
|
||||||
|
let this = Trusted::new(self);
|
||||||
|
self.controller
|
||||||
|
.borrow_mut()
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.create_answer(
|
||||||
|
(move |desc: SessionDescription| {
|
||||||
|
let _ = task_source.queue_with_canceller(
|
||||||
|
task!(answer_created: move || {
|
||||||
|
let this = this.root();
|
||||||
|
if this.offer_answer_generation.get() != generation {
|
||||||
|
// the state has changed since we last created the offer,
|
||||||
|
// create a fresh one
|
||||||
|
this.create_answer();
|
||||||
|
} else {
|
||||||
|
let init: RTCSessionDescriptionInit = desc.into();
|
||||||
|
for promise in this.answer_promises.borrow_mut().drain(..) {
|
||||||
|
promise.resolve_native(&init);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
&canceller,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RTCPeerConnectionMethods for RTCPeerConnection {
|
impl RTCPeerConnectionMethods for RTCPeerConnection {
|
||||||
|
@ -259,6 +297,18 @@ impl RTCPeerConnectionMethods for RTCPeerConnection {
|
||||||
self.create_offer();
|
self.create_offer();
|
||||||
p
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-createoffer
|
||||||
|
fn CreateAnswer(&self, _options: &RTCAnswerOptions) -> Rc<Promise> {
|
||||||
|
let p = Promise::new(&self.global());
|
||||||
|
if self.closed.get() {
|
||||||
|
p.reject_error(Error::InvalidState);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
self.answer_promises.borrow_mut().push(p.clone());
|
||||||
|
self.create_answer();
|
||||||
|
p
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SessionDescription> for RTCSessionDescriptionInit {
|
impl From<SessionDescription> for RTCSessionDescriptionInit {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
Exposed=Window, Pref="dom.webrtc.enabled"]
|
Exposed=Window, Pref="dom.webrtc.enabled"]
|
||||||
interface RTCPeerConnection : EventTarget {
|
interface RTCPeerConnection : EventTarget {
|
||||||
Promise<RTCSessionDescriptionInit> createOffer(optional RTCOfferOptions options);
|
Promise<RTCSessionDescriptionInit> createOffer(optional RTCOfferOptions options);
|
||||||
// Promise<RTCSessionDescriptionInit> createAnswer(optional RTCAnswerOptions options);
|
Promise<RTCSessionDescriptionInit> createAnswer(optional RTCAnswerOptions options);
|
||||||
// Promise<void> setLocalDescription(RTCSessionDescriptionInit description);
|
// Promise<void> setLocalDescription(RTCSessionDescriptionInit description);
|
||||||
// readonly attribute RTCSessionDescription? localDescription;
|
// readonly attribute RTCSessionDescription? localDescription;
|
||||||
// readonly attribute RTCSessionDescription? currentLocalDescription;
|
// readonly attribute RTCSessionDescription? currentLocalDescription;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue