api(jsonrpc): add has_video attribute to call info

This commit is contained in:
link2xt
2025-09-27 17:15:06 +00:00
committed by l
parent 1ba448fe19
commit e968000a89
3 changed files with 15 additions and 3 deletions

View File

@@ -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<JsonrpcCallInfo> {
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,
})
}
}

View File

@@ -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()

View File

@@ -432,7 +432,7 @@ impl Context {
}
/// Returns true if SDP offer has a video.
fn sdp_has_video(sdp: &str) -> Result<bool> {
pub fn sdp_has_video(sdp: &str) -> Result<bool> {
let mut cursor = Cursor::new(sdp);
let session_description =
SessionDescription::unmarshal(&mut cursor).context("Failed to parse SDP")?;