New Calling structure using https://livekit.io/ (: Incomplete, Untested
:)
This commit is contained in:
parent
7493bd4cb7
commit
48ead50947
13 changed files with 1167 additions and 568 deletions
|
|
@ -141,7 +141,7 @@ impl ClientConnection {
|
|||
}
|
||||
|
||||
// Handle get call requests
|
||||
if cv.is_type(CommunicationType::get_call) {
|
||||
if cv.is_type(CommunicationType::call_get) {
|
||||
self.handle_get_call(cv).await;
|
||||
return;
|
||||
}
|
||||
|
|
@ -303,13 +303,14 @@ impl ClientConnection {
|
|||
}
|
||||
};
|
||||
|
||||
// Get call group - placeholder implementation
|
||||
// let call_group = CallManager::get_call_group(call_id, &call_secret_sha.unwrap(), true).await;
|
||||
// if call_group.is_none() {
|
||||
// self.send_error_response(&cv.get_id(), CommunicationType::error)
|
||||
// .await;
|
||||
// return;
|
||||
// }
|
||||
let invited =
|
||||
call_manager::add_invite(call_id, self.user_id.read().await.unwrap(), receiver_id)
|
||||
.await;
|
||||
if invited {
|
||||
self.send_error_response(&cv.get_id(), CommunicationType::error)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
// Find target RhoConnection
|
||||
let target_rho = match rho_manager::get_rho_con_for_user(receiver_id).await {
|
||||
|
|
@ -328,20 +329,16 @@ impl ClientConnection {
|
|||
};
|
||||
|
||||
// Create and send call distribution message
|
||||
let distribute = CommunicationValue::new(CommunicationType::new_call)
|
||||
let forward = CommunicationValue::new(CommunicationType::call_invite)
|
||||
.with_receiver(receiver_id)
|
||||
.with_sender(sender_id)
|
||||
.add_data_str(DataTypes::call_id, call_id.to_string())
|
||||
.add_data_str(DataTypes::receiver_id, receiver_id.to_string())
|
||||
.add_data_str(DataTypes::sender_id, sender_id.to_string());
|
||||
|
||||
target_rho.message_to_client(distribute).await;
|
||||
target_rho.message_to_client(forward).await;
|
||||
|
||||
// Handle call group invitation logic here
|
||||
// This would require implementing CallGroup::Caller and related functionality
|
||||
|
||||
// Send success response
|
||||
let response = CommunicationValue::new(CommunicationType::call_invite).with_id(cv.get_id());
|
||||
let response = CommunicationValue::new(CommunicationType::success).with_id(cv.get_id());
|
||||
self.send_message(&response).await;
|
||||
}
|
||||
|
||||
|
|
@ -368,26 +365,17 @@ impl ClientConnection {
|
|||
}
|
||||
};
|
||||
|
||||
// Get call group
|
||||
let mut response = CommunicationValue::new(CommunicationType::get_call)
|
||||
.with_id(cv.get_id())
|
||||
.with_receiver(user_id);
|
||||
|
||||
if let Some(_call_group) = call_manager::get_group(call_id).await {
|
||||
/*response = response
|
||||
.add_data_str(DataTypes::call_state, call_group.call_state.to_string())
|
||||
.add_data_str(DataTypes::start_date, call_group.started_at.to_string());
|
||||
|
||||
if call_group.lock(). != 0 {
|
||||
response =
|
||||
response.add_data_str(DataTypes::end_date, call_group.ended_at.to_string());
|
||||
}
|
||||
*/
|
||||
if let Some(token) = call_manager::get_call_token(user_id, call_id).await {
|
||||
let response = CommunicationValue::new(CommunicationType::call_get)
|
||||
.with_id(cv.get_id())
|
||||
.with_receiver(user_id)
|
||||
.add_data_str(DataTypes::call_token, token);
|
||||
self.send_message(&response).await;
|
||||
} else {
|
||||
response = response.add_data_str(DataTypes::call_state, "DESTROYED".to_string());
|
||||
self.send_error_response(&cv.get_id(), CommunicationType::error)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
self.send_message(&response).await;
|
||||
}
|
||||
|
||||
/// Forward message to Iota
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use crate::calls::call_group::CallGroup;
|
||||
use crate::calls::call_manager;
|
||||
use crate::util::print::PrintType;
|
||||
use crate::util::print::line;
|
||||
use crate::util::print::line_err;
|
||||
|
|
@ -5,12 +7,14 @@ use async_tungstenite::WebSocketReceiver;
|
|||
use async_tungstenite::WebSocketSender;
|
||||
use async_tungstenite::tungstenite::Message;
|
||||
use json::JsonValue;
|
||||
use json::parse;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Weak},
|
||||
};
|
||||
use tokio::sync::RwLock;
|
||||
use tokio_util::compat::Compat;
|
||||
use tower::retry::backoff::InvalidBackoff;
|
||||
use tungstenite::Utf8Bytes;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
|
@ -278,22 +282,44 @@ impl IotaConnection {
|
|||
/// Handle GET_CHATS message
|
||||
async fn handle_get_chats(&self, cv: CommunicationValue) {
|
||||
let receiver_id = cv.get_receiver();
|
||||
let interested_ids: Vec<Uuid> = Vec::new();
|
||||
let mut interested_ids: Vec<Uuid> = Vec::new();
|
||||
|
||||
let calls: Vec<Arc<CallGroup>> = call_manager::get_call_groups(receiver_id).await;
|
||||
let mut invites: HashMap<Uuid, Vec<Uuid>> = HashMap::new();
|
||||
|
||||
for call in calls {
|
||||
for inviter in call.members.read().await.iter() {
|
||||
let inviter_id = inviter.user_id;
|
||||
if let Some(call_ids) = invites.get_mut(&inviter_id) {
|
||||
call_ids.push(call.call_id);
|
||||
} else {
|
||||
invites.insert(inviter_id, vec![call.call_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process contacts and add call information
|
||||
// Enriched Contacts data:
|
||||
// [{"user_id": "uuid", "calls": ["call_id"]}, {"user_id": "uuid"}]
|
||||
let mut enriched_contacts = JsonValue::new_array();
|
||||
// Contacts data:
|
||||
// [{"user_id": "uuid"}, {"user_id": "uuid"}]
|
||||
if let Some(contacts_data) = cv.get_data(DataTypes::user_ids) {
|
||||
/*let contacts: Vec<(Uuid, String)> = parse_contacts(contacts_data);
|
||||
for contact in &contacts {
|
||||
interested_ids.push(contact.user_id);
|
||||
if let JsonValue::Array(user_ids) = contacts_data {
|
||||
for user_id in user_ids {
|
||||
if let JsonValue::String(user_id_str) = user_id {
|
||||
if let Ok(user_id) = Uuid::parse_str(user_id_str) {
|
||||
interested_ids.push(user_id);
|
||||
let mut enriched_contact = JsonValue::new_object();
|
||||
let _ = enriched_contact.insert("user_id", user_id.to_string());
|
||||
let _ = enriched_contact.insert("calls", JsonValue::new_array());
|
||||
let _ = enriched_contacts.push(enriched_contact);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
enriched_contacts = contacts_data.clone();
|
||||
}
|
||||
|
||||
// Get call invites for receiver
|
||||
let invites = CallManager::get_call_invites(receiver_id).await;
|
||||
|
||||
// Enrich contacts with call information
|
||||
let enriched_contacts = enrich_with_calls(contacts, invites);
|
||||
|
||||
cv = cv.add_data(DataTypes::user_ids, enriched_contacts.into());*/
|
||||
}
|
||||
|
||||
// Notify OmegaConnection about user states
|
||||
|
|
@ -305,7 +331,8 @@ impl IotaConnection {
|
|||
}
|
||||
|
||||
// Forward to client
|
||||
self.forward_to_client(cv).await;
|
||||
self.forward_to_client(cv.add_data(DataTypes::user_ids, enriched_contacts))
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Forward message to client
|
||||
|
|
|
|||
Loading…
Reference in a new issue