script/dom/webrtc/
rtcpeerconnectioniceevent.rs1use dom_struct::dom_struct;
6use js::rust::HandleObject;
7use stylo_atoms::Atom;
8
9use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods;
10use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionIceEventBinding::{
11 RTCPeerConnectionIceEventInit, RTCPeerConnectionIceEventMethods,
12};
13use crate::dom::bindings::error::Fallible;
14use crate::dom::bindings::inheritance::Castable;
15use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
16use crate::dom::bindings::root::{Dom, DomRoot};
17use crate::dom::bindings::str::DOMString;
18use crate::dom::event::Event;
19use crate::dom::rtcicecandidate::RTCIceCandidate;
20use crate::dom::window::Window;
21use crate::script_runtime::CanGc;
22
23#[dom_struct]
24pub(crate) struct RTCPeerConnectionIceEvent {
25 event: Event,
26 candidate: Option<Dom<RTCIceCandidate>>,
27 url: Option<DOMString>,
28}
29
30impl RTCPeerConnectionIceEvent {
31 pub(crate) fn new_inherited(
32 candidate: Option<&RTCIceCandidate>,
33 url: Option<DOMString>,
34 ) -> RTCPeerConnectionIceEvent {
35 RTCPeerConnectionIceEvent {
36 event: Event::new_inherited(),
37 candidate: candidate.map(Dom::from_ref),
38 url,
39 }
40 }
41
42 pub(crate) fn new(
43 window: &Window,
44 ty: Atom,
45 candidate: Option<&RTCIceCandidate>,
46 url: Option<DOMString>,
47 trusted: bool,
48 can_gc: CanGc,
49 ) -> DomRoot<RTCPeerConnectionIceEvent> {
50 Self::new_with_proto(window, None, ty, candidate, url, trusted, can_gc)
51 }
52
53 fn new_with_proto(
54 window: &Window,
55 proto: Option<HandleObject>,
56 ty: Atom,
57 candidate: Option<&RTCIceCandidate>,
58 url: Option<DOMString>,
59 trusted: bool,
60 can_gc: CanGc,
61 ) -> DomRoot<RTCPeerConnectionIceEvent> {
62 let e = reflect_dom_object_with_proto(
63 Box::new(RTCPeerConnectionIceEvent::new_inherited(candidate, url)),
64 window,
65 proto,
66 can_gc,
67 );
68 let evt = e.upcast::<Event>();
69 evt.init_event(ty, false, false); evt.set_trusted(trusted);
71 e
72 }
73}
74
75impl RTCPeerConnectionIceEventMethods<crate::DomTypeHolder> for RTCPeerConnectionIceEvent {
76 fn Constructor(
78 window: &Window,
79 proto: Option<HandleObject>,
80 can_gc: CanGc,
81 ty: DOMString,
82 init: &RTCPeerConnectionIceEventInit,
83 ) -> Fallible<DomRoot<RTCPeerConnectionIceEvent>> {
84 Ok(RTCPeerConnectionIceEvent::new_with_proto(
85 window,
86 proto,
87 ty.into(),
88 init.candidate
89 .as_ref()
90 .and_then(|x| x.as_ref())
91 .map(|x| &**x),
92 init.url.as_ref().and_then(|x| x.clone()),
93 false,
94 can_gc,
95 ))
96 }
97
98 fn GetCandidate(&self) -> Option<DomRoot<RTCIceCandidate>> {
100 self.candidate.as_ref().map(|x| DomRoot::from_ref(&**x))
101 }
102
103 fn GetUrl(&self) -> Option<DOMString> {
105 self.url.clone()
106 }
107
108 fn IsTrusted(&self) -> bool {
110 self.event.IsTrusted()
111 }
112}