fix: use existing node if someone is already in the voice channel
This commit is contained in:
@@ -42,6 +42,10 @@ impl VoiceClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_enabled(&self) -> bool {
|
||||||
|
!self.rooms.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn from_revolt_config() -> Self {
|
pub async fn from_revolt_config() -> Self {
|
||||||
let config = config().await;
|
let config = config().await;
|
||||||
|
|
||||||
@@ -89,8 +93,7 @@ impl VoiceClient {
|
|||||||
Channel::TextChannel { voice: Some(voice), .. } => Some(Cow::Borrowed(voice)),
|
Channel::TextChannel { voice: Some(voice), .. } => Some(Cow::Borrowed(voice)),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
|
.ok_or_else(|| create_error!(NotAVoiceChannel))?;
|
||||||
.ok_or_else(|| create_error!(NotAVoiceChannel))?;
|
|
||||||
|
|
||||||
room.client
|
room.client
|
||||||
.create_room(
|
.create_room(
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ auto_derived!(
|
|||||||
|
|
||||||
/// Join a voice channel
|
/// Join a voice channel
|
||||||
pub struct DataJoinCall {
|
pub struct DataJoinCall {
|
||||||
pub node: String
|
pub node: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use revolt_config::config;
|
use revolt_config::config;
|
||||||
use revolt_models::v0;
|
use revolt_models::v0;
|
||||||
use revolt_database::{util::{permissions::perms, reference::Reference}, voice::{raise_if_in_voice, VoiceClient}, Channel, Database, SystemMessage, User, AMQP};
|
use revolt_database::{util::{permissions::perms, reference::Reference}, voice::{get_channel_node, raise_if_in_voice, VoiceClient}, Channel, Database, SystemMessage, User, AMQP};
|
||||||
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
|
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
|
||||||
use revolt_result::{create_error, Result};
|
use revolt_result::{create_error, Result};
|
||||||
|
|
||||||
@@ -12,10 +12,11 @@ use rocket::{serde::json::Json, State};
|
|||||||
#[openapi(tag = "Voice")]
|
#[openapi(tag = "Voice")]
|
||||||
#[post("/<target>/join_call", data="<data>")]
|
#[post("/<target>/join_call", data="<data>")]
|
||||||
pub async fn call(db: &State<Database>, amqp: &State<AMQP>, voice: &State<VoiceClient>, user: User, target: Reference, data: Json<v0::DataJoinCall>) -> Result<Json<v0::CreateVoiceUserResponse>> {
|
pub async fn call(db: &State<Database>, amqp: &State<AMQP>, voice: &State<VoiceClient>, user: User, target: Reference, data: Json<v0::DataJoinCall>) -> Result<Json<v0::CreateVoiceUserResponse>> {
|
||||||
let config = config().await;
|
if !voice.is_enabled() {
|
||||||
|
return Err(create_error!(LiveKitUnavailable))
|
||||||
|
}
|
||||||
|
|
||||||
let node_host = config.hosts.livekit.get(&data.node)
|
let config = config().await;
|
||||||
.ok_or_else(|| create_error!(UnknownNode))?;
|
|
||||||
|
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
|
|
||||||
@@ -26,8 +27,17 @@ pub async fn call(db: &State<Database>, amqp: &State<AMQP>, voice: &State<VoiceC
|
|||||||
let current_permissions = calculate_channel_permissions(&mut permissions).await;
|
let current_permissions = calculate_channel_permissions(&mut permissions).await;
|
||||||
current_permissions.throw_if_lacking_channel_permission(ChannelPermission::Connect)?;
|
current_permissions.throw_if_lacking_channel_permission(ChannelPermission::Connect)?;
|
||||||
|
|
||||||
let token = voice.create_token(&data.node, &user, current_permissions, &channel)?;
|
let existing_node = get_channel_node(channel.id()).await?;
|
||||||
let room = voice.create_room(&data.node, &channel).await?;
|
|
||||||
|
let node = existing_node.or(data.into_inner().node)
|
||||||
|
.ok_or_else(|| create_error!(UnknownNode))?;
|
||||||
|
|
||||||
|
let node_host = config.hosts.livekit.get(&node)
|
||||||
|
.ok_or_else(|| create_error!(UnknownNode))?
|
||||||
|
.clone();
|
||||||
|
|
||||||
|
let token = voice.create_token(&node, &user, current_permissions, &channel)?;
|
||||||
|
let room = voice.create_room(&node, &channel).await?;
|
||||||
|
|
||||||
log::debug!("Created room {}", room.name);
|
log::debug!("Created room {}", room.name);
|
||||||
|
|
||||||
|
|||||||
@@ -104,6 +104,10 @@ pub async fn edit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let new_voice_channel = if let Some(new_channel) = &data.voice_channel {
|
let new_voice_channel = if let Some(new_channel) = &data.voice_channel {
|
||||||
|
if !voice_client.is_enabled() {
|
||||||
|
return Err(create_error!(LiveKitUnavailable))
|
||||||
|
};
|
||||||
|
|
||||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::MoveMembers)?;
|
permissions.throw_if_lacking_channel_permission(ChannelPermission::MoveMembers)?;
|
||||||
|
|
||||||
// ensure the channel we are moving them to is in the server and is a voice channel
|
// ensure the channel we are moving them to is in the server and is a voice channel
|
||||||
|
|||||||
Reference in New Issue
Block a user