use std::sync::Arc; use futures::lock::Mutex; use tokio::sync::mpsc::UnboundedSender; use tungstenite::Utf8Bytes; use uuid::Uuid; pub struct Caller { pub user_id: Mutex, pub tx: Mutex>>, pub user_state: Mutex, pub streaming: Mutex, } #[derive(Clone)] pub enum CallUserState { Active, Muted, Deafed, Disconnected, } impl Caller { pub fn new(user_id: Uuid, tx: UnboundedSender) -> Self { Self { user_id: Mutex::new(user_id), tx: Mutex::new(Some(tx)), user_state: Mutex::new(CallUserState::Active), streaming: Mutex::new(false), } } pub fn send(&self, msg: impl Into) { if let Some(tx) = &self.tx.lock().await { let _ = tx.send(msg.into()); } } pub fn disconnect(self: Arc) { self.user_state = CallUserState::Disconnected; self.tx = None; } pub fn is_connected(&self) -> bool { if let CallUserState::Disconnected = self.user_state { false } else { true } } }