medea_client_api_proto/state.rs
1//! State of the Media Server which will be used for Client and Server
2//! synchronization.
3
4use std::collections::{HashMap, HashSet};
5
6use serde::{Deserialize, Serialize};
7
8use crate::{
9 ConnectionMode, IceCandidate, IceServer, MediaDirection, MediaType,
10 MemberId, NegotiationRole, PeerId, TrackId,
11};
12
13/// State of a `Room` element.
14#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
15pub struct Room {
16 /// All [`Peer`]s of this [`Room`].
17 pub peers: HashMap<PeerId, Peer>,
18}
19
20/// State of a `Peer` element.
21#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
22pub struct Peer {
23 /// ID of this [`Peer`].
24 pub id: PeerId,
25
26 /// Indicator whether this [`Peer`] is working in a [P2P mesh] or [SFU]
27 /// mode.
28 ///
29 /// [P2P mesh]: https://webrtcglossary.com/mesh
30 /// [SFU]: https://webrtcglossary.com/sfu
31 pub connection_mode: ConnectionMode,
32
33 /// All [`Sender`]s of this [`Peer`].
34 pub senders: HashMap<TrackId, Sender>,
35
36 /// All [`Receiver`]s of this [`Peer`].
37 pub receivers: HashMap<TrackId, Receiver>,
38
39 /// Indicator whether this [`Peer`] should relay all media through a TURN
40 /// server forcibly.
41 pub force_relay: bool,
42
43 /// List of [`IceServer`]s which this [`Peer`] should use.
44 pub ice_servers: Vec<IceServer>,
45
46 /// Current [`NegotiationRole`] of this [`Peer`].
47 pub negotiation_role: Option<NegotiationRole>,
48
49 /// Current SDP offer of this [`Peer`].
50 pub local_sdp: Option<String>,
51
52 /// Current SDP offer of the partner [`Peer`].
53 pub remote_sdp: Option<String>,
54
55 /// Indicator whether ICE restart should be performed.
56 pub restart_ice: bool,
57
58 /// All [`IceCandidate`]s of this [`Peer`].
59 pub ice_candidates: HashSet<IceCandidate>,
60
61 /// Interval (in milliseconds) of [RTCPeerConnection][0]'s stats scraping.
62 ///
63 /// [0]: https://w3.org/TR/webrtc#rtcpeerconnection-interface
64 pub stats_scrape_interval_ms: u32,
65}
66
67/// State of `MediaTrack`s with a `Send` direction.
68#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
69pub struct Sender {
70 /// ID of this [`Sender`].
71 pub id: TrackId,
72
73 /// Indicator whether this [`Sender`] is working in a [P2P mesh] or [SFU]
74 /// mode.
75 ///
76 /// [P2P mesh]: https://webrtcglossary.com/mesh
77 /// [SFU]: https://webrtcglossary.com/sfu
78 pub connection_mode: ConnectionMode,
79
80 /// Mid of this [`Sender`].
81 pub mid: Option<String>,
82
83 /// [`MediaType`] of this [`Sender`].
84 pub media_type: MediaType,
85
86 /// All `Member`s which receive media from this [`Sender`].
87 pub receivers: Vec<MemberId>,
88
89 /// Indicator whether this [`Sender`] is muted.
90 pub muted: bool,
91
92 /// Current general media exchange state of this [`Sender`].
93 pub media_direction: MediaDirection,
94}
95
96/// State of `MediaTrack`s with a `Recv` direction.
97#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
98pub struct Receiver {
99 /// ID of this [`Receiver`].
100 pub id: TrackId,
101
102 /// Indicator whether this [`Receiver`] is working in a [P2P mesh] or [SFU]
103 /// mode.
104 ///
105 /// [P2P mesh]: https://webrtcglossary.com/mesh
106 /// [SFU]: https://webrtcglossary.com/sfu
107 pub connection_mode: ConnectionMode,
108
109 /// Mid of this [`Receiver`].
110 pub mid: Option<String>,
111
112 /// [`MediaType`] of this [`Receiver`].
113 pub media_type: MediaType,
114
115 /// `Member`s which send media to this [`Receiver`].
116 pub sender_id: MemberId,
117
118 /// Indicator whether this [`Receiver`] is muted.
119 pub muted: bool,
120
121 /// Current general media exchange state of this [`Receiver`].
122 pub media_direction: MediaDirection,
123}