ruma_events/call/
invite.rs1use std::collections::BTreeMap;
6
7use js_int::UInt;
8use ruma_common::{OwnedUserId, OwnedVoipId, VoipVersionId};
9use ruma_macros::EventContent;
10use serde::{Deserialize, Serialize};
11
12#[cfg(feature = "unstable-msc2747")]
13use super::CallCapabilities;
14use super::{SessionDescription, StreamMetadata};
15
16#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
20#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
21#[ruma_event(type = "m.call.invite", kind = MessageLike)]
22pub struct CallInviteEventContent {
23 pub call_id: OwnedVoipId,
25
26 #[serde(skip_serializing_if = "Option::is_none")]
28 pub party_id: Option<OwnedVoipId>,
29
30 pub lifetime: UInt,
35
36 pub offer: SessionDescription,
38
39 pub version: VoipVersionId,
41
42 #[cfg(feature = "unstable-msc2747")]
43 #[serde(default, skip_serializing_if = "CallCapabilities::is_default")]
45 pub capabilities: CallCapabilities,
46
47 #[serde(skip_serializing_if = "Option::is_none")]
53 pub invitee: Option<OwnedUserId>,
54
55 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
59 pub sdp_stream_metadata: BTreeMap<String, StreamMetadata>,
60}
61
62impl CallInviteEventContent {
63 pub fn new(
66 call_id: OwnedVoipId,
67 lifetime: UInt,
68 offer: SessionDescription,
69 version: VoipVersionId,
70 ) -> Self {
71 Self {
72 call_id,
73 party_id: None,
74 lifetime,
75 offer,
76 version,
77 #[cfg(feature = "unstable-msc2747")]
78 capabilities: Default::default(),
79 invitee: None,
80 sdp_stream_metadata: Default::default(),
81 }
82 }
83
84 pub fn version_0(call_id: OwnedVoipId, lifetime: UInt, offer: SessionDescription) -> Self {
87 Self::new(call_id, lifetime, offer, VoipVersionId::V0)
88 }
89
90 pub fn version_1(
93 call_id: OwnedVoipId,
94 party_id: OwnedVoipId,
95 lifetime: UInt,
96 offer: SessionDescription,
97 ) -> Self {
98 Self {
99 call_id,
100 party_id: Some(party_id),
101 lifetime,
102 offer,
103 version: VoipVersionId::V1,
104 #[cfg(feature = "unstable-msc2747")]
105 capabilities: Default::default(),
106 invitee: None,
107 sdp_stream_metadata: Default::default(),
108 }
109 }
110}