use std::collections::BTreeMap;
use js_int::UInt;
use ruma_common::{OwnedUserId, OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-msc2747")]
use super::CallCapabilities;
use super::{SessionDescription, StreamMetadata};
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
#[ruma_event(type = "m.call.invite", kind = MessageLike)]
pub struct CallInviteEventContent {
pub call_id: OwnedVoipId,
#[serde(skip_serializing_if = "Option::is_none")]
pub party_id: Option<OwnedVoipId>,
pub lifetime: UInt,
pub offer: SessionDescription,
pub version: VoipVersionId,
#[cfg(feature = "unstable-msc2747")]
#[serde(default, skip_serializing_if = "CallCapabilities::is_default")]
pub capabilities: CallCapabilities,
#[serde(skip_serializing_if = "Option::is_none")]
pub invitee: Option<OwnedUserId>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub sdp_stream_metadata: BTreeMap<String, StreamMetadata>,
}
impl CallInviteEventContent {
pub fn new(
call_id: OwnedVoipId,
lifetime: UInt,
offer: SessionDescription,
version: VoipVersionId,
) -> Self {
Self {
call_id,
party_id: None,
lifetime,
offer,
version,
#[cfg(feature = "unstable-msc2747")]
capabilities: Default::default(),
invitee: None,
sdp_stream_metadata: Default::default(),
}
}
pub fn version_0(call_id: OwnedVoipId, lifetime: UInt, offer: SessionDescription) -> Self {
Self::new(call_id, lifetime, offer, VoipVersionId::V0)
}
pub fn version_1(
call_id: OwnedVoipId,
party_id: OwnedVoipId,
lifetime: UInt,
offer: SessionDescription,
) -> Self {
Self {
call_id,
party_id: Some(party_id),
lifetime,
offer,
version: VoipVersionId::V1,
#[cfg(feature = "unstable-msc2747")]
capabilities: Default::default(),
invitee: None,
sdp_stream_metadata: Default::default(),
}
}
}