Proper hangups implemented
This commit is contained in:
parent
2b35ceca70
commit
c1a28d103c
1 changed files with 39 additions and 15 deletions
|
@ -1,15 +1,13 @@
|
|||
use crate::comm_types::{GstToCallManager::*, MatrixToCallManager::*, *};
|
||||
use crossbeam_channel::{select, Receiver, Sender};
|
||||
use js_int::{uint, UInt};
|
||||
use matrix_sdk::{self, api::r0::voip, events::AnyMessageEventContent, identifiers::RoomId, Client};
|
||||
use matrix_sdk_common::{
|
||||
api::r0::message::send_message_event,
|
||||
events::call::{answer::*, candidates::*, hangup::*, invite::*, SessionDescription, SessionDescriptionType},
|
||||
use matrix_sdk_common::events::call::{
|
||||
answer::*, candidates::*, hangup::*, invite::*, SessionDescription, SessionDescriptionType,
|
||||
};
|
||||
use tokio::time::{delay_for, Duration};
|
||||
use tracing::error;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::comm_types::{GstToCallManager::*, MatrixToCallManager::*, *}; // get the functions i need from my gstream module
|
||||
use uuid::Uuid; // get the functions i need from my gstream module
|
||||
|
||||
#[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 {
|
||||
GstToCallManager::IceCandidate(index, sdp) => {
|
||||
&self.send_call_candidate(index, sdp).await;
|
||||
&self.send_call_candidate(index, sdp).await?;
|
||||
Ok(())
|
||||
}
|
||||
Offer(sdp) => {
|
||||
&self.send_call_offer(sdp).await;
|
||||
&self.send_call_offer(sdp).await?;
|
||||
Ok(())
|
||||
}
|
||||
Answer(sdp) => {
|
||||
&self.send_call_answer(sdp).await;
|
||||
&self.send_call_answer(sdp).await?;
|
||||
Ok(())
|
||||
}
|
||||
CallError(error_message) => {
|
||||
&self.hangup_call().await?;
|
||||
println!("Got some kind of error, terminating call: {}", error_message);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -247,11 +275,7 @@ impl CallManager {
|
|||
Ok(())
|
||||
}
|
||||
CloseActive() => {
|
||||
self.room_id = None;
|
||||
self.call_id = None;
|
||||
self.call_in_progress = false;
|
||||
|
||||
&self.gst_channel.sender.send(CallManagerToGst::CloseActive())?;
|
||||
&self.hangup_call().await?;
|
||||
Ok(())
|
||||
}
|
||||
TriggerCall(_username) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue