Add SignalingState to RTCPeerConnection

This commit is contained in:
Manish Goregaokar 2019-03-06 12:44:14 +05:30
parent fc25a80892
commit 5cb5503a75
3 changed files with 74 additions and 4 deletions

View file

@ -97,6 +97,7 @@ seeked
seeking seeking
select select
serif serif
signalingstatechange
srclang srclang
statechange statechange
storage storage

View file

@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding;
use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::RTCPeerConnectionMethods; use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::RTCPeerConnectionMethods;
use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::{ use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::{
RTCAnswerOptions, RTCBundlePolicy, RTCConfiguration, RTCIceConnectionState, RTCAnswerOptions, RTCBundlePolicy, RTCConfiguration, RTCIceConnectionState,
RTCIceGatheringState, RTCOfferOptions, RTCIceGatheringState, RTCOfferOptions, RTCSignalingState,
}; };
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{ use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
RTCSdpType, RTCSessionDescriptionInit, RTCSdpType, RTCSessionDescriptionInit,
@ -38,7 +38,7 @@ use dom_struct::dom_struct;
use servo_media::streams::MediaStream as BackendMediaStream; use servo_media::streams::MediaStream as BackendMediaStream;
use servo_media::webrtc::{ use servo_media::webrtc::{
BundlePolicy, GatheringState, IceCandidate, IceConnectionState, SdpType, SessionDescription, BundlePolicy, GatheringState, IceCandidate, IceConnectionState, SdpType, SessionDescription,
WebRtcController, WebRtcSignaller, SignalingState, WebRtcController, WebRtcSignaller,
}; };
use servo_media::ServoMedia; use servo_media::ServoMedia;
use servo_media_auto::Backend; use servo_media_auto::Backend;
@ -63,6 +63,7 @@ pub struct RTCPeerConnection {
remote_description: MutNullableDom<RTCSessionDescription>, remote_description: MutNullableDom<RTCSessionDescription>,
gathering_state: Cell<RTCIceGatheringState>, gathering_state: Cell<RTCIceGatheringState>,
ice_connection_state: Cell<RTCIceConnectionState>, ice_connection_state: Cell<RTCIceConnectionState>,
signaling_state: Cell<RTCSignalingState>,
} }
struct RTCSignaller { struct RTCSignaller {
@ -116,6 +117,17 @@ impl WebRtcSignaller for RTCSignaller {
); );
} }
fn update_signaling_state(&self, state: SignalingState) {
let this = self.trusted.clone();
let _ = self.task_source.queue_with_canceller(
task!(update_signaling_state: move || {
let this = this.root();
this.update_signaling_state(state);
}),
&self.canceller,
);
}
fn on_add_stream(&self, _: Box<BackendMediaStream>) {} fn on_add_stream(&self, _: Box<BackendMediaStream>) {}
fn close(&self) { fn close(&self) {
@ -136,6 +148,7 @@ impl RTCPeerConnection {
remote_description: Default::default(), remote_description: Default::default(),
gathering_state: Cell::new(RTCIceGatheringState::New), gathering_state: Cell::new(RTCIceGatheringState::New),
ice_connection_state: Cell::new(RTCIceConnectionState::New), ice_connection_state: Cell::new(RTCIceConnectionState::New),
signaling_state: Cell::new(RTCSignalingState::Stable),
} }
} }
@ -294,6 +307,28 @@ impl RTCPeerConnection {
event.upcast::<Event>().fire(self.upcast()); event.upcast::<Event>().fire(self.upcast());
} }
fn update_signaling_state(&self, state: SignalingState) {
if self.closed.get() {
return;
}
let state: RTCSignalingState = state.into();
if state == self.signaling_state.get() {
return;
}
self.signaling_state.set(state);
let event = Event::new(
&self.global(),
atom!("signalingstatechange"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
);
event.upcast::<Event>().fire(self.upcast());
}
fn create_offer(&self) { fn create_offer(&self) {
let generation = self.offer_answer_generation.get(); let generation = self.offer_answer_generation.get();
let (task_source, canceller) = self let (task_source, canceller) = self
@ -386,6 +421,13 @@ impl RTCPeerConnectionMethods for RTCPeerConnection {
SetOnnegotiationneeded SetOnnegotiationneeded
); );
/// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-signalingstatechange
event_handler!(
signalingstatechange,
GetOnsignalingstatechange,
SetOnsignalingstatechange
);
/// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addicecandidate /// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addicecandidate
fn AddIceCandidate(&self, candidate: &RTCIceCandidateInit) -> Rc<Promise> { fn AddIceCandidate(&self, candidate: &RTCIceCandidateInit) -> Rc<Promise> {
let p = Promise::new(&self.global()); let p = Promise::new(&self.global());
@ -539,6 +581,11 @@ impl RTCPeerConnectionMethods for RTCPeerConnection {
fn IceConnectionState(&self) -> RTCIceConnectionState { fn IceConnectionState(&self) -> RTCIceConnectionState {
self.ice_connection_state.get() self.ice_connection_state.get()
} }
/// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-signalingstate
fn SignalingState(&self) -> RTCSignalingState {
self.signaling_state.get()
}
} }
impl From<SessionDescription> for RTCSessionDescriptionInit { impl From<SessionDescription> for RTCSessionDescriptionInit {
@ -594,3 +641,16 @@ impl From<IceConnectionState> for RTCIceConnectionState {
} }
} }
} }
impl From<SignalingState> for RTCSignalingState {
fn from(state: SignalingState) -> Self {
match state {
SignalingState::Stable => RTCSignalingState::Stable,
SignalingState::HaveLocalOffer => RTCSignalingState::Have_local_offer,
SignalingState::HaveRemoteOffer => RTCSignalingState::Have_remote_offer,
SignalingState::HaveLocalPranswer => RTCSignalingState::Have_local_pranswer,
SignalingState::HaveRemotePranswer => RTCSignalingState::Have_remote_pranswer,
SignalingState::Closed => RTCSignalingState::Closed,
}
}
}

