From 5c6dcbf54e77b94e3d7d2cf11a53144ec783a52a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Mon, 1 Jun 2020 12:19:47 +0200 Subject: [PATCH] Trigger RTCErrorEvent on data channel error --- components/script/dom/rtcdatachannel.rs | 22 ++++++++++++++++++++-- components/script/dom/rtcerror.rs | 2 +- components/script/dom/rtcerrorevent.rs | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/components/script/dom/rtcdatachannel.rs b/components/script/dom/rtcdatachannel.rs index d7388729dbda..a1a0e2075f09 100644 --- a/components/script/dom/rtcdatachannel.rs +++ b/components/script/dom/rtcdatachannel.rs @@ -5,15 +5,18 @@ use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::RTCDataChannelBinding::RTCDataChannelInit; use crate::dom::bindings::codegen::Bindings::RTCDataChannelBinding::RTCDataChannelMethods; +use crate::dom::bindings::codegen::Bindings::RTCErrorBinding::{RTCErrorDetailType, RTCErrorInit}; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::refcounted::Trusted; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; use crate::dom::bindings::root::DomRoot; -use crate::dom::bindings::str::USVString; +use crate::dom::bindings::str::{DOMString, USVString}; use crate::dom::blob::Blob; use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; +use crate::dom::rtcerror::RTCError; +use crate::dom::rtcerrorevent::RTCErrorEvent; use crate::task_source::TaskSource; use dom_struct::dom_struct; use js::rust::CustomAutoRooterGuard; @@ -164,7 +167,22 @@ impl RTCDataChannel { event.upcast::().fire(self.upcast()); } - fn on_error(&self, error: WebRtcError) {} + fn on_error(&self, error: WebRtcError) { + let init = RTCErrorInit { + errorDetail: RTCErrorDetailType::Data_channel_failure, + httpRequestStatusCode: None, + receivedAlert: None, + sctpCauseCode: None, + sdpLineNumber: None, + sentAlert: None, + }; + let message = match error { + WebRtcError::Backend(message) => DOMString::from(message), + }; + let error = RTCError::new(&self.global(), &init, message); + let event = RTCErrorEvent::new(&self.global(), atom!("error"), false, false, &error); + event.upcast::().fire(self.upcast()); + } fn on_message(&self, message: String) {} } diff --git a/components/script/dom/rtcerror.rs b/components/script/dom/rtcerror.rs index db23cd7c0963..615cd267c9fc 100644 --- a/components/script/dom/rtcerror.rs +++ b/components/script/dom/rtcerror.rs @@ -40,7 +40,7 @@ impl RTCError { } } - fn new(global: &GlobalScope, init: &RTCErrorInit, message: DOMString) -> DomRoot { + pub fn new(global: &GlobalScope, init: &RTCErrorInit, message: DOMString) -> DomRoot { reflect_dom_object( Box::new(RTCError::new_inherited(global, init, message)), global, diff --git a/components/script/dom/rtcerrorevent.rs b/components/script/dom/rtcerrorevent.rs index aeaf361aa580..a647fe8bcbd2 100644 --- a/components/script/dom/rtcerrorevent.rs +++ b/components/script/dom/rtcerrorevent.rs @@ -30,7 +30,7 @@ impl RTCErrorEvent { } } - fn new( + pub fn new( global: &GlobalScope, type_: Atom, bubbles: bool,