Skip to content

Commit

Permalink
refactor states
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Mar 18, 2024
1 parent 35782eb commit c6ddbb8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
10 changes: 9 additions & 1 deletion rtc/src/ice_transport/ice_connection_state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};
use std::fmt;

/// RTCIceConnectionState indicates signaling state of the ICE Connection.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum RTCIceConnectionState {
#[default]
Unspecified,
Expand All @@ -10,34 +11,41 @@ pub enum RTCIceConnectionState {
/// in the "new" state and none of them are in the "checking", "disconnected"
/// or "failed" state, or all ICETransports are in the "closed" state, or
/// there are no transports.
#[serde(rename = "new")]
New,

/// ICEConnectionStateChecking indicates that any of the ICETransports
/// are in the "checking" state and none of them are in the "disconnected"
/// or "failed" state.
#[serde(rename = "checking")]
Checking,

/// ICEConnectionStateConnected indicates that all ICETransports are
/// in the "connected", "completed" or "closed" state and at least one of
/// them is in the "connected" state.
#[serde(rename = "connected")]
Connected,

/// ICEConnectionStateCompleted indicates that all ICETransports are
/// in the "completed" or "closed" state and at least one of them is in the
/// "completed" state.
#[serde(rename = "completed")]
Completed,

/// ICEConnectionStateDisconnected indicates that any of the
/// ICETransports are in the "disconnected" state and none of them are
/// in the "failed" state.
#[serde(rename = "disconnected")]
Disconnected,

/// ICEConnectionStateFailed indicates that any of the ICETransports
/// are in the "failed" state.
#[serde(rename = "failed")]
Failed,

/// ICEConnectionStateClosed indicates that the PeerConnection's
/// isClosed is true.
#[serde(rename = "closed")]
Closed,
}

Expand Down
7 changes: 5 additions & 2 deletions rtc/src/ice_transport/ice_gathering_state.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
use std::fmt;

/// ICEGatheringState describes the state of the candidate gathering process.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum RTCIceGatheringState {
#[default]
Unspecified,

/// ICEGatheringStateNew indicates that any of the ICETransports are
/// in the "new" gathering state and none of the transports are in the
/// "gathering" state, or there are no transports.
#[serde(rename = "new")]
New,

/// ICEGatheringStateGathering indicates that any of the ICETransports
/// are in the "gathering" state.
#[serde(rename = "gathering")]
Gathering,

/// ICEGatheringStateComplete indicates that at least one ICETransport
/// exists, and all ICETransports are in the "completed" gathering state.
/// exists, and all ICETransports are in the "complete" gathering state.
#[serde(rename = "complete")]
Complete,
}

Expand Down
9 changes: 8 additions & 1 deletion rtc/src/peer_connection/peer_connection_state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};
use std::fmt;

/// PeerConnectionState indicates the state of the PeerConnection.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum RTCPeerConnectionState {
#[default]
Unspecified,
Expand All @@ -10,29 +11,35 @@ pub enum RTCPeerConnectionState {
/// DTLSTransports are in the "new" state and none of the transports are
/// in the "connecting", "checking", "failed" or "disconnected" state, or
/// all transports are in the "closed" state, or there are no transports.
#[serde(rename = "new")]
New,

/// PeerConnectionStateConnecting indicates that any of the
/// ICETransports or DTLSTransports are in the "connecting" or
/// "checking" state and none of them is in the "failed" state.
#[serde(rename = "connecting")]
Connecting,

/// PeerConnectionStateConnected indicates that all ICETransports and
/// DTLSTransports are in the "connected", "completed" or "closed" state
/// and at least one of them is in the "connected" or "completed" state.
#[serde(rename = "connected")]
Connected,

/// PeerConnectionStateDisconnected indicates that any of the
/// ICETransports or DTLSTransports are in the "disconnected" state
/// and none of them are in the "failed" or "connecting" or "checking" state.
#[serde(rename = "disconnect")]
Disconnected,

/// PeerConnectionStateFailed indicates that any of the ICETransports
/// or DTLSTransports are in a "failed" state.
#[serde(rename = "failed")]
Failed,

/// PeerConnectionStateClosed indicates the peer connection is closed
/// and the isClosed member variable of PeerConnection is true.
#[serde(rename = "closed")]
Closed,
}

Expand Down
8 changes: 7 additions & 1 deletion rtc/src/peer_connection/signaling_state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use serde::{Deserialize, Serialize};
use std::fmt;

use crate::peer_connection::sdp::sdp_type::RTCSdpType;
Expand All @@ -21,32 +22,37 @@ impl fmt::Display for StateChangeOp {
}

/// SignalingState indicates the signaling state of the offer/answer process.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum RTCSignalingState {
#[default]
Unspecified = 0,

/// SignalingStateStable indicates there is no offer/answer exchange in
/// progress. This is also the initial state, in which case the local and
/// remote descriptions are nil.
#[serde(rename = "stable")]
Stable,

/// SignalingStateHaveLocalOffer indicates that a local description, of
/// type "offer", has been successfully applied.
#[serde(rename = "have-local-offer")]
HaveLocalOffer,

/// SignalingStateHaveRemoteOffer indicates that a remote description, of
/// type "offer", has been successfully applied.
#[serde(rename = "have-remote-offer")]
HaveRemoteOffer,

/// SignalingStateHaveLocalPranswer indicates that a remote description
/// of type "offer" has been successfully applied and a local description
/// of type "pranswer" has been successfully applied.
#[serde(rename = "have-local-pranswer")]
HaveLocalPranswer,

/// SignalingStateHaveRemotePranswer indicates that a local description
/// of type "offer" has been successfully applied and a remote description
/// of type "pranswer" has been successfully applied.
#[serde(rename = "have-remote-pranswer")]
HaveRemotePranswer,

/// SignalingStateClosed indicates The PeerConnection has been closed.
Expand Down

0 comments on commit c6ddbb8

Please sign in to comment.