diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main.rs | 6 | ||||
-rw-r--r-- | server/src/protocol.rs | 56 | ||||
-rw-r--r-- | server/src/room.rs | 35 |
3 files changed, 17 insertions, 80 deletions
diff --git a/server/src/main.rs b/server/src/main.rs index 268e2a4..12039c3 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -41,8 +41,10 @@ async fn run() { let index = warp::path!().and(warp::fs::file("../client-web/public/start.html")); let assets = warp::path("_assets").and(warp::fs::dir("../client-web/public/assets")); - let routes = warp::get() - .and(assets.or(app).or(index).or(signaling)) + let routes = assets + .or(app) + .or(index) + .or(signaling) .recover(handle_rejection) .with(warp::log("stuff")); diff --git a/server/src/protocol.rs b/server/src/protocol.rs index f480ce7..5fb1ecb 100644 --- a/server/src/protocol.rs +++ b/server/src/protocol.rs @@ -3,21 +3,10 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum ClientboundPacket { - Init { - your_id: usize, - version: String, - }, - ClientJoin { - id: usize, - name: String, - }, - ClientLeave { - id: usize, - }, - Message { - sender: usize, - message: RelayMessage, - }, + Init { your_id: usize, version: String }, + ClientJoin { id: usize }, + ClientLeave { id: usize }, + Message { sender: usize, message: String }, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -26,41 +15,6 @@ pub enum ServerboundPacket { Ping, Relay { recipient: Option<usize>, - message: RelayMessage, + message: String, }, } - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum RelayMessage { - Offer(RTCSessionDescriptionInit), - Answer(RTCSessionDescriptionInit), - IceCandidate(RTCIceCandidateInit), -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum RTCSdpType { - Answer, - Offer, - PRAnswer, - Rollback, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct RTCSessionDescriptionInit { - sdp: String, - #[serde(rename = "type")] - ty: RTCSdpType, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct RTCIceCandidateInit { - candidate: Option<String>, - #[serde(rename = "sdpMLineIndex")] - sdp_mline_index: Option<i32>, - #[serde(rename = "sdpMid")] - sdp_mid: Option<String>, - #[serde(rename = "usernameFragment")] - username_fragment: Option<String>, -} diff --git a/server/src/room.rs b/server/src/room.rs index db545a6..53479ef 100644 --- a/server/src/room.rs +++ b/server/src/room.rs @@ -5,16 +5,10 @@ use std::{collections::HashMap, sync::atomic::AtomicUsize}; use tokio::sync::{mpsc, RwLock}; use warp::ws::{Message, WebSocket}; -#[derive(Debug)] -pub struct Client { - pub name: String, - pub out: mpsc::UnboundedSender<ClientboundPacket>, -} - #[derive(Debug, Default)] pub struct Room { pub id_counter: AtomicUsize, - pub clients: RwLock<HashMap<usize, Client>>, + pub clients: RwLock<HashMap<usize, mpsc::UnboundedSender<ClientboundPacket>>>, } impl Room { @@ -29,14 +23,7 @@ impl Room { let id = self .id_counter .fetch_add(1, std::sync::atomic::Ordering::Relaxed); - let name = format!("user no. {id}"); - g.insert( - id, - Client { - out: tx, - name: name.clone(), - }, - ); + g.insert(id, tx); drop(g); debug!("assigned id={id}, init connection"); @@ -62,20 +49,14 @@ impl Room { .await; // send join of this client to all clients - self.broadcast(None, ClientboundPacket::ClientJoin { id, name }) + self.broadcast(None, ClientboundPacket::ClientJoin { id }) .await; // send join of all other clients to this one - for (&cid, c) in self.clients.read().await.iter() { + for (&cid, _) in self.clients.read().await.iter() { // skip self if cid != id { - self.send_to_client( - id, - ClientboundPacket::ClientJoin { - id: cid, - name: c.name.clone(), - }, - ) - .await; + self.send_to_client(id, ClientboundPacket::ClientJoin { id: cid }) + .await; } } debug!("client should be ready!"); @@ -108,13 +89,13 @@ impl Room { pub async fn broadcast(&self, sender: Option<usize>, packet: ClientboundPacket) { for (&id, tx) in self.clients.read().await.iter() { if sender != Some(id) { - let _ = tx.out.send(packet.clone()); + let _ = tx.send(packet.clone()); } } } pub async fn send_to_client(&self, recipient: usize, packet: ClientboundPacket) { if let Some(c) = self.clients.read().await.get(&recipient) { - let _ = c.out.send(packet); + let _ = c.send(packet); } } |