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`
* Remove `PartialEq` implementation on `NotificationPowerLevels`
* Remove `PartialEq` implementation for `events::call::SessionDescription`
* Split `events::call::SessionDescription` into `AnswerSessionDescription`
and `OfferSessionDescription`
* Remove `SessionDescriptionType`
Improvements:

View File

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

View File

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

View File

@ -6,7 +6,7 @@ use js_int::UInt;
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::SessionDescription;
use super::OfferSessionDescription;
/// The content of an `m.call.invite` event.
///
@ -25,9 +25,7 @@ pub struct CallInviteEventContent {
pub lifetime: UInt,
/// The session description object.
///
/// The session description type must be *offer*.
pub offer: SessionDescription,
pub offer: OfferSessionDescription,
/// The version of the VoIP specification this messages adheres to.
pub version: UInt,
@ -35,7 +33,12 @@ pub struct CallInviteEventContent {
impl CallInviteEventContent {
/// 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 }
}
}

View File

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

View File

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