Update dependencies and reformat code

pull/30/head
Dominik Nakamura 1 year ago
parent 92aa54c1cd
commit 9edea8f1b7
No known key found for this signature in database

@ -18,27 +18,27 @@ features = ["events", "tls"]
[dependencies] [dependencies]
async-stream = { version = "0.3.3", optional = true } async-stream = { version = "0.3.3", optional = true }
base64 = "0.13.1" base64 = "0.21.0"
bitflags = "1.3.2" bitflags = "1.3.2"
futures-util = { version = "0.3.25", features = ["sink"] } futures-util = { version = "0.3.25", features = ["sink"] }
rgb = { version = "0.8.34", default-features = false } rgb = { version = "0.8.34", default-features = false }
semver = { version = "1.0.14", features = ["serde"] } semver = { version = "1.0.16", features = ["serde"] }
serde = { version = "1.0.148", features = ["derive"] } serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.89" serde_json = "1.0.91"
serde_repr = "0.1.9" serde_repr = "0.1.10"
serde_with = "2.1.0" serde_with = "2.2.0"
sha2 = "0.10.6" sha2 = "0.10.6"
thiserror = "1.0.37" thiserror = "1.0.38"
time = "0.3.17" time = "0.3.17"
tokio = { version = "1.22.0", features = ["net", "rt", "sync", "time"] } tokio = { version = "1.24.2", features = ["net", "rt", "sync", "time"] }
tokio-tungstenite = "0.18.0" tokio-tungstenite = "0.18.0"
tracing = "0.1.37" tracing = "0.1.37"
[dev-dependencies] [dev-dependencies]
anyhow = "1.0.66" anyhow = "1.0.68"
dotenvy = "0.15.6" dotenvy = "0.15.6"
serde_test = "1.0.148" serde_test = "1.0.152"
tokio = { version = "1.22.0", features = ["fs", "macros", "rt-multi-thread", "time"] } tokio = { version = "1.24.2", features = ["fs", "macros", "rt-multi-thread", "time"] }
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
[features] [features]

