vmix_http/traits.rs
1use anyhow::Result;
2use async_trait::async_trait;
3use std::collections::HashMap;
4use vmix_core::Vmix;
5use vmix_tcp::{InputNumber, TallyData};
6
7/// HTTP vMix API client trait
8///
9/// This trait is designed specifically for HTTP-based communication
10/// with vMix instances, providing a request-response pattern.
11#[async_trait]
12pub trait VmixApiClient {
13 /// Execute a vMix function with optional parameters
14 ///
15 /// # Arguments
16 /// * `function` - The vMix function name (e.g., "Cut", "Fade", "PreviewInput")
17 /// * `params` - Function parameters as key-value pairs
18 ///
19 /// # Example
20 /// ```rust,ignore
21 /// use std::collections::HashMap;
22 ///
23 /// let mut params = HashMap::new();
24 /// params.insert("Input".to_string(), "1".to_string());
25 /// params.insert("Duration".to_string(), "1000".to_string());
26 /// client.execute_function("Fade", ¶ms).await?;
27 /// ```
28 async fn execute_function(
29 &self,
30 function: &str,
31 params: &HashMap<String, String>,
32 ) -> Result<()>;
33
34 /// Get the complete vMix XML state
35 ///
36 /// Returns a structured representation of the current vMix configuration
37 /// including inputs, overlays, transitions, and system state.
38 async fn get_xml_state(&self) -> Result<Vmix>;
39
40 /// Get tally data for all inputs
41 ///
42 /// Returns a mapping of input numbers to their tally states (OFF, PROGRAM, PREVIEW).
43 /// This is useful for lighting systems and input status displays.
44 async fn get_tally_data(&self) -> Result<HashMap<InputNumber, TallyData>>;
45
46 /// Check if the client is connected and the vMix instance is responsive
47 async fn is_connected(&self) -> bool;
48
49 /// Get the currently active (program) input number
50 async fn get_active_input(&self) -> Result<InputNumber>;
51
52 /// Get the currently previewed input number
53 async fn get_preview_input(&self) -> Result<InputNumber>;
54}