Implement filter commands

v5-api
Dominik Nakamura 2 years ago
parent 21cbe828b1
commit 749f6cc364
No known key found for this signature in database
GPG Key ID: E4C6A749B2491910

@ -0,0 +1,26 @@
use super::Client;
use crate::{requests::RequestType, responses, Result};
/// API functions related to filters.
pub struct Filters<'a> {
pub(super) client: &'a Client,
}
impl<'a> Filters<'a> {
/// Gets the info for a specific source filter.
///
/// - `source_name`: Name of the source.
/// - `filter_name`: Name of the filter.
pub async fn get_source_filter(
&self,
source_name: &str,
filter_name: &str,
) -> Result<responses::SourceFilter> {
self.client
.send_message(RequestType::GetSourceFilter {
source_name,
filter_name,
})
.await
}
}

@ -29,9 +29,9 @@ use tokio_tungstenite::{tungstenite::Message, MaybeTlsStream, WebSocketStream};
use tracing::{debug, error, trace};
pub use self::{
config::Config, general::General, inputs::Inputs, media_inputs::MediaInputs, outputs::Outputs,
recording::Recording, scene_items::SceneItems, scenes::Scenes, sources::Sources,
streaming::Streaming, transitions::Transitions, ui::Ui,
config::Config, 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,
};
#[cfg(feature = "events")]
use crate::events::Event;
@ -42,6 +42,7 @@ use crate::{
};
mod config;
mod filters;
mod general;
mod inputs;
mod media_inputs;
@ -400,6 +401,11 @@ impl Client {
Config { client: self }
}
/// Access API functions related to filters.
pub fn filters(&self) -> Filters<'_> {
Filters { client: self }
}
/// Access general API functions.
pub fn general(&self) -> General<'_> {
General { client: self }

@ -253,6 +253,16 @@ pub(crate) enum RequestType<'a> {
},
GetRecordDirectory,
// --------------------------------
// Filters
// --------------------------------
#[serde(rename_all = "camelCase")]
GetSourceFilter {
/// Name of the source.
source_name: &'a str,
/// Name of the filter.
filter_name: &'a str,
},
// --------------------------------
// General
// --------------------------------
GetVersion,

@ -277,6 +277,19 @@ pub struct StreamServiceSettings<T> {
pub stream_service_settings: T,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SourceFilter {
/// Whether the filter is enabled.
pub filter_enabled: bool,
/// Index of the filter in the list, beginning at 0.
pub filter_index: u32,
/// The kind of filter.
pub filter_kind: String,
/// Settings object associated with the filter.
pub filter_settings: serde_json::Value,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Version {

@ -18,6 +18,7 @@ pub const TEST_BROWSER_RENAME: &str = "OBWS-TEST-Browser-Renamed";
pub const TEST_MEDIA: &str = "OBWS-TEST-Media";
pub const TEST_GROUP: &str = "OBWS-TEST-Group";
pub const TEST_TRANSITION: &str = "OBWS-TEST-Transition";
pub const TEST_FILTER: &str = "OBWS-TEST-Filter";
pub const INPUT_KIND_TEXT_FT2: &str = "text_ft2_source_v2";
pub const INPUT_KIND_BROWSER: &str = "browser_source";
pub const INPUT_KIND_VLC: &str = "vlc_source";

@ -0,0 +1,13 @@
use anyhow::Result;
use crate::common::{self, TEST_FILTER, TEST_TEXT};
#[tokio::test]
async fn filters() -> Result<()> {
let client = common::new_client().await?;
let client = client.filters();
client.get_source_filter(TEST_TEXT, TEST_FILTER).await?;
Ok(())
}

@ -2,6 +2,7 @@
mod common;
mod config;
mod filters;
mod general;
mod inputs;
mod media_inputs;

Loading…
Cancel
Save