@brightcove/components-embed-code-modal 1.0.6 → 1.0.8
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 +387 -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__/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/{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/utils/embedCodeGenerator.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 +62 -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 +98 -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 +61 -0
- package/src/translations/es.json +61 -0
- package/src/translations/fr.json +61 -0
- package/src/translations/ja.json +61 -0
- package/src/translations/ko.json +61 -0
- package/src/translations/zh.json +61 -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/src/js/components/prism/PrismCodeCard.d.ts +0 -9
- package/src/js/components/prism/PrismCodeCard.d.ts.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/PrismPlayerPreview.d.ts.map +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/i18n.d.ts +0 -0
- /package/{src → build/src}/js/i18n.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/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,13 @@
|
|
|
1
|
+
import { EmbedCodeProperties } from './EmbedCodeModalProps';
|
|
2
|
+
|
|
3
|
+
export type EmbedCodeProps = {
|
|
4
|
+
iframe: boolean;
|
|
5
|
+
accountId: string;
|
|
6
|
+
videoId?: string;
|
|
7
|
+
playerId: string;
|
|
8
|
+
interactivityProjectId?: string;
|
|
9
|
+
embedCodeProperties?: EmbedCodeProperties;
|
|
10
|
+
isOutstreamPlayer?: boolean;
|
|
11
|
+
livePlaybackToken?: string;
|
|
12
|
+
adConfigId?: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare module '@brightcove/player-embed-code' {
|
|
2
|
+
export interface EmbedCodeOptions {
|
|
3
|
+
accountId: string;
|
|
4
|
+
playerId?: string;
|
|
5
|
+
iframe?: boolean;
|
|
6
|
+
videoId?: string;
|
|
7
|
+
interactivityProjectId?: string;
|
|
8
|
+
width?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
responsive?: boolean;
|
|
11
|
+
urlBase?: string;
|
|
12
|
+
playlistIsHorizontal?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default function brightcoveEmbedCode(
|
|
16
|
+
options: EmbedCodeOptions,
|
|
17
|
+
): string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export type PlayerSelectItem = {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type PlayersObjectItem = {
|
|
7
|
+
label: string;
|
|
8
|
+
id: string;
|
|
9
|
+
hasCustomPlugins: boolean;
|
|
10
|
+
hasCampaignPlugin: boolean;
|
|
11
|
+
hasInteractivityPlugin: boolean;
|
|
12
|
+
hasViewerIDSource: boolean;
|
|
13
|
+
hasBcMapTracking: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type PlayersObject = {
|
|
17
|
+
[key: string]: PlayersObjectItem;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type PlayerItem = {
|
|
21
|
+
account_id: string;
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
branches: object;
|
|
26
|
+
created_at: string;
|
|
27
|
+
embed_count: number;
|
|
28
|
+
url: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type GetPlayersPayload = {
|
|
32
|
+
item_count: number;
|
|
33
|
+
items: PlayerItem[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type TabsSelectedId = string | number | undefined;
|
|
37
|
+
|
|
38
|
+
export type CreatePlayerPayload = {
|
|
39
|
+
data: {
|
|
40
|
+
name: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
configuration?: {
|
|
43
|
+
autoplay?;
|
|
44
|
+
loop?: boolean;
|
|
45
|
+
video_cloud?: {
|
|
46
|
+
video: string;
|
|
47
|
+
};
|
|
48
|
+
plugins?: {
|
|
49
|
+
registry_id: string;
|
|
50
|
+
version: string;
|
|
51
|
+
}[];
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type CreatePlayerResponse = {
|
|
57
|
+
id: string;
|
|
58
|
+
url: string;
|
|
59
|
+
embed_code: string;
|
|
60
|
+
embed_in_page: string;
|
|
61
|
+
preview_url: string;
|
|
62
|
+
preview_embed_in_page: string;
|
|
63
|
+
preview_embed_code: string;
|
|
64
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { sortAsc } from 'js/utils/util';
|
|
2
|
+
import {
|
|
3
|
+
GetPlayersPayload,
|
|
4
|
+
PlayerSelectItem,
|
|
5
|
+
PlayersObject,
|
|
6
|
+
} from 'js/types/players';
|
|
7
|
+
import {
|
|
8
|
+
bcHostedPlugins,
|
|
9
|
+
CAMPAIGN_PLUGIN_NAME,
|
|
10
|
+
INTERACTIVITY_REGISTRY_ID,
|
|
11
|
+
INTERACTIVITY_PLUGIN_NAME,
|
|
12
|
+
VIEWER_ID_KEY_NAME,
|
|
13
|
+
BC_MAP_TRACKING_NAME,
|
|
14
|
+
} from 'js/constants/pluginsRegistry';
|
|
15
|
+
|
|
16
|
+
export function addPluginsDataToPlayers(players: GetPlayersPayload) {
|
|
17
|
+
const playerListForSelection: PlayerSelectItem[] = [];
|
|
18
|
+
const playersObject: PlayersObject = {};
|
|
19
|
+
players?.items.forEach((player) => {
|
|
20
|
+
const playerConfig = player.branches['master'].configuration;
|
|
21
|
+
const plugins = playerConfig.plugins ?? [];
|
|
22
|
+
const hasPlugins = plugins ? plugins.length > 0 : false;
|
|
23
|
+
|
|
24
|
+
let hasBCHostedPlugin = false;
|
|
25
|
+
let hasCampaignPlugin = false;
|
|
26
|
+
let hasInteractivityPlugin = false;
|
|
27
|
+
const hasViewerIDSource = !!playerConfig[VIEWER_ID_KEY_NAME];
|
|
28
|
+
let hasBcMapTracking = false;
|
|
29
|
+
|
|
30
|
+
for (const plugin of plugins) {
|
|
31
|
+
const { name } = plugin;
|
|
32
|
+
hasBCHostedPlugin = bcHostedPlugins.includes(name);
|
|
33
|
+
hasCampaignPlugin =
|
|
34
|
+
hasCampaignPlugin || plugin.name === CAMPAIGN_PLUGIN_NAME;
|
|
35
|
+
hasInteractivityPlugin =
|
|
36
|
+
hasInteractivityPlugin ||
|
|
37
|
+
plugin.registry_id === INTERACTIVITY_REGISTRY_ID ||
|
|
38
|
+
plugin.name === INTERACTIVITY_PLUGIN_NAME;
|
|
39
|
+
hasBcMapTracking =
|
|
40
|
+
hasBcMapTracking || plugin.name === BC_MAP_TRACKING_NAME;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
playerListForSelection.push({ label: player.name, value: player.id });
|
|
44
|
+
playersObject[player.id] = {
|
|
45
|
+
label: player.name,
|
|
46
|
+
id: player.id,
|
|
47
|
+
hasCustomPlugins: !hasBCHostedPlugin && hasPlugins,
|
|
48
|
+
hasCampaignPlugin,
|
|
49
|
+
hasInteractivityPlugin,
|
|
50
|
+
hasViewerIDSource,
|
|
51
|
+
hasBcMapTracking,
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
players: playersObject,
|
|
57
|
+
playerListForSelection: sortAsc(playerListForSelection),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const getStudioConfig = () => window.StudioModule.config;
|
|
2
|
+
|
|
3
|
+
export const getAccountId = (): string => {
|
|
4
|
+
const config = getStudioConfig();
|
|
5
|
+
return config.user.currentAccount.id;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const getConfig = () => {
|
|
9
|
+
const config = getStudioConfig();
|
|
10
|
+
const apiConfig = {
|
|
11
|
+
publisherId: getAccountId(),
|
|
12
|
+
api: config.module.api,
|
|
13
|
+
};
|
|
14
|
+
return { apiConfig };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const call = <T>(options): Promise<T> => {
|
|
18
|
+
const studioModule = window.StudioModule;
|
|
19
|
+
const api = studioModule.api();
|
|
20
|
+
|
|
21
|
+
const callback = (resolve, reject) => {
|
|
22
|
+
api.call(options, resolve, reject);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return new Promise(callback);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const callAPI = <T>(apiEndpoint, apiArgs) => {
|
|
29
|
+
const endpoint = apiEndpoint({ ...apiArgs, ...getConfig() });
|
|
30
|
+
return call<T>(endpoint);
|
|
31
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { EmbedCodeAspectRatio } from 'js/types/EmbedCodeModalProps';
|
|
2
|
+
|
|
3
|
+
const precision = 100;
|
|
4
|
+
export const calculateHeight = (
|
|
5
|
+
height: number,
|
|
6
|
+
aspectRatio: EmbedCodeAspectRatio,
|
|
7
|
+
) => {
|
|
8
|
+
height = isNaN(height) ? 0 : height;
|
|
9
|
+
let newHeight: number;
|
|
10
|
+
switch (aspectRatio) {
|
|
11
|
+
case EmbedCodeAspectRatio.CUSTOM:
|
|
12
|
+
return height;
|
|
13
|
+
case EmbedCodeAspectRatio.ONE_ONE:
|
|
14
|
+
newHeight = height;
|
|
15
|
+
break;
|
|
16
|
+
case EmbedCodeAspectRatio.FOUR_THREE:
|
|
17
|
+
newHeight = height / (4 / 3);
|
|
18
|
+
break;
|
|
19
|
+
case EmbedCodeAspectRatio.NINE_SIXTEEN:
|
|
20
|
+
newHeight = height / (9 / 16);
|
|
21
|
+
break;
|
|
22
|
+
case EmbedCodeAspectRatio.SIXTEEN_NINE:
|
|
23
|
+
default:
|
|
24
|
+
newHeight = height / (16 / 9);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
return Math.round(precision * newHeight) / precision;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const calculateWidthForVerticalAspectRatio = (width: number) => {
|
|
31
|
+
return (Math.round(precision * (width * (9 / 16))) / precision).toString();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const shouldUpdateWidth = (
|
|
35
|
+
oldAspectRatio: EmbedCodeAspectRatio,
|
|
36
|
+
aspectRatio: EmbedCodeAspectRatio,
|
|
37
|
+
) =>
|
|
38
|
+
oldAspectRatio !== EmbedCodeAspectRatio.NINE_SIXTEEN &&
|
|
39
|
+
aspectRatio === EmbedCodeAspectRatio.NINE_SIXTEEN;
|
|
40
|
+
|
|
41
|
+
export const calculateDimensions = (
|
|
42
|
+
calculateNewWidth: boolean,
|
|
43
|
+
aspectRatio: EmbedCodeAspectRatio,
|
|
44
|
+
width: number,
|
|
45
|
+
height: number,
|
|
46
|
+
) => {
|
|
47
|
+
return {
|
|
48
|
+
height: calculateNewWidth ? width : calculateHeight(height, aspectRatio),
|
|
49
|
+
width: calculateNewWidth
|
|
50
|
+
? calculateWidthForVerticalAspectRatio(width)
|
|
51
|
+
: height,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import brightcoveEmbedCode from '@brightcove/player-embed-code';
|
|
2
|
+
import { getUrlBase, decodeHtmlEntities } from 'js/utils/util';
|
|
3
|
+
import {
|
|
4
|
+
EmbedCodeProperties,
|
|
5
|
+
EmbedCodeUnits,
|
|
6
|
+
EmbedCodeAspectRatio,
|
|
7
|
+
} from 'js/types/EmbedCodeModalProps';
|
|
8
|
+
|
|
9
|
+
interface GenerateEmbedCodeParams {
|
|
10
|
+
accountId: string;
|
|
11
|
+
playerId: string;
|
|
12
|
+
videoId?: string;
|
|
13
|
+
embedProperties: EmbedCodeProperties;
|
|
14
|
+
isCampaign?: boolean;
|
|
15
|
+
isViewerIdSource?: boolean;
|
|
16
|
+
isBcMapTracking?: boolean;
|
|
17
|
+
interactivityProjectId?: string;
|
|
18
|
+
livePlaybackToken?: string;
|
|
19
|
+
adConfigId?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DEFAULT_HEIGHT = 540;
|
|
23
|
+
const DEFAULT_WIDTH = 960;
|
|
24
|
+
|
|
25
|
+
const defaultConfig = {
|
|
26
|
+
responsive: false,
|
|
27
|
+
width: DEFAULT_WIDTH,
|
|
28
|
+
height: DEFAULT_HEIGHT,
|
|
29
|
+
urlBase: getUrlBase(),
|
|
30
|
+
playlistIsHorizontal: true,
|
|
31
|
+
units: EmbedCodeUnits.PX,
|
|
32
|
+
aspectRatio: EmbedCodeAspectRatio.FLUID,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Breaks the single-line embed snippet onto multiple lines so the
|
|
36
|
+
// PrismCodeCard gutter renders one line number per attribute.
|
|
37
|
+
export const formatEmbedSnippet = (snippet: string): string =>
|
|
38
|
+
snippet
|
|
39
|
+
.replace(/<(iframe|video-js|script)\s+/g, '<$1\n ')
|
|
40
|
+
.replace(/"\s+([a-zA-Z-]+=)/g, '"\n $1')
|
|
41
|
+
.replace(/>\s*<script/g, '>\n<script');
|
|
42
|
+
|
|
43
|
+
const normalizeEmbedProperties = (
|
|
44
|
+
embedProperties: EmbedCodeProperties,
|
|
45
|
+
): EmbedCodeProperties =>
|
|
46
|
+
embedProperties.aspectRatio === EmbedCodeAspectRatio.CUSTOM
|
|
47
|
+
? { ...embedProperties, aspectRatio: EmbedCodeAspectRatio.FLUID }
|
|
48
|
+
: embedProperties;
|
|
49
|
+
|
|
50
|
+
export const generateEmbedCode = ({
|
|
51
|
+
accountId,
|
|
52
|
+
playerId,
|
|
53
|
+
videoId,
|
|
54
|
+
embedProperties,
|
|
55
|
+
interactivityProjectId,
|
|
56
|
+
livePlaybackToken,
|
|
57
|
+
adConfigId,
|
|
58
|
+
}: GenerateEmbedCodeParams): { embedCode: string; embedCodeJS: string } => {
|
|
59
|
+
const normalizedEmbedProperties = normalizeEmbedProperties(embedProperties);
|
|
60
|
+
|
|
61
|
+
const baseConfig = {
|
|
62
|
+
accountId,
|
|
63
|
+
playerId,
|
|
64
|
+
videoId,
|
|
65
|
+
livePlaybackToken,
|
|
66
|
+
adConfigId,
|
|
67
|
+
interactivityProjectId,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Generate iFrame embed code
|
|
71
|
+
const iframeConfig = Object.assign(
|
|
72
|
+
{},
|
|
73
|
+
{
|
|
74
|
+
...defaultConfig,
|
|
75
|
+
...baseConfig,
|
|
76
|
+
...normalizedEmbedProperties,
|
|
77
|
+
iframe: true,
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
if (iframeConfig.aspectRatio) {
|
|
82
|
+
const { ...rest } = iframeConfig;
|
|
83
|
+
const iframeCode = brightcoveEmbedCode(rest);
|
|
84
|
+
const embedCode = formatEmbedSnippet(decodeHtmlEntities(iframeCode));
|
|
85
|
+
|
|
86
|
+
// Generate JavaScript embed code
|
|
87
|
+
const jsConfig = Object.assign(
|
|
88
|
+
{},
|
|
89
|
+
{
|
|
90
|
+
...defaultConfig,
|
|
91
|
+
...baseConfig,
|
|
92
|
+
...normalizedEmbedProperties,
|
|
93
|
+
iframe: false,
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
const { ...jsRest } = jsConfig;
|
|
97
|
+
const jsCode = brightcoveEmbedCode(jsRest);
|
|
98
|
+
const embedCodeJS = formatEmbedSnippet(decodeHtmlEntities(jsCode));
|
|
99
|
+
|
|
100
|
+
return { embedCode, embedCodeJS };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const iframeCode = brightcoveEmbedCode(iframeConfig);
|
|
104
|
+
const embedCode = formatEmbedSnippet(decodeHtmlEntities(iframeCode));
|
|
105
|
+
|
|
106
|
+
// Generate JavaScript embed code
|
|
107
|
+
const jsConfig = Object.assign(
|
|
108
|
+
{},
|
|
109
|
+
{
|
|
110
|
+
...defaultConfig,
|
|
111
|
+
...baseConfig,
|
|
112
|
+
...normalizedEmbedProperties,
|
|
113
|
+
iframe: false,
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
const jsCode = brightcoveEmbedCode(jsConfig);
|
|
117
|
+
const embedCodeJS = formatEmbedSnippet(decodeHtmlEntities(jsCode));
|
|
118
|
+
|
|
119
|
+
return { embedCode, embedCodeJS };
|
|
120
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_PLAYER_ID,
|
|
3
|
+
FAVORITE_PLAYER_SETTING,
|
|
4
|
+
} from 'js/constants/player';
|
|
5
|
+
|
|
6
|
+
const getStudioModule = () => window.StudioModule;
|
|
7
|
+
const getUser = () => getStudioModule()?.getUser();
|
|
8
|
+
|
|
9
|
+
// Gets the favorite player in a user's account
|
|
10
|
+
// If the setting value is not found, use default player
|
|
11
|
+
export const getFavoritePlayer = (): string => {
|
|
12
|
+
const user = getUser();
|
|
13
|
+
const favoritePlayerSetting =
|
|
14
|
+
user.currentAccount.settings.account[FAVORITE_PLAYER_SETTING];
|
|
15
|
+
return (favoritePlayerSetting?.values as string) ?? DEFAULT_PLAYER_ID;
|
|
16
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
QA_URL,
|
|
3
|
+
PROD_URL,
|
|
4
|
+
QA_PREVIEW_URL,
|
|
5
|
+
PROD_PREVIEW_URL,
|
|
6
|
+
} from 'js/constants/baseUrls';
|
|
7
|
+
import { StudioModule, StudioBrightcove } from 'types/studio';
|
|
8
|
+
import { PlayerSelectItem } from '../types/players';
|
|
9
|
+
|
|
10
|
+
const QA = 'qa';
|
|
11
|
+
const PRODUCTION = 'production';
|
|
12
|
+
const TITLE_CHAR_LIMIT = 60;
|
|
13
|
+
export const ROLES = {
|
|
14
|
+
PUBLISHING: 'PUBLISHING',
|
|
15
|
+
};
|
|
16
|
+
export const PREVIEW_URL_BASE = () => {
|
|
17
|
+
const env = getStudioEnvironment();
|
|
18
|
+
const envMap = {
|
|
19
|
+
qa: '.qa',
|
|
20
|
+
staging: '.staging',
|
|
21
|
+
production: '',
|
|
22
|
+
};
|
|
23
|
+
return `//preview-players${envMap[env]}.brightcove.net/v2/accounts`;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get the studio environment as a string.
|
|
28
|
+
* @returns the studio environment
|
|
29
|
+
*/
|
|
30
|
+
export function getStudioEnvironment(): string {
|
|
31
|
+
return window.StudioModule?.config.product.env || PRODUCTION;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Is the module running in QA environment?
|
|
36
|
+
*/
|
|
37
|
+
export function isQA() {
|
|
38
|
+
return getStudioEnvironment() === QA;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Gets the correct player url base depending on environment
|
|
43
|
+
*/
|
|
44
|
+
export function getUrlBase() {
|
|
45
|
+
return isQA() ? QA_URL : PROD_URL;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param options : array of PlayerSelectItem
|
|
51
|
+
* @returns options ordered ascending
|
|
52
|
+
*/
|
|
53
|
+
export function sortAsc(options: PlayerSelectItem[]): PlayerSelectItem[] {
|
|
54
|
+
return options.sort((a, b) => a.label.localeCompare(b.label));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type VideoPreviewLinkOptions = {
|
|
58
|
+
accountId: string;
|
|
59
|
+
videoId?: string;
|
|
60
|
+
interactivityProjectId?: string;
|
|
61
|
+
playerId: string;
|
|
62
|
+
adConfigId?: string;
|
|
63
|
+
livePlaybackToken?: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @param accountId : accountId of current user
|
|
68
|
+
* @param videoId : VideoPayload type info
|
|
69
|
+
* @param interactivityProjectId : id of interactivity project
|
|
70
|
+
* @param playerId : playerId used for preview
|
|
71
|
+
* @returns a working preview link with given information
|
|
72
|
+
* @param adConfigId : token for live playback
|
|
73
|
+
* @param livePlaybackToken : token for live playback
|
|
74
|
+
*/
|
|
75
|
+
export const getVideoPreviewLink = (options: VideoPreviewLinkOptions) => {
|
|
76
|
+
const {
|
|
77
|
+
accountId,
|
|
78
|
+
videoId,
|
|
79
|
+
interactivityProjectId,
|
|
80
|
+
playerId,
|
|
81
|
+
adConfigId,
|
|
82
|
+
livePlaybackToken,
|
|
83
|
+
} = options;
|
|
84
|
+
const params = new URLSearchParams();
|
|
85
|
+
if (interactivityProjectId) {
|
|
86
|
+
params.append('interactivityProjectId', interactivityProjectId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (videoId) {
|
|
90
|
+
params.append('videoId', videoId);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (adConfigId) {
|
|
94
|
+
params.append('adConfigId', adConfigId);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (livePlaybackToken) {
|
|
98
|
+
params.append('livePlaybackToken', livePlaybackToken);
|
|
99
|
+
}
|
|
100
|
+
const paramsString = params.toString();
|
|
101
|
+
return `${getUrlBase()}${accountId}/${playerId}_default/index.html${
|
|
102
|
+
paramsString !== '' ? `?${paramsString}` : ''
|
|
103
|
+
}`;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Truncates a video title property
|
|
108
|
+
* @param videoName - video title
|
|
109
|
+
* @returns truncated video title
|
|
110
|
+
*/
|
|
111
|
+
export const truncateVideoTitle = (videoName: string): string => {
|
|
112
|
+
if (videoName.length > TITLE_CHAR_LIMIT) {
|
|
113
|
+
return `${videoName.substring(0, TITLE_CHAR_LIMIT).trim()}...`;
|
|
114
|
+
}
|
|
115
|
+
return videoName;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export function getPreviewUrlBase() {
|
|
119
|
+
return isQA() ? QA_PREVIEW_URL : PROD_PREVIEW_URL;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
*
|
|
124
|
+
* @param accountId : account id of current user
|
|
125
|
+
* @param playerId : playerId used for preview
|
|
126
|
+
* @returns a working preview url with given information
|
|
127
|
+
*/
|
|
128
|
+
export const getPreviewPlayerUrl = (
|
|
129
|
+
accountId: string,
|
|
130
|
+
playerId: string,
|
|
131
|
+
): string =>
|
|
132
|
+
`${getPreviewUrlBase()}/v2/accounts/${accountId}/players/${playerId}/preview/embeds/default/master/index.html`;
|
|
133
|
+
|
|
134
|
+
export const getStudioModule = (): StudioModule => window.StudioModule;
|
|
135
|
+
|
|
136
|
+
export const getBrightcove = (): StudioBrightcove => window.brightcove;
|
|
137
|
+
|
|
138
|
+
export function getProductPath(): string {
|
|
139
|
+
return getStudioModule()?.config?.product?.path || '/products/videocloud';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @returns Player Manager Module URL
|
|
144
|
+
*/
|
|
145
|
+
export const getPlayerManagerModuleUrl = () => {
|
|
146
|
+
return `${getProductPath()}/players`;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const decodeHtmlEntities = (str: string) => {
|
|
150
|
+
const textarea = document.createElement('textarea');
|
|
151
|
+
textarea.innerHTML = str;
|
|
152
|
+
return textarea.value;
|
|
153
|
+
};
|