From e968000a89afb329144220ce6fd07330d2e1ff6f Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 27 Sep 2025 17:15:06 +0000 Subject: [PATCH] api(jsonrpc): add has_video attribute to call info --- deltachat-jsonrpc/src/api/types/calls.rs | 12 ++++++++++-- deltachat-rpc-client/tests/test_calls.py | 4 ++++ src/calls.rs | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/deltachat-jsonrpc/src/api/types/calls.rs b/deltachat-jsonrpc/src/api/types/calls.rs index 7f477da65..7122c03a6 100644 --- a/deltachat-jsonrpc/src/api/types/calls.rs +++ b/deltachat-jsonrpc/src/api/types/calls.rs @@ -1,6 +1,6 @@ use anyhow::Result; -use deltachat::calls::{call_state, CallState}; +use deltachat::calls::{call_state, sdp_has_video, CallState}; use deltachat::context::Context; use deltachat::message::MsgId; use serde::Serialize; @@ -15,6 +15,9 @@ pub struct JsonrpcCallInfo { /// even if incoming call event was missed. pub sdp_offer: String, + /// True if SDP offer has a video. + pub has_video: bool, + /// Call state. /// /// For example, if the call is accepted, active, cancelled, declined etc. @@ -25,9 +28,14 @@ impl JsonrpcCallInfo { pub async fn from_msg_id(context: &Context, msg_id: MsgId) -> Result { let call_info = context.load_call_by_id(msg_id).await?; let sdp_offer = call_info.place_call_info.clone(); + let has_video = sdp_has_video(&sdp_offer).unwrap_or_default(); let state = JsonrpcCallState::from_msg_id(context, msg_id).await?; - Ok(JsonrpcCallInfo { sdp_offer, state }) + Ok(JsonrpcCallInfo { + sdp_offer, + has_video, + state, + }) } } diff --git a/deltachat-rpc-client/tests/test_calls.py b/deltachat-rpc-client/tests/test_calls.py index 25641b8c9..6ea4810fc 100644 --- a/deltachat-rpc-client/tests/test_calls.py +++ b/deltachat-rpc-client/tests/test_calls.py @@ -17,6 +17,7 @@ def test_calls(acfactory) -> None: assert not incoming_call_event.has_video # Cannot be parsed as SDP, so false by default incoming_call_message = Message(bob, incoming_call_event.msg_id) assert incoming_call_message.get_call_info().state.kind == "Alerting" + assert not incoming_call_message.get_call_info().has_video incoming_call_message.accept_incoming_call(accept_call_info) assert incoming_call_message.get_call_info().sdp_offer == place_call_info @@ -74,6 +75,9 @@ a=extmap:1 urn:ietf:params:rtp-hdrext:sdes:mid\r assert incoming_call_event.place_call_info == place_call_info assert incoming_call_event.has_video + incoming_call_message = Message(bob, incoming_call_event.msg_id) + assert incoming_call_message.get_call_info().has_video + def test_ice_servers(acfactory) -> None: alice = acfactory.get_online_account() diff --git a/src/calls.rs b/src/calls.rs index 64ee7d779..5e67e09c2 100644 --- a/src/calls.rs +++ b/src/calls.rs @@ -432,7 +432,7 @@ impl Context { } /// Returns true if SDP offer has a video. -fn sdp_has_video(sdp: &str) -> Result { +pub fn sdp_has_video(sdp: &str) -> Result { let mut cursor = Cursor::new(sdp); let session_description = SessionDescription::unmarshal(&mut cursor).context("Failed to parse SDP")?;