Coverage Report

Created: 2022-07-04 16:17

src/lib.rs
Line
Count
Source (jump to first uncovered line)
1
1
//! # OBWS - The obws (obvious) remote control library for OBS//! # OBWS - The obws (obvious) remote control library for OBS
2
//!
3
//! Remote control OBS with the [obs-websocket] plugin from Rust 🦀.
4
//!
5
//! [obs-websocket]: https://github.com/Palakis/obs-websocket
6
//!
7
//! ## Example
8
//!
9
//! ```no_run
10
//! use anyhow::Result;
11
//! use obws::Client;
12
//!
13
//! #[tokio::main]
14
//! async fn main() -> Result<()> {
15
//!     /// Connect to the OBS instance through obs-websocket.
16
//!     let client = Client::connect("localhost", 4455, Some("password")).await?;
17
//!
18
//!     /// Get and print out version information of OBS and obs-websocket.
19
//!     let version = client.general().version().await?;
20
//!     println!("{:#?}", version);
21
//!
22
//!     /// Get a list of available scenes and print them out.
23
//!     let scene_list = client.scenes().list().await?;
24
//!     println!("{:#?}", scene_list);
25
//!
26
//!     Ok(())
27
//! }
28
//! ```
29
30
#![warn(missing_docs, rust_2018_idioms, clippy::all)]
31
32
use responses::StatusCode;
33
pub use semver::{Comparator, Version};
34
35
pub use self::client::Client;
36
37
pub mod client;
38
pub mod common;
39
#[cfg(feature = "events")]
40
pub mod events;
41
pub mod requests;
42
pub mod responses;
43
44
mod serde;
45
46
/// Result type used throughout the crate that uses [`Error`] as default error.
47
pub type Result<T, E = Error> = std::result::Result<T, E>;
48
49
/// Errors that can occur while using this crate.
50
0
#[derive(Debug, thiserror::Error)]
Unexecuted instantiation: <obws::Error as core::fmt::Debug>::fmt
Unexecuted instantiation: <obws::Error as core::fmt::Debug>::fmt
Unexecuted instantiation: <obws::Error as std::error::Error>::source
Unexecuted instantiation: <obws::Error as core::fmt::Display>::fmt
Unexecuted instantiation: <obws::Error as core::convert::From<obws::client::connection::HandshakeError>>::from
Unexecuted instantiation: <obws::Error as std::error::Error>::source
Unexecuted instantiation: <obws::Error as core::convert::From<obws::client::connection::HandshakeError>>::from
Unexecuted instantiation: <obws::Error as core::fmt::Display>::fmt
51
pub enum Error {
52
    /// An error occurred while trying to connect to the web-socket.
53
    #[error("failed to connect to the obs-websocket plugin")]
54
    Connect(#[source] tokio_tungstenite::tungstenite::Error),
55
    /// The initial handshake with `obs-websocket` didn't succeed.
56
    #[error("failed to execute the handshake with obs-websocket")]
57
    Handshake(#[from] crate::client::HandshakeError),
58
    /// Failed to serialize the message to be send to the web-socket.
59
    #[error("failed to serialize message")]
60
    SerializeMessage(#[source] serde_json::Error),
61
    /// A message could not be send through the web-socket.
62
    #[error("failed to send message to the obs-websocket plugin")]
63
    Send(#[source] tokio_tungstenite::tungstenite::Error),
64
    /// Tried to receive data while the send side was already closed.
65
    #[error("send side is closed")]
66
    ReceiveMessage(#[source] tokio::sync::oneshot::error::RecvError),
67
    /// Failed to deserialize the message that came back as response.
68
    #[error("the response message could not be deserialized")]
69
    DeserializeResponse(#[source] serde_json::Error),
70
    /// Failed to serialize custom user defined data for a message.
71
    #[error("failed to serialize custom data")]
72
    SerializeCustomData(#[source] serde_json::Error),
73
    /// Custom data didn't serialize into a JSON object.
74
    #[error("custom data must serialize into a JSON object")]
75
    InvalidCustomData,
76
    /// An error returned from the obs-websocket API.
77
    #[error("API error: {code:?}")]
78
    Api {
79
        /// Status code that describes the kind of error.
80
        code: StatusCode,
81
        /// Optional message to provide additional details about the error.
82
        message: Option<String>,
83
    },
84
    /// The obs-websocket API requires authentication but no password was given.
85
    #[error("authentication required but no password provided")]
86
    NoPassword,
87
    /// Unknown flags were found while trying to parse bitflags.
88
    #[error("value {0} contains unknown flags")]
89
    UnknownFlags(u8),
90
    /// Tried to interact with obs-websocket while not connected (for example trying to get a new
91
    /// event stream).
92
    #[error("currently not connected to obs-websocket")]
93
    Disconnected,
94
    /// The OBS studio version of the connected instance doesn't match the required version for this
95
    /// crate.
96
    #[error("obs studio version {0} doesn't match required {1}")]
97
    ObsStudioVersion(Version, Comparator),
98
    /// The obs-websocket plugin version doesn't match the required version for this crate.
99
    #[error("obs-websocket version {0} doesn't match required {1}")]
100
    ObsWebsocketVersion(Version, Comparator),
101
    /// The obs-websocket plugin negotiated a different RPC version than requested.
102
    #[error("RPC version {requested} requested, but server negotiated version {negotiated}")]
103
    RpcVersion {
104
        /// Version requested by the client.
105
        requested: u32,
106
        /// Unexpected version as negotiated by the server.
107
        negotiated: u32,
108
    },
109
}