Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Add AV embed timeout handling to Media Player #2836

Merged
merged 55 commits into from
Jan 15, 2020

Conversation

simonsinclair
Copy link
Contributor

@simonsinclair simonsinclair commented Dec 20, 2019

Resolves bbc/simorgh#4517.

Overall change: Handle AV embed timeouts gracefully by displaying an error message to users.

Code changes:

  • Separate new timeout logic into a custom hook.
  • Add default timeout value, overridable by prop.
  • Refactor Media Player Canonical to use the hook.
  • Update snapshots.
  • Add unit test to validate timeout functionality.

Note:

  • These changes are not designed to cover timeouts that occur once the player has loaded, as these are handled by SMP.
  • We cannot run React code on AMP pages, so this feature will not exist in the AMP version of Media Player.

  • I have assigned myself to this PR and the corresponding issues
  • Automated jest tests added (for new features) or updated (for existing features)
  • This PR requires manual testing

@simonsinclair simonsinclair added ws-articles Tasks for the WS Articles Team articles-av-epic labels Dec 20, 2019
@simonsinclair simonsinclair self-assigned this Dec 20, 2019
@simonsinclair simonsinclair changed the title Add AV embed timeout support to Media Player Add AV embed timeout handling to Media Player Dec 20, 2019
@simonsinclair simonsinclair marked this pull request as ready for review December 23, 2019 16:28
@simonsinclair simonsinclair added the ws-media The World Service media stream label Dec 23, 2019
Copy link
Contributor

@rhenshaw56 rhenshaw56 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coming together nicely, however I was originally of the thought that we would reuse the psammead-embed-error component for this.

@simonsinclair
Copy link
Contributor Author

simonsinclair commented Dec 24, 2019

This is coming together nicely, however I was originally of the thought that we would reuse the psammead-embed-error component for this.

Thanks, Rowland. You raise a good point. The reason I went down this route is because:

  • psammead-embed-error is designed to display terminal errors that come from the server.
  • Using an overlay - keeping the placeholder behind, etc - gives us a chance to re-engage with the user when softer errors like this occur.
  • We might want to introduce other logic (like a retry button, loading indicator, etc) in the future and that would need to be contained by Media Player.

@rhenshaw56
Copy link
Contributor

rhenshaw56 commented Dec 24, 2019

This is coming together nicely, however I was originally of the thought that we would reuse the psammead-embed-error component for this.

Thanks, Rowland. You raise a good point. The reason I went down this route is because:

* `psammead-embed-error` is designed to display terminal errors that come from the server.

* Using an overlay - keeping the placeholder behind, etc - gives us a chance to re-engage with the user when softer errors like this occur.

* We might want to introduce other logic (like a retry button, loading indicator, etc) in the future and that would need to be contained by Media Player.

Thanks for the concise explanation Simon.

I think with regards to #2544, we might have to decouple the timeout logic somehow but I believe this is not a priority right now. 👍

@jamesdonoh
Copy link
Contributor

Thanks for figuring out a solution to this Simon. Although like Rowland I had assumed we would reuse the existing error component just to limit the number of components we have to think about.

My main other observation is that useTimeout.jsx would really benefit from some explanatory comments, but good otherwise.

Copy link
Contributor

@andrewscfc andrewscfc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sorting the wording @simonsinclair looks great :)

Copy link
Contributor

@jamesdonoh jamesdonoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, few small queries but it's good to go as far as I'm concerned.

packages/components/psammead-media-player/README.md Outdated Show resolved Hide resolved
The `mediaInfo` prop is required, and has the following properties.
The `timeoutMs` prop allows you to override the default timeout value. If media fails to load in this time, users are shown a timeout message.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to document that this only applies to canonical and not AMP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not immediately obvious from the files changed diff on GitHub, but the readme is split into Canonical and AMP sections and this prop is only listed beneath Canonical.

* completes, and `false` if it's interrupted.
* @param {object} iframeRef A React Ref. providing access to an iframe DOM node.
* @param {number} timeout The number of milliseconds until the timer completes.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in this file are excellent.

// eslint-disable-next-line consistent-return
useEffect(() => {
if (timeout > 0) {
iframeRef.current.addEventListener('load', handleLoad, { once: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of .current is guaranteed to be defined at this point, right?

Copy link
Contributor Author

@simonsinclair simonsinclair Jan 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If iframeRef is created as documented (as a React Ref), it will be, but perhaps this should be more defensively written. I deliberated over this for a while and appreciate you raising it. It should probably throw if current is falsy. I'll make this change now.

Co-Authored-By: James Donohue <james.donohue@bbc.co.uk>
@simonsinclair simonsinclair changed the title [DNM] Add AV embed timeout handling to Media Player Add AV embed timeout handling to Media Player Jan 10, 2020
@paruchurisilpa paruchurisilpa self-assigned this Jan 13, 2020
@paruchurisilpa
Copy link
Contributor

Looks good to me..

@simonsinclair simonsinclair merged commit 3abe9cb into latest Jan 15, 2020
@simonsinclair simonsinclair deleted the media-player-timeout branch January 15, 2020 09:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
articles-av-epic ws-articles Tasks for the WS Articles Team ws-media The World Service media stream
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle AV embed timeout on client
7 participants