mirror of https://github.com/dnaka91/obws
Implement new output requests
parent
f924919e2a
commit
825514f52b
@ -0,0 +1,80 @@
|
||||
use super::Client;
|
||||
use crate::{requests::RequestType, responses, Result};
|
||||
|
||||
/// API functions related to outputs.
|
||||
pub struct Outputs<'a> {
|
||||
pub(super) client: &'a Client,
|
||||
}
|
||||
|
||||
impl<'a> Outputs<'a> {
|
||||
/// Gets the status of the virtual cam output.
|
||||
pub async fn get_virtual_cam_status(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<responses::OutputActive>(RequestType::GetVirtualCamStatus)
|
||||
.await
|
||||
.map(|oa| oa.output_active)
|
||||
}
|
||||
|
||||
/// Toggles the state of the virtual cam output.
|
||||
pub async fn toggle_virtual_cam(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<responses::OutputActive>(RequestType::ToggleVirtualCam)
|
||||
.await
|
||||
.map(|oa| oa.output_active)
|
||||
}
|
||||
|
||||
/// Starts the virtual cam output.
|
||||
pub async fn start_virtual_cam(&self) -> Result<()> {
|
||||
self.client.send_message(RequestType::StartVirtualCam).await
|
||||
}
|
||||
|
||||
/// Stops the virtual cam output.
|
||||
pub async fn stop_virtual_cam(&self) -> Result<()> {
|
||||
self.client.send_message(RequestType::StopVirtualCam).await
|
||||
}
|
||||
|
||||
/// Gets the status of the replay buffer output.
|
||||
pub async fn get_replay_buffer_status(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<responses::OutputActive>(RequestType::GetReplayBufferStatus)
|
||||
.await
|
||||
.map(|oa| oa.output_active)
|
||||
}
|
||||
|
||||
/// Toggles the state of the replay buffer output.
|
||||
pub async fn toggle_replay_buffer(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<responses::OutputActive>(RequestType::ToggleReplayBuffer)
|
||||
.await
|
||||
.map(|oa| oa.output_active)
|
||||
}
|
||||
|
||||
/// Starts the replay buffer output.
|
||||
pub async fn start_replay_buffer(&self) -> Result<()> {
|
||||
self.client
|
||||
.send_message(RequestType::StartReplayBuffer)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Stops the replay buffer output.
|
||||
pub async fn stop_replay_buffer(&self) -> Result<()> {
|
||||
self.client
|
||||
.send_message(RequestType::StopReplayBuffer)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Saves the contents of the replay buffer output.
|
||||
pub async fn save_replay_buffer(&self) -> Result<()> {
|
||||
self.client
|
||||
.send_message(RequestType::SaveReplayBuffer)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Gets the file name of the last replay buffer save file.
|
||||
pub async fn get_last_replay_buffer_replay(&self) -> Result<String> {
|
||||
self.client
|
||||
.send_message::<responses::SavedReplayPath>(RequestType::GetLastReplayBufferReplay)
|
||||
.await
|
||||
.map(|srp| srp.saved_replay_path)
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
#![cfg(feature = "test-integration")]
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
use obws::events::{Event, OutputState};
|
||||
use tokio::time;
|
||||
|
||||
use crate::{common, wait_for};
|
||||
|
||||
#[tokio::test]
|
||||
async fn outputs() -> Result<()> {
|
||||
let client = common::new_client().await?;
|
||||
let events = client.events()?;
|
||||
let client = client.outputs();
|
||||
|
||||
tokio::pin!(events);
|
||||
|
||||
client.get_virtual_cam_status().await?;
|
||||
|
||||
client.toggle_virtual_cam().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
output_state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.toggle_virtual_cam().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
output_state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.start_virtual_cam().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
output_state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.stop_virtual_cam().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
output_state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
|
||||
client.get_replay_buffer_status().await?;
|
||||
|
||||
client.toggle_replay_buffer().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
output_state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.toggle_replay_buffer().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
output_state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.start_replay_buffer().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
output_state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.save_replay_buffer().await?;
|
||||
client.get_last_replay_buffer_replay().await?;
|
||||
client.stop_replay_buffer().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
output_state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue