diff options
author | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2020-06-01 19:31:15 +0200 |
---|---|---|
committer | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2020-06-29 16:53:48 +0200 |
commit | f5c930087e51df882a65d47950d79954bdf24e50 (patch) | |
tree | a4d7dad6404b13a3e902a44e52d82d8bf36c4ed1 /components/script/dom/rtcpeerconnection.rs | |
parent | 2c5fc3b3c81d862d9f9eab7de11ae4a7b658e2d9 (diff) | |
download | servo-f5c930087e51df882a65d47950d79954bdf24e50.tar.gz servo-f5c930087e51df882a65d47950d79954bdf24e50.zip |
Implement ondatachannel event
Diffstat (limited to 'components/script/dom/rtcpeerconnection.rs')
-rw-r--r-- | components/script/dom/rtcpeerconnection.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/components/script/dom/rtcpeerconnection.rs b/components/script/dom/rtcpeerconnection.rs index 5ce0b109bbd..2e7f05f4873 100644 --- a/components/script/dom/rtcpeerconnection.rs +++ b/components/script/dom/rtcpeerconnection.rs @@ -29,6 +29,7 @@ use crate::dom::mediastream::MediaStream; use crate::dom::mediastreamtrack::MediaStreamTrack; use crate::dom::promise::Promise; use crate::dom::rtcdatachannel::RTCDataChannel; +use crate::dom::rtcdatachannelevent::RTCDataChannelEvent; use crate::dom::rtcicecandidate::RTCIceCandidate; use crate::dom::rtcpeerconnectioniceevent::RTCPeerConnectionIceEvent; use crate::dom::rtcsessiondescription::RTCSessionDescription; @@ -44,7 +45,7 @@ use servo_media::streams::registry::MediaStreamId; use servo_media::streams::MediaStreamType; use servo_media::webrtc::{ BundlePolicy, GatheringState, IceCandidate, IceConnectionState, SdpType, SessionDescription, - SignalingState, WebRtcController, WebRtcSignaller, + SignalingState, WebRtcController, WebRtcDataChannelBackend, WebRtcSignaller, }; use servo_media::ServoMedia; @@ -145,6 +146,18 @@ impl WebRtcSignaller for RTCSignaller { ); } + fn on_data_channel(&self, channel: Box<dyn WebRtcDataChannelBackend>) { + // XXX(ferjm) get label and options from channel properties. + let this = self.trusted.clone(); + let _ = self.task_source.queue_with_canceller( + task!(on_data_channel: move || { + let this = this.root(); + this.on_data_channel(channel); + }), + &self.canceller, + ); + } + fn close(&self) { // do nothing } @@ -259,6 +272,24 @@ impl RTCPeerConnection { event.upcast::<Event>().fire(self.upcast()); } + fn on_data_channel(&self, channel: Box<dyn WebRtcDataChannelBackend>) { + if self.closed.get() { + return; + } + + let channel = RTCDataChannel::new( + &self.global(), + &self.controller, + USVString::from("".to_owned()), + &RTCDataChannelInit::empty(), + Some(channel), + ); + + let event = + RTCDataChannelEvent::new(&self.global(), atom!("datachannel"), false, false, &channel); + event.upcast::<Event>().fire(self.upcast()); + } + /// https://www.w3.org/TR/webrtc/#update-ice-gathering-state fn update_gathering_state(&self, state: GatheringState) { // step 1 @@ -646,7 +677,13 @@ impl RTCPeerConnectionMethods for RTCPeerConnection { label: USVString, dataChannelDict: &RTCDataChannelInit, ) -> DomRoot<RTCDataChannel> { - RTCDataChannel::new(&self.global(), &self.controller, label, dataChannelDict) + RTCDataChannel::new( + &self.global(), + &self.controller, + label, + dataChannelDict, + None, + ) } } |