events: Split SessionDescription between Answer and Offer

This commit is contained in:
Kévin Commaille 2022-05-24 14:40:30 +02:00 committed by GitHub
parent baa6dc591e
commit 1c90770d93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 52 deletions

View File

@ -5,6 +5,9 @@ Breaking changes:
* Add `user_id` field to `PushConditionRoomCtx` * Add `user_id` field to `PushConditionRoomCtx`
* Remove `PartialEq` implementation on `NotificationPowerLevels` * Remove `PartialEq` implementation on `NotificationPowerLevels`
* Remove `PartialEq` implementation for `events::call::SessionDescription` * Remove `PartialEq` implementation for `events::call::SessionDescription`
* Split `events::call::SessionDescription` into `AnswerSessionDescription`
and `OfferSessionDescription`
* Remove `SessionDescriptionType`
Improvements: Improvements:

View File

@ -2,53 +2,41 @@
//! //!
//! This module also contains types shared by events in its child namespaces. //! This module also contains types shared by events in its child namespaces.
use serde::{Deserialize, Serialize};
use crate::{serde::StringEnum, PrivOwnedStr};
pub mod answer; pub mod answer;
pub mod candidates; pub mod candidates;
pub mod hangup; pub mod hangup;
pub mod invite; pub mod invite;
/// A VoIP session description. use serde::{Deserialize, Serialize};
/// A VoIP answer session description.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct SessionDescription { #[serde(tag = "type", rename = "answer")]
/// The type of session description. pub struct AnswerSessionDescription {
#[serde(rename = "type")]
pub session_type: SessionDescriptionType,
/// The SDP text of the session description. /// The SDP text of the session description.
pub sdp: String, pub sdp: String,
} }
impl SessionDescription { impl AnswerSessionDescription {
/// Creates a new `SessionDescription` with the given session type and SDP text. /// Creates a new `AnswerSessionDescription` with the given SDP text.
pub fn new(session_type: SessionDescriptionType, sdp: String) -> Self { pub fn new(sdp: String) -> Self {
Self { session_type, sdp } Self { sdp }
} }
} }
/// The type of VoIP session description. /// A VoIP offer session description.
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))] #[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_enum(rename_all = "snake_case")] #[serde(tag = "type", rename = "offer")]
#[non_exhaustive] pub struct OfferSessionDescription {
pub enum SessionDescriptionType { /// The SDP text of the session description.
/// An answer. pub sdp: String,
Answer,
/// An offer.
Offer,
#[doc(hidden)]
_Custom(PrivOwnedStr),
} }
impl SessionDescriptionType { impl OfferSessionDescription {
/// Creates a string slice from this `SessionDescriptionType`. /// Creates a new `OfferSessionDescription` with the given SDP text.
pub fn as_str(&self) -> &str { pub fn new(sdp: String) -> Self {
self.as_ref() Self { sdp }
} }
} }

View File

