use async_trait::async_trait;
use std::sync::Arc;
use crate::call::domain::CallCommand;
use crate::call::domain::MediaRuntimeProfile;
use crate::proxy::active_call_registry::ActiveProxyCallRegistry;
use super::{CommandExecutor, CommandResult, ExecutionContext, MediaCapabilityCheck};
pub struct SessionActionExecutor {
registry: Arc<ActiveProxyCallRegistry>,
}
impl SessionActionExecutor {
pub fn new(registry: Arc<ActiveProxyCallRegistry>) -> Self {
Self { registry }
}
fn apply_command(
&self,
session_id: &str,
command: CallCommand,
) -> anyhow::Result<CommandResult> {
let Some(handle) = self.registry.get_handle(session_id) else {
return Ok(CommandResult::failure(format!(
"session {} not found",
session_id
)));
};
match handle.send_command(command) {
Ok(_) => Ok(CommandResult::success()),
Err(e) => Ok(CommandResult::failure(format!(
"failed to apply command: {}",
e
))),
}
}
}
#[async_trait]
impl CommandExecutor for SessionActionExecutor {
async fn execute(
&self,
ctx: ExecutionContext,
command: CallCommand,
) -> anyhow::Result<CommandResult> {
match ctx.check_media_capability(&command) {
MediaCapabilityCheck::Denied { reason } => {
return Ok(CommandResult::not_supported(reason));
}
MediaCapabilityCheck::Degraded { reason } => {
let _ = reason; }
MediaCapabilityCheck::Allowed => {
}
}
self.apply_command(&ctx.session_id, command)
}
async fn session_exists(&self, session_id: &str) -> bool {
self.registry.get_handle(session_id).is_some()
}
async fn get_media_profile(&self, _session_id: &str) -> Option<MediaRuntimeProfile> {
Some(MediaRuntimeProfile::default())
}
}
#[cfg(test)]
mod tests {
}