pub struct TokioClient { /* private fields */ }tokio only.Expand description
An async shell driving crate::client::HlsClient over real HTTP.
use hls_runtime::client::tokio_client::TokioClient;
let mut client = TokioClient::new("http://127.0.0.1:8080/live/media.m3u8")?;
while let Some(output) = client.next_output().await? {
// Hand `output` (Init / Samples / Discontinuity / EndOfStream) to a decoder.
let _ = output;
}Implementations§
Source§impl TokioClient
impl TokioClient
Sourcepub fn new(playlist_url: impl Into<String>) -> Result<Self, TokioError>
pub fn new(playlist_url: impl Into<String>) -> Result<Self, TokioError>
Build a client for the Media Playlist at playlist_url, with
TokioClientConfig::default tunables.
§Errors
Only if the underlying reqwest::Client fails to build (e.g. TLS
backend initialisation failure) — not a network error, since no
request has been made yet.
Sourcepub fn with_config(
playlist_url: impl Into<String>,
config: TokioClientConfig,
) -> Result<Self, TokioError>
pub fn with_config( playlist_url: impl Into<String>, config: TokioClientConfig, ) -> Result<Self, TokioError>
Sourcepub fn stats(&self) -> TokioClientStats
pub fn stats(&self) -> TokioClientStats
Diagnostic counters for requests actually made so far — see
TokioClientStats.
Sourcepub async fn next_output(&mut self) -> Result<Option<Output>, TokioError>
pub async fn next_output(&mut self) -> Result<Option<Output>, TokioError>
Drive the sans-IO core — performing whatever HTTP its next
Action needs, retrying transient failures per
TokioClientConfig — until at least one Output is available.
Returns Ok(None) once, right after Output::EndOfStream has
already been yielded by a previous call, signalling the caller to
stop polling. A live stream that never sends #EXT-X-ENDLIST simply
never returns Ok(None) — the caller drives this in a loop (or a
tokio::select! alongside its own shutdown signal) for as long as it
wants to keep playing.
§Errors
TokioError::Client if the sans-IO core rejects a fetched
playlist/resource (malformed playlist, demux failure). Resource fetch
failures are retried/recovered internally (see the module docs) and
never surface here; a playlist fetch failure retries indefinitely
rather than ever returning an TokioError::Http/TokioError::Status
— see the module docs’ “Error recovery” section.