mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-26 02:37:05 +00:00
Delete room when no participants are left
This commit is contained in:
parent
9cf39b1da6
commit
48a1dd1588
5 changed files with 13 additions and 2 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3197,6 +3197,7 @@ dependencies = [
|
||||||
"futures 0.3.24",
|
"futures 0.3.24",
|
||||||
"hmac 0.12.1",
|
"hmac 0.12.1",
|
||||||
"jwt",
|
"jwt",
|
||||||
|
"log",
|
||||||
"prost 0.8.0",
|
"prost 0.8.0",
|
||||||
"prost-build",
|
"prost-build",
|
||||||
"prost-types 0.8.0",
|
"prost-types 0.8.0",
|
||||||
|
|
|
@ -890,11 +890,16 @@ impl Server {
|
||||||
) -> impl Future<Output = Result<()>> {
|
) -> impl Future<Output = Result<()>> {
|
||||||
let client = self.app_state.live_kit_client.clone();
|
let client = self.app_state.live_kit_client.clone();
|
||||||
let room_name = room.live_kit_room.clone();
|
let room_name = room.live_kit_room.clone();
|
||||||
|
let participant_count = room.participants.len();
|
||||||
async move {
|
async move {
|
||||||
if let Some(client) = client {
|
if let Some(client) = client {
|
||||||
client
|
client
|
||||||
.remove_participant(room_name, connection_id.to_string())
|
.remove_participant(room_name.clone(), connection_id.to_string())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
if participant_count == 0 {
|
||||||
|
client.delete_room(room_name).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -495,7 +495,7 @@ impl Store {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let room = if room.participants.is_empty() && room.pending_participant_user_ids.is_empty() {
|
let room = if room.participants.is_empty() {
|
||||||
Cow::Owned(self.rooms.remove(&room_id).unwrap())
|
Cow::Owned(self.rooms.remove(&room_id).unwrap())
|
||||||
} else {
|
} else {
|
||||||
Cow::Borrowed(self.rooms.get(&room_id).unwrap())
|
Cow::Borrowed(self.rooms.get(&room_id).unwrap())
|
||||||
|
|
|
@ -12,6 +12,7 @@ doctest = false
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
hmac = "0.12"
|
hmac = "0.12"
|
||||||
|
log = "0.4"
|
||||||
jwt = "0.16"
|
jwt = "0.16"
|
||||||
prost = "0.8"
|
prost = "0.8"
|
||||||
prost-types = "0.8"
|
prost-types = "0.8"
|
||||||
|
|
|
@ -110,6 +110,7 @@ impl Client {
|
||||||
let client = self.http.clone();
|
let client = self.http.clone();
|
||||||
let token = token::create(&self.key, &self.secret, None, grant);
|
let token = token::create(&self.key, &self.secret, None, grant);
|
||||||
let url = format!("{}/{}", self.url, path);
|
let url = format!("{}/{}", self.url, path);
|
||||||
|
log::info!("Request {}: {:?}", url, body);
|
||||||
async move {
|
async move {
|
||||||
let token = token?;
|
let token = token?;
|
||||||
let response = client
|
let response = client
|
||||||
|
@ -119,9 +120,12 @@ impl Client {
|
||||||
.body(body.encode_to_vec())
|
.body(body.encode_to_vec())
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if response.status().is_success() {
|
if response.status().is_success() {
|
||||||
|
log::info!("Response {}: {:?}", url, response.status());
|
||||||
Ok(Res::decode(response.bytes().await?)?)
|
Ok(Res::decode(response.bytes().await?)?)
|
||||||
} else {
|
} else {
|
||||||
|
log::error!("Response {}: {:?}", url, response.status());
|
||||||
Err(anyhow!(
|
Err(anyhow!(
|
||||||
"POST {} failed with status code {:?}, {:?}",
|
"POST {} failed with status code {:?}, {:?}",
|
||||||
url,
|
url,
|
||||||
|
|
Loading…
Reference in a new issue