pub struct SnapcastConnection {
pub state: Arc<State>,
/* private fields */
}
Expand description
Struct representing a connection to a Snapcast server. Contains the current state of the server and methods to interact with it.
call SnapcastConnection::open
to create a new connection.
Fields§
§state: Arc<State>
The current state of the server. The state is Send + Sync, so it can be shared between threads.
Implementations§
Source§impl SnapcastConnection
impl SnapcastConnection
Sourcepub async fn open(address: SocketAddr) -> Self
pub async fn open(address: SocketAddr) -> Self
open a new connection to a Snapcast server
§args
address
: std::net::SocketAddr - the address of the Snapcast server
§returns
a new SnapcastConnection struct
§example
let mut client = SnapcastConnection::open("127.0.0.1:1705".parse().expect("could not parse socket address")).await;
Sourcepub async fn recv(&mut self) -> Option<Result<ValidMessage, ClientError>>
pub async fn recv(&mut self) -> Option<Result<ValidMessage, ClientError>>
receive a message from the Snapcast server
uses a futures::stream::Next under the hood, so:
creates a future that resolves to the next item in the stream
§returns
an Option containing an Ok with a ValidMessage if a message was received,
an Option containing an Err with a ClientError if there was an error,
or None if the stream has ended
§example
let message = client.recv().await.expect("could not receive message");
Sourcepub async fn client_get_status(&mut self, id: String) -> Result<(), ClientError>
pub async fn client_get_status(&mut self, id: String) -> Result<(), ClientError>
request the current status of a client from the Snapcast server
wrapper for sending a ClientGetStatus command
§args
id
: String - the id of the client
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.client_get_status("client_id".to_string()).await.expect("could not get client status");
Sourcepub async fn client_set_volume(
&mut self,
id: String,
volume: ClientVolume,
) -> Result<(), ClientError>
pub async fn client_set_volume( &mut self, id: String, volume: ClientVolume, ) -> Result<(), ClientError>
set the volume and mute status of a client
wrapper for sending a ClientSetVolume command
§args
id
: String - the id of the client
volume
: client::ClientVolume - the volume and mute status to set
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.client_set_mute("client_id".to_string(), client::ClientVolume { mute: false, volume: 50 }).await.expect("could not set client mute");
Sourcepub async fn client_set_latency(
&mut self,
id: String,
latency: usize,
) -> Result<(), ClientError>
pub async fn client_set_latency( &mut self, id: String, latency: usize, ) -> Result<(), ClientError>
set the latency of a client
wrapper for sending a ClientSetLatency command
§args
id
: String - the id of the client
latency
: usize - the latency to set
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.client_set_latency("client_id".to_string(), 100).await.expect("could not set client latency");
Sourcepub async fn client_set_name(
&mut self,
id: String,
name: String,
) -> Result<(), ClientError>
pub async fn client_set_name( &mut self, id: String, name: String, ) -> Result<(), ClientError>
set the name of a client
wrapper for sending a ClientSetName command
§args
id
: String - the id of the client
name
: String - the name to set
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.client_set_name("client_id".to_string(), "new_name".to_string()).await.expect("could not set client name");
Sourcepub async fn group_get_status(&mut self, id: String) -> Result<(), ClientError>
pub async fn group_get_status(&mut self, id: String) -> Result<(), ClientError>
request the current status of a group from the Snapcast server
wrapper for sending a GroupGetStatus command
§args
id
: String - the id of the group
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.group_get_status("group_id".to_string()).await.expect("could not get group status");
Sourcepub async fn group_set_mute(
&mut self,
id: String,
mute: bool,
) -> Result<(), ClientError>
pub async fn group_set_mute( &mut self, id: String, mute: bool, ) -> Result<(), ClientError>
set the mute status of a group
wrapper for sending a GroupSetMute command
§args
id
: String - the id of the group
mute
: bool - the mute status to set
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.group_set_mute("group_id".to_string(), true).await.expect("could not set group mute");
Sourcepub async fn group_set_stream(
&mut self,
id: String,
stream_id: String,
) -> Result<(), ClientError>
pub async fn group_set_stream( &mut self, id: String, stream_id: String, ) -> Result<(), ClientError>
set the stream of a group
wrapper for sending a GroupSetStream command
§args
id
: String - the id of the group
stream_id
: String - the id of the stream to set
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.group_set_stream("group_id".to_string(), "stream_id".to_string()).await.expect("could not set group stream");
Sourcepub async fn group_set_clients(
&mut self,
id: String,
clients: Vec<String>,
) -> Result<(), ClientError>
pub async fn group_set_clients( &mut self, id: String, clients: Vec<String>, ) -> Result<(), ClientError>
set the clients of a group
wrapper for sending a GroupSetClients command
§args
id
: String - the id of the group
clients
: Vec<String> - the ids of the clients to set
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.group_set_clients("group_id".to_string(), vec!["client_id".to_string()]).await.expect("could not set group clients");
Sourcepub async fn group_set_name(
&mut self,
id: String,
name: String,
) -> Result<(), ClientError>
pub async fn group_set_name( &mut self, id: String, name: String, ) -> Result<(), ClientError>
set the name of a group
wrapper for sending a GroupSetName command
§args
id
: String - the id of the group
name
: String - the name to set
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.group_set_name("group_id".to_string(), "new_name".to_string()).await.expect("could not set group name");
Sourcepub async fn server_get_rpc_version(&mut self) -> Result<(), ClientError>
pub async fn server_get_rpc_version(&mut self) -> Result<(), ClientError>
request the rpc version of the Snapcast server
wrapper for sending a ServerGetStatus command
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.server_get_rpc_version().await.expect("could not get server rpc version");
Sourcepub async fn server_get_status(&mut self) -> Result<(), ClientError>
pub async fn server_get_status(&mut self) -> Result<(), ClientError>
request the current status of the Snapcast server, this is a full refresh for state
wrapper for sending a ServerGetStatus command
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.server_get_status().await.expect("could not get server status");
Sourcepub async fn server_delete_client(
&mut self,
id: String,
) -> Result<(), ClientError>
pub async fn server_delete_client( &mut self, id: String, ) -> Result<(), ClientError>
forcefully delete a client from the Snapcast server
wrapper for sending a ServerDeleteClient command
§args
id
: String - the id of the client to delete
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.server_delete_client("client_id".to_string()).await.expect("could not delete client");
Sourcepub async fn stream_add_stream(
&mut self,
stream_uri: String,
) -> Result<(), ClientError>
pub async fn stream_add_stream( &mut self, stream_uri: String, ) -> Result<(), ClientError>
add a new stream to the Snapcast server
wrapper for sending a StreamAddStream command
§args
stream_uri
: String - the uri of the stream to add
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.stream_add_stream("librespot:///usr/bin/librespot?name=Spotify&...".to_string()).await.expect("could not add stream");
Sourcepub async fn stream_remove_stream(
&mut self,
id: String,
) -> Result<(), ClientError>
pub async fn stream_remove_stream( &mut self, id: String, ) -> Result<(), ClientError>
remove a stream from the Snapcast server
wrapper for sending a StreamRemoveStream command
§args
id
: String - the id of the stream to remove
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.stream_remove_stream("stream_id".to_string()).await.expect("could not remove stream");
Sourcepub async fn stream_control(
&mut self,
id: String,
command: ControlCommand,
) -> Result<(), ClientError>
pub async fn stream_control( &mut self, id: String, command: ControlCommand, ) -> Result<(), ClientError>
control a stream on the Snapcast server
wrapper for sending a StreamControl command
§args
id
: String - the id of the stream to control
command
: stream::ControlCommand - the command to send to the stream
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.stream_control("stream_id".to_string(), stream::ControlCommand::Pause).await.expect("could not control stream");
Sourcepub async fn stream_set_property(
&mut self,
id: String,
properties: SetPropertyProperties,
) -> Result<(), ClientError>
pub async fn stream_set_property( &mut self, id: String, properties: SetPropertyProperties, ) -> Result<(), ClientError>
set the property of a stream on the Snapcast server
wrapper for sending a StreamSetProperty command
§args
id
: String - the id of the stream to control
properties
: stream::SetPropertyProperties - the properties to set on the stream
§returns
an empty Ok if the command was sent successfully, or a ClientError if there was an error
§example
client.stream_set_property("stream_id".to_string(), stream::SetPropertyProperties::Shuffle(true)).await.expect("could not set stream property");