events: Stabilize VoIP signalling improvements

This commit is contained in:
Kévin Commaille 2023-05-26 12:28:57 +02:00 committed by Kévin Commaille
parent a2b64c20bc
commit 07ea09548f
14 changed files with 440 additions and 536 deletions

View File

@ -18,6 +18,8 @@ Breaking changes:
- Remove `SessionDescriptionType`, use a `String` instead. A clarification in MSC2746 / Matrix 1.7
explains that the `type` field should not be validated but passed as-is to the WebRTC API. It
also avoids an unnecessary conversion between the WebRTC API and the Ruma type.
- The `reason` field in `CallHangupEventContent` is now required an defaults to `Reason::UserHangup`
(MSC2746 / Matrix 1.7)
Improvements:
@ -43,6 +45,7 @@ Improvements:
- Add `MatrixVersion::V1_7`
- Stabilize support for annotations and reactions (MSC2677 / Matrix 1.7)
- Add support for intentional mentions push rules (MSC3952 / Matrix 1.7)
- Stabilize support for VoIP signalling improvements (MSC2746 / Matrix 1.7)
# 0.11.3

View File

@ -30,7 +30,6 @@ rand = ["dep:rand", "dep:uuid"]
unstable-exhaustive-types = []
unstable-msc1767 = []
unstable-msc2448 = []
unstable-msc2746 = []
unstable-msc2747 = []
unstable-msc2870 = []
unstable-msc3245 = ["unstable-msc3246"]

View File

@ -6,11 +6,8 @@ pub mod answer;
pub mod candidates;
pub mod hangup;
pub mod invite;
#[cfg(feature = "unstable-msc2746")]
pub mod negotiate;
#[cfg(feature = "unstable-msc2746")]
pub mod reject;
#[cfg(feature = "unstable-msc2746")]
pub mod select_answer;
use serde::{Deserialize, Serialize};
@ -31,9 +28,8 @@ pub struct SessionDescription {
/// The SDP text of the session description.
///
/// With the `unstable-msc2746` feature, this field is unused if the type is `rollback` and
/// defaults to an empty string.
#[cfg_attr(feature = "unstable-msc2746", serde(default))]
/// Defaults to an empty string.
#[serde(default)]
pub sdp: String,
}

View File

