Split up `config` category further

v5-api
Dominik Nakamura 2 years ago
parent 953124998c
commit 3e0147df7b
No known key found for this signature in database
GPG Key ID: E4C6A749B2491910

@ -2,7 +2,7 @@ use serde::{de::DeserializeOwned, Serialize};
use super::Client;
use crate::{
requests::config::{Realm, Request, SetPersistentData, SetProfileParameter, SetVideoSettings},
requests::config::{Realm, Request, SetPersistentData, SetVideoSettings},
responses, Error, Result,
};
@ -30,74 +30,6 @@ impl<'a> Config<'a> {
.await
}
/// Gets an array of all scene collections.
pub async fn list_scene_collections(&self) -> Result<responses::SceneCollections> {
self.client.send_message(Request::ListSceneColletions).await
}
/// Switches to a scene collection.
///
/// **Note:** This will block until the collection has finished changing.
pub async fn set_current_scene_collection(&self, name: &str) -> Result<()> {
self.client
.send_message(Request::SetCurrentSceneCollection { 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_scene_collection(&self, name: &str) -> Result<()> {
self.client
.send_message(Request::CreateSceneCollection { name })
.await
}
/// Gets an array of all profiles.
pub async fn list_profiles(&self) -> Result<responses::Profiles> {
self.client.send_message(Request::ListProfiles).await
}
/// Switches to a profile.
pub async fn set_current_profile(&self, name: &str) -> Result<()> {
self.client
.send_message(Request::SetCurrentProfile { name })
.await
}
/// Creates a new profile, switching to it in the process.
pub async fn create_profile(&self, name: &str) -> Result<()> {
self.client
.send_message(Request::CreateProfile { name })
.await
}
/// Removes a profile. If the current profile is chosen, it will change to a different profile
/// first.
pub async fn remove_profile(&self, name: &str) -> Result<()> {
self.client
.send_message(Request::RemoveProfile { name })
.await
}
/// Gets a parameter from the current profile's configuration.
pub async fn get_profile_parameter(
&self,
category: &str,
name: &str,
) -> Result<responses::ProfileParameter> {
self.client
.send_message(Request::GetProfileParameter { category, name })
.await
}
/// Sets the value of a parameter in the current profile's configuration.
pub async fn set_profile_parameter(&self, parameter: SetProfileParameter<'_>) -> Result<()> {
self.client
.send_message(Request::SetProfileParameter(parameter))
.await
}
/// Gets the current video settings.
///
/// **Note:** To get the true FPS value, divide the FPS numerator by the FPS denominator.

@ -30,8 +30,9 @@ use tracing::{debug, error, info, trace};
use self::connection::{ReceiverList, ReidentifyReceiverList};
pub use self::{
config::Config, connection::HandshakeError, filters::Filters, general::General, inputs::Inputs,
media_inputs::MediaInputs, outputs::Outputs, recording::Recording, scene_items::SceneItems,
scenes::Scenes, sources::Sources, streaming::Streaming, transitions::Transitions, ui::Ui,
media_inputs::MediaInputs, outputs::Outputs, profiles::Profiles, recording::Recording,
scene_collections::SceneCollections, scene_items::SceneItems, scenes::Scenes, sources::Sources,
streaming::Streaming, transitions::Transitions, ui::Ui,
};
#[cfg(feature = "events")]
use crate::events::Event;
@ -48,7 +49,9 @@ mod general;
mod inputs;
mod media_inputs;
mod outputs;
mod profiles;
mod recording;
mod scene_collections;
mod scene_items;
mod scenes;
mod sources;
@ -476,11 +479,21 @@ impl Client {
Outputs { client: self }
}
/// Access API functions related to profiles.
pub fn profiles(&self) -> Profiles<'_> {
Profiles { client: self }
}
/// Access API functions related to recording.
pub fn recording(&self) -> Recording<'_> {
Recording { client: self }
}
/// Access API functions related to scene collections.
pub fn scene_collections(&self) -> SceneCollections<'_> {
SceneCollections { client: self }
}
/// Access API functions related to scene items.
pub fn scene_items(&self) -> SceneItems<'_> {
SceneItems { client: self }

@ -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
}
}

