mirror of https://github.com/dnaka91/obws
Upgrade to obs-websocket 4.9.1 API
parent
7c79c5b20b
commit
b6e5835a64
@ -0,0 +1,35 @@
|
|||||||
|
use super::Client;
|
||||||
|
use crate::requests::RequestType;
|
||||||
|
use crate::responses;
|
||||||
|
use crate::Result;
|
||||||
|
|
||||||
|
/// API functions related to the virtual cam.
|
||||||
|
pub struct VirtualCam<'a> {
|
||||||
|
pub(super) client: &'a Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> VirtualCam<'a> {
|
||||||
|
/// Get current virtual cam status.
|
||||||
|
pub async fn get_virtual_cam_status(&self) -> Result<responses::VirtualCamStatus> {
|
||||||
|
self.client
|
||||||
|
.send_message(RequestType::GetVirtualCamStatus)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Toggle virtual cam on or off (depending on the current virtual cam state).
|
||||||
|
pub async fn start_stop_virtual_cam(&self) -> Result<()> {
|
||||||
|
self.client
|
||||||
|
.send_message(RequestType::StartStopVirtualCam)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start virtual cam. Will return an `error` if virtual cam is already active.
|
||||||
|
pub async fn start_virtual_cam(&self) -> Result<()> {
|
||||||
|
self.client.send_message(RequestType::StartVirtualCam).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stop virtual cam. Will return an error if virtual cam is not active.
|
||||||
|
pub async fn stop_virtual_cam(&self) -> Result<()> {
|
||||||
|
self.client.send_message(RequestType::StopVirtualCam).await
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
#![cfg(feature = "test-integration")]
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use futures_util::{pin_mut, StreamExt};
|
||||||
|
use obws::events::{Event, EventType};
|
||||||
|
use tokio::time;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn main() -> Result<()> {
|
||||||
|
let client = common::new_client().await?;
|
||||||
|
let events = client.events()?;
|
||||||
|
let client = client.virtual_cam();
|
||||||
|
|
||||||
|
pin_mut!(events);
|
||||||
|
|
||||||
|
client.get_virtual_cam_status().await?;
|
||||||
|
|
||||||
|
client.start_stop_virtual_cam().await?;
|
||||||
|
wait_for!(events, EventType::VirtualCamStarted { .. });
|
||||||
|
client.start_stop_virtual_cam().await?;
|
||||||
|
wait_for!(events, EventType::VirtualCamStopped { .. });
|
||||||
|
|
||||||
|
// Wait a little more as the virtual cam sometimes doesn't start when started/stopped
|
||||||
|
// frequently.
|
||||||
|
time::sleep(Duration::from_secs(1)).await;
|
||||||
|
|
||||||
|
client.start_virtual_cam().await?;
|
||||||
|
wait_for!(events, EventType::VirtualCamStarted { .. });
|
||||||
|
client.stop_virtual_cam().await?;
|
||||||
|
wait_for!(events, EventType::VirtualCamStopped { .. });
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue