mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 22:46:29 +03:00
api: add call_info() JSON-RPC API
This commit is contained in:
@@ -48,6 +48,7 @@ pub mod types;
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
use types::account::Account;
|
||||
use types::calls::JsonrpcCallInfo;
|
||||
use types::chat::FullChat;
|
||||
use types::contact::{ContactObject, VcardContact};
|
||||
use types::events::Event;
|
||||
@@ -2117,6 +2118,13 @@ impl CommandApi {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns information about the call.
|
||||
async fn call_info(&self, account_id: u32, msg_id: u32) -> Result<JsonrpcCallInfo> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let call_info = JsonrpcCallInfo::from_msg_id(&ctx, MsgId::new(msg_id)).await?;
|
||||
Ok(call_info)
|
||||
}
|
||||
|
||||
/// Returns JSON with ICE servers, to be used for WebRTC video calls.
|
||||
async fn ice_servers(&self, account_id: u32) -> Result<String> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
|
||||
53
deltachat-jsonrpc/src/api/types/calls.rs
Normal file
53
deltachat-jsonrpc/src/api/types/calls.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use anyhow::Result;
|
||||
|
||||
use deltachat::context::Context;
|
||||
use deltachat::message::MsgId;
|
||||
use serde::Serialize;
|
||||
use typescript_type_def::TypeDef;
|
||||
|
||||
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
|
||||
#[serde(rename = "CallInfo", rename_all = "camelCase")]
|
||||
pub struct JsonrpcCallInfo {
|
||||
/// True if the call is an incoming call.
|
||||
pub is_incoming: bool,
|
||||
|
||||
/// True if the call should not ring anymore.
|
||||
pub is_stale: bool,
|
||||
|
||||
/// True if the call is accepted.
|
||||
pub is_accepted: bool,
|
||||
|
||||
/// True if the call has been ended.
|
||||
pub is_ended: bool,
|
||||
|
||||
/// Call duration in seconds.
|
||||
pub duration: i64,
|
||||
|
||||
/// SDP offer.
|
||||
///
|
||||
/// Can be used to manually answer the call
|
||||
/// even if incoming call event was missed.
|
||||
pub sdp_offer: String,
|
||||
}
|
||||
|
||||
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 is_incoming = call_info.is_incoming();
|
||||
let is_stale = call_info.is_stale();
|
||||
let is_accepted = call_info.is_accepted();
|
||||
let is_ended = call_info.is_ended();
|
||||
let duration = call_info.duration_seconds();
|
||||
let sdp_offer = call_info.place_call_info.clone();
|
||||
|
||||
Ok(JsonrpcCallInfo {
|
||||
is_incoming,
|
||||
is_stale,
|
||||
is_accepted,
|
||||
is_ended,
|
||||
duration,
|
||||
sdp_offer,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod account;
|
||||
pub mod calls;
|
||||
pub mod chat;
|
||||
pub mod chat_list;
|
||||
pub mod contact;
|
||||
|
||||
Reference in New Issue
Block a user