diff options
-rw-r--r-- | readme.md | 1 | ||||
-rw-r--r-- | server/src/main.rs | 24 |
2 files changed, 7 insertions, 18 deletions
@@ -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<impl Reply, Infallible> { 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 { |