I think Im sending everything to the CM now
This commit is contained in:
parent
5a30505852
commit
4b0d0fefd6
2 changed files with 189 additions and 199 deletions
|
@ -1,3 +1,5 @@
|
|||
use matrix_sdk::identifiers::RoomId;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
pub struct TurnAuth {
|
||||
|
@ -26,7 +28,8 @@ pub struct CallCandidateDesc {
|
|||
#[derive(Clone, Debug)]
|
||||
|
||||
pub enum MatrixToCallManager {
|
||||
StartActive(String),
|
||||
StartActive(Box<RoomId>, String),
|
||||
AnswerCall(String),
|
||||
IceCandidate(Vec<CallCandidateDesc>),
|
||||
CloseActive(),
|
||||
TriggerCall(Option<String>),
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
config,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use crossbeam_channel::{Receiver, Sender};
|
||||
use crossbeam_channel::{select, Receiver, Sender};
|
||||
use js_int::UInt;
|
||||
use matrix_sdk::{
|
||||
self,
|
||||
|
@ -31,6 +31,7 @@ use matrix_sdk::{
|
|||
Client, ClientConfig, EventEmitter, JsonStore, Room, Sas, SyncRoom, SyncSettings,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use tokio::{join, task, time::Duration};
|
||||
use url::Url; // get the functions i need from my gstream module
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -99,7 +100,7 @@ async fn handle_call_invite(
|
|||
_call_id: String,
|
||||
user: String,
|
||||
_server: String,
|
||||
_offer: SessionDescription,
|
||||
offer: SessionDescription,
|
||||
)
|
||||
{
|
||||
let myself = client.user_id().await.unwrap();
|
||||
|
@ -107,25 +108,20 @@ async fn handle_call_invite(
|
|||
println!("Incoming call from {}", user);
|
||||
|
||||
let message = MessageEventContent::Text(TextMessageEventContent {
|
||||
body: format!("🎉🎊🥳 let's PARTY!! 🥳🎊🎉 {:?}", myself), /* This is renderng weirdly in vscode,
|
||||
body: format!("Got call invite, trying to setup gst {:?}", myself), /* This is renderng weirdly in vscode,
|
||||
* ignore the spaces for my sanity */
|
||||
formatted: None,
|
||||
relates_to: None,
|
||||
});
|
||||
|
||||
//client.share_group_session(room_id);
|
||||
let encrypted = {
|
||||
let room = client.get_joined_room(room_id).await;
|
||||
|
||||
match room {
|
||||
Some(r) => r.read().await.is_encrypted(),
|
||||
None => false,
|
||||
}
|
||||
};
|
||||
|
||||
println!("Encrypted?: {:?}", encrypted);
|
||||
let offer_sdp: String = offer.sdp;
|
||||
// Do the naive thing and just box a clone of the room to send
|
||||
// This'll let us not have to worry about the lifetime on this side
|
||||
let boxed_room = Box::new(room_id.clone());
|
||||
|
||||
client.room_send(room_id, message, None).await.unwrap();
|
||||
sender.send(StartActive(boxed_room, offer_sdp)).unwrap();
|
||||
}
|
||||
|
||||
async fn handle_call_answer(
|
||||
|
@ -140,28 +136,17 @@ async fn handle_call_answer(
|
|||
{
|
||||
let myself = client.user_id().await.unwrap();
|
||||
|
||||
println!("Incoming call from {}", user);
|
||||
println!("Call Answer from {}", user);
|
||||
|
||||
let message = MessageEventContent::Text(TextMessageEventContent {
|
||||
body: format!("🎉🎊🥳 let's PARTY!! 🥳🎊🎉 {:?}", myself), /* This is renderng weirdly in vscode,
|
||||
body: format!("got call answer, trying to accept {:?}", myself), /* This is renderng weirdly in vscode,
|
||||
* ignore the spaces for my sanity */
|
||||
formatted: None,
|
||||
relates_to: None,
|
||||
});
|
||||
|
||||
//client.share_group_session(room_id);
|
||||
let encrypted = {
|
||||
let room = client.get_joined_room(room_id).await;
|
||||
|
||||
match room {
|
||||
Some(r) => r.read().await.is_encrypted(),
|
||||
None => false,
|
||||
}
|
||||
};
|
||||
|
||||
println!("Encrypted?: {:?}", encrypted);
|
||||
|
||||
client.room_send(room_id, message, None).await.unwrap();
|
||||
sender.send(AnswerCall(answer.sdp)).unwrap();
|
||||
}
|
||||
|
||||
async fn handle_call_candidate(
|
||||
|
@ -193,7 +178,7 @@ async fn handle_call_candidate(
|
|||
index: u64::from(item.sdp_m_line_index),
|
||||
})
|
||||
.collect();
|
||||
let cm_message = MatrixToCallManager::IceCandidate(candidates_desc);
|
||||
let cm_message = IceCandidate(candidates_desc);
|
||||
|
||||
sender.send(cm_message).unwrap();
|
||||
|
||||
|
@ -211,28 +196,17 @@ async fn handle_call_hangup(
|
|||
{
|
||||
let myself = client.user_id().await.unwrap();
|
||||
|
||||
println!("Incoming call from {}", user);
|
||||
println!("Call hangup from {}", user);
|
||||
|
||||
let message = MessageEventContent::Text(TextMessageEventContent {
|
||||
body: format!("🎉🎊🥳 let's PARTY!! 🥳🎊🎉 {:?}", myself), /* This is renderng weirdly in vscode,
|
||||
body: format!("You hung up on me :( {:?}", myself), /* This is renderng weirdly in vscode,
|
||||
* ignore the spaces for my sanity */
|
||||
formatted: None,
|
||||
relates_to: None,
|
||||
});
|
||||
|
||||
//client.share_group_session(room_id);
|
||||
let encrypted = {
|
||||
let room = client.get_joined_room(room_id).await;
|
||||
|
||||
match room {
|
||||
Some(r) => r.read().await.is_encrypted(),
|
||||
None => false,
|
||||
}
|
||||
};
|
||||
|
||||
println!("Encrypted?: {:?}", encrypted);
|
||||
|
||||
client.room_send(room_id, message, None).await.unwrap();
|
||||
sender.send(CloseActive()).unwrap();
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -356,8 +330,7 @@ pub async fn sync_and_loop(
|
|||
// needed this to get it to stop complaining about the move below, /me shrugs
|
||||
let sender = &sender_channel.clone();
|
||||
|
||||
client
|
||||
.sync_forever(settings, async move |response| {
|
||||
let sync_forever_fut = client.sync_forever(settings, async move |response| {
|
||||
let client = &client_ref;
|
||||
|
||||
for event in &response.to_device.events {
|
||||
|
@ -520,8 +493,22 @@ pub async fn sync_and_loop(
|
|||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
});
|
||||
|
||||
let cm_task_fut = tokio::task::spawn(async move {
|
||||
loop {
|
||||
select!(
|
||||
recv(receiver_channel) -> msg => match msg {
|
||||
e => println!("DEBUG: {:?}", e),
|
||||
},
|
||||
default(Duration::from_secs(1)) => println!("heartbeat"),
|
||||
);
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
});
|
||||
|
||||
// TODO check for errors
|
||||
let (_r1, _r2) = join!(sync_forever_fut, cm_task_fut);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue