Skip to content

Commit

Permalink
Trigger RTCErrorEvent on data channel error
Browse files Browse the repository at this point in the history
  • Loading branch information
ferjm committed Jun 29, 2020
1 parent 84598a5 commit 5c6dcbf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
22 changes: 20 additions & 2 deletions components/script/dom/rtcdatachannel.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -164,7 +167,22 @@ impl RTCDataChannel {
event.upcast::<Event>().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::<Event>().fire(self.upcast());
}

fn on_message(&self, message: String) {}
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/rtcerror.rs
Expand Up @@ -40,7 +40,7 @@ impl RTCError {
}
}

fn new(global: &GlobalScope, init: &RTCErrorInit, message: DOMString) -> DomRoot<RTCError> {
pub fn new(global: &GlobalScope, init: &RTCErrorInit, message: DOMString) -> DomRoot<RTCError> {
reflect_dom_object(
Box::new(RTCError::new_inherited(global, init, message)),
global,
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/rtcerrorevent.rs
Expand Up @@ -30,7 +30,7 @@ impl RTCErrorEvent {
}
}

fn new(
pub fn new(
global: &GlobalScope,
type_: Atom,
bubbles: bool,
Expand Down

0 comments on commit 5c6dcbf

Please sign in to comment.