use serde::{Serialize, de::DeserializeOwned};
use super::Client;
use crate::{
error::Result,
requests::config::{Realm, Request, SetPersistentData, SetVideoSettings},
responses::config as responses,
};
pub struct Config<'a> {
pub(super) client: &'a Client,
}
impl<'a> Config<'a> {
#[doc(alias = "GetPersistentData")]
pub async fn get_persistent_data(
&self,
realm: Realm,
slot_name: &str,
) -> Result<serde_json::Value> {
self.client
.send_message(Request::GetPersistentData { realm, slot_name })
.await
}
#[doc(alias = "SetPersistentData")]
pub async fn set_persistent_data(&self, data: SetPersistentData<'_>) -> Result<()> {
self.client
.send_message(Request::SetPersistentData(data))
.await
}
#[doc(alias = "GetVideoSettings")]
pub async fn video_settings(&self) -> Result<responses::VideoSettings> {
self.client.send_message(Request::VideoSettings).await
}
#[doc(alias = "SetVideoSettings")]
pub async fn set_video_settings(&self, settings: SetVideoSettings) -> Result<()> {
self.client
.send_message(Request::SetVideoSettings(settings))
.await
}
#[doc(alias = "GetStreamServiceSettings")]
pub async fn stream_service_settings<T>(&self) -> Result<responses::StreamServiceSettings<T>>
where
T: DeserializeOwned,
{
self.client
.send_message(Request::StreamServiceSettings)
.await
}
#[doc(alias = "SetStreamServiceSettings")]
pub async fn set_stream_service_settings<T>(&self, r#type: &'a str, settings: &T) -> Result<()>
where
T: Serialize,
{
self.client
.send_message(Request::SetStreamServiceSettings {
r#type,
settings: serde_json::to_value(settings)
.map_err(crate::error::SerializeCustomDataError)?,
})
.await
}
#[doc(alias = "GetRecordDirectory")]
pub async fn record_directory(&self) -> Result<String> {
self.client
.send_message::<_, responses::RecordDirectory>(Request::RecordDirectory)
.await
.map(|rd| rd.record_directory)
}
#[doc(alias = "SetRecordDirectory")]
pub async fn set_record_directory(&self, directory: &'a str) -> Result<()> {
self.client
.send_message(Request::SetRecordDirectory { directory })
.await
}
}