5
5
//! So, no database changes are needed at this stage.
6
6
//! When it comes to relay calls over iroh, we may need a dedicated table, and this may change.
7
7
use crate :: chat:: { send_msg, Chat , ChatId } ;
8
+ use crate :: config:: Config ;
8
9
use crate :: constants:: Chattype ;
9
10
use crate :: context:: Context ;
10
11
use crate :: events:: EventType ;
11
12
use crate :: message:: { self , rfc724_mid_exists, Message , MsgId , Viewtype } ;
12
13
use crate :: mimeparser:: { MimeMessage , SystemMessage } ;
13
14
use crate :: param:: Param ;
14
15
use crate :: sync:: SyncData ;
15
- use crate :: tools:: time;
16
- use anyhow:: { ensure, Result } ;
16
+ use crate :: tools:: { create_id , time} ;
17
+ use anyhow:: { bail , ensure, Result } ;
17
18
use std:: time:: Duration ;
18
19
use tokio:: task;
19
20
use tokio:: time:: sleep;
@@ -71,12 +72,24 @@ impl Context {
71
72
let chat = Chat :: load_from_db ( self , chat_id) . await ?;
72
73
ensure ! ( chat. typ == Chattype :: Single && !chat. is_self_talk( ) ) ;
73
74
75
+ let instance = if let Some ( instance) = self . get_config ( Config :: WebrtcInstance ) . await ? {
76
+ if !instance. is_empty ( ) {
77
+ instance
78
+ } else {
79
+ bail ! ( "webrtc_instance is empty" ) ;
80
+ }
81
+ } else {
82
+ bail ! ( "webrtc_instance not set" ) ;
83
+ } ;
84
+ let instance = Message :: create_webrtc_instance ( & instance, & create_id ( ) ) ;
85
+
74
86
let mut call = Message {
75
87
viewtype : Viewtype :: Text ,
76
88
text : "Calling..." . into ( ) ,
77
89
..Default :: default ( )
78
90
} ;
79
91
call. param . set_cmd ( SystemMessage :: OutgoingCall ) ;
92
+ call. param . set ( Param :: WebrtcRoom , & instance) ;
80
93
call. id = send_msg ( self , chat_id, & mut call) . await ?;
81
94
82
95
let wait = RINGING_SECONDS ;
@@ -284,6 +297,8 @@ mod tests {
284
297
let bob2 = tcm. bob ( ) . await ;
285
298
for t in [ & alice, & alice2, & bob, & bob2] {
286
299
t. set_config_bool ( Config :: SyncMsgs , true ) . await ?;
300
+ t. set_config ( Config :: WebrtcInstance , Some ( "https://foo.bar" ) )
301
+ . await ?;
287
302
}
288
303
289
304
// Alice creates a chat with Bob and places an outgoing call there.
@@ -295,12 +310,17 @@ mod tests {
295
310
assert_eq ! ( sent1. sender_msg_id, test_msg_id) ;
296
311
assert ! ( alice_call. is_info( ) ) ;
297
312
assert_eq ! ( alice_call. get_info_type( ) , SystemMessage :: OutgoingCall ) ;
313
+ let alice_url = alice_call. get_videochat_url ( ) . unwrap ( ) ;
314
+ assert ! ( alice_url. starts_with( "https://foo.bar/" ) ) ;
298
315
let info = alice. load_call_by_root_id ( alice_call. id ) . await ?;
299
316
assert ! ( !info. accepted) ;
300
317
301
318
let alice2_call = alice2. recv_msg ( & sent1) . await ;
302
319
assert ! ( alice2_call. is_info( ) ) ;
303
320
assert_eq ! ( alice2_call. get_info_type( ) , SystemMessage :: OutgoingCall ) ;
321
+ let alice2_url = alice2_call. get_videochat_url ( ) . unwrap ( ) ;
322
+ assert ! ( alice2_url. starts_with( "https://foo.bar/" ) ) ;
323
+ assert_eq ! ( alice_url, alice2_url) ;
304
324
let info = alice2. load_call_by_root_id ( alice2_call. id ) . await ?;
305
325
assert ! ( !info. accepted) ;
306
326
@@ -312,6 +332,9 @@ mod tests {
312
332
. await ;
313
333
assert ! ( bob_call. is_info( ) ) ;
314
334
assert_eq ! ( bob_call. get_info_type( ) , SystemMessage :: IncomingCall ) ;
335
+ let bob_url = bob_call. get_videochat_url ( ) . unwrap ( ) ;
336
+ assert ! ( bob_url. starts_with( "https://foo.bar/" ) ) ;
337
+ assert_eq ! ( alice_url, bob_url) ;
315
338
316
339
let bob2_call = bob2. recv_msg ( & sent1) . await ;
317
340
assert ! ( bob2_call. is_info( ) ) ;
0 commit comments