98 lines
2.1 KiB
Rust
98 lines
2.1 KiB
Rust
use crossbeam_channel::{Receiver, Sender};
|
|
|
|
use matrix_sdk::{self, api::r0::voip, identifiers::RoomId, Client};
|
|
use tracing::error;
|
|
|
|
use crate::comm_types::*; // get the functions i need from my gstream module
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct GstChannel {
|
|
sender: Sender<CallManagerToGst>,
|
|
receiver: Receiver<GstToCallManager>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct MatrixChannel {
|
|
sender: Sender<CallManagerToMatrix>,
|
|
receiver: Receiver<MatrixToCallManager>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct CallManager {
|
|
botname: String,
|
|
client: Client,
|
|
call_in_progress: bool,
|
|
prescence_state: String,
|
|
call_id: Option<String>,
|
|
room_id: Option<RoomId>,
|
|
gst_channel: GstChannel,
|
|
matrix_channel: MatrixChannel,
|
|
}
|
|
|
|
impl CallManager {
|
|
pub fn new(
|
|
botname: &String,
|
|
client: Client,
|
|
gst_sender: Sender<CallManagerToGst>,
|
|
gst_receiver: Receiver<GstToCallManager>,
|
|
matrix_sender: Sender<CallManagerToMatrix>,
|
|
matrix_receiver: Receiver<MatrixToCallManager>,
|
|
) -> Self
|
|
{
|
|
|
|
Self {
|
|
botname: botname.to_string(),
|
|
client,
|
|
call_in_progress: false,
|
|
prescence_state: "".to_string(),
|
|
call_id: None,
|
|
room_id: None,
|
|
gst_channel: GstChannel {
|
|
sender: gst_sender,
|
|
receiver: gst_receiver,
|
|
},
|
|
matrix_channel: MatrixChannel {
|
|
sender: matrix_sender,
|
|
receiver: matrix_receiver,
|
|
},
|
|
}
|
|
}
|
|
|
|
pub async fn get_turn_server(&self) -> Result<(), anyhow::Error> {
|
|
|
|
let client = &self.client;
|
|
|
|
let request = voip::get_turn_server_info::Request {};
|
|
|
|
let resp = client.send(request).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub fn can_start_call(&self) -> bool { !&self.call_in_progress }
|
|
|
|
pub async fn start_incoming_call(&self, offer: String, room_id: RoomId) -> Result<(), anyhow::Error> {
|
|
|
|
if self.call_in_progress {
|
|
|
|
error!("Existing call in progress already");
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn start_outgoing_call(&self, room_id: RoomId) -> Result<(), anyhow::Error> {
|
|
|
|
if self.call_in_progress {
|
|
|
|
error!("Existing call in progress already");
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn handle_calls(&self) -> Result<(), anyhow::Error> { loop {} }
|
|
}
|