vtubestudio-rs
A library for interacting with the VTube Studio API.
Basic usage
The example below creates a Client
using the provided builder, which:
- connects to
ws://localhost:8001
using tokio_tungstenite
- authenticates with an existing token (if present and valid)
- reconnects when disconnected, and retries the failed request on reconnection success
- requests a new auth token on receiving an auth error, and retries the initial failed
request on authentication success
use vtubestudio::data::StatisticsRequest;
use vtubestudio::{Client, ClientEvent, Error};
#[tokio::main]
async fn main() -> Result<(), Error> {
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) => {
println!("Got new auth token: {new_token}");
}
_ => {
println!("Got event: {:?}", event);
}
}
}
});
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.