Proper hangups implemented

This commit is contained in:
Ryan Voots 2020-08-26 09:02:21 -07:00
parent 2b35ceca70
commit c1a28d103c

View file

@ -1,15 +1,13 @@
use crate::comm_types::{GstToCallManager::*, MatrixToCallManager::*, *};
use crossbeam_channel::{select, Receiver, Sender}; use crossbeam_channel::{select, Receiver, Sender};
use js_int::{uint, UInt}; use js_int::{uint, UInt};
use matrix_sdk::{self, api::r0::voip, events::AnyMessageEventContent, identifiers::RoomId, Client}; use matrix_sdk::{self, api::r0::voip, events::AnyMessageEventContent, identifiers::RoomId, Client};
use matrix_sdk_common::{ use matrix_sdk_common::events::call::{
api::r0::message::send_message_event, answer::*, candidates::*, hangup::*, invite::*, SessionDescription, SessionDescriptionType,
events::call::{answer::*, candidates::*, hangup::*, invite::*, SessionDescription, SessionDescriptionType},
}; };
use tokio::time::{delay_for, Duration}; use tokio::time::{delay_for, Duration};
use tracing::error; use tracing::error;
use uuid::Uuid; use uuid::Uuid; // get the functions i need from my gstream module
use crate::comm_types::{GstToCallManager::*, MatrixToCallManager::*, *}; // get the functions i need from my gstream module
#[derive(Debug)] #[derive(Debug)]
@ -207,19 +205,49 @@ impl CallManager {
} }
} }
pub async fn handle_gst_msg(&mut self, message: GstToCallManager) { pub async fn hangup_call(&mut self) -> Result<(), anyhow::Error> {
if let (Some(room_id), Some(call_id)) = (&self.room_id, &self.call_id) {
let hangup_content = HangupEventContent {
call_id: call_id.to_string(),
reason: None,
version: uint!(0), // this is good as far as r0.6.0 of the matrix spec
};
let content = AnyMessageEventContent::CallHangup(hangup_content);
self.client.room_send(&room_id, content, None).await?;
self.call_id = None;
self.room_id = None;
self.call_in_progress = false;
&self.gst_channel.sender.send(CallManagerToGst::CloseActive())?;
Ok(())
} else {
self.call_id = None;
self.room_id = None;
self.call_in_progress = false;
&self.gst_channel.sender.send(CallManagerToGst::CloseActive())?;
Ok(()) // this never actually happens
}
}
pub async fn handle_gst_msg(&mut self, message: GstToCallManager) -> Result<(), anyhow::Error> {
match message { match message {
GstToCallManager::IceCandidate(index, sdp) => { GstToCallManager::IceCandidate(index, sdp) => {
&self.send_call_candidate(index, sdp).await; &self.send_call_candidate(index, sdp).await?;
Ok(())
} }
Offer(sdp) => { Offer(sdp) => {
&self.send_call_offer(sdp).await; &self.send_call_offer(sdp).await?;
Ok(())
} }
Answer(sdp) => { Answer(sdp) => {
&self.send_call_answer(sdp).await; &self.send_call_answer(sdp).await?;
Ok(())
} }
CallError(error_message) => { CallError(error_message) => {
&self.hangup_call().await?;
println!("Got some kind of error, terminating call: {}", error_message); println!("Got some kind of error, terminating call: {}", error_message);
Ok(())
} }
} }
} }
@ -247,11 +275,7 @@ impl CallManager {
Ok(()) Ok(())
} }
CloseActive() => { CloseActive() => {
self.room_id = None; &self.hangup_call().await?;
self.call_id = None;
self.call_in_progress = false;
&self.gst_channel.sender.send(CallManagerToGst::CloseActive())?;
Ok(()) Ok(())
} }
TriggerCall(_username) => { TriggerCall(_username) => {