Skip to content

Commit

Permalink
fix: StreamingServer statistics when response is null
Browse files Browse the repository at this point in the history
Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed Dec 5, 2023
1 parent f7d6c46 commit 08d4195
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/models/streaming_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for StreamingServer {
let selected_effects =
eq_update(&mut self.selected.statistics, Some(request.to_owned()));
let statistics_effects = eq_update(&mut self.statistics, Some(Loadable::Loading));

Effects::one(get_torrent_statistics::<E>(
&self.selected.transport_url,
request,
Expand Down Expand Up @@ -589,8 +590,11 @@ fn get_torrent_statistics<E: Env + 'static>(url: &Url, request: &StatisticsReque
.header(http::header::CONTENT_TYPE, "application/json")
.body(())
.expect("request builder failed");

// It's happening when the engine is destroyed for inactivity:
// If it was downloaded to 100% and that the stream is paused, then played,
// it will create a new engine and return the correct stats
EffectFuture::Concurrent(
// `null`` can be returned when the stream has been loaded 100%
E::fetch::<_, Option<Statistics>>(request)
.map(enclose!((url) move |result|
Msg::Internal(Internal::StreamingServerStatisticsResult((url, statistics_request), result))
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/msg/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ pub enum Internal {
///
/// Server will return None (or `null`) in response for [`Statistics`]`,
/// when stream has been fully loaded up to 100%
StreamingServerStatisticsResult((Url, StatisticsRequest), Result<Option<Statistics>, EnvError>),
StreamingServerStatisticsResult(
(Url, StatisticsRequest),
Result<Option<Statistics>, EnvError>,
),
/// Result for fetching resource from addons.
ResourceRequestResult(ResourceRequest, Box<Result<ResourceResponse, EnvError>>),
/// Result for fetching manifest from addon.
Expand Down

0 comments on commit 08d4195

Please sign in to comment.