From ed7d41152410f0bbcdd4c62ec0521f23740c331a Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Tue, 29 Dec 2020 21:46:27 +0900 Subject: [PATCH] Update readme and add some basic usage docs --- README.md | 58 ++++++++++++++++++++++++++++++++++++++++- examples/events.rs | 3 +-- examples/iter_scenes.rs | 3 +-- examples/screenshot.rs | 3 +-- examples/simple.rs | 3 +-- src/lib.rs | 30 +++++++++++++++++++++ 6 files changed, 91 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8cb0268..6617b45 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,65 @@ # OBWS - The obws (obvious) remote control library for OBS -Library to remote control OBS with the [obs-websocket] plugin. +[![Repository][crates-img]][crates-url] +[![Documentation][doc-img]][doc-url] + +[crates-img]: https://img.shields.io/crates/v/obws?style=for-the-badge +[crates-url]: https://crates.io/crates/obws +[doc-img]: https://img.shields.io/badge/docs.rs-obws-4d76ae?style=for-the-badge +[doc-url]: https://docs.rs/obws + +Remote control OBS with the [obs-websocket] plugin from Rust 🦀. [obs-websocket]: https://github.com/Palakis/obs-websocket +## Usage + +Add `obws` to your project with `cargo add obws` (needs [cargo-edit]) or add it manually to your +`Cargo.toml`: + +```toml +[dependencies] +obws = "0.1.0" +``` + +In addition, you will need to use the [tokio](https://tokio.rs) runtime (currently `v0.3.x`), to +use this library as it makes heavy use of async/await and is bound to this runtime. + + +[cargo-edit]: https://github.com/killercup/cargo-edit + +### Example + +Here we connect to a OBS instance, get some version information and log in to access the whole API +and lastly print out a list of available scenes. + +For more usage instructions see the [docs](doc-url) or check out the [examples](examples/README.md). + +```rust +use anyhow::Result; +use obws::Client; + +#[tokio::main] +async fn main() -> Result<()> { + /// Connect to the OBS instance through obs-websocket. + let client = Client::connect("localhost", 4444).await?; + + /// Get and print out version information of OBS and obs-websocket. + let version = client.general().get_version().await?; + println!("{:#?}", version); + + /// Optionally log-in (if enabled in obs-websocket) to allow other APIs and receive events. + client.login(Some("password")).await?; + + /// Get a list of available scenes and print them out. + let scene_list = client.scenes().get_scene_list().await?; + println!("{:#?}", scene_list); + + Ok(()) +} + +``` + ## License This project is licensed under [MIT License](LICENSE) (or ). diff --git a/examples/events.rs b/examples/events.rs index 565676f..c5d6aa1 100644 --- a/examples/events.rs +++ b/examples/events.rs @@ -2,8 +2,7 @@ use std::env; use anyhow::Result; use futures_util::{pin_mut, StreamExt}; - -use obws::client::Client; +use obws::Client; #[tokio::main] async fn main() -> Result<()> { diff --git a/examples/iter_scenes.rs b/examples/iter_scenes.rs index b461304..edb47be 100644 --- a/examples/iter_scenes.rs +++ b/examples/iter_scenes.rs @@ -1,8 +1,7 @@ use std::{env, time::Duration}; use anyhow::Result; - -use obws::client::Client; +use obws::Client; #[tokio::main] async fn main() -> Result<()> { diff --git a/examples/screenshot.rs b/examples/screenshot.rs index c4aa04b..cae3c9f 100644 --- a/examples/screenshot.rs +++ b/examples/screenshot.rs @@ -1,10 +1,9 @@ use std::env; use anyhow::Result; +use obws::{requests::SourceScreenshot, Client}; use tokio::fs; -use obws::{client::Client, requests::SourceScreenshot}; - #[tokio::main] async fn main() -> Result<()> { dotenv::dotenv().ok(); diff --git a/examples/simple.rs b/examples/simple.rs index ae4b95f..89b4341 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,8 +1,7 @@ use std::env; use anyhow::Result; - -use obws::client::Client; +use obws::Client; #[tokio::main] async fn main() -> Result<()> { diff --git a/src/lib.rs b/src/lib.rs index 53c569b..853e9bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,34 @@ //! # OBSWS - The obws (obvious) remote control library for OBS +//! +//! Remote control OBS with the [obs-websocket] plugin from Rust 🦀. +//! +//! [obs-websocket]: https://github.com/Palakis/obs-websocket +//! +//! ## Example +//! +//! ```no_run +//! use anyhow::Result; +//! use obws::Client; +//! +//! #[tokio::main] +//! async fn main() -> Result<()> { +//! /// Connect to the OBS instance through obs-websocket. +//! let client = Client::connect("localhost", 4444).await?; +//! +//! /// Get and print out version information of OBS and obs-websocket. +//! let version = client.general().get_version().await?; +//! println!("{:#?}", version); +//! +//! /// Optionally log-in (if enabled in obs-websocket) to allow other APIs and receive events. +//! client.login(Some("password")).await?; +//! +//! /// Get a list of available scenes and print them out. +//! let scene_list = client.scenes().get_scene_list().await?; +//! println!("{:#?}", scene_list); +//! +//! Ok(()) +//! } +//! ``` #![warn(missing_docs, rust_2018_idioms, clippy::all)]