Skip to content

Commit 4478945

Browse files
committed
Reintroduce m3u8 on web behind a feature switch
1 parent 357502c commit 4478945

File tree

7 files changed

+65
-13
lines changed

7 files changed

+65
-13
lines changed

dotcom-rendering/src/components/ShowMore.importable.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export const ShowMore = ({
121121
cardInTagPage: false,
122122
editionId,
123123
discussionApiUrl,
124+
enableHlsSupport: true,
124125
}).filter((card) => !existingCardLinks.includes(card.url));
125126

126127
const showMoreContainerId = `show-more-${collectionId}`;

dotcom-rendering/src/lib/video.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@ export type Source = {
88
mimeType: SupportedVideoFileType;
99
};
1010

11+
/**
12+
* This is required whilst test m3u8 support
13+
*/
14+
export const supportedMP4VideoFileTypes = [
15+
'video/mp4', // MP4 format
16+
] as const;
17+
1118
/**
1219
* Order is important here - the browser will use the first type it supports.
13-
* 'application/x-mpegURL' & 'application/vnd.apple.mpegurl' have been filtered out
14-
* whilst a hls chrome bug is investigated
15-
* https://issues.chromium.org/issues/454630434
1620
*/
1721
export const supportedVideoFileTypes = [
18-
// 'application/x-mpegURL', // HLS format
19-
// 'application/vnd.apple.mpegurl', // Alternative HLS format
22+
'application/x-mpegURL', // HLS format
23+
'application/vnd.apple.mpegurl', // Alternative HLS format
2024
'video/mp4', // MP4 format
2125
] as const;
2226

2327
export type SupportedVideoFileType = (typeof supportedVideoFileTypes)[number];
28+
29+
export type SupportedMP4VideoFileType =
30+
(typeof supportedMP4VideoFileTypes)[number];

