Fire negotiationneeded and icecandidate events

This commit is contained in:
Manish Goregaokar 2019-01-26 20:02:08 -08:00
parent 5bfa42094e
commit 841dd1eb4b
3 changed files with 56 additions and 6 deletions

View file

@ -36,6 +36,7 @@ fullscreenerror
gattserverdisconnected gattserverdisconnected
hashchange hashchange
hidden hidden
icecandidate
image image
input input
invalid invalid
@ -54,6 +55,7 @@ message
monospace monospace
month month
mouseover mouseover
negotiationneeded
none none
number number
onchange onchange

View file

@ -3,15 +3,21 @@
* 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::cell::DomRefCell;
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::codegen::Bindings::RTCPeerConnectionBinding::{
self, RTCPeerConnectionMethods,
};
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::refcounted::Trusted; 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::event::{Event, EventBubbles, EventCancelable};
use crate::dom::eventtarget::EventTarget; use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::rtcicecandidate::RTCIceCandidate;
use crate::dom::rtcpeerconnectioniceevent::RTCPeerConnectionIceEvent;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::task::TaskCanceller; use crate::task::TaskCanceller;
use crate::task_source::networking::NetworkingTaskSource; use crate::task_source::networking::NetworkingTaskSource;
@ -109,11 +115,53 @@ impl RTCPeerConnection {
}) })
} }
fn on_ice_candidate(&self, _candidate: IceCandidate) { fn on_ice_candidate(&self, candidate: IceCandidate) {
// todo if self.closed.get() {
return;
}
let candidate = RTCIceCandidate::new(
&self.global(),
candidate.candidate.into(),
None,
Some(candidate.sdp_mline_index as u16),
None,
);
let event = RTCPeerConnectionIceEvent::new(
&self.global(),
atom!("icecandidate"),
Some(&candidate),
None,
true,
);
event
.upcast::<Event>()
.fire(self.upcast());
} }
fn on_negotiation_needed(&self) { fn on_negotiation_needed(&self) {
// todo if self.closed.get() {
return;
}
let event = Event::new(
&self.global(),
atom!("negotiationneeded"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
);
event
.upcast::<Event>()
.fire(self.upcast());
} }
} }
impl RTCPeerConnectionMethods for RTCPeerConnection {
/// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-icecandidate
event_handler!(icecandidate, GetOnicecandidate, SetOnicecandidate);
/// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-onnegotiationneeded
event_handler!(
negotiationneeded,
GetOnnegotiationneeded,
SetOnnegotiationneeded
);
}

View file

@ -27,8 +27,8 @@ interface RTCPeerConnection : EventTarget {
// RTCConfiguration getConfiguration(); // RTCConfiguration getConfiguration();
// void setConfiguration(RTCConfiguration configuration); // void setConfiguration(RTCConfiguration configuration);
// void close(); // void close();
// attribute EventHandler onnegotiationneeded; attribute EventHandler onnegotiationneeded;
// attribute EventHandler onicecandidate; attribute EventHandler onicecandidate;
// attribute EventHandler onicecandidateerror; // attribute EventHandler onicecandidateerror;
// attribute EventHandler onsignalingstatechange; // attribute EventHandler onsignalingstatechange;
// attribute EventHandler oniceconnectionstatechange; // attribute EventHandler oniceconnectionstatechange;