Struct SnapcastConnection

Source
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

Source

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;
Source

pub async fn send(&mut self, command: Method) -> Result<(), ClientError>

send a raw command to the Snapcast server

§args

command: Method - the command to send

§returns

an empty Ok if the command was sent successfully, or a ClientError if there was an error

§example
client.send(Method::ServerGetStatus).await.expect("could not send command");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more