Crates.io | vtubestudio |
lib.rs | vtubestudio |
version | 0.9.0 |
source | src |
created_at | 2021-11-12 05:59:53.563148 |
updated_at | 2024-06-13 01:39:53.19228 |
description | A library for interacting with the VTube Studio API. |
homepage | https://github.com/walfie/vtubestudio-rs |
repository | https://github.com/walfie/vtubestudio-rs |
max_upload_size | |
id | 480796 |
size | 270,877 |
A library for interacting with the VTube Studio API.
The example below creates a Client
using the provided builder, which:
ws://localhost:8001
using tokio_tungstenite
use vtubestudio::data::StatisticsRequest;
use vtubestudio::{Client, ClientEvent, Error};
#[tokio::main]
async fn main() -> Result<(), Error> {
// An auth token from a previous successful authentication request
let stored_token = Some("...".to_string());
let (mut client, mut events) = Client::builder()
.auth_token(stored_token)
.authentication("Plugin name", "Developer name", None)
.build_tungstenite();
tokio::spawn(async move {
while let Some(event) = events.next().await {
match event {
ClientEvent::NewAuthToken(new_token) => {
// This returns whenever the authentication middleware receives a new auth
// token. We can handle it by saving it somewhere, etc.
println!("Got new auth token: {new_token}");
}
_ => {
// Other events, such as connections/disconnections, API events, etc
println!("Got event: {:?}", event);
}
}
}
});
// Use the client to send a `StatisticsRequest`, handling authentication if necessary.
// The return type is inferred from the input type to be `StatisticsResponse`.
let resp = client.send(&StatisticsRequest {}).await?;
println!("VTube Studio has been running for {}ms", resp.uptime);
Ok(())
}
For more details, please check the documentation on docs.rs.