Initial commit: Rust WebSocket/UDP signaling and media relay server

This commit is contained in:
srtk 2026-02-08 15:40:45 +05:30
commit c644aed661
6 changed files with 373 additions and 0 deletions

52
src/state.rs Normal file
View file

@ -0,0 +1,52 @@
use dashmap::DashMap;
use shared::{ControlMsg, UserId};
use std::net::SocketAddr;
use std::sync::Arc;
use tokio::sync::broadcast;
#[derive(Debug, Clone)]
pub struct AppState {
pub rooms: Arc<DashMap<String, Room>>,
pub peers_by_addr: Arc<DashMap<SocketAddr, PeerLocation>>,
}
#[derive(Debug, Clone)]
pub struct PeerLocation {
pub room_id: String,
pub user_id: UserId,
}
#[derive(Debug, Clone)]
pub struct Room {
pub id: String,
pub peers: DashMap<UserId, Peer>,
// Channel for broadcasting control messages within the room
pub tx: broadcast::Sender<ControlMsg>,
}
#[derive(Debug, Clone)]
pub struct Peer {
pub id: UserId,
pub display_name: String,
pub addr: Option<SocketAddr>, // UDP address
}
impl AppState {
pub fn new() -> Self {
Self {
rooms: Arc::new(DashMap::new()),
peers_by_addr: Arc::new(DashMap::new()),
}
}
}
impl Room {
pub fn new(id: String) -> Self {
let (tx, _) = broadcast::channel(100);
Self {
id,
peers: DashMap::new(),
tx,
}
}
}