@ -6,7 +6,7 @@ use js_int::UInt;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::SessionDescription; use super::AnswerSessionDescription;
/// The content of an `m.call.answer` event. /// The content of an `m.call.answer` event.
/// ///
@ -16,9 +16,7 @@ use super::SessionDescription;
#[ruma_event(type = "m.call.answer", kind = MessageLike)] #[ruma_event(type = "m.call.answer", kind = MessageLike)]
pub struct CallAnswerEventContent { pub struct CallAnswerEventContent {
/// The VoIP session description object. /// The VoIP session description object.
/// pub answer: AnswerSessionDescription,
/// The session description type must be *answer*.
pub answer: SessionDescription,
/// The ID of the call this event relates to. /// The ID of the call this event relates to.
pub call_id: String, pub call_id: String,
@ -29,7 +27,7 @@ pub struct CallAnswerEventContent {
impl CallAnswerEventContent { impl CallAnswerEventContent {
/// Creates an `AnswerEventContent` with the given answer, call ID and VoIP version. /// Creates an `AnswerEventContent` with the given answer, call ID and VoIP version.
pub fn new(answer: SessionDescription, call_id: String, version: UInt) -> Self { pub fn new(answer: AnswerSessionDescription, call_id: String, version: UInt) -> Self {
Self { answer, call_id, version } Self { answer, call_id, version }
} }
} }

View File

@ -6,7 +6,7 @@ use js_int::UInt;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::SessionDescription; use super::OfferSessionDescription;
/// The content of an `m.call.invite` event. /// The content of an `m.call.invite` event.
/// ///
@ -25,9 +25,7 @@ pub struct CallInviteEventContent {
pub lifetime: UInt, pub lifetime: UInt,
/// The session description object. /// The session description object.
/// pub offer: OfferSessionDescription,
/// The session description type must be *offer*.
pub offer: SessionDescription,
/// The version of the VoIP specification this messages adheres to. /// The version of the VoIP specification this messages adheres to.
pub version: UInt, pub version: UInt,
@ -35,7 +33,12 @@ pub struct CallInviteEventContent {
impl CallInviteEventContent { impl CallInviteEventContent {
/// Creates a new `InviteEventContent` with the given call ID, lifetime and VoIP version. /// Creates a new `InviteEventContent` with the given call ID, lifetime and VoIP version.
pub fn new(call_id: String, lifetime: UInt, offer: SessionDescription, version: UInt) -> Self { pub fn new(
call_id: String,
lifetime: UInt,
offer: OfferSessionDescription,
version: UInt,
) -> Self {
Self { call_id, lifetime, offer, version } Self { call_id, lifetime, offer, version }
} }
} }

View File

@ -6,7 +6,7 @@ use ruma_common::{
use serde_json::{from_value as from_json_value, json}; use serde_json::{from_value as from_json_value, json};
use ruma_common::events::{ use ruma_common::events::{
call::{answer::CallAnswerEventContent, SessionDescription, SessionDescriptionType}, call::{answer::CallAnswerEventContent, AnswerSessionDescription},
AnyMessageLikeEvent, OriginalMessageLikeEvent, AnyMessageLikeEvent, OriginalMessageLikeEvent,
}; };
@ -41,8 +41,7 @@ fn deserialize_message_event() {
.unwrap(), .unwrap(),
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(OriginalMessageLikeEvent { AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(OriginalMessageLikeEvent {
content: CallAnswerEventContent { content: CallAnswerEventContent {
answer: SessionDescription { answer: AnswerSessionDescription {
session_type: SessionDescriptionType::Answer,
sdp, sdp,
.. ..
}, },

View File

@ -4,7 +4,7 @@ use matches::assert_matches;
use ruma_common::{ use ruma_common::{
event_id, event_id,
events::{ events::{
call::{answer::CallAnswerEventContent, SessionDescription, SessionDescriptionType}, call::{answer::CallAnswerEventContent, AnswerSessionDescription},
room::{ImageInfo, MediaSource, ThumbnailInfo}, room::{ImageInfo, MediaSource, ThumbnailInfo},
sticker::StickerEventContent, sticker::StickerEventContent,
AnyMessageLikeEvent, AnyMessageLikeEventContent, AnySyncMessageLikeEvent, MessageLikeEvent, AnyMessageLikeEvent, AnyMessageLikeEventContent, AnySyncMessageLikeEvent, MessageLikeEvent,
@ -136,8 +136,7 @@ fn deserialize_message_call_answer_content() {
.deserialize_content(MessageLikeEventType::CallAnswer) .deserialize_content(MessageLikeEventType::CallAnswer)
.unwrap(), .unwrap(),
AnyMessageLikeEventContent::CallAnswer(CallAnswerEventContent { AnyMessageLikeEventContent::CallAnswer(CallAnswerEventContent {
answer: SessionDescription { answer: AnswerSessionDescription {
session_type: SessionDescriptionType::Answer,
sdp, sdp,
.. ..
}, },
@ -170,8 +169,7 @@ fn deserialize_message_call_answer() {
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(), from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(OriginalMessageLikeEvent { AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(OriginalMessageLikeEvent {
content: CallAnswerEventContent { content: CallAnswerEventContent {
answer: SessionDescription { answer: AnswerSessionDescription {
session_type: SessionDescriptionType::Answer,
sdp, sdp,
.. ..
}, },
@ -296,8 +294,7 @@ fn deserialize_message_then_convert_to_full() {
sync_ev.into_full_event(rid.to_owned()), sync_ev.into_full_event(rid.to_owned()),
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(OriginalMessageLikeEvent { AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(OriginalMessageLikeEvent {
content: CallAnswerEventContent { content: CallAnswerEventContent {
answer: SessionDescription { answer: AnswerSessionDescription {
session_type: SessionDescriptionType::Answer,
sdp, sdp,
.. ..
}, },