Implement new output requests

v5-api
Dominik Nakamura 2 years ago
parent f924919e2a
commit 825514f52b
No known key found for this signature in database
GPG Key ID: E4C6A749B2491910

@ -29,7 +29,7 @@ use tokio_tungstenite::{tungstenite::Message, MaybeTlsStream, WebSocketStream};
use tracing::{debug, error, trace};
pub use self::{
config::Config, general::General, inputs::Inputs, media_inputs::MediaInputs,
config::Config, general::General, inputs::Inputs, media_inputs::MediaInputs, outputs::Outputs,
recording::Recording, scene_items::SceneItems, scenes::Scenes, sources::Sources,
streaming::Streaming,
};
@ -45,6 +45,7 @@ mod config;
mod general;
mod inputs;
mod media_inputs;
mod outputs;
mod recording;
mod scene_items;
mod scenes;
@ -412,6 +413,11 @@ impl Client {
MediaInputs { client: self }
}
/// Access API functions related to outputs.
pub fn outputs(&self) -> Outputs<'_> {
Outputs { client: self }
}
/// Access API functions related to recording.
pub fn recording(&self) -> Recording<'_> {
Recording { client: self }

@ -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)
}
}

@ -412,6 +412,19 @@ pub(crate) enum RequestType<'a> {
media_action: MediaAction,
},
// --------------------------------
// Outputs
// --------------------------------
GetVirtualCamStatus,
ToggleVirtualCam,
StartVirtualCam,
StopVirtualCam,
GetReplayBufferStatus,
ToggleReplayBuffer,
StartReplayBuffer,
StopReplayBuffer,
SaveReplayBuffer,
GetLastReplayBufferReplay,
// --------------------------------
// Recording
// --------------------------------
GetRecordStatus,

@ -454,6 +454,12 @@ pub(crate) struct RecordDirectory {
pub record_directory: String,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct SavedReplayPath {
pub saved_replay_path: String,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct SceneItemId {
@ -626,7 +632,7 @@ pub struct StreamStatus {
pub output_active: bool,
/// Whether the output is currently reconnecting.
pub output_reconnecting: bool,
/// Current timecode for the output.
/// Current time code for the output.
#[serde(deserialize_with = "crate::de::duration_timecode")]
pub output_timecode: Duration,
/// Current duration for the output.

@ -108,6 +108,18 @@ async fn ensure_obs_setup(client: &Client) -> Result<()> {
"recording active, required to be stopped for recording tests"
);
let virtual_cam_active = client.outputs().get_virtual_cam_status().await?;
ensure!(
!virtual_cam_active,
"virtual cam active, required to be stopped for outputs tests"
);
let replay_buffer_active = client.outputs().get_replay_buffer_status().await?;
ensure!(
!replay_buffer_active,
"replay buffer active, required to be stopped for outputs tests"
);
client
.scenes()
.set_current_program_scene(TEST_SCENE)

@ -1,5 +1,3 @@
#![cfg(feature = "test-integration")]
use std::time::Duration;
use anyhow::Result;

@ -1,5 +1,3 @@
#![cfg(feature = "test-integration")]
use anyhow::Result;
use obws::{events::Event, requests::KeyModifiers};
use serde::Serialize;

@ -1,5 +1,3 @@
#![cfg(feature = "test-integration")]
use anyhow::Result;
use obws::{
requests::{SetInputSettings, Volume},

@ -1,8 +1,11 @@
#![cfg(feature = "test-integration")]
mod common;
mod config;
mod general;
mod inputs;
mod media_inputs;
mod outputs;
mod recording;
mod scenes;
mod sources;

@ -1,5 +1,3 @@
#![cfg(feature = "test-integration")]
use anyhow::Result;
use obws::common::MediaAction;
use time::Duration;

@ -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(())
}

@ -1,5 +1,3 @@
#![cfg(feature = "test-integration")]
use std::time::Duration;
use anyhow::Result;

@ -1,5 +1,3 @@
#![cfg(feature = "test-integration")]
use anyhow::Result;
use crate::common::{self, TEST_SCENE, TEST_SCENE_CREATE, TEST_SCENE_RENAME};

@ -1,5 +1,3 @@
#![cfg(feature = "test-integration")]
use std::env;
use anyhow::Result;

@ -1,5 +1,3 @@
#![cfg(feature = "test-integration")]
use anyhow::Result;
use crate::common;

Loading…
Cancel
Save