Crates.io | snapcast-control |
lib.rs | snapcast-control |
version | 0.1.0 |
source | src |
created_at | 2024-06-25 16:14:19.617563 |
updated_at | 2024-06-25 16:14:19.617563 |
description | a wrapper for the Snapcast JSON-RPC Control API based on tokio |
homepage | https://github.com/JoeyEamigh/snapcast-control |
repository | https://github.com/JoeyEamigh/snapcast-control.git |
max_upload_size | |
id | 1283470 |
size | 134,530 |
snapcast-control
is a Rust api client for Snapcast. It supports all features of the Snapcast JSON-RPC API as of version 0.28.0 (2024/6/25).
Documentation is available at docs.rs.
cargo add snapcast-control
The best example of this crate's usage is snapcast-multiroom, the project I designed it for.
A simple example of usage:
use snapcast_control::{SnapcastConnection, ValidMessage};
#[tokio::main]
async fn main() {
let mut client = SnapcastConnection::open("127.0.0.1:1705".parse().expect("could not parse socket address")).await;
// client state is updated with each message received
let state = client.state.clone();
// state is empty initially, sending the server_get_status request will populate it
client.server_get_status().await.expect("could not send request");
loop {
tokio::select! {
// as messages are received, they are stored in the client's recv buffer
Some(message) = client.recv() => {
if let Ok(response) = message {
// handle response
match response {
ValidMessage::Result { id, jsonrpc, result } => {},
ValidMessage::Notification { method, jsonrpc } => {},
}
} else if let Err(err) = message {
// handle error
}
},
_ = tokio::signal::ctrl_c() => {
break;
}
}
}
}