@brightcove/components-embed-code-modal 1.0.7 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +7 -0
- package/.eslintrc +23 -0
- package/.github/workflows/ci.yml +23 -0
- package/.husky/pre-commit +4 -0
- package/.nvmrc +1 -0
- package/.prettierignore +7 -0
- package/.prettierrc +5 -0
- package/.release-it.json +40 -0
- package/.whitesource +3 -0
- package/CHANGELOG.md +398 -0
- package/CODEOWNERS +37 -0
- package/PULL_REQUEST_TEMPLATE.md +17 -0
- package/__tests__/EmbedCode.test.tsx +51 -0
- package/__tests__/InteractivityProject.test.tsx +50 -0
- package/__tests__/PlayerPreview.test.tsx +23 -0
- package/__tests__/PrismPlayerPreview.test.tsx +168 -0
- package/__tests__/TabsHeader.test.tsx +19 -0
- package/__tests__/TabsSection.test.tsx +46 -0
- package/__tests__/TitleWithTooltip.test.tsx +45 -0
- package/__tests__/VideoPlayer.test.tsx +38 -0
- package/__tests__/embedCodeGenerator.test.ts +111 -0
- package/__tests__/util.test.ts +89 -0
- package/babel.config.json +17 -0
- package/build/README.md +109 -0
- package/build/__tests__/PrismPlayerPreview.test.d.ts +2 -0
- package/build/__tests__/PrismPlayerPreview.test.d.ts.map +1 -0
- package/{index.js → build/index.js} +1 -1
- package/build/index.js.map +1 -0
- package/build/package.json +100 -0
- package/{src → build/src}/js/components/prism/PrismPlayerPreview.d.ts.map +1 -1
- package/{src → build/src}/js/i18n.d.ts +30 -6
- package/{src → build/src}/js/i18n.d.ts.map +1 -1
- package/etc/wildcard.brightcove.com.key +27 -0
- package/etc/wildcard.brightcove.com.pem +96 -0
- package/jest/jest.setup.js +90 -0
- package/jest/jest.stub.js +4 -0
- package/jest.config.js +24 -0
- package/package.json +15 -5
- package/scripts/create-dist-pkg-prod.js +18 -0
- package/src/index.ts +17 -0
- package/src/js/EmbedCodeModal.tsx +105 -0
- package/src/js/components/CustomSettingsDropdown.tsx +184 -0
- package/src/js/components/EmbedCopySection.tsx +130 -0
- package/src/js/components/ModalContainer.tsx +367 -0
- package/src/js/components/NoPlayerModal.tsx +42 -0
- package/src/js/components/PlayerPreview.tsx +116 -0
- package/src/js/components/TabsHeader.tsx +31 -0
- package/src/js/components/TabsSection.tsx +74 -0
- package/src/js/components/TitleWithTooltip.tsx +39 -0
- package/src/js/components/VideoLinks.tsx +83 -0
- package/src/js/components/VideoPlayer.tsx +324 -0
- package/src/js/components/index.ts +9 -0
- package/src/js/components/prism/PrismLiveModal.tsx +162 -0
- package/src/js/components/prism/PrismPlayerControls.tsx +343 -0
- package/src/js/components/prism/PrismPlayerPreview.tsx +188 -0
- package/src/js/components/prism/index.ts +3 -0
- package/src/js/constants/baseUrls.ts +4 -0
- package/src/js/constants/embed.ts +12 -0
- package/src/js/constants/player.ts +32 -0
- package/src/js/constants/pluginsRegistry.ts +30 -0
- package/src/js/hooks/useGetPlayers.ts +12 -0
- package/src/js/i18n.ts +43 -0
- package/src/js/services/players-api.ts +26 -0
- package/src/js/services/url-shortener.ts +10 -0
- package/src/js/types/EmbedCodeModalProps.ts +72 -0
- package/src/js/types/EmbedCodeProps.ts +13 -0
- package/src/js/types/brightcoveEmbedCode.d.ts +18 -0
- package/src/js/types/players.ts +64 -0
- package/src/js/types/react-i18next.d.ts +8 -0
- package/src/js/types/studioModule.ts +7 -0
- package/src/js/utils/addPluginsDataToPlayers.ts +59 -0
- package/src/js/utils/call.ts +31 -0
- package/src/js/utils/dimensions.ts +53 -0
- package/src/js/utils/embedCodeGenerator.ts +120 -0
- package/src/js/utils/featureSwitches.ts +16 -0
- package/src/js/utils/util.ts +153 -0
- package/src/module.tsx +280 -0
- package/src/styles/CustomSettingsDropdown.sass +42 -0
- package/src/styles/EmbedCode.sass +30 -0
- package/src/styles/EmbedCodeModal.sass +76 -0
- package/src/styles/base.sass +1 -0
- package/src/styles/prism/PrismLiveModal.sass +155 -0
- package/src/styles/theme.sass +11 -0
- package/src/styles/typings.td.ts +9 -0
- package/src/translations/en.json +65 -0
- package/src/translations/es.json +65 -0
- package/src/translations/fr.json +65 -0
- package/src/translations/ja.json +65 -0
- package/src/translations/ko.json +65 -0
- package/src/translations/zh.json +65 -0
- package/src/types/studio.ts +197 -0
- package/tsconfig.json +34 -0
- package/webpack.config.js +117 -0
- package/index.js.map +0 -1
- /package/{__tests__ → build/__tests__}/EmbedCode.test.d.ts +0 -0
- /package/{__tests__ → build/__tests__}/EmbedCode.test.d.ts.map +0 -0
- /package/{__tests__ → build/__tests__}/InteractivityProject.test.d.ts +0 -0
- /package/{__tests__ → build/__tests__}/InteractivityProject.test.d.ts.map +0 -0
- /package/{__tests__ → build/__tests__}/PlayerPreview.test.d.ts +0 -0
- /package/{__tests__ → build/__tests__}/PlayerPreview.test.d.ts.map +0 -0
- /package/{__tests__ → build/__tests__}/TabsHeader.test.d.ts +0 -0
- /package/{__tests__ → build/__tests__}/TabsHeader.test.d.ts.map +0 -0
- /package/{__tests__ → build/__tests__}/TabsSection.test.d.ts +0 -0
- /package/{__tests__ → build/__tests__}/TabsSection.test.d.ts.map +0 -0
- /package/{__tests__ → build/__tests__}/TitleWithTooltip.test.d.ts +0 -0
- /package/{__tests__ → build/__tests__}/TitleWithTooltip.test.d.ts.map +0 -0
- /package/{__tests__ → build/__tests__}/VideoPlayer.test.d.ts +0 -0
- /package/{__tests__ → build/__tests__}/VideoPlayer.test.d.ts.map +0 -0
- /package/{__tests__ → build/__tests__}/embedCodeGenerator.test.d.ts +0 -0
- /package/{__tests__ → build/__tests__}/embedCodeGenerator.test.d.ts.map +0 -0
- /package/{__tests__ → build/__tests__}/util.test.d.ts +0 -0
- /package/{__tests__ → build/__tests__}/util.test.d.ts.map +0 -0
- /package/{src → build/src}/index.d.ts +0 -0
- /package/{src → build/src}/index.d.ts.map +0 -0
- /package/{src → build/src}/js/EmbedCodeModal.d.ts +0 -0
- /package/{src → build/src}/js/EmbedCodeModal.d.ts.map +0 -0
- /package/{src → build/src}/js/components/CustomSettingsDropdown.d.ts +0 -0
- /package/{src → build/src}/js/components/CustomSettingsDropdown.d.ts.map +0 -0
- /package/{src → build/src}/js/components/EmbedCopySection.d.ts +0 -0
- /package/{src → build/src}/js/components/EmbedCopySection.d.ts.map +0 -0
- /package/{src → build/src}/js/components/ModalContainer.d.ts +0 -0
- /package/{src → build/src}/js/components/ModalContainer.d.ts.map +0 -0
- /package/{src → build/src}/js/components/NoPlayerModal.d.ts +0 -0
- /package/{src → build/src}/js/components/NoPlayerModal.d.ts.map +0 -0
- /package/{src → build/src}/js/components/PlayerPreview.d.ts +0 -0
- /package/{src → build/src}/js/components/PlayerPreview.d.ts.map +0 -0
- /package/{src → build/src}/js/components/TabsHeader.d.ts +0 -0
- /package/{src → build/src}/js/components/TabsHeader.d.ts.map +0 -0
- /package/{src → build/src}/js/components/TabsSection.d.ts +0 -0
- /package/{src → build/src}/js/components/TabsSection.d.ts.map +0 -0
- /package/{src → build/src}/js/components/TitleWithTooltip.d.ts +0 -0
- /package/{src → build/src}/js/components/TitleWithTooltip.d.ts.map +0 -0
- /package/{src → build/src}/js/components/VideoLinks.d.ts +0 -0
- /package/{src → build/src}/js/components/VideoLinks.d.ts.map +0 -0
- /package/{src → build/src}/js/components/VideoPlayer.d.ts +0 -0
- /package/{src → build/src}/js/components/VideoPlayer.d.ts.map +0 -0
- /package/{src → build/src}/js/components/index.d.ts +0 -0
- /package/{src → build/src}/js/components/index.d.ts.map +0 -0
- /package/{src → build/src}/js/components/prism/PrismLiveModal.d.ts +0 -0
- /package/{src → build/src}/js/components/prism/PrismLiveModal.d.ts.map +0 -0
- /package/{src → build/src}/js/components/prism/PrismPlayerControls.d.ts +0 -0
- /package/{src → build/src}/js/components/prism/PrismPlayerControls.d.ts.map +0 -0
- /package/{src → build/src}/js/components/prism/PrismPlayerPreview.d.ts +0 -0
- /package/{src → build/src}/js/components/prism/index.d.ts +0 -0
- /package/{src → build/src}/js/components/prism/index.d.ts.map +0 -0
- /package/{src → build/src}/js/constants/baseUrls.d.ts +0 -0
- /package/{src → build/src}/js/constants/baseUrls.d.ts.map +0 -0
- /package/{src → build/src}/js/constants/embed.d.ts +0 -0
- /package/{src → build/src}/js/constants/embed.d.ts.map +0 -0
- /package/{src → build/src}/js/constants/player.d.ts +0 -0
- /package/{src → build/src}/js/constants/player.d.ts.map +0 -0
- /package/{src → build/src}/js/constants/pluginsRegistry.d.ts +0 -0
- /package/{src → build/src}/js/constants/pluginsRegistry.d.ts.map +0 -0
- /package/{src → build/src}/js/hooks/useGetPlayers.d.ts +0 -0
- /package/{src → build/src}/js/hooks/useGetPlayers.d.ts.map +0 -0
- /package/{src → build/src}/js/services/players-api.d.ts +0 -0
- /package/{src → build/src}/js/services/players-api.d.ts.map +0 -0
- /package/{src → build/src}/js/services/url-shortener.d.ts +0 -0
- /package/{src → build/src}/js/services/url-shortener.d.ts.map +0 -0
- /package/{src → build/src}/js/types/EmbedCodeModalProps.d.ts +0 -0
- /package/{src → build/src}/js/types/EmbedCodeModalProps.d.ts.map +0 -0
- /package/{src → build/src}/js/types/EmbedCodeProps.d.ts +0 -0
- /package/{src → build/src}/js/types/EmbedCodeProps.d.ts.map +0 -0
- /package/{src → build/src}/js/types/players.d.ts +0 -0
- /package/{src → build/src}/js/types/players.d.ts.map +0 -0
- /package/{src → build/src}/js/types/studioModule.d.ts +0 -0
- /package/{src → build/src}/js/types/studioModule.d.ts.map +0 -0
- /package/{src → build/src}/js/utils/addPluginsDataToPlayers.d.ts +0 -0
- /package/{src → build/src}/js/utils/addPluginsDataToPlayers.d.ts.map +0 -0
- /package/{src → build/src}/js/utils/call.d.ts +0 -0
- /package/{src → build/src}/js/utils/call.d.ts.map +0 -0
- /package/{src → build/src}/js/utils/dimensions.d.ts +0 -0
- /package/{src → build/src}/js/utils/dimensions.d.ts.map +0 -0
- /package/{src → build/src}/js/utils/embedCodeGenerator.d.ts +0 -0
- /package/{src → build/src}/js/utils/embedCodeGenerator.d.ts.map +0 -0
- /package/{src → build/src}/js/utils/featureSwitches.d.ts +0 -0
- /package/{src → build/src}/js/utils/featureSwitches.d.ts.map +0 -0
- /package/{src → build/src}/js/utils/util.d.ts +0 -0
- /package/{src → build/src}/js/utils/util.d.ts.map +0 -0
- /package/{src → build/src}/module.d.ts +0 -0
- /package/{src → build/src}/module.d.ts.map +0 -0
- /package/{src → build/src}/styles/typings.td.d.ts +0 -0
- /package/{src → build/src}/styles/typings.td.d.ts.map +0 -0
- /package/{src → build/src}/types/studio.d.ts +0 -0
- /package/{src → build/src}/types/studio.d.ts.map +0 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
RadioGroup,
|
|
4
|
+
Select,
|
|
5
|
+
Input,
|
|
6
|
+
Icon,
|
|
7
|
+
ICONS,
|
|
8
|
+
Fadeable,
|
|
9
|
+
} from '@brightcove/studio-components';
|
|
10
|
+
import { useTranslation } from 'react-i18next';
|
|
11
|
+
|
|
12
|
+
import css from 'styles/CustomSettingsDropdown.sass';
|
|
13
|
+
import {
|
|
14
|
+
EmbedCodeAspectRatio,
|
|
15
|
+
EmbedCodeProperties,
|
|
16
|
+
EmbedCodeUnits,
|
|
17
|
+
} from 'js/types/EmbedCodeModalProps';
|
|
18
|
+
import {
|
|
19
|
+
calculateDimensions,
|
|
20
|
+
calculateHeight,
|
|
21
|
+
shouldUpdateWidth,
|
|
22
|
+
} from 'js/utils/dimensions';
|
|
23
|
+
|
|
24
|
+
export enum Sizing {
|
|
25
|
+
FIXED = 'Fixed',
|
|
26
|
+
RESPONSIVE = 'Responsive',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const CustomSettingsDropdown = ({
|
|
30
|
+
setEmbedProperties,
|
|
31
|
+
embedProperties,
|
|
32
|
+
}: {
|
|
33
|
+
embedProperties: EmbedCodeProperties;
|
|
34
|
+
setEmbedProperties: (value: EmbedCodeProperties) => void;
|
|
35
|
+
}) => {
|
|
36
|
+
const { t } = useTranslation();
|
|
37
|
+
const [isHidden, setIsHidden] = useState<boolean>(true);
|
|
38
|
+
const [prevAspectRatio, setPrevAspectRatio] = useState(
|
|
39
|
+
embedProperties.aspectRatio,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const handlePropertiesUpdate = (
|
|
43
|
+
name: string,
|
|
44
|
+
value: string | boolean | number,
|
|
45
|
+
) => {
|
|
46
|
+
if (name === 'aspectRatio') {
|
|
47
|
+
const calculateNewWidth = shouldUpdateWidth(
|
|
48
|
+
prevAspectRatio,
|
|
49
|
+
value as EmbedCodeAspectRatio,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
setPrevAspectRatio(value as EmbedCodeAspectRatio);
|
|
53
|
+
|
|
54
|
+
const dimensions = calculateDimensions(
|
|
55
|
+
calculateNewWidth,
|
|
56
|
+
value as EmbedCodeAspectRatio,
|
|
57
|
+
embedProperties.width,
|
|
58
|
+
embedProperties.height,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
setEmbedProperties({
|
|
62
|
+
...embedProperties,
|
|
63
|
+
aspectRatio: value as EmbedCodeAspectRatio,
|
|
64
|
+
width: dimensions.width as number,
|
|
65
|
+
height: dimensions.height,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return;
|
|
69
|
+
} else if (
|
|
70
|
+
name === 'width' &&
|
|
71
|
+
embedProperties.aspectRatio !== EmbedCodeAspectRatio.CUSTOM
|
|
72
|
+
) {
|
|
73
|
+
const height = calculateHeight(
|
|
74
|
+
value as number,
|
|
75
|
+
embedProperties.aspectRatio,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
setEmbedProperties({
|
|
79
|
+
...embedProperties,
|
|
80
|
+
width: value as number,
|
|
81
|
+
height,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setEmbedProperties({
|
|
88
|
+
...embedProperties,
|
|
89
|
+
[name]: value,
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div className={css.featuresDropdown}>
|
|
95
|
+
<div className={css.topArea} onClick={() => setIsHidden(!isHidden)}>
|
|
96
|
+
<div className={css.title}>Custom settings</div>
|
|
97
|
+
<div className={css.right}>
|
|
98
|
+
<div className={css.description}>Sizing & ratio</div>
|
|
99
|
+
<Icon
|
|
100
|
+
name={isHidden ? ICONS.CARET_DOWN : ICONS.CARET_UP}
|
|
101
|
+
className={css.icon}
|
|
102
|
+
/>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
<Fadeable show={!isHidden} className={css.hiddenArea}>
|
|
106
|
+
<div className={css.hiddenAreaContainer}>
|
|
107
|
+
<RadioGroup
|
|
108
|
+
inline
|
|
109
|
+
name='sizing'
|
|
110
|
+
label={t('customSettings.sizing')}
|
|
111
|
+
value={
|
|
112
|
+
embedProperties.responsive ? Sizing.RESPONSIVE : Sizing.FIXED
|
|
113
|
+
}
|
|
114
|
+
options={[Sizing.FIXED, Sizing.RESPONSIVE]}
|
|
115
|
+
onChange={(value: string) =>
|
|
116
|
+
handlePropertiesUpdate('responsive', value === Sizing.RESPONSIVE)
|
|
117
|
+
}
|
|
118
|
+
testName='embed-sizing-radio-group'
|
|
119
|
+
/>
|
|
120
|
+
<Select
|
|
121
|
+
label={t('customSettings.aspectRatio')}
|
|
122
|
+
value={embedProperties.aspectRatio}
|
|
123
|
+
options={[
|
|
124
|
+
EmbedCodeAspectRatio.SIXTEEN_NINE,
|
|
125
|
+
EmbedCodeAspectRatio.NINE_SIXTEEN,
|
|
126
|
+
EmbedCodeAspectRatio.ONE_ONE,
|
|
127
|
+
EmbedCodeAspectRatio.FOUR_THREE,
|
|
128
|
+
EmbedCodeAspectRatio.CUSTOM,
|
|
129
|
+
]}
|
|
130
|
+
className={css.aspectRatioSelect}
|
|
131
|
+
onChange={(value: string) =>
|
|
132
|
+
handlePropertiesUpdate('aspectRatio', value)
|
|
133
|
+
}
|
|
134
|
+
testName='embed-aspect-ratio-select'
|
|
135
|
+
/>
|
|
136
|
+
<div className={css.sizeEdit}>
|
|
137
|
+
<Input
|
|
138
|
+
label={t('customSettings.playerWidth')}
|
|
139
|
+
value={embedProperties.width}
|
|
140
|
+
onChange={(value: string) =>
|
|
141
|
+
handlePropertiesUpdate('width', value)
|
|
142
|
+
}
|
|
143
|
+
error={
|
|
144
|
+
embedProperties.width <= 0
|
|
145
|
+
? 'Can only be positive integers'
|
|
146
|
+
: ''
|
|
147
|
+
}
|
|
148
|
+
testName='embed-width-input'
|
|
149
|
+
/>
|
|
150
|
+
<Input
|
|
151
|
+
label={t('customSettings.playerHeight')}
|
|
152
|
+
value={embedProperties.height}
|
|
153
|
+
onChange={(value: string) =>
|
|
154
|
+
handlePropertiesUpdate('height', value)
|
|
155
|
+
}
|
|
156
|
+
disabled={
|
|
157
|
+
embedProperties.aspectRatio !== EmbedCodeAspectRatio.CUSTOM
|
|
158
|
+
}
|
|
159
|
+
error={
|
|
160
|
+
embedProperties.height <= 0
|
|
161
|
+
? 'Can only be positive integers'
|
|
162
|
+
: ''
|
|
163
|
+
}
|
|
164
|
+
testName='embed-height-input'
|
|
165
|
+
/>
|
|
166
|
+
<Select
|
|
167
|
+
label={t('customSettings.units')}
|
|
168
|
+
value={embedProperties.units}
|
|
169
|
+
options={[
|
|
170
|
+
EmbedCodeUnits.PX,
|
|
171
|
+
EmbedCodeUnits.EM,
|
|
172
|
+
EmbedCodeUnits.PERCENT,
|
|
173
|
+
]}
|
|
174
|
+
onChange={(value: string) =>
|
|
175
|
+
handlePropertiesUpdate('units', value)
|
|
176
|
+
}
|
|
177
|
+
testName='embed-units-select'
|
|
178
|
+
/>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
</Fadeable>
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
|
|
4
|
+
import brightcoveEmbedCode from '@brightcove/player-embed-code';
|
|
5
|
+
import {
|
|
6
|
+
Flex,
|
|
7
|
+
FlexItem,
|
|
8
|
+
CopyField,
|
|
9
|
+
PlainTextArea,
|
|
10
|
+
} from '@brightcove/studio-components';
|
|
11
|
+
|
|
12
|
+
import { EmbedCodeProps } from 'js/types/EmbedCodeProps';
|
|
13
|
+
import { getUrlBase, getBrightcove, decodeHtmlEntities } from 'js/utils/util';
|
|
14
|
+
|
|
15
|
+
import css from 'styles/EmbedCode.sass';
|
|
16
|
+
import {
|
|
17
|
+
EmbedCodeAspectRatio,
|
|
18
|
+
EmbedCodeUnits,
|
|
19
|
+
} from 'js/types/EmbedCodeModalProps';
|
|
20
|
+
|
|
21
|
+
interface EmbedCodeConfig {
|
|
22
|
+
accountId: string;
|
|
23
|
+
responsive: boolean;
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
iframe: boolean;
|
|
27
|
+
videoId?: string;
|
|
28
|
+
interactivityProjectId?: string;
|
|
29
|
+
playerId: string;
|
|
30
|
+
urlBase: string;
|
|
31
|
+
playlistIsHorizontal: boolean;
|
|
32
|
+
units: EmbedCodeUnits;
|
|
33
|
+
aspectRatio?: EmbedCodeAspectRatio;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const DEFAULT_HEIGHT = 540;
|
|
37
|
+
const DEFAULT_WIDTH = 960;
|
|
38
|
+
const defaultConfig = {
|
|
39
|
+
responsive: false,
|
|
40
|
+
width: DEFAULT_WIDTH,
|
|
41
|
+
height: DEFAULT_HEIGHT,
|
|
42
|
+
urlBase: getUrlBase(),
|
|
43
|
+
playlistIsHorizontal: true,
|
|
44
|
+
units: EmbedCodeUnits.PX,
|
|
45
|
+
aspectRatio: EmbedCodeAspectRatio.FLUID,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const createEmbedConfigObject = ({
|
|
49
|
+
embedCodeProperties,
|
|
50
|
+
accountId,
|
|
51
|
+
iframe,
|
|
52
|
+
videoId,
|
|
53
|
+
playerId,
|
|
54
|
+
interactivityProjectId,
|
|
55
|
+
livePlaybackToken,
|
|
56
|
+
adConfigId,
|
|
57
|
+
}: EmbedCodeProps): EmbedCodeConfig => {
|
|
58
|
+
const config = {
|
|
59
|
+
accountId,
|
|
60
|
+
iframe,
|
|
61
|
+
videoId,
|
|
62
|
+
playerId,
|
|
63
|
+
livePlaybackToken,
|
|
64
|
+
adConfigId,
|
|
65
|
+
interactivityProjectId,
|
|
66
|
+
};
|
|
67
|
+
return Object.assign(
|
|
68
|
+
{},
|
|
69
|
+
{ ...defaultConfig, ...config, ...embedCodeProperties },
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const EmbedCode = (config: EmbedCodeProps) => {
|
|
74
|
+
const { t } = useTranslation();
|
|
75
|
+
const [embedCode, setEmbedCode] = useState('');
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const embedConfigObj = createEmbedConfigObject(config);
|
|
79
|
+
|
|
80
|
+
if (embedConfigObj.aspectRatio) {
|
|
81
|
+
embedConfigObj.aspectRatio =
|
|
82
|
+
embedConfigObj.aspectRatio === EmbedCodeAspectRatio.CUSTOM
|
|
83
|
+
? EmbedCodeAspectRatio.FLUID
|
|
84
|
+
: embedConfigObj.aspectRatio;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const embedCode = decodeHtmlEntities(brightcoveEmbedCode(embedConfigObj));
|
|
88
|
+
setEmbedCode(embedCode);
|
|
89
|
+
}, [config]);
|
|
90
|
+
|
|
91
|
+
const HelperTextNodeNew = (
|
|
92
|
+
<Flex>
|
|
93
|
+
<FlexItem flexGrow='1' className={css.helperText}>
|
|
94
|
+
{t('tabs.helperText')}
|
|
95
|
+
</FlexItem>
|
|
96
|
+
</Flex>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<>
|
|
101
|
+
<CopyField
|
|
102
|
+
className={css.copyInput}
|
|
103
|
+
helperNode={HelperTextNodeNew}
|
|
104
|
+
Component={PlainTextArea}
|
|
105
|
+
componentProps={{
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
disabled: true,
|
|
109
|
+
disableResizing: true,
|
|
110
|
+
className: css.textAreaDimensions,
|
|
111
|
+
onChange: () => void 0,
|
|
112
|
+
}}
|
|
113
|
+
onCopy={() => {
|
|
114
|
+
getBrightcove().Toaster.success({
|
|
115
|
+
title: t('toasterTitle'),
|
|
116
|
+
message: t('toasterMessage'),
|
|
117
|
+
});
|
|
118
|
+
}}
|
|
119
|
+
onError={() => {
|
|
120
|
+
getBrightcove().Toaster.error({
|
|
121
|
+
message: t('toasterErrorMessage'),
|
|
122
|
+
});
|
|
123
|
+
}}
|
|
124
|
+
value={embedCode}
|
|
125
|
+
hideButton={true}
|
|
126
|
+
testName='embed-copy-section'
|
|
127
|
+
/>
|
|
128
|
+
</>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import useGetPlayers from 'js/hooks/useGetPlayers';
|
|
5
|
+
import { Modal, Flex, Button } from '@brightcove/studio-components';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
EmbedCodeModalTypes,
|
|
9
|
+
PlayerPayload,
|
|
10
|
+
NoInteractivityPlayerModalTypes,
|
|
11
|
+
EmbedCodeProperties,
|
|
12
|
+
LivePayload,
|
|
13
|
+
} from 'js/types/EmbedCodeModalProps';
|
|
14
|
+
import { EmbedCodeModalProps } from 'js/EmbedCodeModal';
|
|
15
|
+
import { addPluginsDataToPlayers } from 'js/utils/addPluginsDataToPlayers';
|
|
16
|
+
import { PlayerSelectItem, PlayersObject } from 'js/types/players';
|
|
17
|
+
import { createPlayer } from 'js/services/players-api';
|
|
18
|
+
import { getStudioModule, getBrightcove, ROLES } from 'js/utils/util';
|
|
19
|
+
import { DEFAULT_INTERACTIVITY_PLAYER } from 'js/constants/player';
|
|
20
|
+
|
|
21
|
+
import css from 'styles/EmbedCodeModal.sass';
|
|
22
|
+
import { VideoPlayer } from './VideoPlayer';
|
|
23
|
+
import { PlayerPreview } from './PlayerPreview';
|
|
24
|
+
import { getAccountId } from '../utils/call';
|
|
25
|
+
import { NoPlayerModal } from './NoPlayerModal';
|
|
26
|
+
import { PrismLiveModal } from './prism';
|
|
27
|
+
|
|
28
|
+
interface ModalContainerProps extends EmbedCodeModalProps {
|
|
29
|
+
handleSetComponentKey: () => void;
|
|
30
|
+
handleSetHasCreatedPlayer: (value: boolean) => void;
|
|
31
|
+
hasCreatedPlayer: boolean;
|
|
32
|
+
embedCodeProperties?: EmbedCodeProperties;
|
|
33
|
+
isOutstreamPlayer?: boolean;
|
|
34
|
+
onDVRClick?: (newValue: boolean) => void;
|
|
35
|
+
dvrTime?: number;
|
|
36
|
+
showLowLatency?: boolean;
|
|
37
|
+
onLowLatencyClick?: (newValue: boolean) => void;
|
|
38
|
+
ssai?: boolean;
|
|
39
|
+
adConfigOptions?: Array<{ label: string; value: string }>;
|
|
40
|
+
onAdConfigChange?: (value: string) => void;
|
|
41
|
+
theme?: 'blueSteel' | 'prism';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const ModalContainer = ({
|
|
45
|
+
handleSetComponentKey,
|
|
46
|
+
data,
|
|
47
|
+
embedCodeModalType = EmbedCodeModalTypes.VIDEO,
|
|
48
|
+
handleSetHasCreatedPlayer,
|
|
49
|
+
hasCreatedPlayer,
|
|
50
|
+
embedCodeProperties,
|
|
51
|
+
isOutstreamPlayer,
|
|
52
|
+
showDVR,
|
|
53
|
+
onDVRClick,
|
|
54
|
+
dvrTime,
|
|
55
|
+
showLowLatency,
|
|
56
|
+
onLowLatencyClick,
|
|
57
|
+
ssai,
|
|
58
|
+
adConfigOptions = [],
|
|
59
|
+
onAdConfigChange,
|
|
60
|
+
theme,
|
|
61
|
+
}: ModalContainerProps) => {
|
|
62
|
+
const { t } = useTranslation();
|
|
63
|
+
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
|
|
64
|
+
const { isFetching, data: playersData } = useGetPlayers(
|
|
65
|
+
embedCodeModalType !== EmbedCodeModalTypes.PLAYER,
|
|
66
|
+
);
|
|
67
|
+
const [players, setPlayers] = useState<PlayersObject>({});
|
|
68
|
+
const [playerListForSelection, setPlayerListForSelection] = useState<
|
|
69
|
+
PlayerSelectItem[]
|
|
70
|
+
>([]);
|
|
71
|
+
const [hasPublishingRole, setHasPublishingRole] = useState(false);
|
|
72
|
+
const [buttonSpinner, setButtonSpinner] = useState(false);
|
|
73
|
+
const [adConfigValue, setAdConfigValue] = useState('');
|
|
74
|
+
const [hasInitialized, setHasInitialized] = useState(false);
|
|
75
|
+
|
|
76
|
+
const handleAdConfigChange = (value: string) => {
|
|
77
|
+
setAdConfigValue(value);
|
|
78
|
+
if (onAdConfigChange) {
|
|
79
|
+
onAdConfigChange(value);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (adConfigOptions.length > 0) {
|
|
85
|
+
const initialValue = adConfigOptions[0].value;
|
|
86
|
+
|
|
87
|
+
// Only initialize if we haven't initialized yet, or if the current value is not in the new options
|
|
88
|
+
if (
|
|
89
|
+
!hasInitialized ||
|
|
90
|
+
!adConfigOptions.some((option) => option.value === adConfigValue)
|
|
91
|
+
) {
|
|
92
|
+
setAdConfigValue(initialValue);
|
|
93
|
+
setHasInitialized(true);
|
|
94
|
+
|
|
95
|
+
if (onAdConfigChange) {
|
|
96
|
+
onAdConfigChange(initialValue);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, [adConfigOptions, hasInitialized, onAdConfigChange, adConfigValue]);
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
const { roles } = getStudioModule().getCurrentUserAccount();
|
|
104
|
+
if (roles.length && roles.includes(ROLES.PUBLISHING)) {
|
|
105
|
+
setHasPublishingRole(true);
|
|
106
|
+
}
|
|
107
|
+
}, []);
|
|
108
|
+
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (embedCodeModalType === EmbedCodeModalTypes.PLAYER) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!isFetching && playersData && (playersData?.items.length ?? 0) > 0) {
|
|
114
|
+
const { playerListForSelection, players = {} } =
|
|
115
|
+
addPluginsDataToPlayers(playersData);
|
|
116
|
+
let filteredPlayerListForSelection = playerListForSelection;
|
|
117
|
+
|
|
118
|
+
if (embedCodeModalType === EmbedCodeModalTypes.PROJECT) {
|
|
119
|
+
filteredPlayerListForSelection = playerListForSelection.filter(
|
|
120
|
+
(player) => players[player.value].hasInteractivityPlugin,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
setPlayers(players);
|
|
125
|
+
setPlayerListForSelection(filteredPlayerListForSelection);
|
|
126
|
+
}
|
|
127
|
+
}, [isFetching, playersData, embedCodeModalType]);
|
|
128
|
+
|
|
129
|
+
const hasInteractivityEnabledPlayer = useMemo(
|
|
130
|
+
() =>
|
|
131
|
+
Object.values(players).some((player) => player.hasInteractivityPlugin),
|
|
132
|
+
[players],
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (data) {
|
|
137
|
+
setIsModalOpen(true);
|
|
138
|
+
}
|
|
139
|
+
}, [data]);
|
|
140
|
+
|
|
141
|
+
const closeModal = useCallback(() => {
|
|
142
|
+
setIsModalOpen(false);
|
|
143
|
+
handleSetHasCreatedPlayer(false);
|
|
144
|
+
}, [handleSetHasCreatedPlayer]);
|
|
145
|
+
|
|
146
|
+
const createInteractivityPlayer = () => {
|
|
147
|
+
const { name, registry_id, version, options } =
|
|
148
|
+
DEFAULT_INTERACTIVITY_PLAYER;
|
|
149
|
+
|
|
150
|
+
setButtonSpinner(true);
|
|
151
|
+
|
|
152
|
+
const payload = {
|
|
153
|
+
data: {
|
|
154
|
+
name,
|
|
155
|
+
configuration: {
|
|
156
|
+
plugins: [
|
|
157
|
+
{
|
|
158
|
+
registry_id,
|
|
159
|
+
version,
|
|
160
|
+
options,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
createPlayer(payload)
|
|
168
|
+
.then((res) => {
|
|
169
|
+
if (res && res.id) {
|
|
170
|
+
handleSetHasCreatedPlayer(true);
|
|
171
|
+
handleSetComponentKey();
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
.catch((reason) => {
|
|
175
|
+
console.error(reason);
|
|
176
|
+
getBrightcove().Toaster.error({
|
|
177
|
+
title: t('createPlayerFailedTitle'),
|
|
178
|
+
message: t('createPlayerFailedMessage'),
|
|
179
|
+
});
|
|
180
|
+
})
|
|
181
|
+
.finally(() => {
|
|
182
|
+
setButtonSpinner(false);
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
let content: JSX.Element | null = null;
|
|
187
|
+
let modalTitle = t('modalHeader');
|
|
188
|
+
let isLargeModal = true;
|
|
189
|
+
let buttons = [
|
|
190
|
+
<Button
|
|
191
|
+
key={'close-button'}
|
|
192
|
+
text={t('done')}
|
|
193
|
+
onClick={closeModal}
|
|
194
|
+
testName={'close-modal-btn'}
|
|
195
|
+
/>,
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
if (
|
|
199
|
+
embedCodeModalType === EmbedCodeModalTypes.LIVE &&
|
|
200
|
+
theme === 'prism' &&
|
|
201
|
+
'videoId' in data
|
|
202
|
+
) {
|
|
203
|
+
return (
|
|
204
|
+
<PrismLiveModal
|
|
205
|
+
isOpen={isModalOpen}
|
|
206
|
+
onClose={closeModal}
|
|
207
|
+
video={data as LivePayload}
|
|
208
|
+
players={players}
|
|
209
|
+
playerListForSelection={playerListForSelection}
|
|
210
|
+
showDVR={showDVR}
|
|
211
|
+
onDVRClick={onDVRClick}
|
|
212
|
+
dvrTime={dvrTime}
|
|
213
|
+
showLowLatency={showLowLatency}
|
|
214
|
+
onLowLatencyClick={onLowLatencyClick}
|
|
215
|
+
adConfigValue={adConfigValue}
|
|
216
|
+
onAdConfigChange={handleAdConfigChange}
|
|
217
|
+
ssai={ssai}
|
|
218
|
+
adConfigOptions={adConfigOptions}
|
|
219
|
+
/>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
switch (embedCodeModalType) {
|
|
224
|
+
case EmbedCodeModalTypes.LIVE:
|
|
225
|
+
content =
|
|
226
|
+
'videoId' in data ? (
|
|
227
|
+
<VideoPlayer
|
|
228
|
+
video={data}
|
|
229
|
+
embedCodeModalType={embedCodeModalType}
|
|
230
|
+
players={players}
|
|
231
|
+
playerListForSelection={playerListForSelection}
|
|
232
|
+
showDVR={showDVR}
|
|
233
|
+
onDVRClick={onDVRClick}
|
|
234
|
+
dvrTime={dvrTime}
|
|
235
|
+
showLowLatency={showLowLatency}
|
|
236
|
+
onLowLatencyClick={onLowLatencyClick}
|
|
237
|
+
adConfigValue={adConfigValue}
|
|
238
|
+
onAdConfigChange={handleAdConfigChange}
|
|
239
|
+
ssai={ssai}
|
|
240
|
+
adConfigOptions={adConfigOptions}
|
|
241
|
+
/>
|
|
242
|
+
) : null;
|
|
243
|
+
break;
|
|
244
|
+
case EmbedCodeModalTypes.VIDEO:
|
|
245
|
+
content =
|
|
246
|
+
'videoId' in data ? (
|
|
247
|
+
<VideoPlayer
|
|
248
|
+
video={data}
|
|
249
|
+
embedCodeModalType={embedCodeModalType}
|
|
250
|
+
players={players}
|
|
251
|
+
playerListForSelection={playerListForSelection}
|
|
252
|
+
showDVR={showDVR}
|
|
253
|
+
onDVRClick={onDVRClick}
|
|
254
|
+
dvrTime={dvrTime}
|
|
255
|
+
showLowLatency={showLowLatency}
|
|
256
|
+
onLowLatencyClick={onLowLatencyClick}
|
|
257
|
+
/>
|
|
258
|
+
) : null;
|
|
259
|
+
break;
|
|
260
|
+
case EmbedCodeModalTypes.PLAYER:
|
|
261
|
+
{
|
|
262
|
+
const accountId = data.accountId || getAccountId();
|
|
263
|
+
content =
|
|
264
|
+
'id' in data && accountId ? (
|
|
265
|
+
<PlayerPreview
|
|
266
|
+
{...(data as PlayerPayload)}
|
|
267
|
+
accountId={accountId}
|
|
268
|
+
embedCodeProperties={embedCodeProperties}
|
|
269
|
+
isOutstreamPlayer={isOutstreamPlayer}
|
|
270
|
+
/>
|
|
271
|
+
) : null;
|
|
272
|
+
}
|
|
273
|
+
break;
|
|
274
|
+
case EmbedCodeModalTypes.PROJECT:
|
|
275
|
+
if (!isFetching) {
|
|
276
|
+
if (!hasInteractivityEnabledPlayer && !hasPublishingRole) {
|
|
277
|
+
modalTitle = t('activateModal');
|
|
278
|
+
isLargeModal = false;
|
|
279
|
+
buttons = [
|
|
280
|
+
<Button
|
|
281
|
+
key={'close-button'}
|
|
282
|
+
text={t('close')}
|
|
283
|
+
onClick={closeModal}
|
|
284
|
+
testName={'close-modal-done-btn'}
|
|
285
|
+
/>,
|
|
286
|
+
];
|
|
287
|
+
content = (
|
|
288
|
+
<NoPlayerModal
|
|
289
|
+
modalType={NoInteractivityPlayerModalTypes.NO_PERMISSION}
|
|
290
|
+
/>
|
|
291
|
+
);
|
|
292
|
+
} else if (!hasInteractivityEnabledPlayer) {
|
|
293
|
+
modalTitle = t('noPlayerModalHeader');
|
|
294
|
+
isLargeModal = false;
|
|
295
|
+
buttons = [
|
|
296
|
+
<Button
|
|
297
|
+
key={'cancel-button'}
|
|
298
|
+
text={t('cancel')}
|
|
299
|
+
onClick={closeModal}
|
|
300
|
+
testName={'cancel-button'}
|
|
301
|
+
look='tertiary'
|
|
302
|
+
/>,
|
|
303
|
+
<Button
|
|
304
|
+
key={'create-player-button'}
|
|
305
|
+
text={t('createPlayerNow')}
|
|
306
|
+
spinner={buttonSpinner}
|
|
307
|
+
onClick={createInteractivityPlayer}
|
|
308
|
+
testName={'create-player-button'}
|
|
309
|
+
/>,
|
|
310
|
+
];
|
|
311
|
+
content = (
|
|
312
|
+
<NoPlayerModal
|
|
313
|
+
modalType={NoInteractivityPlayerModalTypes.NO_PLAYER}
|
|
314
|
+
/>
|
|
315
|
+
);
|
|
316
|
+
} else {
|
|
317
|
+
content =
|
|
318
|
+
'videoId' in data && 'interactivityProjectId' in data ? (
|
|
319
|
+
<VideoPlayer
|
|
320
|
+
video={data}
|
|
321
|
+
embedCodeModalType={embedCodeModalType}
|
|
322
|
+
playerListForSelection={playerListForSelection}
|
|
323
|
+
players={players}
|
|
324
|
+
hasCreatedPlayer={hasCreatedPlayer}
|
|
325
|
+
/>
|
|
326
|
+
) : null;
|
|
327
|
+
}
|
|
328
|
+
} else {
|
|
329
|
+
content =
|
|
330
|
+
'videoId' in data && 'interactivityProjectId' in data ? (
|
|
331
|
+
<VideoPlayer
|
|
332
|
+
video={data}
|
|
333
|
+
embedCodeModalType={embedCodeModalType}
|
|
334
|
+
playerListForSelection={playerListForSelection}
|
|
335
|
+
players={players}
|
|
336
|
+
hasCreatedPlayer={hasCreatedPlayer}
|
|
337
|
+
/>
|
|
338
|
+
) : null;
|
|
339
|
+
}
|
|
340
|
+
break;
|
|
341
|
+
default: {
|
|
342
|
+
console.warn(`EmbedModal with ${embedCodeModalType} is not supported`);
|
|
343
|
+
content = null;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (!content) {
|
|
349
|
+
console.warn(
|
|
350
|
+
`EmbedModal called with wrong props for type: ${embedCodeModalType}`,
|
|
351
|
+
);
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return (
|
|
356
|
+
<Modal
|
|
357
|
+
testName='embed-modal'
|
|
358
|
+
title={modalTitle}
|
|
359
|
+
isOpen={isModalOpen}
|
|
360
|
+
large={isLargeModal}
|
|
361
|
+
onClose={closeModal}
|
|
362
|
+
buttons={buttons}
|
|
363
|
+
>
|
|
364
|
+
<Flex className={css.videoDetailsContainer}>{content}</Flex>
|
|
365
|
+
</Modal>
|
|
366
|
+
);
|
|
367
|
+
};
|