-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathbuildSettings.ts
More file actions
94 lines (82 loc) · 2.35 KB
/
buildSettings.ts
File metadata and controls
94 lines (82 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import onClient from '#app/lib/utilities/onClient';
import isLive from '#app/lib/utilities/isLive';
import filterForBlockType from '#app/lib/utilities/blockHandlers';
import { LIVE_TV_PAGE } from '#app/routes/utils/pageTypes';
import { BuildConfigProps, PlayerConfig } from '../types';
import configForMediaBlockType from '../configs';
const isTestRequested = () => {
if (isLive()) {
return false;
}
if (onClient()) {
const testLiterals = window.location.hostname.match(/localhost|test/g);
const isTest = testLiterals && testLiterals.length > 0;
const queryParams = new URLSearchParams(window.location.search);
const isRenderEnvTest = queryParams.get('renderer_env') === 'test';
return isTest && isRenderEnvTest;
}
return false;
};
const dazzlerStreamLangs = ['hi'];
const buildSettings = ({
id,
blocks,
counterName,
statsDestination,
producer,
isAmp,
lang,
pageType,
service,
translations,
adsEnabled = false,
showAdsBasedOnLocation = false,
embedded,
}: BuildConfigProps) => {
const { model: mediaOverrides } =
filterForBlockType(blocks, 'mediaOverrides') || {};
// Base configuration that all media players should have
const basePlayerConfig: PlayerConfig = {
autoplay: true,
product: 'news',
enableToucan: true,
appType: isAmp ? 'amp' : 'responsive',
appName: service !== 'news' ? `news-${service}` : 'news',
ui: {
skin: 'classic',
controls: { enabled: true },
locale: { lang: mediaOverrides?.language || lang || 'en' },
subtitles: { enabled: true, defaultOn: true },
fullscreen: { enabled: true },
},
...(!embedded && { superResponsive: true }),
...(counterName && { counterName }),
...(isTestRequested() && {
mediator: {
host:
dazzlerStreamLangs.includes(lang) && pageType === LIVE_TV_PAGE
? 'open.live.bbc.co.uk'
: 'open.test.bbc.co.uk',
},
}),
statsObject: {
destination: statsDestination,
producer,
},
};
// Augment base configuration with settings that are specific to the media type
const config = configForMediaBlockType(blocks)?.({
id,
basePlayerConfig,
blocks,
pageType,
translations,
adsEnabled,
showAdsBasedOnLocation,
embedded,
lang,
});
if (!config) return null;
return config;
};
export default buildSettings;