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
62/// State of `MediaTrack`s with a `Send` direction.
63#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
64pub struct Sender {
65 /// ID of this [`Sender`].
66 pub id: TrackId,
67
68 /// Indicator whether this [`Sender`] is working in a [P2P mesh] or [SFU]
69 /// mode.
70 ///
71 /// [P2P mesh]: https://webrtcglossary.com/mesh
72 /// [SFU]: https://webrtcglossary.com/sfu
73 pub connection_mode: ConnectionMode,
74
75 /// Mid of this [`Sender`].
76 pub mid: Option<String>,
77
78 /// [`MediaType`] of this [`Sender`].
79 pub media_type: MediaType,
80
81 /// All `Member`s which receive media from this [`Sender`].
82 pub receivers: Vec<MemberId>,
83
84 /// Indicator whether this [`Sender`] is muted.
85 pub muted: bool,
86
87 /// Current general media exchange state of this [`Sender`].
88 pub media_direction: MediaDirection,
89}
90
91/// State of `MediaTrack`s with a `Recv` direction.
92#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
93pub struct Receiver {
94 /// ID of this [`Receiver`].
95 pub id: TrackId,
96
97 /// Indicator whether this [`Receiver`] is working in a [P2P mesh] or [SFU]
98 /// mode.
99 ///
100 /// [P2P mesh]: https://webrtcglossary.com/mesh
101 /// [SFU]: https://webrtcglossary.com/sfu
102 pub connection_mode: ConnectionMode,
103
104 /// Mid of this [`Receiver`].
105 pub mid: Option<String>,
106
107 /// [`MediaType`] of this [`Receiver`].
108 pub media_type: MediaType,
109
110 /// `Member`s which send media to this [`Receiver`].
111 pub sender_id: MemberId,
112
113 /// Indicator whether this [`Receiver`] is muted.
114 pub muted: bool,
115
116 /// Current general media exchange state of this [`Receiver`].
117 pub media_direction: MediaDirection,
118}