View file

@ -18,7 +18,7 @@ interface RTCPeerConnection : EventTarget {
// readonly attribute RTCSessionDescription? currentRemoteDescription; // readonly attribute RTCSessionDescription? currentRemoteDescription;
// readonly attribute RTCSessionDescription? pendingRemoteDescription; // readonly attribute RTCSessionDescription? pendingRemoteDescription;
Promise<void> addIceCandidate(optional RTCIceCandidateInit candidate); Promise<void> addIceCandidate(optional RTCIceCandidateInit candidate);
// readonly attribute RTCSignalingState signalingState; readonly attribute RTCSignalingState signalingState;
readonly attribute RTCIceGatheringState iceGatheringState; readonly attribute RTCIceGatheringState iceGatheringState;
readonly attribute RTCIceConnectionState iceConnectionState; readonly attribute RTCIceConnectionState iceConnectionState;
// readonly attribute RTCPeerConnectionState connectionState; // readonly attribute RTCPeerConnectionState connectionState;
@ -30,7 +30,7 @@ interface RTCPeerConnection : EventTarget {
attribute EventHandler onnegotiationneeded; attribute EventHandler onnegotiationneeded;
attribute EventHandler onicecandidate; attribute EventHandler onicecandidate;
// attribute EventHandler onicecandidateerror; // attribute EventHandler onicecandidateerror;
// attribute EventHandler onsignalingstatechange; attribute EventHandler onsignalingstatechange;
attribute EventHandler oniceconnectionstatechange; attribute EventHandler oniceconnectionstatechange;
attribute EventHandler onicegatheringstatechange; attribute EventHandler onicegatheringstatechange;
// attribute EventHandler onconnectionstatechange; // attribute EventHandler onconnectionstatechange;
@ -105,3 +105,12 @@ enum RTCIceConnectionState {
"failed", "failed",
"closed" "closed"
}; };
enum RTCSignalingState {
"stable",
"have-local-offer",
"have-remote-offer",
"have-local-pranswer",
"have-remote-pranswer",
"closed"
};