Skip to content

Commit 7ee6f2c

Browse files
authored
api: add JSON-RPC API for calls (#7194)
1 parent 5d9b887 commit 7ee6f2c

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

deltachat-jsonrpc/src/api.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,40 @@ impl CommandApi {
20682068
.map(|msg_id| msg_id.to_u32()))
20692069
}
20702070

2071+
/// Starts an outgoing call.
2072+
async fn place_outgoing_call(
2073+
&self,
2074+
account_id: u32,
2075+
chat_id: u32,
2076+
place_call_info: String,
2077+
) -> Result<u32> {
2078+
let ctx = self.get_context(account_id).await?;
2079+
let msg_id = ctx
2080+
.place_outgoing_call(ChatId::new(chat_id), place_call_info)
2081+
.await?;
2082+
Ok(msg_id.to_u32())
2083+
}
2084+
2085+
/// Accepts an incoming call.
2086+
async fn accept_incoming_call(
2087+
&self,
2088+
account_id: u32,
2089+
msg_id: u32,
2090+
accept_call_info: String,
2091+
) -> Result<()> {
2092+
let ctx = self.get_context(account_id).await?;
2093+
ctx.accept_incoming_call(MsgId::new(msg_id), accept_call_info)
2094+
.await?;
2095+
Ok(())
2096+
}
2097+
2098+
/// Ends incoming or outgoing call.
2099+
async fn end_call(&self, account_id: u32, msg_id: u32) -> Result<()> {
2100+
let ctx = self.get_context(account_id).await?;
2101+
ctx.end_call(MsgId::new(msg_id)).await?;
2102+
Ok(())
2103+
}
2104+
20712105
/// Makes an HTTP GET request and returns a response.
20722106
///
20732107
/// `url` is the HTTP or HTTPS URL.

deltachat-rpc-client/src/deltachat_rpc_client/chat.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,8 @@ def send_contact(self, contact: Contact):
289289
f.write(vcard.encode())
290290
f.flush()
291291
self._rpc.send_msg(self.account.id, self.id, {"viewtype": ViewType.VCARD, "file": f.name})
292+
293+
def place_outgoing_call(self, place_call_info: str) -> Message:
294+
"""Starts an outgoing call."""
295+
msg_id = self._rpc.place_outgoing_call(self.account.id, self.id, place_call_info)
296+
return Message(self.account, msg_id)

deltachat-rpc-client/src/deltachat_rpc_client/const.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class EventType(str, Enum):
7373
CHATLIST_ITEM_CHANGED = "ChatlistItemChanged"
7474
ACCOUNTS_CHANGED = "AccountsChanged"
7575
ACCOUNTS_ITEM_CHANGED = "AccountsItemChanged"
76+
INCOMING_CALL = "IncomingCall"
77+
INCOMING_CALL_ACCEPTED = "IncomingCallAccepted"
78+
OUTGOING_CALL_ACCEPTED = "OutgoingCallAccepted"
79+
CALL_ENDED = "CallEnded"
7680
CONFIG_SYNCED = "ConfigSynced"
7781
WEBXDC_REALTIME_DATA = "WebxdcRealtimeData"
7882
WEBXDC_REALTIME_ADVERTISEMENT_RECEIVED = "WebxdcRealtimeAdvertisementReceived"

deltachat-rpc-client/src/deltachat_rpc_client/message.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ def send_webxdc_realtime_advertisement(self):
102102
def send_webxdc_realtime_data(self, data) -> None:
103103
"""Send data to the realtime channel."""
104104
yield self._rpc.send_webxdc_realtime_data.future(self.account.id, self.id, list(data))
105+
106+
def accept_incoming_call(self, accept_call_info):
107+
"""Accepts an incoming call."""
108+
self._rpc.accept_incoming_call(self.account.id, self.id, accept_call_info)
109+
110+
def end_call(self):
111+
"""Ends incoming or outgoing call."""
112+
self._rpc.end_call(self.account.id, self.id)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from deltachat_rpc_client import EventType, Message
2+
3+
4+
def test_calls(acfactory) -> None:
5+
alice, bob = acfactory.get_online_accounts(2)
6+
7+
place_call_info = "offer"
8+
accept_call_info = "answer"
9+
10+
alice_contact_bob = alice.create_contact(bob, "Bob")
11+
alice_chat_bob = alice_contact_bob.create_chat()
12+
outgoing_call_message = alice_chat_bob.place_outgoing_call(place_call_info)
13+
14+
incoming_call_event = bob.wait_for_event(EventType.INCOMING_CALL)
15+
assert incoming_call_event.place_call_info == place_call_info
16+
incoming_call_message = Message(bob, incoming_call_event.msg_id)
17+
18+
incoming_call_message.accept_incoming_call(accept_call_info)
19+
outgoing_call_accepted_event = alice.wait_for_event(EventType.OUTGOING_CALL_ACCEPTED)
20+
assert outgoing_call_accepted_event.accept_call_info == accept_call_info
21+
22+
outgoing_call_message.end_call()
23+
24+
end_call_event = bob.wait_for_event(EventType.CALL_ENDED)
25+
assert end_call_event.msg_id == outgoing_call_message.id

0 commit comments

Comments
 (0)