medea_control_api_proto/control/endpoint/
mod.rs

1//! [`Endpoint`] definitions.
2
3pub mod web_rtc_play;
4pub mod web_rtc_publish;
5
6use derive_more::with_trait::{AsRef, Display, From, Into};
7use ref_cast::RefCast;
8#[cfg(feature = "serde")]
9use serde::{Deserialize, Serialize};
10
11#[doc(inline)]
12pub use self::{web_rtc_play::WebRtcPlay, web_rtc_publish::WebRtcPublish};
13
14/// Media [`Element`] flowing one or more media data streams through itself.
15///
16/// [`Element`]: crate::Element
17#[derive(Clone, Debug, Eq, PartialEq)]
18pub struct Endpoint {
19    /// ID of this [`Endpoint`] media [`Element`].
20    ///
21    /// [`Element`]: crate::Element
22    pub id: Id,
23
24    /// [`Spec`] of this [`Endpoint`] media [`Element`].
25    ///
26    /// [`Element`]: crate::Element
27    pub spec: Spec,
28}
29
30impl From<WebRtcPlay> for Endpoint {
31    fn from(play: WebRtcPlay) -> Self {
32        Self { id: play.id.into(), spec: play.spec.into() }
33    }
34}
35
36impl From<WebRtcPublish> for Endpoint {
37    fn from(publish: WebRtcPublish) -> Self {
38        Self { id: publish.id.into(), spec: publish.spec.into() }
39    }
40}
41
42/// Spec of an [`Endpoint`] media [`Element`].
43///
44/// [`Element`]: crate::Element
45#[derive(Clone, Debug, Eq, From, PartialEq)]
46#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
47#[cfg_attr(feature = "serde", serde(tag = "kind", content = "spec"))]
48pub enum Spec {
49    /// [`WebRtcPublish`] media [`Element`] spec.
50    ///
51    /// [`Element`]: crate::Element
52    WebRtcPublishEndpoint(web_rtc_publish::Spec),
53
54    /// [`WebRtcPlay`] media [`Element`] spec.
55    ///
56    /// [`Element`]: crate::Element
57    WebRtcPlayEndpoint(web_rtc_play::Spec),
58}
59
60/// ID of an [`Endpoint`] media [`Element`].
61///
62/// [`Element`]: crate::Element
63#[derive(
64    AsRef,
65    Clone,
66    Debug,
67    Display,
68    Eq,
69    From,
70    Hash,
71    Into,
72    Ord,
73    PartialEq,
74    PartialOrd,
75    RefCast,
76)]
77#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
78#[cfg_attr(feature = "serde", serde(transparent))]
79#[from(Box<str>, &str, String, web_rtc_play::Id, web_rtc_publish::Id)]
80#[into(Box<str>, String, web_rtc_play::Id, web_rtc_publish::Id)]
81#[repr(transparent)]
82pub struct Id(Box<str>);
83
84impl AsRef<web_rtc_play::Id> for Id {
85    fn as_ref(&self) -> &web_rtc_play::Id {
86        web_rtc_play::Id::ref_cast(&self.0)
87    }
88}
89
90impl AsRef<web_rtc_publish::Id> for Id {
91    fn as_ref(&self) -> &web_rtc_publish::Id {
92        web_rtc_publish::Id::ref_cast(&self.0)
93    }
94}