adding a basic setup for connecting OBS
This commit is contained in:
parent
511c34ee41
commit
c6c3ed5d42
5 changed files with 324 additions and 10 deletions
38
src/rust/obs.rs
Normal file
38
src/rust/obs.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use std::error::Error;
|
||||
|
||||
use obws::Client;
|
||||
use obws::responses::scenes::Scenes;
|
||||
use tracing::debug;
|
||||
pub struct Obs {
|
||||
scenes: Scenes,
|
||||
client: Client,
|
||||
}
|
||||
|
||||
impl Obs {
|
||||
pub async fn setup(mut self) -> Result<(), Box<dyn Error>> {
|
||||
let client = Client::connect("localhost", 4455, Some("")).await?;
|
||||
let scene_list = client.scenes().list().await?;
|
||||
debug!(?scene_list);
|
||||
self.scenes = scene_list;
|
||||
self.client = client;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_list(self) -> Result<Vec<String>, String> {
|
||||
let scenes = self.scenes.scenes.iter().map(|x| x.name).collect::<Vec<String>>();
|
||||
if scenes.len() > 0 {
|
||||
Ok(scenes)
|
||||
} else {
|
||||
Err(format!("Scenes found: {}", scenes.len()))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_scene(self, scene: String) -> Result<(), String> {
|
||||
if let Some(scene) = self.scenes.scenes.iter().filter(|x| x.name == scene).next() {
|
||||
self.client.scenes().set_current_program_scene(scene.name.as_str());
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Couldn't set the scene".to_string())
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue