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 c74d1c1 commit f7d6c46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/models/streaming_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ impl<E: Env + 'static> UpdateWithCtx<E> 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))
Expand Down Expand Up @@ -588,7 +590,8 @@ fn get_torrent_statistics<E: Env + 'static>(url: &Url, request: &StatisticsReque
.body(())
.expect("request builder failed");
EffectFuture::Concurrent(
E::fetch::<_, Statistics>(request)
// `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
9 changes: 6 additions & 3 deletions src/runtime/msg/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ 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<Statistics, EnvError>),
/// 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<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 f7d6c46

Please sign in to comment.