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
|
|
@ -1,49 +1,26 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use futures::lock::Mutex;
|
||||
use tokio::sync::{RwLock, mpsc::UnboundedSender};
|
||||
use tungstenite::Utf8Bytes;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::calls::call_util;
|
||||
|
||||
pub struct Caller {
|
||||
pub user_id: RwLock<Uuid>,
|
||||
pub tx: Mutex<Option<UnboundedSender<Utf8Bytes>>>,
|
||||
pub user_state: RwLock<CallUserState>,
|
||||
pub streaming: RwLock<bool>,
|
||||
}
|
||||
#[derive(Clone)]
|
||||
pub enum CallUserState {
|
||||
Active,
|
||||
Muted,
|
||||
Deafed,
|
||||
Disconnected,
|
||||
pub user_id: Uuid,
|
||||
pub call_id: Uuid,
|
||||
pub inviters: Vec<Uuid>,
|
||||
}
|
||||
|
||||
impl Caller {
|
||||
pub fn new(user_id: Uuid, tx: UnboundedSender<Utf8Bytes>) -> Self {
|
||||
Self {
|
||||
user_id: RwLock::new(user_id),
|
||||
tx: Mutex::new(Some(tx)),
|
||||
user_state: RwLock::new(CallUserState::Active),
|
||||
streaming: RwLock::new(false),
|
||||
pub fn new(user_id: Uuid, call_id: Uuid, inviter_id: Uuid) -> Self {
|
||||
Caller {
|
||||
user_id,
|
||||
call_id,
|
||||
inviters: vec![inviter_id],
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn send(&self, msg: impl Into<Utf8Bytes>) {
|
||||
if let Some(tx) = &*self.tx.lock().await {
|
||||
let _ = tx.send(msg.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn disconnect(self: &Arc<Self>) {
|
||||
*self.user_state.write().await = CallUserState::Disconnected;
|
||||
*self.tx.lock().await = None;
|
||||
}
|
||||
|
||||
pub async fn is_connected(&self) -> bool {
|
||||
if let CallUserState::Disconnected = *self.user_state.read().await {
|
||||
false
|
||||
pub fn create_token(&self) -> String {
|
||||
if let Ok(token) = call_util::create_token(self.user_id, self.call_id) {
|
||||
token
|
||||
} else {
|
||||
true
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue