mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Add ICEConnectionState to RTCPeerConnection
This commit is contained in:
parent
209caa418b
commit
fc25a80892
3 changed files with 76 additions and 7 deletions
|
@ -37,6 +37,7 @@ gattserverdisconnected
|
||||||
hashchange
|
hashchange
|
||||||
hidden
|
hidden
|
||||||
icecandidate
|
icecandidate
|
||||||
|
iceconnectionstatechange
|
||||||
icegatheringstatechange
|
icegatheringstatechange
|
||||||
image
|
image
|
||||||
input
|
input
|
||||||
|
|
|
@ -7,7 +7,8 @@ use crate::dom::bindings::codegen::Bindings::RTCIceCandidateBinding::RTCIceCandi
|
||||||
use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding;
|
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, RTCIceGatheringState, RTCOfferOptions,
|
RTCAnswerOptions, RTCBundlePolicy, RTCConfiguration, RTCIceConnectionState,
|
||||||
|
RTCIceGatheringState, RTCOfferOptions,
|
||||||
};
|
};
|
||||||
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
|
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
|
||||||
RTCSdpType, RTCSessionDescriptionInit,
|
RTCSdpType, RTCSessionDescriptionInit,
|
||||||
|
@ -36,8 +37,8 @@ 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, SdpType, SessionDescription, WebRtcController,
|
BundlePolicy, GatheringState, IceCandidate, IceConnectionState, SdpType, SessionDescription,
|
||||||
WebRtcSignaller,
|
WebRtcController, WebRtcSignaller,
|
||||||
};
|
};
|
||||||
use servo_media::ServoMedia;
|
use servo_media::ServoMedia;
|
||||||
use servo_media_auto::Backend;
|
use servo_media_auto::Backend;
|
||||||
|
@ -61,6 +62,7 @@ pub struct RTCPeerConnection {
|
||||||
local_description: MutNullableDom<RTCSessionDescription>,
|
local_description: MutNullableDom<RTCSessionDescription>,
|
||||||
remote_description: MutNullableDom<RTCSessionDescription>,
|
remote_description: MutNullableDom<RTCSessionDescription>,
|
||||||
gathering_state: Cell<RTCIceGatheringState>,
|
gathering_state: Cell<RTCIceGatheringState>,
|
||||||
|
ice_connection_state: Cell<RTCIceConnectionState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RTCSignaller {
|
struct RTCSignaller {
|
||||||
|
@ -103,6 +105,17 @@ impl WebRtcSignaller for RTCSignaller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_ice_connection_state(&self, state: IceConnectionState) {
|
||||||
|
let this = self.trusted.clone();
|
||||||
|
let _ = self.task_source.queue_with_canceller(
|
||||||
|
task!(update_ice_connection_state: move || {
|
||||||
|
let this = this.root();
|
||||||
|
this.update_ice_connection_state(state);
|
||||||
|
}),
|
||||||
|
&self.canceller,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn on_add_stream(&self, _: Box<BackendMediaStream>) {}
|
fn on_add_stream(&self, _: Box<BackendMediaStream>) {}
|
||||||
|
|
||||||
fn close(&self) {
|
fn close(&self) {
|
||||||
|
@ -122,6 +135,7 @@ impl RTCPeerConnection {
|
||||||
local_description: Default::default(),
|
local_description: Default::default(),
|
||||||
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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,11 +264,30 @@ impl RTCPeerConnection {
|
||||||
);
|
);
|
||||||
event.upcast::<Event>().fire(self.upcast());
|
event.upcast::<Event>().fire(self.upcast());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://www.w3.org/TR/webrtc/#update-ice-connection-state
|
||||||
|
fn update_ice_connection_state(&self, state: IceConnectionState) {
|
||||||
|
// step 1
|
||||||
|
if self.closed.get() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// step 2 (state derivation already done by gstreamer)
|
||||||
|
let state: RTCIceConnectionState = state.into();
|
||||||
|
|
||||||
|
// step 3
|
||||||
|
if state == self.ice_connection_state.get() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// step 4
|
||||||
|
self.ice_connection_state.set(state);
|
||||||
|
|
||||||
// step 5
|
// step 5
|
||||||
let event = Event::new(
|
let event = Event::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
atom!("icegatheringstatechange"),
|
atom!("iceconnectionstatechange"),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable,
|
EventCancelable::NotCancelable,
|
||||||
);
|
);
|
||||||
|
@ -332,6 +365,13 @@ impl RTCPeerConnectionMethods for RTCPeerConnection {
|
||||||
/// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-icecandidate
|
/// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-icecandidate
|
||||||
event_handler!(icecandidate, GetOnicecandidate, SetOnicecandidate);
|
event_handler!(icecandidate, GetOnicecandidate, SetOnicecandidate);
|
||||||
|
|
||||||
|
/// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-iceconnectionstatechange
|
||||||
|
event_handler!(
|
||||||
|
iceconnectionstatechange,
|
||||||
|
GetOniceconnectionstatechange,
|
||||||
|
SetOniceconnectionstatechange
|
||||||
|
);
|
||||||
|
|
||||||
/// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-icegatheringstatechange
|
/// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-icegatheringstatechange
|
||||||
event_handler!(
|
event_handler!(
|
||||||
icegatheringstatechange,
|
icegatheringstatechange,
|
||||||
|
@ -494,6 +534,11 @@ impl RTCPeerConnectionMethods for RTCPeerConnection {
|
||||||
fn IceGatheringState(&self) -> RTCIceGatheringState {
|
fn IceGatheringState(&self) -> RTCIceGatheringState {
|
||||||
self.gathering_state.get()
|
self.gathering_state.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-iceconnectionstate
|
||||||
|
fn IceConnectionState(&self) -> RTCIceConnectionState {
|
||||||
|
self.ice_connection_state.get()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SessionDescription> for RTCSessionDescriptionInit {
|
impl From<SessionDescription> for RTCSessionDescriptionInit {
|
||||||
|
@ -526,7 +571,6 @@ impl<'a> From<&'a RTCSessionDescriptionInit> for SessionDescription {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl From<GatheringState> for RTCIceGatheringState {
|
impl From<GatheringState> for RTCIceGatheringState {
|
||||||
fn from(state: GatheringState) -> Self {
|
fn from(state: GatheringState) -> Self {
|
||||||
match state {
|
match state {
|
||||||
|
@ -536,3 +580,17 @@ impl From<GatheringState> for RTCIceGatheringState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<IceConnectionState> for RTCIceConnectionState {
|
||||||
|
fn from(state: IceConnectionState) -> Self {
|
||||||
|
match state {
|
||||||
|
IceConnectionState::New => RTCIceConnectionState::New,
|
||||||
|
IceConnectionState::Checking => RTCIceConnectionState::Checking,
|
||||||
|
IceConnectionState::Connected => RTCIceConnectionState::Connected,
|
||||||
|
IceConnectionState::Completed => RTCIceConnectionState::Completed,
|
||||||
|
IceConnectionState::Disconnected => RTCIceConnectionState::Disconnected,
|
||||||
|
IceConnectionState::Failed => RTCIceConnectionState::Failed,
|
||||||
|
IceConnectionState::Closed => RTCIceConnectionState::Closed,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ interface RTCPeerConnection : EventTarget {
|
||||||
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;
|
||||||
// readonly attribute boolean? canTrickleIceCandidates;
|
// readonly attribute boolean? canTrickleIceCandidates;
|
||||||
// static sequence<RTCIceServer> getDefaultIceServers();
|
// static sequence<RTCIceServer> getDefaultIceServers();
|
||||||
|
@ -31,7 +31,7 @@ interface RTCPeerConnection : EventTarget {
|
||||||
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;
|
||||||
|
|
||||||
|
@ -95,3 +95,13 @@ enum RTCIceGatheringState {
|
||||||
"gathering",
|
"gathering",
|
||||||
"complete"
|
"complete"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum RTCIceConnectionState {
|
||||||
|
"new",
|
||||||
|
"checking",
|
||||||
|
"connected",
|
||||||
|
"completed",
|
||||||
|
"disconnected",
|
||||||
|
"failed",
|
||||||
|
"closed"
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue