Skip to content

Commit

Permalink
WSTEAM1-827: Add EMP core work. (#11347)
Browse files Browse the repository at this point in the history
* WSTEAM1-493: Add Media Player

* WSTEAM1-493: Add format functions

* WSTEAM1-493: Refactor component

* WSTEAM1-493: Refactor

* WSTEAM1-493: Refactor

* WSTEAM1-493: Add live page alterations

* WSTEAM1-493: Add live page alterations

* WSTEAM1-493: Make counterName optional

* WSTEAM1-493: Increase bundle size

* WSTEAM1-493: Update unit tests

* WSTEAM1-493: Only add MediaPlayer to Live

* WSTEAM1-493: Update tests

* WSTEAM1-493: Add counter name

* WSTEAM1-493: Update snapshots

* WSTEAM1-493: Update initilizer

* WSTEAM1-493: Update Snapshots

* WSTEAM1-493: Add data-e2e tag

* WSTEAM1-493: Add placeholder

* WSTEAM1-493: Add tests

* WSTEAM1-493: Refactor onClient logic

* WSTEAM1-493: Add caption

* WSTEAM1-827: Update tests

* WSTEAM1-827: Update tests.

* WSTEAM1-827: Update tests.

* WSTEAM1-827: Add require congig mock for tests

* WSTEAM1-827: update tests

* WSTEAM1-827: Update types

* WSTEAM1-827: Update test

* WSTEAM1-827: Alter tests

* WSTEAM1-827: Alter tests

* WSTEAM1-827: Refactor

* WSTEAM1-827: Refactor

* WSTEAM1-827: Add global.d.ts

* WSTEAM1-827: Elevate to TS

* WSTEAM1-827: Add styles

* WSTEAM1-827: Refactor

* WSTEAM1-827: Use restore mocks instead

* WSTEAM1-827: Refactor

* WSTEAM1-827: Update

* WSTEAM1-827: Fix types

* WSTEAM1-827: Refactor

* WSTEAM1-827: Add import

* WSTEAM1-827: Alter import

* WSTEAM1-827: Refactor

* WSTEAM1-827: Update unit tests

* WSTEAM1-827: add Storybook

* WSTEAM1-827: Update storybook

* WSTEAM1-827: Add test

* WSTEAM1-827: Alter mediator setting logic

* WSTEAM1-827: Change mediator logic

* WSTEAM1-827: Expose env vars

* WSTEAM1-827: Refactor

* WSTEAM1-827: lint

---------

Co-authored-by: Aaron Moore <aaron.moore@bbc.co.uk>
  • Loading branch information
shayneahchoon and amoore108 authored Mar 4, 2024
1 parent 070c64b commit 78f6f93
Show file tree
Hide file tree
Showing 27 changed files with 807 additions and 85 deletions.
4 changes: 2 additions & 2 deletions scripts/bundleSize/bundleSizeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
* We are allowing a variance of -5 on `MIN_SIZE` and +5 on `MAX_SIZE` to avoid the need for frequent changes, as bundle sizes can fluctuate
*/

export const MIN_SIZE = 485 - 5;
export const MAX_SIZE = 1250 + 5;
export const MIN_SIZE = 637 - 5;
export const MAX_SIZE = 1260 + 5;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MediaPlayer Calls the amp media player 1`] = `
exports[`LegacyLiveMediaPlayer Calls the amp media player 1`] = `
@media (max-width: 14.9375rem) {
.emotion-0 {
margin-left: 0%;
Expand Down Expand Up @@ -33,7 +33,7 @@ exports[`MediaPlayer Calls the amp media player 1`] = `
@media (min-width: 80rem) {
.emotion-0 {
margin-left: 40%;
margin-left: 20%;
}
}
Expand Down Expand Up @@ -86,9 +86,9 @@ exports[`MediaPlayer Calls the amp media player 1`] = `
@media (min-width: 80rem) {
.emotion-0 {
grid-template-columns: repeat(10, 1fr);
grid-column-end: span 10;
grid-column-start: 5;
grid-template-columns: repeat(5, 1fr);
grid-column-end: span 5;
grid-column-start: 2;
}
}
}
Expand Down Expand Up @@ -208,7 +208,7 @@ exports[`MediaPlayer Calls the amp media player 1`] = `
<div>
<div
class="emotion-0 emotion-1"
class="MediaPlayer emotion-0 emotion-1"
dir="ltr"
>
<figure
Expand Down Expand Up @@ -258,7 +258,7 @@ exports[`MediaPlayer Calls the amp media player 1`] = `
</div>
`;

exports[`MediaPlayer Calls the canonical media player, with a placeholder 1`] = `
exports[`LegacyLiveMediaPlayer Calls the canonical media player, with a placeholder 1`] = `
@media (max-width: 14.9375rem) {
.emotion-0 {
margin-left: 0%;
Expand Down Expand Up @@ -291,7 +291,7 @@ exports[`MediaPlayer Calls the canonical media player, with a placeholder 1`] =
@media (min-width: 80rem) {
.emotion-0 {
margin-left: 40%;
margin-left: 20%;
}
}
Expand Down Expand Up @@ -344,9 +344,9 @@ exports[`MediaPlayer Calls the canonical media player, with a placeholder 1`] =
@media (min-width: 80rem) {
.emotion-0 {
grid-template-columns: repeat(10, 1fr);
grid-column-end: span 10;
grid-column-start: 5;
grid-template-columns: repeat(5, 1fr);
grid-column-end: span 5;
grid-column-start: 2;
}
}
}
Expand Down Expand Up @@ -560,7 +560,7 @@ exports[`MediaPlayer Calls the canonical media player, with a placeholder 1`] =
<div>
<div
class="emotion-0 emotion-1"
class="MediaPlayer emotion-0 emotion-1"
dir="ltr"
>
<figure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import { LIVE_PAGE } from '#app/routes/utils/pageTypes';
import { render } from '../../../components/react-testing-library-with-providers';
import { render } from '../react-testing-library-with-providers';
import LivePageMediaPlayer from '.';
import { validLivePageVideoWithCaptionBlock } from '../MediaPlayer/fixtureData';
import { validLivePageVideoWithCaptionBlock } from '../../legacy/containers/MediaPlayer/fixtureData';
import { LIVE_PAGE } from '../../routes/utils/pageTypes';
import { MediaBlock } from '../MediaLoader/types';

const GenerateMediaPlayer = ({
/* eslint-disable react/prop-types */
blocks,
/* eslint-enable react/prop-types */
}) => (
const GenerateMediaPlayer = ({ blocks }: { blocks: MediaBlock[] }) => (
<BrowserRouter>
<LivePageMediaPlayer blocks={blocks} />
<LivePageMediaPlayer blocks={blocks} className="MediaPlayer" />
</BrowserRouter>
);

describe('MediaPlayer', () => {
describe('LegacyLiveMediaPlayer', () => {
it('Calls the canonical media player, with a placeholder', () => {
const { container } = render(
<GenerateMediaPlayer blocks={validLivePageVideoWithCaptionBlock} />,
<GenerateMediaPlayer
blocks={validLivePageVideoWithCaptionBlock as MediaBlock[]}
/>,
{
id: 'c7p765ynk9qt',
service: 'pidgin',
Expand All @@ -32,7 +31,9 @@ describe('MediaPlayer', () => {

it('Calls the amp media player', () => {
const { container } = render(
<GenerateMediaPlayer blocks={validLivePageVideoWithCaptionBlock} />,
<GenerateMediaPlayer
blocks={validLivePageVideoWithCaptionBlock as MediaBlock[]}
/>,
{
isAmp: true,
id: 'c7p765ynk9qt',
Expand Down
33 changes: 33 additions & 0 deletions src/app/components/LegacyLivePageMediaPlayer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useContext } from 'react';
import MediaPlayerContainer from '../../legacy/containers/MediaPlayer';
import { RequestContext } from '../../contexts/RequestContext';
import { MediaBlock } from '../MediaLoader/types';
import { GridItemMediumNoMargin } from '../../legacy/components/Grid';

const LegacyLivePageMediaPlayer = ({ blocks, className }: Props) => {
const { id } = useContext(RequestContext);

if (!id) return null;

return (
<GridItemMediumNoMargin
className={className}
gridColumnStart={2}
gridSpan={5}
>
<MediaPlayerContainer
blocks={blocks}
assetId={id}
assetType="live"
showPlaceholder
/>
</GridItemMediumNoMargin>
);
};

type Props = {
blocks: MediaBlock[];
className: string;
};

export default LegacyLivePageMediaPlayer;
22 changes: 22 additions & 0 deletions src/app/components/MediaLoader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Media Loader

## Description

This component loads a media player into our webpage. It uses the BBC Universal Media Player module (BUMP) to choose the correct Embedded Media Player (EMP) for the user's device. Using BUMP removes the concerns involved in serving different devices and web-browsers as BUMP automatically provides the best fitting EMP for the client. For example, BUMP can cater for differences between mobiles, laptops and desktops, but also factors such as whether the user is using network data (3G) or a WIFI.


## Local Development
So that the EMP can load video data, our localhost's domain name should be altered from `localhost:7080` to `localhost.bbc.com:7080` to fully encorporate the bbc domain name (bbc) and top-level domain (.com).

First, run the command (you only need to run this once):

`sudo -- sh -c -e "echo '127.0.0.1 localhost.bbc.com' >> /etc/hosts";`

Then, access local pages using: `localhost.bbc.com:7080/`,
eg.
Express pages: `http://localhost.bbc.com:7080/afaanoromoo/articles/c4g19kgl85ko`

Next pages: `http://localhost.bbc.com:7081/pidgin/live/c7p765ynk9qt?renderer_env=test`


Currently, the EMP is set to only load Live video assets by default. To load test assets, append the query `?renderer_env=test` to the url. Eg. `http://localhost.bbc.com:7080/afaanoromoo/articles/c4g19kgl85ko?renderer_env=test`
139 changes: 139 additions & 0 deletions src/app/components/MediaLoader/fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
const sampleBlocks = [
{
id: '80e150c0',
type: 'aresMedia',
model: {
blocks: [
{
id: 'c77c0598',
blockId: 'urn:bbc:ares::clip:p01k6msm',
type: 'aresMediaMetadata',
model: {
id: 'p01k6msm',
subType: 'clip',
format: 'video',
title: 'Five things ants can teach us about management',
synopses: {
short:
'They may be tiny, but us humans could learn a thing or two from ants.',
},
imageUrl: 'ichef.test.bbci.co.uk/images/ic/$recipe/p01k6mtv.jpg',
imageCopyright: 'BBC',
embedding: true,
advertising: true,
versions: [
{
versionId: 'p01k6msp',
types: ['Original'],
duration: 191,
durationISO8601: 'PT3M11S',
warnings: {
short: 'Contains strong language and adult humour.',
long: 'Contains strong language and adult humour.',
},
availableTerritories: {
uk: true,
nonUk: true,
},
availableFrom: 1540218932000,
},
],
syndication: {
destinations: [],
},
smpKind: 'programme',
},
position: [5, 2, 1],
},
{
id: 'd8f26383',
type: 'image',
model: {
blocks: [
{
id: 'fcdba133',
type: 'rawImage',
model: {
width: 1920,
height: 1080,
locator:
'ichef.test.bbci.co.uk/images/ic/$widthxn/p01k6mtv.jpg',
originCode: 'mpv',
copyrightHolder: 'BBC',
},
},
{
id: '63679c9e',
type: 'altText',
model: {
blocks: [
{
id: '33876888',
type: 'text',
model: {
blocks: [
{
id: '26dbfca2',
type: 'paragraph',
model: {
text: 'Ants',
blocks: [
{
id: 'ed9f30c9',
type: 'fragment',
model: {
text: 'Ants',
attributes: [],
},
},
],
},
},
],
},
},
],
},
},
],
},
},
],
},
},
{
id: '31318aec',
type: 'caption',
model: {
blocks: [
{
id: '8ac45ed2',
type: 'text',
model: {
blocks: [
{
id: '935f130e',
type: 'paragraph',
model: {
text: 'This is a caption!',
blocks: [
{
id: 'deaf6139',
type: 'fragment',
model: {
text: 'This is a caption!',
attributes: [],
},
},
],
},
},
],
},
},
],
},
},
];

export default sampleBlocks;
48 changes: 48 additions & 0 deletions src/app/components/MediaLoader/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import { PageTypes, Services } from '#app/models/types/global';
import { RequestContextProvider } from '#app/contexts/RequestContext';
import { ServiceContextProvider } from '../../contexts/ServiceContext';
import MediaLoaderComponent from '.';
import ThemeProvider from '../ThemeProvider';
import md from './README.md';
import sample from './fixture';

type Props = {
pageType: PageTypes;
service: Services;
};

const Component = ({ service, pageType }: Props) => (
<ServiceContextProvider service={service}>
<RequestContextProvider
id="testID"
isAmp={false}
isApp={false}
pageType={pageType}
pathname=""
service={service}
counterName="testCounterName"
>
<ThemeProvider service={service}>
<MediaLoaderComponent className="MediaLoader" blocks={sample} />
</ThemeProvider>
</RequestContextProvider>
</ServiceContextProvider>
);

export default {
title: 'Components/MediaLoader',
Component,
parameters: {
docs: {
component: {
title: 'MediaLoader',
},
page: md,
},
},
};

export const ArticleMediaLoader = () => (
<Component service="pidgin" pageType="article" />
);
Loading

0 comments on commit 78f6f93

Please sign in to comment.