use crate::client::{url_encode, AriClient};
use crate::error::Result;
use crate::event::LiveRecording;
#[derive(Debug, Clone, serde::Deserialize)]
pub struct StoredRecording {
pub name: String,
pub format: String,
}
#[derive(Debug, Clone)]
pub struct RecordingHandle {
name: String,
client: AriClient,
}
impl RecordingHandle {
pub fn new(name: impl Into<String>, client: AriClient) -> Self {
Self {
name: name.into(),
client,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub async fn stop(&self) -> Result<()> {
self.client
.post_empty(&format!("/recordings/live/{}/stop", url_encode(&self.name)))
.await
}
pub async fn pause(&self) -> Result<()> {
self.client
.post_empty(&format!(
"/recordings/live/{}/pause",
url_encode(&self.name)
))
.await
}
pub async fn unpause(&self) -> Result<()> {
self.client
.delete(&format!(
"/recordings/live/{}/pause",
url_encode(&self.name)
))
.await
}
pub async fn mute(&self) -> Result<()> {
self.client
.post_empty(&format!("/recordings/live/{}/mute", url_encode(&self.name)))
.await
}
pub async fn unmute(&self) -> Result<()> {
self.client
.delete(&format!("/recordings/live/{}/mute", url_encode(&self.name)))
.await
}
pub async fn get(&self) -> Result<LiveRecording> {
self.client
.get(&format!("/recordings/live/{}", url_encode(&self.name)))
.await
}
}
pub async fn list_stored(client: &AriClient) -> Result<Vec<StoredRecording>> {
client.get("/recordings/stored").await
}