dotcom-rendering/src/model/enhanceCards.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe.skip('Enhance Cards', () => {
3939
const cardTrailImage = '';
4040

4141
expect(
42-
getActiveMediaAtom(videoReplace, mediaAtom, cardTrailImage),
42+
getActiveMediaAtom(videoReplace, true, mediaAtom, cardTrailImage),
4343
).toEqual({
4444
atomId: 'atomID',
4545
duration: 15,
@@ -99,7 +99,7 @@ describe.skip('Enhance Cards', () => {
9999
const cardTrailImage = '';
100100

101101
expect(
102-
getActiveMediaAtom(videoReplace, mediaAtom, cardTrailImage),
102+
getActiveMediaAtom(videoReplace, true, mediaAtom, cardTrailImage),
103103
).toEqual({
104104
atomId: 'atomID',
105105
duration: 15,

dotcom-rendering/src/model/enhanceCards.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { isUndefined } from '@guardian/libs';
22
import type {
33
FEFrontCard,
4+
FEMediaAsset,
45
FEMediaAtom,
56
FESupportingContent,
67
} from '../frontend/feFront';
@@ -14,8 +15,14 @@ import type { EditionId } from '../lib/edition';
1415
import type { Group } from '../lib/getDataLinkName';
1516
import { getDataLinkNameCard } from '../lib/getDataLinkName';
1617
import { getLargestImageSize } from '../lib/image';
17-
import type { SupportedVideoFileType } from '../lib/video';
18-
import { supportedVideoFileTypes } from '../lib/video';
18+
import type {
19+
SupportedVideoFileType,
20+
SupportedMP4VideoFileType,
21+
} from '../lib/video';
22+
import {
23+
supportedMP4VideoFileTypes,
24+
supportedVideoFileTypes,
25+
} from '../lib/video';
1926
import type { Image } from '../types/content';
2027
import type {
2128
DCRFrontCard,
@@ -196,6 +203,7 @@ const decideMediaAtomImage = (
196203

197204
export const getActiveMediaAtom = (
198205
videoReplace: boolean,
206+
enableHlsSupport: boolean,
199207
mediaAtom?: FEMediaAtom,
200208
cardTrailImage?: string,
201209
): MainMedia | undefined => {
@@ -220,10 +228,13 @@ export const getActiveMediaAtom = (
220228
* Therefore, we check the platform of the first asset and assume the rest are the same.
221229
*/
222230
if (assets[0]?.platform === 'Url') {
231+
const supportedFileTypes = enableHlsSupport
232+
? supportedVideoFileTypes
233+
: supportedMP4VideoFileTypes;
223234
/**
224235
* Take one source for each supported video file type.
225236
*/
226-
const sources = supportedVideoFileTypes.reduce<typeof assets>(
237+
const sources = supportedFileTypes.reduce<typeof assets>(
227238
(acc, type) => {
228239
const source = assets.find(
229240
({ mimeType }) => mimeType === type,
@@ -239,13 +250,18 @@ export const getActiveMediaAtom = (
239250
({ assetType }) => assetType === 'Subtitles',
240251
);
241252

253+
const getMimeType = (source: FEMediaAsset) =>
254+
enableHlsSupport
255+
? (source.mimeType as SupportedVideoFileType)
256+
: (source.mimeType as SupportedMP4VideoFileType);
257+
242258
return {
243259
type: 'SelfHostedVideo',
244260
videoStyle: 'Loop',
245261
atomId: mediaAtom.id,
246262
sources: sources.map((source) => ({
247263
src: source.id,
248-
mimeType: source.mimeType as SupportedVideoFileType,
264+
mimeType: getMimeType(source),
249265
})),
250266
subtitleSource: subtitleAsset?.id,
251267
duration: mediaAtom.duration ?? 0,
@@ -281,6 +297,7 @@ export const getActiveMediaAtom = (
281297

282298
const decideMedia = (
283299
format: ArticleFormat,
300+
enableHlsSupport: boolean,
284301
showMainVideo?: boolean,
285302
mediaAtom?: FEMediaAtom,
286303
galleryCount: number = 0,
@@ -293,7 +310,12 @@ const decideMedia = (
293310
// If the showVideo toggle is enabled in the fronts tool,
294311
// we should return the active mediaAtom regardless of the design
295312
if (!!showMainVideo || !!videoReplace) {
296-
return getActiveMediaAtom(!!videoReplace, mediaAtom, cardImage);
313+
return getActiveMediaAtom(
314+
!!videoReplace,
315+
enableHlsSupport,
316+
mediaAtom,
317+
cardImage,
318+
);
297319
}
298320

299321
switch (format.design) {
@@ -308,7 +330,12 @@ const decideMedia = (
308330
};
309331

310332
case ArticleDesign.Video: {
311-
return getActiveMediaAtom(false, mediaAtom, cardImage);
333+
return getActiveMediaAtom(
334+
false,
335+
enableHlsSupport,
336+
mediaAtom,
337+
cardImage,
338+
);
312339
}
313340

314341
default:
@@ -325,6 +352,7 @@ export const enhanceCards = (
325352
pageId,
326353
discussionApiUrl,
327354
stripBranding = false,
355+
enableHlsSupport = false,
328356
}: {
329357
cardInTagPage: boolean;
330358
/** Used for the data link name to indicate card position in container */
@@ -334,6 +362,7 @@ export const enhanceCards = (
334362
discussionApiUrl: string;
335363
/** We strip branding from cards if the branding will appear at the collection level instead */
336364
stripBranding?: boolean;
365+
enableHlsSupport: boolean;
337366
},
338367
): DCRFrontCard[] =>
339368
collections.map((faciaCard, index) => {
@@ -378,6 +407,7 @@ export const enhanceCards = (
378407

379408
const mainMedia = decideMedia(
380409
format,
410+
enableHlsSupport,
381411
faciaCard.properties.showMainVideo ??
382412
faciaCard.properties.mediaSelect?.showMainVideo,
383413
faciaCard.mediaAtom ??

dotcom-rendering/src/model/enhanceCollections.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const enhanceCollections = ({
6565
frontBranding,
6666
onPageDescription,
6767
isOnPaidContentFront,
68+
enableHlsSupport,
6869
}: {
6970
collections: FECollection[];
7071
editionId: EditionId;
@@ -73,6 +74,7 @@ export const enhanceCollections = ({
7374
frontBranding: Branding | undefined;
7475
onPageDescription?: string;
7576
isOnPaidContentFront?: boolean;
77+
enableHlsSupport: boolean;
7678
}): DCRCollectionType[] => {
7779
const indexToShowFrontBranding =
7880
findCollectionSuitableForFrontBranding(collections);
@@ -133,18 +135,21 @@ export const enhanceCollections = ({
133135
editionId,
134136
discussionApiUrl,
135137
stripBrandingFromCards,
138+
enableHlsSupport,
136139
),
137140
curated: enhanceCards(collection.curated, {
138141
cardInTagPage: false,
139142
editionId,
140143
discussionApiUrl,
141144
stripBranding: stripBrandingFromCards,
145+
enableHlsSupport,
142146
}),
143147
backfill: enhanceCards(collection.backfill, {
144148
cardInTagPage: false,
145149
editionId,
146150
discussionApiUrl,
147151
stripBranding: stripBrandingFromCards,
152+
enableHlsSupport,
148153
}),
149154
treats: enhanceTreats(
150155
collection.treats,

dotcom-rendering/src/model/groupCards.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const groupCards = (
3232
editionId: EditionId,
3333
discussionApiUrl: string,
3434
stripBranding: boolean = false,
35+
enableHlsSupport: boolean,
3536
): DCRGroupedTrails => {
3637
switch (container) {
3738
case 'dynamic/fast':
@@ -49,20 +50,23 @@ export const groupCards = (
4950
editionId,
5051
discussionApiUrl,
5152
stripBranding,
53+
enableHlsSupport,
5254
}),
5355
veryBig: enhanceCards(veryBig, {
5456
cardInTagPage: false,
5557
offset: huge.length,
5658
editionId,
5759
discussionApiUrl,
5860
stripBranding,
61+
enableHlsSupport,
5962
}),
6063
big: enhanceCards(big, {
6164
cardInTagPage: false,
6265
offset: huge.length + veryBig.length,
6366
editionId,
6467
discussionApiUrl,
6568
stripBranding,
69+
enableHlsSupport,
6670
}),
6771
standard: enhanceCards(
6872
// Backfilled cards will always be treated as 'standard' cards
@@ -74,6 +78,7 @@ export const groupCards = (
7478
offset: huge.length + veryBig.length + big.length,
7579
editionId,
7680
discussionApiUrl,
81+
enableHlsSupport,
7782
},
7883
),
7984
};
@@ -96,6 +101,7 @@ export const groupCards = (
96101
discussionApiUrl,
97102
offset,
98103
stripBranding,
104+
enableHlsSupport,
99105
});
100106

101107
return {
@@ -122,6 +128,7 @@ export const groupCards = (
122128
discussionApiUrl,
123129
offset,
124130
stripBranding,
131+
enableHlsSupport,
125132
});
126133

127134
return {

dotcom-rendering/src/server/handler.front.web.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const enhanceFront = (body: unknown): Front => {
4545
.editionBrandings,
4646
data.editionId,
4747
),
48+
enableHlsSupport: !!data.config.switches.enableHlsSupport,
4849
}),
4950
},
5051
mostViewed: data.mostViewed.map((trail) => decideTrail(trail)),
@@ -98,6 +99,7 @@ const enhanceTagPage = (body: unknown): TagPage => {
9899
discussionApiUrl: data.config.discussionApiUrl,
99100
editionId: data.editionId,
100101
stripBranding: !!tagPageBranding,
102+
enableHlsSupport: !!data.config.switches.enableHlsSupport,
101103
});
102104

103105
const speed = getSpeedFromTrails(data.contents);

0 commit comments

Comments
 (0)