From 820ea452e78cda3e0a7c866d21bf675e34852367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Fri, 12 Jun 2020 15:58:23 +0200 Subject: [PATCH] Set data channels as closed on peer connection close --- components/script/dom/rtcdatachannel.rs | 8 ++++++-- components/script/dom/rtcpeerconnection.rs | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/components/script/dom/rtcdatachannel.rs b/components/script/dom/rtcdatachannel.rs index 80d543f0441..c0a3db51cc4 100644 --- a/components/script/dom/rtcdatachannel.rs +++ b/components/script/dom/rtcdatachannel.rs @@ -133,6 +133,9 @@ impl RTCDataChannel { } pub fn on_error(&self, error: WebRtcError) { + let global = self.global(); + let cx = global.get_cx(); + let _ac = JSAutoRealm::new(*cx, self.reflector().get_jsobject().get()); let init = RTCErrorInit { errorDetail: RTCErrorDetailType::Data_channel_failure, httpRequestStatusCode: None, @@ -144,8 +147,8 @@ impl RTCDataChannel { 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); + let error = RTCError::new(&global, &init, message); + let event = RTCErrorEvent::new(&global, atom!("error"), false, false, &error); event.upcast::().fire(self.upcast()); } @@ -299,6 +302,7 @@ impl RTCDataChannelMethods for RTCDataChannel { self.id } + // https://www.w3.org/TR/webrtc/#dom-datachannel-readystate fn ReadyState(&self) -> RTCDataChannelState { *self.ready_state.borrow() } diff --git a/components/script/dom/rtcpeerconnection.rs b/components/script/dom/rtcpeerconnection.rs index 7ffbe5c72a7..348fef25256 100644 --- a/components/script/dom/rtcpeerconnection.rs +++ b/components/script/dom/rtcpeerconnection.rs @@ -44,7 +44,7 @@ use dom_struct::dom_struct; use servo_media::streams::registry::MediaStreamId; use servo_media::streams::MediaStreamType; use servo_media::webrtc::{ - BundlePolicy, DataChannelEvent, DataChannelId, GatheringState, IceCandidate, + BundlePolicy, DataChannelEvent, DataChannelId, DataChannelState, GatheringState, IceCandidate, IceConnectionState, SdpType, SessionDescription, SignalingState, WebRtcController, WebRtcSignaller, }; @@ -169,7 +169,6 @@ impl WebRtcSignaller for RTCSignaller { fn close(&self) { // do nothing - // XXX(ferjm) close all data channels. } } @@ -716,8 +715,13 @@ impl RTCPeerConnectionMethods for RTCPeerConnection { // Step 5 handled by backend self.controller.borrow_mut().as_ref().unwrap().quit(); - // Step 6-10 - // (no current support for data channels, transports, etc) + // Step 6 + for (_, val) in self.data_channels.borrow().iter() { + val.on_state_change(DataChannelState::Closed); + } + + // Step 7-10 + // (no current support for transports, etc) // Step 11 self.ice_connection_state.set(RTCIceConnectionState::Closed);