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
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a05bd2d
Bump package version
simonsinclair Dec 20, 2019
449938b
Add changelog entry
simonsinclair Dec 20, 2019
8b76e8e
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Dec 23, 2019
8e85f35
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Dec 23, 2019
338933f
Add useTimeout hook
simonsinclair Dec 23, 2019
44b87f6
Refactor Canonical to use timeout hook
simonsinclair Dec 23, 2019
50aa239
Update snapshots
simonsinclair Dec 23, 2019
cc265d0
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Dec 23, 2019
a047835
Prune former effect dependency
simonsinclair Dec 23, 2019
8d31be2
Merge branch 'media-player-timeout' of https://github.com/bbc/psammea…
simonsinclair Jan 6, 2020
c8dee83
Move useTimeout hook to Canonical
simonsinclair Jan 6, 2020
25166f9
Bump TIMEOUT_MS to '5000'
simonsinclair Jan 6, 2020
0f592b0
Rename 'iframe' reference to 'iframeRef'
simonsinclair Jan 6, 2020
5e02b82
Housekeeping
simonsinclair Jan 6, 2020
8362ee4
Add JSDoc
simonsinclair Jan 6, 2020
326e938
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Jan 6, 2020
6dfa9a8
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Jan 7, 2020
fb9da72
Merge branch 'media-player-timeout' of https://github.com/bbc/psammea…
simonsinclair Jan 7, 2020
49fe6bb
Remove hook dependency on 'timeout'
simonsinclair Jan 7, 2020
310ebcd
Expand on hook comments
simonsinclair Jan 7, 2020
423ee27
Merge branch 'latest' into media-player-timeout
simonsinclair Jan 7, 2020
65169f9
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Jan 7, 2020
66bd1b1
Merge branch 'media-player-timeout' of https://github.com/bbc/psammea…
simonsinclair Jan 7, 2020
76e8e44
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Jan 8, 2020
b9bccce
Replace 'noJsClassName' with actual required prop
simonsinclair Jan 8, 2020
deca192
Update JSDoc comment on 'iframeRef'
simonsinclair Jan 8, 2020
9a876fe
Protect against nullish 'timeout' and other insane values
simonsinclair Jan 8, 2020
78b962a
Refactor TIMEOUT_MS to be configurable
simonsinclair Jan 8, 2020
e163eb1
Update 'shoulder render an iframe' test
simonsinclair Jan 8, 2020
b8395ad
Add 'should render a timeout message...' test
simonsinclair Jan 8, 2020
ec760c9
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Jan 8, 2020
ae78387
Add 'timeoutMs' prop to README
simonsinclair Jan 8, 2020
6fb2afe
Editor whitespace cleanup
simonsinclair Jan 8, 2020
06c0ada
Merge branch 'latest' into media-player-timeout
simonsinclair Jan 9, 2020
e8072b0
Update timeout message
simonsinclair Jan 9, 2020
a3d06fe
Merge branch 'latest' into media-player-timeout
simonsinclair Jan 9, 2020
9132b3a
Merge branch 'latest' into media-player-timeout
simonsinclair Jan 9, 2020
299ffb7
Amend default timeoutMs value on parent for clarity
simonsinclair Jan 9, 2020
1ee9c6e
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Jan 9, 2020
d72cab9
Merge branch 'media-player-timeout' of https://github.com/bbc/psammea…
simonsinclair Jan 9, 2020
6e005c7
Let me fix that
simonsinclair Jan 9, 2020
9601a5d
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Jan 9, 2020
fb761f2
Merge branch 'latest' into media-player-timeout
simonsinclair Jan 10, 2020
d51abc5
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Jan 10, 2020
d804acd
Merge branch 'media-player-timeout' of https://github.com/bbc/psammea…
simonsinclair Jan 10, 2020
48619b0
Improve useTimeout comments
simonsinclair Jan 10, 2020
a02664e
Validate iframeRef before binding events
simonsinclair Jan 10, 2020
e3d2d4f
Merge branch 'latest' into media-player-timeout
simonsinclair Jan 13, 2020
6cf8d3e
Merge branch 'latest' into media-player-timeout
paruchurisilpa Jan 13, 2020
24d9783
Merge branch 'latest' into media-player-timeout
simonsinclair Jan 13, 2020
08390da
Merge branch 'latest' of https://github.com/bbc/psammead into media-p…
simonsinclair Jan 14, 2020
564b400
Use afterEach cleanup in favour of unmount
simonsinclair Jan 14, 2020
6214146
Add 'should not render a timeout message...' test
simonsinclair Jan 14, 2020
b27eaac
Update test title for consistency
simonsinclair Jan 14, 2020
336c70b
Add useTimeout.test.jsx
simonsinclair Jan 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/psammead-media-player/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- prettier-ignore -->
| Version | Description |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| 2.5.0 | [PR#2836](https://github.com/bbc/psammead/pull/2836) Add AV embed timeout handling. |
| 2.4.4 | [PR#2830](https://github.com/bbc/psammead/pull/2830) Talos - Bump Dependencies - @bbc/psammead-play-button |
| 2.4.3 | [PR#2827](https://github.com/bbc/psammead/pull/2827) Talos - Bump Dependencies - @bbc/psammead-assets |
| 2.4.2 | [PR#2806](https://github.com/bbc/psammead/pull/2806) Fix StyledPlaceholder cursor when Javascript is disabled |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/components/psammead-media-player/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbc/psammead-media-player",
"version": "2.4.4",
"version": "2.5.0",
"description": "Provides a media player with optional placeholder",
"main": "dist/index.js",
"module": "esm/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@

exports[`Media Player: Canonical should render an iframe 1`] = `
.c0 {
left: 0;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.c1 {
border: 0;
overflow: hidden;
height: 100%;
width: 100%;
}

<iframe
allow="autoplay; fullscreen"
allowfullscreen=""
<div
class="c0"
scrolling="no"
src="https://foo.bar/iframe"
title="Media player"
/>
>
<iframe
allow="autoplay; fullscreen"
allowfullscreen=""
class="c1"
scrolling="no"
src="https://foo.bar/iframe"
title="Media player"
/>
</div>
`;
65 changes: 45 additions & 20 deletions packages/components/psammead-media-player/src/Canonical/index.jsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,63 @@
import React from 'react';
import React, { useState, useRef } from 'react';
import { string } from 'prop-types';
import styled from 'styled-components';
import styled, { css } from 'styled-components';
import Guidance from '../Guidance';
import useTimeout from '../useTimeout';

const Canonical = ({ src, title, placeholderSrc }) => {
const backgroundStyle = `
background-image: url(${placeholderSrc});
background-repeat: no-repeat;
background-size: contain;
`;
const TIMEOUT_MS = 3000;

const StyledIframe = styled.iframe`
const Canonical = ({ service, src, title, placeholderSrc }) => {
const [hasTimedOut, setHasTimedOut] = useState(null);
chris-hinds marked this conversation as resolved.
Show resolved Hide resolved
const iframe = useRef(null);

useTimeout(setHasTimedOut, iframe, TIMEOUT_MS);

const CanonicalWrapper = styled.div`
left: 0;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
${placeholderSrc &&
css`
background-image: url(${placeholderSrc});
background-repeat: no-repeat;
background-size: contain;
`}
`;

const StyledIframe = styled.iframe`
border: 0;
overflow: hidden;
${placeholderSrc ? backgroundStyle : ''}
height: 100%;
width: 100%;
`;

return (
<StyledIframe
src={src}
title={title}
allow="autoplay; fullscreen"
scrolling="no"
gesture="media"
allowFullScreen
/>
<CanonicalWrapper>
{hasTimedOut ? (
<Guidance
service={service}
guidanceMessage="The server did not respond. Please check your connection and try again."
andrewscfc marked this conversation as resolved.
Show resolved Hide resolved
noJsClassName="no-js"
/>
) : (
<StyledIframe
ref={iframe}
src={src}
title={title}
allow="autoplay; fullscreen"
scrolling="no"
gesture="media"
allowFullScreen
/>
)}
</CanonicalWrapper>
);
};

Canonical.propTypes = {
service: string.isRequired,
src: string.isRequired,
title: string.isRequired,
placeholderSrc: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,26 +685,35 @@ exports[`Media Player: Canonical Entry renders an iframe when showPlaceholder is
}

.c1 {
left: 0;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.c2 {
border: 0;
overflow: hidden;
height: 100%;
width: 100%;
}

<div
class="c0"
>
<iframe
allow="autoplay; fullscreen"
allowfullscreen=""
<div
class="c1"
scrolling="no"
src="http://foo.bar/iframe"
title="Media player"
/>
>
<iframe
allow="autoplay; fullscreen"
allowfullscreen=""
class="c2"
scrolling="no"
src="http://foo.bar/iframe"
title="Media player"
/>
</div>
</div>
`;

Expand All @@ -716,26 +725,35 @@ exports[`Media Player: Canonical Entry renders the audio skin 1`] = `
}

.c1 {
left: 0;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.c2 {
border: 0;
overflow: hidden;
height: 100%;
width: 100%;
}

<div
class="c0"
>
<iframe
allow="autoplay; fullscreen"
allowfullscreen=""
<div
class="c1"
scrolling="no"
src="https://www.test.bbc.com/ws/av-embeds/media/bbc_korean_radio/liveradio"
title="Audio player"
/>
>
<iframe
allow="autoplay; fullscreen"
allowfullscreen=""
class="c2"
scrolling="no"
src="https://www.test.bbc.com/ws/av-embeds/media/bbc_korean_radio/liveradio"
title="Audio player"
/>
</div>
</div>
`;

Expand Down
7 changes: 6 additions & 1 deletion packages/components/psammead-media-player/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ export const CanonicalMediaPlayer = ({
noJsMessage={noJsMessage}
/>
) : (
<Canonical src={src} title={title} placeholderSrc={placeholderSrc} />
<Canonical
service={service}
src={src}
title={title}
placeholderSrc={placeholderSrc}
/>
)}
</StyledContainer>
);
Expand Down
22 changes: 22 additions & 0 deletions packages/components/psammead-media-player/src/useTimeout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useRef, useEffect } from 'react';

const useTimeout = (callback, iframe, timeout) => {
const timer = useRef(null);

const handleLoad = () => {
clearTimeout(timer.current);
callback(false);
};

useEffect(() => {
iframe.current.addEventListener('load', handleLoad);
timer.current = setTimeout(() => {
callback(true);
}, timeout);
return () => {
clearTimeout(timer.current);
};
}, []);
};

export default useTimeout;