@ -17,51 +17,6 @@ pub(crate) enum Request<'a> {
},
#[serde(rename = "SetPersistentData")]
SetPersistentData(SetPersistentData<'a>),
#[serde(rename = "GetSceneCollectionList")]
ListSceneColletions,
#[serde(rename = "SetCurrentSceneCollection")]
SetCurrentSceneCollection {
/// Name of the scene collection to switch to.
#[serde(rename = "sceneCollectionName")]
name: &'a str,
},
#[serde(rename = "CreateSceneCollection")]
CreateSceneCollection {
/// Name for the new scene collection.
#[serde(rename = "sceneCollectionName")]
name: &'a str,
},
#[serde(rename = "GetProfileList")]
ListProfiles,
#[serde(rename = "SetCurrentProfile")]
SetCurrentProfile {
/// Name of the profile to switch to.
#[serde(rename = "profileName")]
name: &'a str,
},
#[serde(rename = "CreateProfile")]
CreateProfile {
/// Name for the new profile.
#[serde(rename = "profileName")]
name: &'a str,
},
#[serde(rename = "RemoveProfile")]
RemoveProfile {
/// Name of the profile to remove.
#[serde(rename = "profileName")]
name: &'a str,
},
#[serde(rename = "GetProfileParameter")]
GetProfileParameter {
/// 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")]
SetProfileParameter(SetProfileParameter<'a>),
#[serde(rename = "GetVideoSettings")]
VideoSettings,
#[serde(rename = "SetVideoSettings")]
@ -114,21 +69,6 @@ pub struct SetPersistentData<'a> {
pub slot_value: &'a serde_json::Value,
}
/// Request information for [`crate::client::Config::set_profile_parameter`].
#[skip_serializing_none]
#[derive(Default, Serialize)]
pub struct SetProfileParameter<'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>,
}
/// Request information for [`crate::client::Config::set_video_settings`].
#[skip_serializing_none]
#[derive(Default, Serialize)]

@ -12,7 +12,9 @@ pub mod general;
pub mod inputs;
pub(crate) mod media_inputs;
pub(crate) mod outputs;
pub mod profiles;
pub(crate) mod recording;
pub(crate) mod scene_collections;
pub mod scene_items;
pub mod scenes;
mod ser;
@ -212,7 +214,9 @@ pub(crate) enum RequestType<'a> {
Inputs(self::inputs::Request<'a>),
MediaInputs(self::media_inputs::Request<'a>),
Outputs(self::outputs::Request),
Profiles(self::profiles::Request<'a>),
Recording(self::recording::Request),
SceneCollections(self::scene_collections::Request<'a>),
SceneItems(self::scene_items::Request<'a>),
Scenes(self::scenes::Request<'a>),
Sources(self::sources::Request<'a>),
@ -233,7 +237,9 @@ impl<'a> Serialize for RequestType<'a> {
Self::Inputs(req) => req.serialize(serializer),
Self::MediaInputs(req) => req.serialize(serializer),
Self::Outputs(req) => req.serialize(serializer),
Self::Profiles(req) => req.serialize(serializer),
Self::Recording(req) => req.serialize(serializer),
Self::SceneCollections(req) => req.serialize(serializer),
Self::SceneItems(req) => req.serialize(serializer),
Self::Scenes(req) => req.serialize(serializer),
Self::Sources(req) => req.serialize(serializer),

@ -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)
}
}

@ -119,7 +119,7 @@ async fn ensure_obs_setup(client: &Client) -> Result<()> {
TEST_FILTER_RENAME
);
let profiles = client.config().list_profiles().await?.profiles;
let profiles = client.profiles().list().await?.profiles;
ensure!(
profiles.iter().map(String::as_str).any(is_required_profile),
"profile `{}` not found, required for profiles tests",

@ -1,11 +1,7 @@
use std::time::Duration;
use anyhow::Result;
use obws::{
requests::config::{Realm, SetPersistentData, SetProfileParameter},
responses::{Profiles, SceneCollections},
requests::config::{Realm, SetPersistentData},
};
use tokio::time;
use crate::common;
@ -25,41 +21,6 @@ async fn config() -> Result<()> {
.get_persistent_data(Realm::Profile, "obws-test")
.await?;
let SceneCollections {
current,
collections,
} = client.list_scene_collections().await?;
let other = collections.iter().find(|sc| *sc != &current).unwrap();
client.set_current_scene_collection(other).await?;
time::sleep(Duration::from_secs(1)).await;
client.set_current_scene_collection(&current).await?;
time::sleep(Duration::from_secs(1)).await;
let Profiles { current, profiles } = client.list_profiles().await?;
let other = profiles.iter().find(|p| *p != &current).unwrap();
client.set_current_profile(other).await?;
time::sleep(Duration::from_secs(1)).await;
client.set_current_profile(&current).await?;
time::sleep(Duration::from_secs(1)).await;
client.create_profile("OBWS-TEST-New-Profile").await?;
client.remove_profile("OBWS-TEST-New-Profile").await?;
client.get_profile_parameter("General", "Name").await?;
client
.set_profile_parameter(SetProfileParameter {
category: "OBWS",
name: "Test",
value: Some("Value"),
})
.await?;
client
.set_profile_parameter(SetProfileParameter {
category: "OBWS",
name: "Test",
value: None,
})
.await?;
let settings = client.video_settings().await?;
client.set_video_settings(settings.into()).await?;

@ -7,7 +7,9 @@ mod general;
mod inputs;
mod media_inputs;
mod outputs;
mod profiles;
mod recording;
mod scene_collections;
mod scene_items;
mod scenes;
mod sources;

@ -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 != &current).unwrap();
client.set_current(other).await?;
time::sleep(Duration::from_secs(1)).await;
client.set_current(&current).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 != &current).unwrap();
client.set_current(other).await?;
time::sleep(Duration::from_secs(1)).await;
client.set_current(&current).await?;
time::sleep(Duration::from_secs(1)).await;
Ok(())
}
Loading…
Cancel
Save