Skip to content

Commit

Permalink
move to new task
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroMS25 committed Mar 15, 2024
1 parent aa62edd commit afd995b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/api/routes/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use axum::response::{IntoResponse, Response};
use serde::Deserialize;
use songbird::input::{AuxMetadata, Compose, Input, YoutubeDl};
use songbird::tracks::TrackHandle;
use tracing::{info, warn};
use tracing::{error, info, warn};
use uuid::Uuid;

use crate::api::extractors::player::PlayerExtractor;
Expand All @@ -35,22 +35,22 @@ pub async fn update(
body: Option<Json<DeserializableConnectionInfo>>
) -> impl IntoResponse {
info!("Incoming connection request");
let player = session.playback.get_or_create(guild, Arc::clone(&session)).await;
tokio::spawn(async move {
let player = session.playback.get_or_create(guild, Arc::clone(&session)).await;

let info = body.map(|j| j.0.into_songbird(session.playback.user_id.0, guild));
let info = body.map(|j| j.0.into_songbird(session.playback.user_id.0, guild));

let mut lock = player.lock().await;
match lock.update(info).await {
Ok(_) => Response::builder()
.status(StatusCode::OK)
.body(Body::empty())
.unwrap(),
let mut lock = player.lock().await;

Err(e) => Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::from(format!(r#"{{"message": "{e}" }}"#)))
.unwrap()
}
if let Err(why) = lock.update(info).await {
error!("Failed to leave voice channel, error: {why}");
}
});

Response::builder()
.status(StatusCode::OK)
.body(Body::empty())
.unwrap()
}

pub async fn play(
Expand Down

0 comments on commit afd995b

Please sign in to comment.