botserver/src/meet/mod.rs

90 lines
2.2 KiB
Rust
Raw Normal View History

2025-11-20 13:28:35 -03:00
use axum::{
extract::State,
http::StatusCode,
response::{IntoResponse, Json},
};
2025-10-18 12:03:07 -03:00
use log::{error, info};
2025-11-20 13:28:35 -03:00
use serde_json::Value;
use std::sync::Arc;
2025-10-18 12:03:07 -03:00
use crate::shared::state::AppState;
2025-11-20 13:28:35 -03:00
pub async fn voice_start(
State(data): State<Arc<AppState>>,
Json(info): Json<Value>,
) -> impl IntoResponse {
2025-10-18 12:03:07 -03:00
let session_id = info
.get("session_id")
.and_then(|s| s.as_str())
.unwrap_or("");
let user_id = info
.get("user_id")
.and_then(|u| u.as_str())
.unwrap_or("user");
2025-11-20 13:28:35 -03:00
2025-10-18 12:03:07 -03:00
info!(
"Voice session start request - session: {}, user: {}",
session_id, user_id
);
2025-11-20 13:28:35 -03:00
2025-10-18 12:03:07 -03:00
match data
.voice_adapter
.start_voice_session(session_id, user_id)
.await
{
Ok(token) => {
info!(
"Voice session started successfully for session {}",
session_id
);
2025-11-20 13:28:35 -03:00
(
StatusCode::OK,
Json(serde_json::json!({"token": token, "status": "started"})),
)
2025-10-18 12:03:07 -03:00
}
Err(e) => {
error!(
"Failed to start voice session for session {}: {}",
session_id, e
);
2025-11-20 13:28:35 -03:00
(
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({"error": e.to_string()})),
)
2025-10-18 12:03:07 -03:00
}
}
}
2025-11-20 13:28:35 -03:00
pub async fn voice_stop(
State(data): State<Arc<AppState>>,
Json(info): Json<Value>,
) -> impl IntoResponse {
2025-10-18 12:03:07 -03:00
let session_id = info
.get("session_id")
.and_then(|s| s.as_str())
.unwrap_or("");
2025-11-20 13:28:35 -03:00
2025-10-18 12:03:07 -03:00
match data.voice_adapter.stop_voice_session(session_id).await {
Ok(()) => {
info!(
"Voice session stopped successfully for session {}",
session_id
);
2025-11-20 13:28:35 -03:00
(
StatusCode::OK,
Json(serde_json::json!({"status": "stopped"})),
)
2025-10-18 12:03:07 -03:00
}
Err(e) => {
error!(
"Failed to stop voice session for session {}: {}",
session_id, e
);
2025-11-20 13:28:35 -03:00
(
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({"error": e.to_string()})),
)
2025-10-18 12:03:07 -03:00
}
}
}