@ -23,7 +23,6 @@ pub struct CallAnswerEventContent {
/// A unique identifier for the call.
pub call_id: OwnedVoipId,
#[cfg(feature = "unstable-msc2746")]
/// **Required in VoIP version 1.** A unique ID for this session for the duration of the call.
#[serde(skip_serializing_if = "Option::is_none")]
pub party_id: Option<OwnedVoipId>,
@ -43,7 +42,6 @@ impl CallAnswerEventContent {
Self {
answer,
call_id,
#[cfg(feature = "unstable-msc2746")]
party_id: None,
version,
#[cfg(feature = "unstable-msc2747")]
@ -59,7 +57,6 @@ impl CallAnswerEventContent {
/// Convenience method to create a VoIP version 1 `CallAnswerEventContent` with all the required
/// fields.
#[cfg(feature = "unstable-msc2746")]
pub fn version_1(
answer: SessionDescription,
call_id: OwnedVoipId,

View File

@ -19,7 +19,6 @@ pub struct CallCandidatesEventContent {
/// A unique identifier for the call.
pub call_id: OwnedVoipId,
#[cfg(feature = "unstable-msc2746")]
/// **Required in VoIP version 1.** The unique ID for this session for the duration of the
/// call.
///
@ -30,8 +29,8 @@ pub struct CallCandidatesEventContent {
/// A list of candidates.
///
/// With the `unstable-msc2746` feature, in VoIP version 1, this list should end with a
/// `Candidate` with an empty `candidate` field when no more candidates will be sent.
/// In VoIP version 1, this list should end with a `Candidate` with an empty `candidate` field
/// when no more candidates will be sent.
pub candidates: Vec<Candidate>,
/// The version of the VoIP specification this messages adheres to.
@ -42,13 +41,7 @@ impl CallCandidatesEventContent {
/// Creates a new `CallCandidatesEventContent` with the given call id, candidate list and VoIP
/// version.
pub fn new(call_id: OwnedVoipId, candidates: Vec<Candidate>, version: VoipVersionId) -> Self {
Self {
call_id,
candidates,
version,
#[cfg(feature = "unstable-msc2746")]
party_id: None,
}
Self { call_id, candidates, version, party_id: None }
}
/// Convenience method to create a VoIP version 0 `CallCandidatesEventContent` with all the
@ -59,7 +52,6 @@ impl CallCandidatesEventContent {
/// Convenience method to create a VoIP version 1 `CallCandidatesEventContent` with all the
/// required fields.
#[cfg(feature = "unstable-msc2746")]
pub fn version_1(
call_id: OwnedVoipId,
party_id: OwnedVoipId,

View File

@ -3,8 +3,6 @@
//! [`m.call.hangup`]: https://spec.matrix.org/latest/client-server-api/#mcallhangup
use ruma_macros::EventContent;
#[cfg(feature = "unstable-msc2746")]
use serde::Serializer;
use serde::{Deserialize, Serialize};
use crate::{serde::StringEnum, OwnedVoipId, PrivOwnedStr, VoipVersionId};
@ -16,9 +14,9 @@ use crate::{serde::StringEnum, OwnedVoipId, PrivOwnedStr, VoipVersionId};
/// In VoIP version 0, this can be sent either once the call has been established or before to abort
/// the call.
///
/// With the `unstable-msc2746` feature, and if the call is using VoIP version 1, this should only
/// be sent by the caller after sending the invite or by the callee after answering the invite. To
/// reject an invite, send an [`m.call.reject`] event.
/// If the call is using VoIP version 1, this should only be sent by the caller after sending the
/// invite or by the callee after answering the invite. To reject an invite, send an
/// [`m.call.reject`] event.
///
/// [`m.call.reject`]: super::reject::CallRejectEventContent
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
@ -28,7 +26,6 @@ pub struct CallHangupEventContent {
/// A unique identifier for the call.
pub call_id: OwnedVoipId,
#[cfg(feature = "unstable-msc2746")]
/// **Required in VoIP version 1.** A unique ID for this session for the duration of the call.
///
/// Must be the same as the one sent by the previous invite or answer from
@ -39,30 +36,17 @@ pub struct CallHangupEventContent {
/// The version of the VoIP specification this messages adheres to.
pub version: VoipVersionId,
/// Optional error reason for the hangup.
/// Error reason for the hangup.
///
/// With the `unstable-msc2746` feature, this field defaults to `Some(Reason::UserHangup)`.
#[cfg_attr(not(feature = "unstable-msc2746"), serde(skip_serializing_if = "Option::is_none"))]
#[cfg_attr(
feature = "unstable-msc2746",
serde(
default = "Reason::option_with_default",
serialize_with = "Reason::serialize_option_with_default"
)
)]
pub reason: Option<Reason>,
/// Defaults to `Reason::UserHangup`.
#[serde(default)]
pub reason: Reason,
}
impl CallHangupEventContent {
/// Creates a new `CallHangupEventContent` with the given call ID and VoIP version.
pub fn new(call_id: OwnedVoipId, version: VoipVersionId) -> Self {
Self {
call_id,
#[cfg(feature = "unstable-msc2746")]
party_id: None,
version,
reason: Default::default(),
}
Self { call_id, party_id: None, version, reason: Default::default() }
}
/// Convenience method to create a VoIP version 0 `CallHangupEventContent` with all the required
@ -73,9 +57,8 @@ impl CallHangupEventContent {
/// Convenience method to create a VoIP version 1 `CallHangupEventContent` with all the required
/// fields.
#[cfg(feature = "unstable-msc2746")]
pub fn version_1(call_id: OwnedVoipId, party_id: OwnedVoipId, reason: Reason) -> Self {
Self { call_id, party_id: Some(party_id), version: VoipVersionId::V1, reason: Some(reason) }
Self { call_id, party_id: Some(party_id), version: VoipVersionId::V1, reason }
}
}
@ -85,8 +68,7 @@ impl CallHangupEventContent {
/// in the call negotiation, this should be `ice_failed` for when ICE negotiation fails or
/// `invite_timeout` for when the other party did not answer in time.
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, PartialEq, Eq, StringEnum)]
#[cfg_attr(feature = "unstable-msc2746", derive(Default))]
#[derive(Clone, Default, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Reason {
@ -101,50 +83,23 @@ pub enum Reason {
/// Note that, in the case of an ICE renegotiation, a client should be sure to send
/// `ice_timeout` rather than `ice_failed` if media had previously been received successfully,
/// even if the ICE renegotiation itself failed.
#[cfg(feature = "unstable-msc2746")]
IceTimeout,
/// The user chose to end the call.
#[cfg(feature = "unstable-msc2746")]
#[default]
UserHangup,
/// The client was unable to start capturing media in such a way as it is unable to continue
/// the call.
#[cfg(feature = "unstable-msc2746")]
UserMediaFailed,
/// The user is busy.
#[cfg(feature = "unstable-msc2746")]
UserBusy,
/// Some other failure occurred that meant the client was unable to continue the call rather
/// than the user choosing to end it.
#[cfg(feature = "unstable-msc2746")]
UnknownError,
#[doc(hidden)]
_Custom(PrivOwnedStr),
}
impl Reason {
#[cfg(feature = "unstable-msc2746")]
fn serialize_option_with_default<S>(
reason: &Option<Reason>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if let Some(reason) = &reason {
reason.serialize(serializer)
} else {
Self::default().serialize(serializer)
}
}
#[cfg(feature = "unstable-msc2746")]
fn option_with_default() -> Option<Self> {
Some(Self::default())
}
}

View File

@ -9,9 +9,7 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-msc2747")]
use super::CallCapabilities;
use super::SessionDescription;
#[cfg(feature = "unstable-msc2746")]
use crate::OwnedUserId;
use crate::{OwnedVoipId, VoipVersionId};
use crate::{OwnedUserId, OwnedVoipId, VoipVersionId};
/// The content of an `m.call.invite` event.
///
@ -23,7 +21,6 @@ pub struct CallInviteEventContent {
/// A unique identifier for the call.
pub call_id: OwnedVoipId,
#[cfg(feature = "unstable-msc2746")]
/// **Required in VoIP version 1.** A unique ID for this session for the duration of the call.
#[serde(skip_serializing_if = "Option::is_none")]
pub party_id: Option<OwnedVoipId>,
@ -45,7 +42,6 @@ pub struct CallInviteEventContent {
#[serde(default, skip_serializing_if = "CallCapabilities::is_default")]
pub capabilities: CallCapabilities,
#[cfg(feature = "unstable-msc2746")]
/// **Added in VoIP version 1.** The intended target of the invite, if any.
///
/// If this is `None`, the invite is intended for any member of the room, except the sender.
@ -66,14 +62,12 @@ impl CallInviteEventContent {
) -> Self {
Self {
call_id,
#[cfg(feature = "unstable-msc2746")]
party_id: None,
lifetime,
offer,
version,
#[cfg(feature = "unstable-msc2747")]
capabilities: Default::default(),
#[cfg(feature = "unstable-msc2746")]
invitee: None,
}
}
@ -86,7 +80,6 @@ impl CallInviteEventContent {
/// Convenience method to create a version 1 `CallInviteEventContent` with all the required
/// fields.
#[cfg(feature = "unstable-msc2746")]
pub fn version_1(
call_id: OwnedVoipId,
party_id: OwnedVoipId,

View File

@ -1,6 +1,6 @@
//! Types for the `m.call.negotiate` event [MSC2746].
//! Types for the [`m.call.negotiate`] event.
//!
//! [MSC2746]: https://github.com/matrix-org/matrix-spec-proposals/pull/2746
//! [`m.call.negotiate`]: https://spec.matrix.org/latest/client-server-api/#mcallnegotiate
use js_int::UInt;
use ruma_macros::EventContent;

View File

@ -1,6 +1,6 @@
//! Types for the `m.call.reject` event [MSC2746].
//! Types for the [`m.call.reject`] event.
//!
//! [MSC2746]: https://github.com/matrix-org/matrix-spec-proposals/pull/2746
//! [`m.call.reject`]: https://spec.matrix.org/latest/client-server-api/#mcallreject
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};

View File

@ -1,6 +1,6 @@
//! Types for the `m.call.select_answer` event [MSC2746].
//! Types for the [`m.call.select_answer`] event.
//!
//! [MSC2746]: https://github.com/matrix-org/matrix-spec-proposals/pull/2746
//! [`m.call.select_answer`]: https://spec.matrix.org/latest/client-server-api/#mcallselect_answer
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};

View File

@ -40,11 +40,8 @@ event_enum! {
"m.call.invite" => super::call::invite,
"m.call.hangup" => super::call::hangup,
"m.call.candidates" => super::call::candidates,
#[cfg(feature = "unstable-msc2746")]
"m.call.negotiate" => super::call::negotiate,
#[cfg(feature = "unstable-msc2746")]
"m.call.reject" => super::call::reject,
#[cfg(feature = "unstable-msc2746")]
"m.call.select_answer" => super::call::select_answer,
#[cfg(feature = "unstable-msc3954")]
#[ruma_enum(alias = "m.emote")]
@ -340,9 +337,10 @@ impl AnyMessageLikeEventContent {
}
#[cfg(feature = "unstable-msc3381")]
Self::PollStart(_) => None,
#[cfg(feature = "unstable-msc2746")]
Self::CallNegotiate(_) | Self::CallReject(_) | Self::CallSelectAnswer(_) => None,
Self::CallAnswer(_)
Self::CallNegotiate(_)
| Self::CallReject(_)
| Self::CallSelectAnswer(_)
| Self::CallAnswer(_)
| Self::CallInvite(_)
| Self::CallHangup(_)
| Self::CallCandidates(_)

View File

@ -34,7 +34,6 @@ pub enum VoipVersionId {
V0,
/// A version 1 VoIP call.
#[cfg(feature = "unstable-msc2746")]
V1,
#[doc(hidden)]
@ -46,7 +45,6 @@ impl VoipVersionId {
pub fn as_str(&self) -> &str {
match &self {
Self::V0 => "0",
#[cfg(feature = "unstable-msc2746")]
Self::V1 => "1",
Self::_Custom(PrivOwnedStr(s)) => s,
}
@ -133,7 +131,6 @@ where
T: AsRef<str> + Into<Box<str>>,
{
match s.as_ref() {
#[cfg(feature = "unstable-msc2746")]
"1" => VoipVersionId::V1,
_ => VoipVersionId::_Custom(PrivOwnedStr(s.into())),
}
@ -174,7 +171,6 @@ mod tests {
}
#[test]
#[cfg(feature = "unstable-msc2746")]
fn valid_version_1() {
assert_eq!(VoipVersionId::try_from("1"), Ok(VoipVersionId::V1));
}
@ -199,13 +195,11 @@ mod tests {
}
#[test]
#[cfg(feature = "unstable-msc2746")]
fn serialize_version_1() {
assert_eq!(to_json_value(&VoipVersionId::V1).unwrap(), json!("1"));
}
#[test]
#[cfg(feature = "unstable-msc2746")]
fn deserialize_version_1() {
assert_eq!(from_json_value::<VoipVersionId>(json!("1")).unwrap(), VoipVersionId::V1);
}

View File

@ -1,13 +1,19 @@
use assert_matches::assert_matches;
#[cfg(feature = "unstable-msc2747")]
use assign::assign;
use js_int::uint;
#[cfg(feature = "unstable-msc2747")]
use ruma_common::events::call::CallCapabilities;
use ruma_common::{
events::{
call::{
answer::CallAnswerEventContent,
candidates::{CallCandidatesEventContent, Candidate},
hangup::CallHangupEventContent,
hangup::{CallHangupEventContent, Reason},
invite::CallInviteEventContent,
negotiate::CallNegotiateEventContent,
reject::CallRejectEventContent,
select_answer::CallSelectAnswerEventContent,
SessionDescription,
},
AnyMessageLikeEvent, AnySyncMessageLikeEvent, MessageLikeEvent,
@ -19,7 +25,7 @@ use ruma_common::{
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
#[test]
fn answer_content_serialization() {
fn answer_v0_content_serialization() {
let event_content = CallAnswerEventContent::version_0(
SessionDescription::new("answer".to_owned(), "not a real sdp".to_owned()),
"abcdef".into(),
@ -39,7 +45,7 @@ fn answer_content_serialization() {
}
#[test]
fn answer_content_deserialization() {
fn answer_v0_content_deserialization() {
let json_data = json!({
"answer": {
"type": "answer",
@ -58,7 +64,7 @@ fn answer_content_deserialization() {
}
#[test]
fn answer_event_deserialization() {
fn answer_v0_event_deserialization() {
let json_data = json!({
"content": {
"answer": {
@ -93,7 +99,7 @@ fn answer_event_deserialization() {
}
#[test]
fn answer_event_deserialization_then_convert_to_full() {
fn answer_v0_event_deserialization_then_convert_to_full() {
let rid = room_id!("!roomid:room.com");
let json_data = json!({
"content": {
@ -129,7 +135,7 @@ fn answer_event_deserialization_then_convert_to_full() {
}
#[test]
fn invite_content_serialization() {
fn invite_v0_content_serialization() {
let event_content = CallInviteEventContent::version_0(
"abcdef".into(),
uint!(30000),
@ -151,7 +157,7 @@ fn invite_content_serialization() {
}
#[test]
fn candidates_content_serialization() {
fn candidates_v0_content_serialization() {
let event_content = CallCandidatesEventContent::version_0(
"abcdef".into(),
vec![Candidate::new("not a real candidate".to_owned(), "0".to_owned(), uint!(0))],
@ -174,7 +180,7 @@ fn candidates_content_serialization() {
}
#[test]
fn hangup_content_serialization() {
fn hangup_v0_content_serialization() {
let event_content = CallHangupEventContent::version_0("abcdef".into());
assert_eq!(
@ -187,439 +193,412 @@ fn hangup_content_serialization() {
);
}
#[cfg(feature = "unstable-msc2746")]
mod msc2746 {
use assert_matches::assert_matches;
#[cfg(feature = "unstable-msc2747")]
use assign::assign;
use js_int::uint;
#[cfg(feature = "unstable-msc2747")]
use ruma_common::events::call::CallCapabilities;
use ruma_common::{
events::{
call::{
answer::CallAnswerEventContent,
candidates::{CallCandidatesEventContent, Candidate},
hangup::{CallHangupEventContent, Reason},
invite::CallInviteEventContent,
negotiate::CallNegotiateEventContent,
reject::CallRejectEventContent,
select_answer::CallSelectAnswerEventContent,
SessionDescription,
#[test]
fn invite_v1_event_serialization() {
let content = CallInviteEventContent::version_1(
"abcdef".into(),
"9876".into(),
uint!(60000),
SessionDescription::new("offer".to_owned(), "not a real sdp".to_owned()),
);
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"lifetime": 60000,
"version": "1",
"offer": {
"type": "offer",
"sdp": "not a real sdp",
},
})
);
}
#[test]
fn invite_v1_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"lifetime": 60000,
"version": "1",
"offer": {
"type": "offer",
"sdp": "not a real sdp",
},
AnyMessageLikeEvent, MessageLikeEvent,
},
VoipVersionId,
};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.invite",
});
#[test]
fn invite_event_serialization() {
let content = CallInviteEventContent::version_1(
"abcdef".into(),
"9876".into(),
uint!(60000),
SessionDescription::new("offer".to_owned(), "not a real sdp".to_owned()),
);
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallInvite(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id.unwrap(), "9876");
assert_eq!(content.lifetime, uint!(60000));
assert_eq!(content.version, VoipVersionId::V1);
assert_eq!(content.offer.session_type, "offer");
assert_eq!(content.offer.sdp, "not a real sdp");
}
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"lifetime": 60000,
"version": "1",
"offer": {
"type": "offer",
"sdp": "not a real sdp",
},
})
);
}
#[test]
fn answer_v1_event_serialization() {
let content = CallAnswerEventContent::version_1(
SessionDescription::new("answer".to_owned(), "not a real sdp".to_owned()),
"abcdef".into(),
"9876".into(),
);
#[test]
fn invite_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"lifetime": 60000,
"version": "1",
"offer": {
"type": "offer",
"sdp": "not a real sdp",
},
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"answer": {
"type": "answer",
"sdp": "not a real sdp",
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.invite",
});
})
);
}
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallInvite(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id.unwrap(), "9876");
assert_eq!(content.lifetime, uint!(60000));
assert_eq!(content.version, VoipVersionId::V1);
assert_eq!(content.offer.session_type, "offer");
assert_eq!(content.offer.sdp, "not a real sdp");
}
#[test]
fn answer_event_serialization() {
let content = CallAnswerEventContent::version_1(
#[cfg(feature = "unstable-msc2747")]
#[test]
fn answer_v1_event_capabilities_serialization() {
let content = assign!(
CallAnswerEventContent::version_1(
SessionDescription::new("answer".to_owned(), "not a real sdp".to_owned()),
"abcdef".into(),
"9876".into(),
);
"9876".into()
),
{
capabilities: assign!(CallCapabilities::new(), { dtmf: true }),
}
);
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"answer": {
"type": "answer",
"sdp": "not a real sdp",
},
})
);
}
#[cfg(feature = "unstable-msc2747")]
#[test]
fn answer_event_capabilities_serialization() {
let content = assign!(
CallAnswerEventContent::version_1(
SessionDescription::new("answer".to_owned(), "not a real sdp".to_owned()),
"abcdef".into(),
"9876".into()
),
{
capabilities: assign!(CallCapabilities::new(), { dtmf: true }),
}
);
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"answer": {
"type": "answer",
"sdp": "not a real sdp",
},
"capabilities": {
"m.call.dtmf": true,
},
})
);
}
#[test]
fn answer_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"version": "org.matrix.1b",
"answer": {
"type": "answer",
"sdp": "not a real sdp",
},
"capabilities": {
"m.call.dtmf": true,
},
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"answer": {
"type": "answer",
"sdp": "not a real sdp",
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.answer",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id.unwrap(), "9876");
assert_eq!(content.version.as_ref(), "org.matrix.1b");
assert_eq!(content.answer.session_type, "answer");
assert_eq!(content.answer.sdp, "not a real sdp");
#[cfg(feature = "unstable-msc2747")]
assert!(content.capabilities.dtmf);
}
#[test]
fn candidates_event_serialization() {
let content = CallCandidatesEventContent::version_1(
"abcdef".into(),
"9876".into(),
vec![
Candidate::new("not a real candidate".to_owned(), "0".to_owned(), uint!(0)),
Candidate::new("another fake candidate".to_owned(), "0".to_owned(), uint!(1)),
],
);
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"candidates": [
{
"candidate": "not a real candidate",
"sdpMid": "0",
"sdpMLineIndex": 0,
},
{
"candidate": "another fake candidate",
"sdpMid": "0",
"sdpMLineIndex": 1,
},
],
})
);
}
#[test]
fn candidates_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"candidates": [
{
"candidate": "not a real candidate",
"sdpMid": "0",
"sdpMLineIndex": 0,
},
{
"candidate": "another fake candidate",
"sdpMid": "0",
"sdpMLineIndex": 1,
},
],
"capabilities": {
"m.call.dtmf": true,
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.candidates",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallCandidates(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id.unwrap(), "9876");
assert_eq!(content.version, VoipVersionId::V1);
assert_eq!(content.candidates.len(), 2);
assert_eq!(content.candidates[0].candidate, "not a real candidate");
assert_eq!(content.candidates[0].sdp_mid, "0");
assert_eq!(content.candidates[0].sdp_m_line_index, uint!(0));
assert_eq!(content.candidates[1].candidate, "another fake candidate");
assert_eq!(content.candidates[1].sdp_mid, "0");
assert_eq!(content.candidates[1].sdp_m_line_index, uint!(1));
}
#[test]
fn hangup_event_serialization() {
let content =
CallHangupEventContent::version_1("abcdef".into(), "9876".into(), Reason::IceFailed);
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"reason": "ice_failed",
})
);
}
#[test]
fn hangup_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.hangup",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallHangup(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id.unwrap(), "9876");
assert_eq!(content.version, VoipVersionId::V1);
assert_eq!(content.reason, Some(Reason::UserHangup));
}
#[test]
fn negotiate_event_serialization() {
let content = CallNegotiateEventContent::version_1(
"abcdef".into(),
"9876".into(),
uint!(30000),
SessionDescription::new("offer".to_owned(), "not a real sdp".to_owned()),
);
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"lifetime": 30000,
"description": {
"type": "offer",
"sdp": "not a real sdp",
},
})
);
}
#[test]
fn negotiate_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"lifetime": 30000,
"description": {
"type": "answer",
"sdp": "not a real sdp",
}
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.negotiate",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallNegotiate(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id, "9876");
assert_eq!(content.lifetime, uint!(30000));
assert_eq!(content.description.session_type, "answer");
assert_eq!(content.description.sdp, "not a real sdp");
}
#[test]
fn reject_event_serialization() {
let content = CallRejectEventContent::version_1("abcdef".into(), "9876".into());
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
})
);
}
#[test]
fn reject_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.reject",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallReject(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id, "9876");
assert_eq!(content.version, VoipVersionId::V1);
}
#[test]
fn select_answer_event_serialization() {
let content =
CallSelectAnswerEventContent::version_1("abcdef".into(), "9876".into(), "6336".into());
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"selected_party_id": "6336",
"version": "1",
})
);
}
#[test]
fn select_answer_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"selected_party_id": "6336",
"version": "1",
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.select_answer",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallSelectAnswer(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id, "9876");
assert_eq!(content.selected_party_id, "6336");
assert_eq!(content.version, VoipVersionId::V1);
}
})
);
}
#[test]
fn answer_unknown_version_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"version": "org.matrix.1b",
"answer": {
"type": "answer",
"sdp": "not a real sdp",
},
"capabilities": {
"m.call.dtmf": true,
},
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.answer",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id.unwrap(), "9876");
assert_eq!(content.version.as_ref(), "org.matrix.1b");
assert_eq!(content.answer.session_type, "answer");
assert_eq!(content.answer.sdp, "not a real sdp");
#[cfg(feature = "unstable-msc2747")]
assert!(content.capabilities.dtmf);
}
#[test]
fn candidates_v1_event_serialization() {
let content = CallCandidatesEventContent::version_1(
"abcdef".into(),
"9876".into(),
vec![
Candidate::new("not a real candidate".to_owned(), "0".to_owned(), uint!(0)),
Candidate::new("another fake candidate".to_owned(), "0".to_owned(), uint!(1)),
],
);
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"candidates": [
{
"candidate": "not a real candidate",
"sdpMid": "0",
"sdpMLineIndex": 0,
},
{
"candidate": "another fake candidate",
"sdpMid": "0",
"sdpMLineIndex": 1,
},
],
})
);
}
#[test]
fn candidates_v1_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"candidates": [
{
"candidate": "not a real candidate",
"sdpMid": "0",
"sdpMLineIndex": 0,
},
{
"candidate": "another fake candidate",
"sdpMid": "0",
"sdpMLineIndex": 1,
},
],
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.candidates",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallCandidates(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id.unwrap(), "9876");
assert_eq!(content.version, VoipVersionId::V1);
assert_eq!(content.candidates.len(), 2);
assert_eq!(content.candidates[0].candidate, "not a real candidate");
assert_eq!(content.candidates[0].sdp_mid, "0");
assert_eq!(content.candidates[0].sdp_m_line_index, uint!(0));
assert_eq!(content.candidates[1].candidate, "another fake candidate");
assert_eq!(content.candidates[1].sdp_mid, "0");
assert_eq!(content.candidates[1].sdp_m_line_index, uint!(1));
}
#[test]
fn hangup_v1_event_serialization() {
let content =
CallHangupEventContent::version_1("abcdef".into(), "9876".into(), Reason::IceFailed);
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"reason": "ice_failed",
})
);
}
#[test]
fn hangup_v1_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.hangup",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallHangup(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id.unwrap(), "9876");
assert_eq!(content.version, VoipVersionId::V1);
assert_eq!(content.reason, Reason::UserHangup);
}
#[test]
fn negotiate_v1_event_serialization() {
let content = CallNegotiateEventContent::version_1(
"abcdef".into(),
"9876".into(),
uint!(30000),
SessionDescription::new("offer".to_owned(), "not a real sdp".to_owned()),
);
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"lifetime": 30000,
"description": {
"type": "offer",
"sdp": "not a real sdp",
},
})
);
}
#[test]
fn negotiate_v1_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
"lifetime": 30000,
"description": {
"type": "answer",
"sdp": "not a real sdp",
}
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.negotiate",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallNegotiate(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id, "9876");
assert_eq!(content.lifetime, uint!(30000));
assert_eq!(content.description.session_type, "answer");
assert_eq!(content.description.sdp, "not a real sdp");
}
#[test]
fn reject_v1_event_serialization() {
let content = CallRejectEventContent::version_1("abcdef".into(), "9876".into());
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
})
);
}
#[test]
fn reject_v1_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"version": "1",
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.reject",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallReject(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id, "9876");
assert_eq!(content.version, VoipVersionId::V1);
}
#[test]
fn select_v1_answer_event_serialization() {
let content =
CallSelectAnswerEventContent::version_1("abcdef".into(), "9876".into(), "6336".into());
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"call_id": "abcdef",
"party_id": "9876",
"selected_party_id": "6336",
"version": "1",
})
);
}
#[test]
fn select_v1_answer_event_deserialization() {
let json_data = json!({
"content": {
"call_id": "abcdef",
"party_id": "9876",
"selected_party_id": "6336",
"version": "1",
},
"event_id": "$event:notareal.hs",
"origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs",
"type": "m.call.select_answer",
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
event,
AnyMessageLikeEvent::CallSelectAnswer(MessageLikeEvent::Original(message_event)) => message_event
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");
assert_eq!(content.party_id, "9876");
assert_eq!(content.selected_party_id, "6336");
assert_eq!(content.version, VoipVersionId::V1);
}

View File

@ -156,7 +156,6 @@ unstable-msc2448 = [
]
unstable-msc2654 = ["ruma-client-api?/unstable-msc2654"]
unstable-msc2666 = ["ruma-client-api?/unstable-msc2666"]
unstable-msc2746 = ["ruma-common/unstable-msc2746"]
unstable-msc2747 = ["ruma-common/unstable-msc2747"]
unstable-msc2870 = ["ruma-common/unstable-msc2870"]
unstable-msc2965 = ["ruma-client-api?/unstable-msc2965"]
@ -200,7 +199,6 @@ __ci = [
"unstable-msc2448",
"unstable-msc2654",
"unstable-msc2666",
"unstable-msc2746",
"unstable-msc2747",
"unstable-msc2870",
"unstable-msc2965",