pub struct PersistentClient { /* private fields */ }
Expand description
MPD client which automatically attempts to reconnect if the connection cannot be established or is lost.
Commands sent to a disconnected client are queued.
Implementations§
Source§impl PersistentClient
impl PersistentClient
pub fn new(host: String, retry_interval: Duration) -> Self
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Gets whether there is a valid connection to the server
Sourcepub async fn wait_for_client(&self) -> Arc<Client>
pub async fn wait_for_client(&self) -> Arc<Client>
Waits for a valid connection to the server to be established. If already connected, resolves immediately.
Sourcepub async fn with_client<F, Fut, T>(&self, f: F) -> T
pub async fn with_client<F, Fut, T>(&self, f: F) -> T
Runs the provided callback as soon as the connected client is available.
Sourcepub async fn recv(&mut self) -> Result<Arc<ConnectionEvent>, RecvError>
pub async fn recv(&mut self) -> Result<Arc<ConnectionEvent>, RecvError>
Receives an event from the MPD server.
Sourcepub fn subscribe(&self) -> Receiver<Arc<ConnectionEvent>>
pub fn subscribe(&self) -> Receiver<Arc<ConnectionEvent>>
Creates a new receiver to be able to receive events
outside the context of &self
.
When you have access to the client instance, prefer recv()
instead.
Sourcepub async fn command<C: Command>(
&self,
cmd: C,
) -> Result<C::Response, CommandError>
pub async fn command<C: Command>( &self, cmd: C, ) -> Result<C::Response, CommandError>
Runs the provided command on the MPD server.
Waits for a valid connection and response before the future is completed.
Sourcepub async fn status(&self) -> Result<Status, CommandError>
pub async fn status(&self) -> Result<Status, CommandError>
Runs the status
command on the MPD server.
Waits for a valid connection and response before the future is completed.
Sourcepub async fn current_song(&self) -> Result<Option<SongInQueue>, CommandError>
pub async fn current_song(&self) -> Result<Option<SongInQueue>, CommandError>
Runs the currentsong
command on the MPD server.
Waits for a valid connection and response before the future is completed.