use std::sync::Arc;
use crate::api::unified::UnifiedCoordinator;
use crate::SessionId;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum TransferError {
#[error("transfer failed: {0}")]
Failed(String),
}
impl From<crate::errors::SessionError> for TransferError {
fn from(err: crate::errors::SessionError) -> Self {
TransferError::Failed(err.to_string())
}
}
pub async fn blind_transfer(
coordinator: &Arc<UnifiedCoordinator>,
source_session: &SessionId,
target_uri: &str,
) -> Result<(), TransferError> {
coordinator
.refer(source_session, target_uri.to_string())
.send()
.await
.map_err(Into::into)
}
pub async fn attended_transfer(
coordinator: &Arc<UnifiedCoordinator>,
source_session: &SessionId,
target_uri: &str,
replaces: &str,
) -> Result<(), TransferError> {
coordinator
.refer(source_session, target_uri.to_string())
.with_replaces(replaces.to_string())
.send()
.await
.map_err(Into::into)
}
pub async fn accept_inbound_refer(
coordinator: &UnifiedCoordinator,
session_id: &SessionId,
) -> Result<(), TransferError> {
coordinator
.accept_refer(session_id)
.await
.map_err(Into::into)
}