1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
//! State of the Media Server which will be used for Client and Server
//! synchronization.

use std::collections::{HashMap, HashSet};

use serde::{Deserialize, Serialize};

use crate::{
    IceCandidate, IceServer, MediaType, MemberId, NegotiationRole, PeerId,
    TrackId,
};

/// State of a `Room` element.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct Room {
    /// All [`Peer`]s of this [`Room`].
    pub peers: HashMap<PeerId, Peer>,
}

/// State of a `Peer` element.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct Peer {
    /// ID of this [`Peer`].
    pub id: PeerId,

    /// All [`Sender`]s of this [`Peer`].
    pub senders: HashMap<TrackId, Sender>,

    /// All [`Receiver`]s of this [`Peer`].
    pub receivers: HashMap<TrackId, Receiver>,

    /// Indicator whether this [`Peer`] should relay all media through a TURN
    /// server forcibly.
    pub force_relay: bool,

    /// List of [`IceServer`]s which this [`Peer`] should use.
    pub ice_servers: Vec<IceServer>,

    /// Current [`NegotiationRole`] of this [`Peer`].
    pub negotiation_role: Option<NegotiationRole>,

    /// Current SDP offer of this [`Peer`].
    pub local_sdp: Option<String>,

    /// Current SDP offer of the partner [`Peer`].
    pub remote_sdp: Option<String>,

    /// Indicator whether ICE restart should be performed.
    pub restart_ice: bool,

    /// All [`IceCandidate`]s of this [`Peer`].
    pub ice_candidates: HashSet<IceCandidate>,
}

/// State of `MediaTrack`s with a `Send` direction.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct Sender {
    /// ID of this [`Sender`].
    pub id: TrackId,

    /// Mid of this [`Sender`].
    pub mid: Option<String>,

    /// [`MediaType`] of this [`Sender`].
    pub media_type: MediaType,

    /// All `Member`s which receive media from this [`Sender`].
    pub receivers: Vec<MemberId>,

    /// Indicator whether this [`Sender`] is enabled on a `Send` direction
    /// side.
    pub enabled_individual: bool,

    /// Indicator whether this [`Sender`] is enabled on a `Send` __and__ `Recv`
    /// direction sides.
    pub enabled_general: bool,

    /// Indicator whether this [`Sender`] is muted.
    pub muted: bool,
}

/// State of `MediaTrack`s with a `Recv` direction.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct Receiver {
    /// ID of this [`Receiver`].
    pub id: TrackId,

    /// Mid of this [`Receiver`].
    pub mid: Option<String>,

    /// [`MediaType`] of this [`Receiver`].
    pub media_type: MediaType,

    /// `Member`s which send media to this [`Receiver`].
    pub sender_id: MemberId,

    /// Indicator whether this [`Receiver`] is enabled on a `Recv` direction
    /// side.
    pub enabled_individual: bool,

    /// Indicator whether this [`Receiver`] is enabled on a `Send` __and__
    /// `Recv` direction sides.
    pub enabled_general: bool,

    /// Indicator whether this [`Receiver`] is muted.
    pub muted: bool,
}