use js_int::UInt;
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
#[ruma_event(type = "m.call.candidates", kind = MessageLike)]
pub struct CallCandidatesEventContent {
pub call_id: OwnedVoipId,
#[serde(skip_serializing_if = "Option::is_none")]
pub party_id: Option<OwnedVoipId>,
pub candidates: Vec<Candidate>,
pub version: VoipVersionId,
}
impl CallCandidatesEventContent {
pub fn new(call_id: OwnedVoipId, candidates: Vec<Candidate>, version: VoipVersionId) -> Self {
Self { call_id, candidates, version, party_id: None }
}
pub fn version_0(call_id: OwnedVoipId, candidates: Vec<Candidate>) -> Self {
Self::new(call_id, candidates, VoipVersionId::V0)
}
pub fn version_1(
call_id: OwnedVoipId,
party_id: OwnedVoipId,
candidates: Vec<Candidate>,
) -> Self {
Self { call_id, party_id: Some(party_id), candidates, version: VoipVersionId::V1 }
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
#[serde(rename_all = "camelCase")]
pub struct Candidate {
pub candidate: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub sdp_mid: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sdp_m_line_index: Option<UInt>,
}
impl Candidate {
pub fn new(candidate: String) -> Self {
Self { candidate, sdp_mid: None, sdp_m_line_index: None }
}
pub fn version_0(candidate: String, sdp_mid: String, sdp_m_line_index: UInt) -> Self {
Self { candidate, sdp_mid: Some(sdp_mid), sdp_m_line_index: Some(sdp_m_line_index) }
}
}