guest promotion (#3969)

Release Notes:

- Adds the ability to promote read-only guests to read-write
participants in calls
This commit is contained in:
Conrad Irwin 2024-01-09 22:21:13 -07:00 committed by GitHub
commit 5d3f5611e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 579 additions and 163 deletions

View file

@ -3,7 +3,7 @@ use async_trait::async_trait;
use collections::{BTreeMap, HashMap};
use futures::Stream;
use gpui::BackgroundExecutor;
use live_kit_server::token;
use live_kit_server::{proto, token};
use media::core_video::CVImageBuffer;
use parking_lot::Mutex;
use postage::watch;
@ -151,6 +151,21 @@ impl TestServer {
Ok(())
}
async fn update_participant(
&self,
room_name: String,
identity: String,
permission: proto::ParticipantPermission,
) -> Result<()> {
self.executor.simulate_random_delay().await;
let mut server_rooms = self.rooms.lock();
let room = server_rooms
.get_mut(&room_name)
.ok_or_else(|| anyhow!("room {} does not exist", room_name))?;
room.participant_permissions.insert(identity, permission);
Ok(())
}
pub async fn disconnect_client(&self, client_identity: String) {
self.executor.simulate_random_delay().await;
let mut server_rooms = self.rooms.lock();
@ -172,6 +187,17 @@ impl TestServer {
.get_mut(&*room_name)
.ok_or_else(|| anyhow!("room {} does not exist", room_name))?;
let can_publish = room
.participant_permissions
.get(&identity)
.map(|permission| permission.can_publish)
.or(claims.video.can_publish)
.unwrap_or(true);
if !can_publish {
return Err(anyhow!("user is not allowed to publish"));
}
let track = Arc::new(RemoteVideoTrack {
sid: nanoid::nanoid!(17),
publisher_id: identity.clone(),
@ -210,6 +236,17 @@ impl TestServer {
.get_mut(&*room_name)
.ok_or_else(|| anyhow!("room {} does not exist", room_name))?;
let can_publish = room
.participant_permissions
.get(&identity)
.map(|permission| permission.can_publish)
.or(claims.video.can_publish)
.unwrap_or(true);
if !can_publish {
return Err(anyhow!("user is not allowed to publish"));
}
let track = Arc::new(RemoteAudioTrack {
sid: nanoid::nanoid!(17),
publisher_id: identity.clone(),
@ -265,6 +302,7 @@ struct TestServerRoom {
client_rooms: HashMap<Sid, Arc<Room>>,
video_tracks: Vec<Arc<RemoteVideoTrack>>,
audio_tracks: Vec<Arc<RemoteAudioTrack>>,
participant_permissions: HashMap<Sid, proto::ParticipantPermission>,
}
impl TestServerRoom {}
@ -297,6 +335,19 @@ impl live_kit_server::api::Client for TestApiClient {
Ok(())
}
async fn update_participant(
&self,
room: String,
identity: String,
permission: live_kit_server::proto::ParticipantPermission,
) -> Result<()> {
let server = TestServer::get(&self.url)?;
server
.update_participant(room, identity, permission)
.await?;
Ok(())
}
fn room_token(&self, room: &str, identity: &str) -> Result<String> {
let server = TestServer::get(&self.url)?;
token::create(