From 841dd1eb4b73621e4bd29cabcdcc43eeb6ce549f Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 26 Jan 2019 20:02:08 -0800 Subject: [PATCH] Fire negotiationneeded and icecandidate events --- components/atoms/static_atoms.txt | 2 + components/script/dom/rtcpeerconnection.rs | 56 +++++++++++++++++-- .../dom/webidls/RTCPeerConnection.webidl | 4 +- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/components/atoms/static_atoms.txt b/components/atoms/static_atoms.txt index db5680256f7..74f24a23e30 100644 --- a/components/atoms/static_atoms.txt +++ b/components/atoms/static_atoms.txt @@ -36,6 +36,7 @@ fullscreenerror gattserverdisconnected hashchange hidden +icecandidate image input invalid @@ -54,6 +55,7 @@ message monospace month mouseover +negotiationneeded none number onchange diff --git a/components/script/dom/rtcpeerconnection.rs b/components/script/dom/rtcpeerconnection.rs index 8fa6b58023d..6c3cd614364 100644 --- a/components/script/dom/rtcpeerconnection.rs +++ b/components/script/dom/rtcpeerconnection.rs @@ -3,15 +3,21 @@ * 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::RTCConfiguration; +use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::{ + self, RTCPeerConnectionMethods, +}; use crate::dom::bindings::error::Fallible; +use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::refcounted::Trusted; use crate::dom::bindings::reflector::reflect_dom_object; use crate::dom::bindings::reflector::DomObject; use crate::dom::bindings::root::DomRoot; +use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; +use crate::dom::rtcicecandidate::RTCIceCandidate; +use crate::dom::rtcpeerconnectioniceevent::RTCPeerConnectionIceEvent; use crate::dom::window::Window; use crate::task::TaskCanceller; use crate::task_source::networking::NetworkingTaskSource; @@ -109,11 +115,53 @@ impl RTCPeerConnection { }) } - fn on_ice_candidate(&self, _candidate: IceCandidate) { - // todo + fn on_ice_candidate(&self, candidate: IceCandidate) { + 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::() + .fire(self.upcast()); } 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::() + .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 + ); +} diff --git a/components/script/dom/webidls/RTCPeerConnection.webidl b/components/script/dom/webidls/RTCPeerConnection.webidl index ec4ec83028c..6408382cc39 100644 --- a/components/script/dom/webidls/RTCPeerConnection.webidl +++ b/components/script/dom/webidls/RTCPeerConnection.webidl @@ -27,8 +27,8 @@ interface RTCPeerConnection : EventTarget { // RTCConfiguration getConfiguration(); // void setConfiguration(RTCConfiguration configuration); // void close(); - // attribute EventHandler onnegotiationneeded; - // attribute EventHandler onicecandidate; + attribute EventHandler onnegotiationneeded; + attribute EventHandler onicecandidate; // attribute EventHandler onicecandidateerror; // attribute EventHandler onsignalingstatechange; // attribute EventHandler oniceconnectionstatechange;