mirror of https://github.com/dnaka91/obws
Split outputs into virtual cam and replay buffer
parent
b237b8b471
commit
db12a54e72
@ -1,74 +0,0 @@
|
||||
use super::Client;
|
||||
use crate::{requests::outputs::Request, 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 virtual_cam_status(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<_, responses::OutputActive>(Request::VirtualCamStatus)
|
||||
.await
|
||||
.map(|oa| oa.active)
|
||||
}
|
||||
|
||||
/// Toggles the state of the virtual cam output.
|
||||
pub async fn toggle_virtual_cam(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<_, responses::OutputActive>(Request::ToggleVirtualCam)
|
||||
.await
|
||||
.map(|oa| oa.active)
|
||||
}
|
||||
|
||||
/// Starts the virtual cam output.
|
||||
pub async fn start_virtual_cam(&self) -> Result<()> {
|
||||
self.client.send_message(Request::StartVirtualCam).await
|
||||
}
|
||||
|
||||
/// Stops the virtual cam output.
|
||||
pub async fn stop_virtual_cam(&self) -> Result<()> {
|
||||
self.client.send_message(Request::StopVirtualCam).await
|
||||
}
|
||||
|
||||
/// Gets the status of the replay buffer output.
|
||||
pub async fn replay_buffer_status(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<_, responses::OutputActive>(Request::ReplayBufferStatus)
|
||||
.await
|
||||
.map(|oa| oa.active)
|
||||
}
|
||||
|
||||
/// Toggles the state of the replay buffer output.
|
||||
pub async fn toggle_replay_buffer(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<_, responses::OutputActive>(Request::ToggleReplayBuffer)
|
||||
.await
|
||||
.map(|oa| oa.active)
|
||||
}
|
||||
|
||||
/// Starts the replay buffer output.
|
||||
pub async fn start_replay_buffer(&self) -> Result<()> {
|
||||
self.client.send_message(Request::StartReplayBuffer).await
|
||||
}
|
||||
|
||||
/// Stops the replay buffer output.
|
||||
pub async fn stop_replay_buffer(&self) -> Result<()> {
|
||||
self.client.send_message(Request::StopReplayBuffer).await
|
||||
}
|
||||
|
||||
/// Saves the contents of the replay buffer output.
|
||||
pub async fn save_replay_buffer(&self) -> Result<()> {
|
||||
self.client.send_message(Request::SaveReplayBuffer).await
|
||||
}
|
||||
|
||||
/// Gets the file name of the last replay buffer save file.
|
||||
pub async fn last_replay_buffer_replay(&self) -> Result<String> {
|
||||
self.client
|
||||
.send_message::<_, responses::SavedReplayPath>(Request::LastReplayBufferReplay)
|
||||
.await
|
||||
.map(|srp| srp.saved_replay_path)
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
use super::Client;
|
||||
use crate::{requests::replay_buffer::Request, responses, Result};
|
||||
|
||||
/// API functions related to the replay buffer.
|
||||
pub struct ReplayBuffer<'a> {
|
||||
pub(super) client: &'a Client,
|
||||
}
|
||||
|
||||
impl<'a> ReplayBuffer<'a> {
|
||||
/// Gets the status of the replay buffer output.
|
||||
pub async fn status(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<_, responses::OutputActive>(Request::Status)
|
||||
.await
|
||||
.map(|oa| oa.active)
|
||||
}
|
||||
|
||||
/// Toggles the state of the replay buffer output.
|
||||
pub async fn toggle(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<_, responses::OutputActive>(Request::Toggle)
|
||||
.await
|
||||
.map(|oa| oa.active)
|
||||
}
|
||||
|
||||
/// Starts the replay buffer output.
|
||||
pub async fn start(&self) -> Result<()> {
|
||||
self.client.send_message(Request::Start).await
|
||||
}
|
||||
|
||||
/// Stops the replay buffer output.
|
||||
pub async fn stop(&self) -> Result<()> {
|
||||
self.client.send_message(Request::Stop).await
|
||||
}
|
||||
|
||||
/// Saves the contents of the replay buffer output.
|
||||
pub async fn save(&self) -> Result<()> {
|
||||
self.client.send_message(Request::Save).await
|
||||
}
|
||||
|
||||
/// Gets the file name of the last replay buffer save file.
|
||||
pub async fn last_replay(&self) -> Result<String> {
|
||||
self.client
|
||||
.send_message::<_, responses::SavedReplayPath>(Request::LastReplay)
|
||||
.await
|
||||
.map(|srp| srp.saved_replay_path)
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
use super::Client;
|
||||
use crate::{requests::virtual_cam::Request, responses, Result};
|
||||
|
||||
/// API functions related to the virtual camera.
|
||||
pub struct VirtualCam<'a> {
|
||||
pub(super) client: &'a Client,
|
||||
}
|
||||
|
||||
impl<'a> VirtualCam<'a> {
|
||||
/// Gets the status of the virtual cam output.
|
||||
pub async fn status(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<_, responses::OutputActive>(Request::Status)
|
||||
.await
|
||||
.map(|oa| oa.active)
|
||||
}
|
||||
|
||||
/// Toggles the state of the virtual cam output.
|
||||
pub async fn toggle(&self) -> Result<bool> {
|
||||
self.client
|
||||
.send_message::<_, responses::OutputActive>(Request::Toggle)
|
||||
.await
|
||||
.map(|oa| oa.active)
|
||||
}
|
||||
|
||||
/// Starts the virtual cam output.
|
||||
pub async fn start(&self) -> Result<()> {
|
||||
self.client.send_message(Request::Start).await
|
||||
}
|
||||
|
||||
/// Stops the virtual cam output.
|
||||
pub async fn stop(&self) -> Result<()> {
|
||||
self.client.send_message(Request::Stop).await
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
//! Requests related to the virtual camera.
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(tag = "requestType", content = "requestData")]
|
||||
pub(crate) enum Request {
|
||||
#[serde(rename = "GetVirtualCamStatus")]
|
||||
Status,
|
||||
#[serde(rename = "ToggleVirtualCam")]
|
||||
Toggle,
|
||||
#[serde(rename = "StartVirtualCam")]
|
||||
Start,
|
||||
#[serde(rename = "StopVirtualCam")]
|
||||
Stop,
|
||||
}
|
||||
|
||||
impl<'a> From<Request> for super::RequestType<'a> {
|
||||
fn from(value: Request) -> Self {
|
||||
super::RequestType::VirtualCam(value)
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
#![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.virtual_cam_status().await?;
|
||||
|
||||
client.toggle_virtual_cam().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.toggle_virtual_cam().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.start_virtual_cam().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.stop_virtual_cam().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
|
||||
client.replay_buffer_status().await?;
|
||||
|
||||
client.toggle_replay_buffer().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.toggle_replay_buffer().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.start_replay_buffer().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.save_replay_buffer().await?;
|
||||
client.last_replay_buffer_replay().await?;
|
||||
client.stop_replay_buffer().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
#![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 replay_buffer() -> Result<()> {
|
||||
let client = common::new_client().await?;
|
||||
let events = client.events()?;
|
||||
let client = client.replay_buffer();
|
||||
|
||||
tokio::pin!(events);
|
||||
|
||||
client.status().await?;
|
||||
|
||||
client.toggle().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.toggle().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.start().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.save().await?;
|
||||
client.last_replay().await?;
|
||||
client.stop().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::ReplayBufferStateChanged {
|
||||
state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
#![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 virtual_cam() -> Result<()> {
|
||||
let client = common::new_client().await?;
|
||||
let events = client.events()?;
|
||||
let client = client.virtual_cam();
|
||||
|
||||
tokio::pin!(events);
|
||||
|
||||
client.status().await?;
|
||||
|
||||
client.toggle().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.toggle().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.start().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
state: OutputState::Started,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
client.stop().await?;
|
||||
wait_for!(
|
||||
events,
|
||||
Event::VirtualcamStateChanged {
|
||||
state: OutputState::Stopped,
|
||||
..
|
||||
}
|
||||
);
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue