From 8147d03b44323172454601523a18060edbb0ab9f Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 9 Sep 2022 20:15:54 +0200 Subject: clean code --- readme.md | 1 + server/src/main.rs | 24 ++++++------------------ 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/readme.md b/readme.md index 77af7e9..c6f4a2b 100644 --- a/readme.md +++ b/readme.md @@ -76,6 +76,7 @@ Booleans can be either `1`, `true`, `yes` or their opposites. - Built-in storage for known keys - Prevent a client from sendin differing user names to other clients - Fix chat CSS (impossibleā„¢) +- Relay RTC when there are a lot of clients ## Protocol diff --git a/server/src/main.rs b/server/src/main.rs index 9f5cb91..ddc00af 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -102,24 +102,12 @@ async fn handle_rejection(err: Rejection) -> Result { fn signaling_connect(rname: String, rooms: Rooms, ws: warp::ws::Ws) -> impl Reply { async fn inner(sock: WebSocket, rname: String, rooms: Rooms) { debug!("ws upgrade"); - let guard = rooms.read().await; - let room = match guard.get(&rname) { - Some(r) => { - let x = r.to_owned(); - drop(guard); - x - } - None => { - debug!("aquire lock for insertion"); - drop(guard); // make sure read-lock is dropped to avoid deadlock - let mut guard = rooms.write().await; - debug!("create new room"); - guard.insert(rname.to_owned(), Default::default()); - let x = guard.get(&rname).unwrap().to_owned(); - drop(guard); - x - } - }; + let mut guard = rooms.write().await; + let room = guard + .entry(rname.clone()) + .or_insert_with(|| Default::default()) + .to_owned(); + drop(guard); room.client_connect(sock).await; if room.should_remove().await { -- cgit v1.3.1