diff --git a/src/models/streaming_server.rs b/src/models/streaming_server.rs index da5500564..8ebf0ad71 100644 --- a/src/models/streaming_server.rs +++ b/src/models/streaming_server.rs @@ -180,6 +180,7 @@ impl UpdateWithCtx 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::( &self.selected.transport_url, request, @@ -315,7 +316,9 @@ impl UpdateWithCtx for StreamingServer { && self.selected.statistics.as_ref() == Some(request) => { let loadable = match result { - Ok(statistics) => Loadable::Ready(statistics.to_owned()), + Ok(Some(statistics)) => Loadable::Ready(statistics.to_owned()), + // we've loaded the whole stream, no need to update the statistics. + Ok(None) => return Effects::none().unchanged(), Err(error) => Loadable::Err(error.to_owned()), }; eq_update(&mut self.statistics, Some(loadable)) @@ -587,8 +590,12 @@ fn get_torrent_statistics(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( - E::fetch::<_, Statistics>(request) + E::fetch::<_, Option>(request) .map(enclose!((url) move |result| Msg::Internal(Internal::StreamingServerStatisticsResult((url, statistics_request), result)) )) diff --git a/src/runtime/msg/internal.rs b/src/runtime/msg/internal.rs index 8ea5a0fb1..3c9a00886 100644 --- a/src/runtime/msg/internal.rs +++ b/src/runtime/msg/internal.rs @@ -100,10 +100,16 @@ pub enum Internal { StreamingServerUpdateSettingsResult(Url, Result<(), EnvError>), /// Result for creating a torrent. StreamingServerCreateTorrentResult(String, Result<(), EnvError>), - // Result for playing on device. + /// Result for playing on device. StreamingServerPlayOnDeviceResult(String, Result<(), EnvError>), - // Result for streaming server statistics. - StreamingServerStatisticsResult((Url, StatisticsRequest), Result), + /// Result for streaming server statistics. + /// + /// Server will return None (or `null`) in response for [`Statistics`]`, + /// when stream has been fully loaded up to 100% + StreamingServerStatisticsResult( + (Url, StatisticsRequest), + Result, EnvError>, + ), /// Result for fetching resource from addons. ResourceRequestResult(ResourceRequest, Box>), /// Result for fetching manifest from addon.