@@ -8,12 +8,14 @@ use crate::contact::ContactId;
88use crate :: context:: Context ;
99use crate :: events:: EventType ;
1010use crate :: headerdef:: HeaderDef ;
11- use crate :: log:: info;
11+ use crate :: log:: { info, warn } ;
1212use crate :: message:: { self , Message , MsgId , Viewtype } ;
1313use crate :: mimeparser:: { MimeMessage , SystemMessage } ;
1414use crate :: param:: Param ;
1515use crate :: tools:: time;
16- use anyhow:: { Result , ensure} ;
16+ use anyhow:: { Context as _, Result , ensure} ;
17+ use sdp:: SessionDescription ;
18+ use std:: io:: Cursor ;
1719use std:: time:: Duration ;
1820use tokio:: task;
1921use tokio:: time:: sleep;
@@ -259,16 +261,25 @@ impl Context {
259261 ) -> Result < ( ) > {
260262 if mime_message. is_call ( ) {
261263 let call = self . load_call_by_id ( call_id) . await ?;
264+
262265 if call. is_incoming ( ) {
263266 if call. is_stale ( ) {
264267 call. update_text ( self , "Missed call" ) . await ?;
265268 self . emit_incoming_msg ( call. msg . chat_id , call_id) ; // notify missed call
266269 } else {
267270 call. update_text ( self , "Incoming call" ) . await ?;
268271 self . emit_msgs_changed ( call. msg . chat_id , call_id) ; // ringing calls are not additionally notified
272+ let has_video = match sdp_has_video ( & call. place_call_info ) {
273+ Ok ( has_video) => has_video,
274+ Err ( err) => {
275+ warn ! ( self , "Failed to determine if SDP offer has video: {err:#}." ) ;
276+ false
277+ }
278+ } ;
269279 self . emit_event ( EventType :: IncomingCall {
270280 msg_id : call. msg . id ,
271281 place_call_info : call. place_call_info . to_string ( ) ,
282+ has_video,
272283 } ) ;
273284 let wait = call. remaining_ring_seconds ( ) ;
274285 task:: spawn ( Context :: emit_end_call_if_unaccepted (
@@ -369,5 +380,18 @@ impl Context {
369380 }
370381}
371382
383+ /// Returns true if SDP offer has a video.
384+ fn sdp_has_video ( sdp : & str ) -> Result < bool > {
385+ let mut cursor = Cursor :: new ( sdp) ;
386+ let session_description =
387+ SessionDescription :: unmarshal ( & mut cursor) . context ( "Failed to parse SDP" ) ?;
388+ for media_description in & session_description. media_descriptions {
389+ if media_description. media_name . media == "video" {
390+ return Ok ( true ) ;
391+ }
392+ }
393+ Ok ( false )
394+ }
395+
372396#[ cfg( test) ]
373397mod calls_tests;
0 commit comments