@ -1,6 +1,7 @@
use std::env; use std::env;
use anyhow::Result; use anyhow::Result;
use base64::engine::{general_purpose, Engine};
use obws::{requests::sources::TakeScreenshot, Client}; use obws::{requests::sources::TakeScreenshot, Client};
use tokio::fs; use tokio::fs;
@ -25,7 +26,7 @@ async fn main() -> Result<()> {
.await?; .await?;
let pos = screenshot.find("base64,").unwrap(); let pos = screenshot.find("base64,").unwrap();
let image = base64::decode(&screenshot[pos + 7..])?; let image = general_purpose::STANDARD.decode(&screenshot[pos + 7..])?;
fs::write("screenshot.png", &image).await?; fs::write("screenshot.png", &image).await?;

@ -1,2 +1,7 @@
comment_width = 100
format_strings = true
group_imports = "StdExternalCrate" group_imports = "StdExternalCrate"
imports_granularity = "Crate" imports_granularity = "Crate"
reorder_impl_items = true
use_field_init_shorthand = true
wrap_comments = true

@ -202,6 +202,7 @@ pub(super) async fn handshake(
} }
fn create_auth_response(challenge: &str, salt: &str, password: &str) -> String { fn create_auth_response(challenge: &str, salt: &str, password: &str) -> String {
use base64::engine::{general_purpose, Engine};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
@ -210,13 +211,13 @@ fn create_auth_response(challenge: &str, salt: &str, password: &str) -> String {
let mut auth = String::with_capacity(Sha256::output_size() * 4 / 3 + 4); let mut auth = String::with_capacity(Sha256::output_size() * 4 / 3 + 4);
base64::encode_config_buf(hasher.finalize_reset(), base64::STANDARD, &mut auth); general_purpose::STANDARD.encode_string(hasher.finalize_reset(), &mut auth);
hasher.update(auth.as_bytes()); hasher.update(auth.as_bytes());
hasher.update(challenge.as_bytes()); hasher.update(challenge.as_bytes());
auth.clear(); auth.clear();
base64::encode_config_buf(hasher.finalize(), base64::STANDARD, &mut auth); general_purpose::STANDARD.encode_string(hasher.finalize(), &mut auth);
auth auth
} }

@ -99,8 +99,8 @@ pub enum Error {
/// event stream). /// event stream).
#[error("currently not connected to obs-websocket")] #[error("currently not connected to obs-websocket")]
Disconnected, Disconnected,
/// The OBS studio version of the connected instance doesn't match the required version for this /// The OBS studio version of the connected instance doesn't match the required version for
/// crate. /// this crate.
#[error("obs studio version {0} doesn't match required {1}")] #[error("obs studio version {0} doesn't match required {1}")]
ObsStudioVersion(Version, Comparator), ObsStudioVersion(Version, Comparator),
/// The obs-websocket plugin version doesn't match the required version for this crate. /// The obs-websocket plugin version doesn't match the required version for this crate.

@ -157,8 +157,8 @@ pub enum CropMode<'a> {
/// List up windows with empty names in the UI drop-down selection. /// List up windows with empty names in the UI drop-down selection.
show_empty_names: bool, show_empty_names: bool,
}, },
/// A combination of [`Self::ToWindow`] and [`Self::Manual`], cropping to the window first, then /// A combination of [`Self::ToWindow`] and [`Self::Manual`], cropping to the window first,
/// applying manual cropping. /// then applying manual cropping.
ToWindowAndManual { ToWindowAndManual {
/// Owner of the window. Usually the program name. /// Owner of the window. Usually the program name.
owner_name: &'a str, owner_name: &'a str,
@ -437,8 +437,8 @@ pub struct FfmpegSource<'a> {
pub input_format: &'a str, pub input_format: &'a str,
/// Reconnect delay in seconds. Only used if [`Self::is_local_file`] is set to `false`. /// Reconnect delay in seconds. Only used if [`Self::is_local_file`] is set to `false`.
pub reconnect_delay_sec: u8, pub reconnect_delay_sec: u8,
/// Restart playback when source becomes active. Only used if [`Self::is_local_file`] is set to /// Restart playback when source becomes active. Only used if [`Self::is_local_file`] is set
/// `true`. /// to `true`.
pub restart_on_activate: bool, pub restart_on_activate: bool,
/// Show nothing when playback ends. /// Show nothing when playback ends.
pub clear_on_media_end: bool, pub clear_on_media_end: bool,

@ -90,9 +90,9 @@ pub(crate) struct Identify {
pub rpc_version: u32, pub rpc_version: u32,
#[serde(rename = "authentication")] #[serde(rename = "authentication")]
pub authentication: Option<String>, pub authentication: Option<String>,
/// Bit mask of event subscription items to subscribe to events and event categories at will. By /// Bit mask of event subscription items to subscribe to events and event categories at will.
/// default, all event categories are subscribed, except for events marked as high volume. High /// By default, all event categories are subscribed, except for events marked as high
/// volume events must be explicitly subscribed to. /// volume. High volume events must be explicitly subscribed to.
#[serde(rename = "eventSubscriptions")] #[serde(rename = "eventSubscriptions")]
pub event_subscriptions: Option<EventSubscription>, pub event_subscriptions: Option<EventSubscription>,
} }

@ -179,6 +179,8 @@ impl QtGeometry {
/// | 4 | Screen width | /// | 4 | Screen width |
/// | 16 | Main rectangle (left, top, right, bottom) 4 bytes each | /// | 16 | Main rectangle (left, top, right, bottom) 4 bytes each |
pub(crate) fn serialize(&self) -> String { pub(crate) fn serialize(&self) -> String {
use base64::engine::{general_purpose, Engine};
/// Indicator for serialized Qt geometry data. /// Indicator for serialized Qt geometry data.
const MAGIC_NUMBER: u32 = 0x1D9D0CB; const MAGIC_NUMBER: u32 = 0x1D9D0CB;
/// Major version of this format. /// Major version of this format.
@ -211,7 +213,7 @@ impl QtGeometry {
serialize_rect(&mut data, &self.rect); serialize_rect(&mut data, &self.rect);
base64::encode(data) general_purpose::STANDARD.encode(data)
} }
} }
@ -265,7 +267,6 @@ impl QtWindowState {
/// │ bottom /// │ bottom
/// │ /// │
/// Y /// Y
///
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug, Default)]
pub struct QtRect { pub struct QtRect {
/// Left or X/horizontal position of the rectangle. /// Left or X/horizontal position of the rectangle.

@ -20,8 +20,8 @@ pub struct Version {
/// Image formats available in `GetSourceScreenshot` and `SaveSourceScreenshot` requests. /// Image formats available in `GetSourceScreenshot` and `SaveSourceScreenshot` requests.
#[serde(rename = "supportedImageFormats")] #[serde(rename = "supportedImageFormats")]
pub supported_image_formats: Vec<String>, pub supported_image_formats: Vec<String>,
/// Name of the platform. Usually `windows`, `macos`, or `ubuntu` (Linux flavor). Not guaranteed /// Name of the platform. Usually `windows`, `macos`, or `ubuntu` (Linux flavor). Not
/// to be any of those. /// guaranteed to be any of those.
#[serde(rename = "platform")] #[serde(rename = "platform")]
pub platform: String, pub platform: String,
/// Description of the platform, like `Windows 10 (10.0)`. /// Description of the platform, like `Windows 10 (10.0)`.

@ -24,9 +24,9 @@ use serde_repr::{Deserialize_repr, Serialize_repr};
#[derive(Debug)] #[derive(Debug)]
pub(crate) enum ServerMessage { pub(crate) enum ServerMessage {
/// First message sent from the server immediately on client connection. Contains authentication /// First message sent from the server immediately on client connection. Contains
/// information if authentication is required. Also contains RPC version for version /// authentication information if authentication is required. Also contains RPC version for
/// negotiation. /// version negotiation.
Hello(Hello), Hello(Hello),
/// The identify request was received and validated, and the connection is now ready for normal /// The identify request was received and validated, and the connection is now ready for normal
/// operation. /// operation.
@ -65,10 +65,11 @@ impl<'de> Deserialize<'de> for ServerMessage {
Identified = 2, Identified = 2,
/// The message sent by obs-websocket containing an event payload. /// The message sent by obs-websocket containing an event payload.
Event = 5, Event = 5,
/// The message sent by obs-websocket in response to a particular request from a client. /// The message sent by obs-websocket in response to a particular request from a
/// client.
RequestResponse = 7, RequestResponse = 7,
/// The message sent by obs-websocket in response to a particular batch of requests from /// The message sent by obs-websocket in response to a particular batch of requests
/// a client. /// from a client.
RequestBatchResponse = 9, RequestBatchResponse = 9,
} }
@ -230,8 +231,8 @@ pub enum StatusCode {
/// The resource was not found. /// The resource was not found.
/// ///
/// **Note:** Resources are any kind of object in obs-websocket, like inputs, profiles, outputs, /// **Note:** Resources are any kind of object in obs-websocket, like inputs, profiles,
/// etc. /// outputs, etc.
ResourceNotFound = 600, ResourceNotFound = 600,
/// The resource already exists. /// The resource already exists.
ResourceAlreadyExists = 601, ResourceAlreadyExists = 601,

@ -221,8 +221,7 @@ mod tests {
Token::U64(u64::MAX), Token::U64(u64::MAX),
Token::StructEnd, Token::StructEnd,
], ],
"value is too large for an i64: \ "value is too large for an i64: out of range integral type conversion attempted",
out of range integral type conversion attempted",
); );
} }
} }

Loading…
Cancel
Save