ruma_events/
call.rs

1//! Modules for events in the `m.call` namespace.
2//!
3//! This module also contains types shared by events in its child namespaces.
4
5pub mod answer;
6pub mod candidates;
7pub mod hangup;
8pub mod invite;
9#[cfg(feature = "unstable-msc3401")]
10pub mod member;
11pub mod negotiate;
12#[cfg(feature = "unstable-msc4075")]
13#[allow(deprecated)]
14pub mod notify;
15pub mod reject;
16pub mod sdp_stream_metadata_changed;
17pub mod select_answer;
18
19use ruma_macros::StringEnum;
20use serde::{Deserialize, Serialize};
21
22use crate::PrivOwnedStr;
23
24/// A VoIP session description.
25///
26/// This is the same type as WebRTC's [`RTCSessionDescriptionInit`].
27///
28/// [`RTCSessionDescriptionInit`]: (https://www.w3.org/TR/webrtc/#dom-rtcsessiondescriptioninit):
29#[derive(Clone, Debug, Deserialize, Serialize)]
30#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
31pub struct SessionDescription {
32    /// The type of session description.
33    ///
34    /// This is the `type` field of `RTCSessionDescriptionInit`.
35    #[serde(rename = "type")]
36    pub session_type: String,
37
38    /// The SDP text of the session description.
39    ///
40    /// Defaults to an empty string.
41    #[serde(default)]
42    pub sdp: String,
43}
44
45impl SessionDescription {
46    /// Creates a new `SessionDescription` with the given session type and SDP text.
47    pub fn new(session_type: String, sdp: String) -> Self {
48        Self { session_type, sdp }
49    }
50}
51
52/// Metadata about a VoIP stream.
53#[derive(Clone, Debug, Serialize, Deserialize)]
54#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
55pub struct StreamMetadata {
56    /// The purpose of the stream.
57    pub purpose: StreamPurpose,
58
59    /// Whether the audio track of the stream is muted.
60    ///
61    /// Defaults to `false`.
62    #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
63    pub audio_muted: bool,
64
65    /// Whether the video track of the stream is muted.
66    ///
67    /// Defaults to `false`.
68    #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
69    pub video_muted: bool,
70}
71
72impl StreamMetadata {
73    /// Creates a new `StreamMetadata` with the given purpose.
74    pub fn new(purpose: StreamPurpose) -> Self {
75        Self { purpose, audio_muted: false, video_muted: false }
76    }
77}
78
79/// The purpose of a VoIP stream.
80#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
81#[derive(Clone, PartialEq, Eq, StringEnum)]
82#[ruma_enum(rename_all = "m.lowercase")]
83#[non_exhaustive]
84pub enum StreamPurpose {
85    /// `m.usermedia`.
86    ///
87    /// A stream that contains the webcam and/or microphone tracks.
88    UserMedia,
89
90    /// `m.screenshare`.
91    ///
92    /// A stream with the screen-sharing tracks.
93    ScreenShare,
94
95    #[doc(hidden)]
96    _Custom(PrivOwnedStr),
97}
98
99/// The capabilities of a client in a VoIP call.
100#[cfg(feature = "unstable-msc2747")]
101#[derive(Clone, Debug, Default, Serialize, Deserialize)]
102#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
103pub struct CallCapabilities {
104    /// Whether this client supports [DTMF].
105    ///
106    /// Defaults to `false`.
107    ///
108    /// [DTMF]: https://w3c.github.io/webrtc-pc/#peer-to-peer-dtmf
109    #[serde(rename = "m.call.dtmf", default)]
110    pub dtmf: bool,
111}
112
113#[cfg(feature = "unstable-msc2747")]
114impl CallCapabilities {
115    /// Creates a default `CallCapabilities`.
116    pub fn new() -> Self {
117        Self::default()
118    }
119
120    /// Whether this `CallCapabilities` only contains default values.
121    pub fn is_default(&self) -> bool {
122        !self.dtmf
123    }
124}