mirror of https://github.com/dnaka91/obws
Split up `config` category further
parent
953124998c
commit
3e0147df7b
@ -0,0 +1,65 @@
|
||||
use super::Client;
|
||||
use crate::{
|
||||
requests::profiles::{Request, SetParameter},
|
||||
responses, Result,
|
||||
};
|
||||
|
||||
/// API functions related to profiles.
|
||||
pub struct Profiles<'a> {
|
||||
pub(super) client: &'a Client,
|
||||
}
|
||||
|
||||
impl<'a> Profiles<'a> {
|
||||
/// Gets an array of all profiles.
|
||||
pub async fn list(&self) -> Result<responses::Profiles> {
|
||||
self.client.send_message(Request::List).await
|
||||
}
|
||||
|
||||
/// Get the currently active profile name.
|
||||
pub async fn current(&self) -> Result<String> {
|
||||
self.client
|
||||
.send_message::<_, responses::Profiles>(Request::List)
|
||||
.await
|
||||
.map(|p| p.current)
|
||||
}
|
||||
|
||||
/// Switches to a profile.
|
||||
pub async fn set_current(&self, name: &str) -> Result<()> {
|
||||
self.client
|
||||
.send_message(Request::SetCurrent { name })
|
||||
.await
|
||||
}
|
||||
|
||||
/// Creates a new profile, switching to it in the process.
|
||||
pub async fn create(&self, name: &str) -> Result<()> {
|
||||
self.client
|
||||
.send_message(Request::Create { name })
|
||||
.await
|
||||
}
|
||||
|
||||
/// Removes a profile. If the current profile is chosen, it will change to a different profile
|
||||
/// first.
|
||||
pub async fn remove(&self, name: &str) -> Result<()> {
|
||||
self.client
|
||||
.send_message(Request::Remove { name })
|
||||
.await
|
||||
}
|
||||
|
||||
/// Gets a parameter from the current profile's configuration.
|
||||
pub async fn parameter(
|
||||
&self,
|
||||
category: &str,
|
||||
name: &str,
|
||||
) -> Result<responses::ProfileParameter> {
|
||||
self.client
|
||||
.send_message(Request::Parameter { category, name })
|
||||
.await
|
||||
}
|
||||
|
||||
/// Sets the value of a parameter in the current profile's configuration.
|
||||
pub async fn set_parameter(&self, parameter: SetParameter<'_>) -> Result<()> {
|
||||
self.client
|
||||
.send_message(Request::SetParameter(parameter))
|
||||
.await
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
use super::Client;
|
||||
use crate::{requests::scene_collections::Request, responses, Result};
|
||||
|
||||
/// API functions related to scene collections.
|
||||
pub struct SceneCollections<'a> {
|
||||
pub(super) client: &'a Client,
|
||||
}
|
||||
|
||||
impl<'a> SceneCollections<'a> {
|
||||
/// Gets an array of all scene collections.
|
||||
pub async fn list(&self) -> Result<responses::SceneCollections> {
|
||||
self.client.send_message(Request::List).await
|
||||
}
|
||||
|
||||
/// Get the currently active scene collection name.
|
||||
pub async fn current(&self) -> Result<String> {
|
||||
self.client
|
||||
.send_message::<_, responses::SceneCollections>(Request::List)
|
||||
.await
|
||||
.map(|sc| sc.current)
|
||||
}
|
||||
|
||||
/// Switches to a scene collection.
|
||||
///
|
||||
/// **Note:** This will block until the collection has finished changing.
|
||||
pub async fn set_current(&self, name: &str) -> Result<()> {
|
||||
self.client
|
||||
.send_message(Request::SetCurrent { name })
|
||||
.await
|
||||
}
|
||||
|
||||
/// Creates a new scene collection, switching to it in the process.
|
||||
///
|
||||
/// **Note:** This will block until the collection has finished changing.
|
||||
pub async fn create(&self, name: &str) -> Result<()> {
|
||||
self.client
|
||||
.send_message(Request::Create { name })
|
||||
.await
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
//! Requests related to profiles.
|
||||
|
||||
use serde::Serialize;
|
||||
use serde_with::skip_serializing_none;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(tag = "requestType", content = "requestData")]
|
||||
pub(crate) enum Request<'a> {
|
||||
#[serde(rename = "GetProfileList")]
|
||||
List,
|
||||
#[serde(rename = "SetCurrentProfile")]
|
||||
SetCurrent {
|
||||
/// Name of the profile to switch to.
|
||||
#[serde(rename = "profileName")]
|
||||
name: &'a str,
|
||||
},
|
||||
#[serde(rename = "CreateProfile")]
|
||||
Create {
|
||||
/// Name for the new profile.
|
||||
#[serde(rename = "profileName")]
|
||||
name: &'a str,
|
||||
},
|
||||
#[serde(rename = "RemoveProfile")]
|
||||
Remove {
|
||||
/// Name of the profile to remove.
|
||||
#[serde(rename = "profileName")]
|
||||
name: &'a str,
|
||||
},
|
||||
#[serde(rename = "GetProfileParameter")]
|
||||
Parameter {
|
||||
/// Category of the parameter to get.
|
||||
#[serde(rename = "parameterCategory")]
|
||||
category: &'a str,
|
||||
/// Name of the parameter to get.
|
||||
#[serde(rename = "parameterName")]
|
||||
name: &'a str,
|
||||
},
|
||||
#[serde(rename = "SetProfileParameter")]
|
||||
SetParameter(SetParameter<'a>),
|
||||
}
|
||||
|
||||
impl<'a> From<Request<'a>> for super::RequestType<'a> {
|
||||
fn from(value: Request<'a>) -> Self {
|
||||
super::RequestType::Profiles(value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Request information for [`crate::client::Config::set_profile_parameter`].
|
||||
#[skip_serializing_none]
|
||||
#[derive(Default, Serialize)]
|
||||
pub struct SetParameter<'a> {
|
||||
/// Category of the parameter to set.
|
||||
#[serde(rename = "parameterCategory")]
|
||||
pub category: &'a str,
|
||||
/// Name of the parameter to set.
|
||||
#[serde(rename = "parameterName")]
|
||||
pub name: &'a str,
|
||||
/// Value of the parameter to set. Use [`None`] to delete.
|
||||
#[serde(rename = "parameterValue")]
|
||||
pub value: Option<&'a str>,
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
//! Requests related to scene collections.
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(tag = "requestType", content = "requestData")]
|
||||
pub(crate) enum Request<'a> {
|
||||
#[serde(rename = "GetSceneCollectionList")]
|
||||
List,
|
||||
#[serde(rename = "SetCurrentSceneCollection")]
|
||||
SetCurrent {
|
||||
/// Name of the scene collection to switch to.
|
||||
#[serde(rename = "sceneCollectionName")]
|
||||
name: &'a str,
|
||||
},
|
||||
#[serde(rename = "CreateSceneCollection")]
|
||||
Create {
|
||||
/// Name for the new scene collection.
|
||||
#[serde(rename = "sceneCollectionName")]
|
||||
name: &'a str,
|
||||
},
|
||||
}
|
||||
|
||||
impl<'a> From<Request<'a>> for super::RequestType<'a> {
|
||||
fn from(value: Request<'a>) -> Self {
|
||||
super::RequestType::SceneCollections(value)
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
use obws::{requests::profiles::SetParameter, responses::Profiles};
|
||||
use tokio::time;
|
||||
|
||||
use crate::common;
|
||||
|
||||
#[tokio::test]
|
||||
async fn profiles() -> Result<()> {
|
||||
let client = common::new_client().await?;
|
||||
let client = client.profiles();
|
||||
|
||||
let Profiles { current, profiles } = client.list().await?;
|
||||
client.current().await?;
|
||||
let other = profiles.iter().find(|p| *p != ¤t).unwrap();
|
||||
client.set_current(other).await?;
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.set_current(¤t).await?;
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.create("OBWS-TEST-New-Profile").await?;
|
||||
client.remove("OBWS-TEST-New-Profile").await?;
|
||||
|
||||
client.parameter("General", "Name").await?;
|
||||
client
|
||||
.set_parameter(SetParameter {
|
||||
category: "OBWS",
|
||||
name: "Test",
|
||||
value: Some("Value"),
|
||||
})
|
||||
.await?;
|
||||
client
|
||||
.set_parameter(SetParameter {
|
||||
category: "OBWS",
|
||||
name: "Test",
|
||||
value: None,
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
use obws::responses::SceneCollections;
|
||||
use tokio::time;
|
||||
|
||||
use crate::common;
|
||||
|
||||
#[tokio::test]
|
||||
async fn scene_collections() -> Result<()> {
|
||||
let client = common::new_client().await?;
|
||||
let client = client.scene_collections();
|
||||
|
||||
let SceneCollections {
|
||||
current,
|
||||
collections,
|
||||
} = client.list().await?;
|
||||
client.current().await?;
|
||||
let other = collections.iter().find(|sc| *sc != ¤t).unwrap();
|
||||
client.set_current(other).await?;
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.set_current(¤t).await?;
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue