@brightcove/components-embed-code-modal 0.8.1 → 0.8.3

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.
Files changed (164) hide show
  1. package/.eslintignore +7 -0
  2. package/.eslintrc +23 -0
  3. package/.husky/pre-commit +4 -0
  4. package/.nvmrc +1 -0
  5. package/.prettierignore +7 -0
  6. package/.prettierrc +5 -0
  7. package/.release-it.json +40 -0
  8. package/.whitesource +3 -0
  9. package/CHANGELOG.md +342 -0
  10. package/CODEOWNERS +37 -0
  11. package/PULL_REQUEST_TEMPLATE.md +17 -0
  12. package/__tests__/EmbedCode.test.tsx +51 -0
  13. package/__tests__/InteractivityProject.test.tsx +50 -0
  14. package/__tests__/PlayerPreview.test.tsx +23 -0
  15. package/__tests__/TabsHeader.test.tsx +19 -0
  16. package/__tests__/TabsSection.test.tsx +46 -0
  17. package/__tests__/TitleWithTooltip.test.tsx +45 -0
  18. package/__tests__/VideoPlayer.test.tsx +38 -0
  19. package/__tests__/util.test.ts +89 -0
  20. package/babel.config.json +17 -0
  21. package/etc/wildcard.brightcove.com.key +27 -0
  22. package/etc/wildcard.brightcove.com.pem +96 -0
  23. package/jest/jest.setup.js +62 -0
  24. package/jest/jest.stub.js +4 -0
  25. package/jest.config.js +24 -0
  26. package/package.json +15 -5
  27. package/scripts/create-dist-pkg-prod.js +18 -0
  28. package/src/index.ts +16 -0
  29. package/src/js/EmbedCodeModal.tsx +88 -0
  30. package/src/js/components/CustomSettingsDropdown.tsx +184 -0
  31. package/src/js/components/EmbedCopySection.tsx +130 -0
  32. package/src/js/components/ModalContainer.tsx +274 -0
  33. package/src/js/components/NoPlayerModal.tsx +42 -0
  34. package/src/js/components/PlayerPreview.tsx +116 -0
  35. package/src/js/components/TabsHeader.tsx +31 -0
  36. package/src/js/components/TabsSection.tsx +74 -0
  37. package/src/js/components/TitleWithTooltip.tsx +39 -0
  38. package/src/js/components/VideoLinks.tsx +83 -0
  39. package/src/js/components/VideoPlayer.tsx +303 -0
  40. package/src/js/components/{index.d.ts → index.ts} +0 -1
  41. package/src/js/constants/baseUrls.ts +4 -0
  42. package/src/js/constants/embed.ts +12 -0
  43. package/src/js/constants/player.ts +32 -0
  44. package/src/js/constants/pluginsRegistry.ts +30 -0
  45. package/src/js/hooks/useGetPlayers.ts +12 -0
  46. package/src/js/i18n.ts +43 -0
  47. package/src/js/services/players-api.ts +26 -0
  48. package/src/js/services/url-shortener.ts +10 -0
  49. package/src/js/types/EmbedCodeModalProps.ts +72 -0
  50. package/src/js/types/EmbedCodeProps.ts +13 -0
  51. package/src/js/types/brightcoveEmbedCode.d.ts +18 -0
  52. package/src/js/types/players.ts +64 -0
  53. package/src/js/types/react-i18next.d.ts +8 -0
  54. package/src/js/types/studioModule.ts +7 -0
  55. package/src/js/utils/addPluginsDataToPlayers.ts +59 -0
  56. package/src/js/utils/call.ts +31 -0
  57. package/src/js/utils/dimensions.ts +53 -0
  58. package/src/js/utils/featureSwitches.ts +16 -0
  59. package/src/js/utils/util.ts +153 -0
  60. package/src/module.tsx +246 -0
  61. package/src/styles/CustomSettingsDropdown.sass +42 -0
  62. package/src/styles/EmbedCode.sass +30 -0
  63. package/src/styles/EmbedCodeModal.sass +76 -0
  64. package/src/styles/base.sass +1 -0
  65. package/src/styles/theme.sass +11 -0
  66. package/src/styles/typings.td.ts +9 -0
  67. package/src/translations/en.json +53 -0
  68. package/src/translations/es.json +53 -0
  69. package/src/translations/fr.json +53 -0
  70. package/src/translations/ja.json +53 -0
  71. package/src/translations/ko.json +53 -0
  72. package/src/translations/zh.json +53 -0
  73. package/src/types/studio.ts +197 -0
  74. package/tsconfig.json +34 -0
  75. package/webpack.config.js +97 -0
  76. package/__tests__/EmbedCode.test.d.ts +0 -2
  77. package/__tests__/EmbedCode.test.d.ts.map +0 -1
  78. package/__tests__/InteractivityProject.test.d.ts +0 -2
  79. package/__tests__/InteractivityProject.test.d.ts.map +0 -1
  80. package/__tests__/PlayerPreview.test.d.ts +0 -2
  81. package/__tests__/PlayerPreview.test.d.ts.map +0 -1
  82. package/__tests__/PlayersDropdown.test.d.ts +0 -2
  83. package/__tests__/PlayersDropdown.test.d.ts.map +0 -1
  84. package/__tests__/TabsHeader.test.d.ts +0 -2
  85. package/__tests__/TabsHeader.test.d.ts.map +0 -1
  86. package/__tests__/TabsSection.test.d.ts +0 -2
  87. package/__tests__/TabsSection.test.d.ts.map +0 -1
  88. package/__tests__/TitleWithTooltip.test.d.ts +0 -2
  89. package/__tests__/TitleWithTooltip.test.d.ts.map +0 -1
  90. package/__tests__/VideoPlayer.test.d.ts +0 -2
  91. package/__tests__/VideoPlayer.test.d.ts.map +0 -1
  92. package/__tests__/util.test.d.ts +0 -2
  93. package/__tests__/util.test.d.ts.map +0 -1
  94. package/index.js +0 -56
  95. package/index.js.map +0 -1
  96. package/src/index.d.ts +0 -5
  97. package/src/index.d.ts.map +0 -1
  98. package/src/js/EmbedCodeModal.d.ts +0 -17
  99. package/src/js/EmbedCodeModal.d.ts.map +0 -1
  100. package/src/js/components/ActivateInteractivityModal.d.ts +0 -3
  101. package/src/js/components/ActivateInteractivityModal.d.ts.map +0 -1
  102. package/src/js/components/CustomSettingsDropdown.d.ts +0 -11
  103. package/src/js/components/CustomSettingsDropdown.d.ts.map +0 -1
  104. package/src/js/components/EmbedCopySection.d.ts +0 -4
  105. package/src/js/components/EmbedCopySection.d.ts.map +0 -1
  106. package/src/js/components/ModalContainer.d.ts +0 -17
  107. package/src/js/components/ModalContainer.d.ts.map +0 -1
  108. package/src/js/components/NoPlayerModal.d.ts +0 -8
  109. package/src/js/components/NoPlayerModal.d.ts.map +0 -1
  110. package/src/js/components/PlayerPreview.d.ts +0 -4
  111. package/src/js/components/PlayerPreview.d.ts.map +0 -1
  112. package/src/js/components/PlayersDropdown.d.ts +0 -9
  113. package/src/js/components/PlayersDropdown.d.ts.map +0 -1
  114. package/src/js/components/TabsHeader.d.ts +0 -11
  115. package/src/js/components/TabsHeader.d.ts.map +0 -1
  116. package/src/js/components/TabsSection.d.ts +0 -15
  117. package/src/js/components/TabsSection.d.ts.map +0 -1
  118. package/src/js/components/TitleWithTooltip.d.ts +0 -8
  119. package/src/js/components/TitleWithTooltip.d.ts.map +0 -1
  120. package/src/js/components/VideoLinks.d.ts +0 -9
  121. package/src/js/components/VideoLinks.d.ts.map +0 -1
  122. package/src/js/components/VideoPlayer.d.ts +0 -17
  123. package/src/js/components/VideoPlayer.d.ts.map +0 -1
  124. package/src/js/components/index.d.ts.map +0 -1
  125. package/src/js/constants/baseUrls.d.ts +0 -5
  126. package/src/js/constants/baseUrls.d.ts.map +0 -1
  127. package/src/js/constants/embed.d.ts +0 -9
  128. package/src/js/constants/embed.d.ts.map +0 -1
  129. package/src/js/constants/player.d.ts +0 -27
  130. package/src/js/constants/player.d.ts.map +0 -1
  131. package/src/js/constants/pluginsRegistry.d.ts +0 -7
  132. package/src/js/constants/pluginsRegistry.d.ts.map +0 -1
  133. package/src/js/hooks/useGetPlayers.d.ts +0 -3
  134. package/src/js/hooks/useGetPlayers.d.ts.map +0 -1
  135. package/src/js/i18n.d.ts +0 -330
  136. package/src/js/i18n.d.ts.map +0 -1
  137. package/src/js/services/players-api.d.ts +0 -5
  138. package/src/js/services/players-api.d.ts.map +0 -1
  139. package/src/js/services/url-shortener.d.ts +0 -4
  140. package/src/js/services/url-shortener.d.ts.map +0 -1
  141. package/src/js/types/EmbedCodeModalProps.d.ts +0 -59
  142. package/src/js/types/EmbedCodeModalProps.d.ts.map +0 -1
  143. package/src/js/types/EmbedCodeProps.d.ts +0 -13
  144. package/src/js/types/EmbedCodeProps.d.ts.map +0 -1
  145. package/src/js/types/players.d.ts +0 -58
  146. package/src/js/types/players.d.ts.map +0 -1
  147. package/src/js/types/studioModule.d.ts +0 -8
  148. package/src/js/types/studioModule.d.ts.map +0 -1
  149. package/src/js/utils/addPluginsDataToPlayers.d.ts +0 -6
  150. package/src/js/utils/addPluginsDataToPlayers.d.ts.map +0 -1
  151. package/src/js/utils/call.d.ts +0 -14
  152. package/src/js/utils/call.d.ts.map +0 -1
  153. package/src/js/utils/dimensions.d.ts +0 -9
  154. package/src/js/utils/dimensions.d.ts.map +0 -1
  155. package/src/js/utils/featureSwitches.d.ts +0 -2
  156. package/src/js/utils/featureSwitches.d.ts.map +0 -1
  157. package/src/js/utils/util.d.ts +0 -67
  158. package/src/js/utils/util.d.ts.map +0 -1
  159. package/src/module.d.ts +0 -2
  160. package/src/module.d.ts.map +0 -1
  161. package/src/styles/typings.td.d.ts +0 -13
  162. package/src/styles/typings.td.d.ts.map +0 -1
  163. package/src/types/studio.d.ts +0 -202
  164. package/src/types/studio.d.ts.map +0 -1
@@ -0,0 +1,30 @@
1
+ // Plugins available in the BC registry
2
+ export const bcHostedPlugins = [
3
+ 'bcAa',
4
+ 'bcAirplay',
5
+ 'bcGa',
6
+ 'bcGtm',
7
+ 'bcPlaylistUi',
8
+ 'bcTealium',
9
+ 'bcMapPlugin',
10
+ 'chromecastReceiver',
11
+ 'customEndscreen',
12
+ 'eme',
13
+ 'ima3',
14
+ 'interactivityViewer',
15
+ 'kollective',
16
+ 'overlay',
17
+ 'pip',
18
+ 'playlistEndscreen',
19
+ 'qualityMenu',
20
+ 'social',
21
+ 'ssai',
22
+ 'thumbnails',
23
+ ];
24
+
25
+ export const CAMPAIGN_PLUGIN_NAME = 'bcMapPlugin';
26
+ export const VIEWER_ID_KEY_NAME = 'viewer_id_source';
27
+ export const BC_MAP_TRACKING_NAME = 'bcMapTracking';
28
+ export const INTERACTIVITY_PLUGIN_NAME = 'interactivityViewer';
29
+ export const INTERACTIVITY_REGISTRY_ID =
30
+ '@brightcove/videojs-interactivity-viewer';
@@ -0,0 +1,12 @@
1
+ import { useQuery } from 'react-query';
2
+
3
+ import { getPlayers } from 'js/services/players-api';
4
+
5
+ const useGetPlayers = (isPlayersCallEnabled: boolean) => {
6
+ return useQuery(['players'], () => getPlayers(), {
7
+ refetchOnWindowFocus: false,
8
+ enabled: isPlayersCallEnabled,
9
+ });
10
+ };
11
+
12
+ export default useGetPlayers;
package/src/js/i18n.ts ADDED
@@ -0,0 +1,43 @@
1
+ import i18n from 'i18next';
2
+ import { initReactI18next } from 'react-i18next';
3
+
4
+ import common_en from 'translations/en.json';
5
+ import common_es from 'translations/es.json';
6
+ import common_fr from 'translations/fr.json';
7
+ import common_ja from 'translations/ja.json';
8
+ import common_ko from 'translations/ko.json';
9
+ import common_zh from 'translations/zh.json';
10
+
11
+ export const resources = {
12
+ en: {
13
+ translation: common_en,
14
+ },
15
+ es: {
16
+ translation: common_es,
17
+ },
18
+ fr: {
19
+ translation: common_fr,
20
+ },
21
+ ja: {
22
+ translation: common_ja,
23
+ },
24
+ ko: {
25
+ translation: common_ko,
26
+ },
27
+ zh: {
28
+ translation: common_zh,
29
+ },
30
+ };
31
+
32
+ i18n.use(initReactI18next).init({
33
+ lng: window.StudioModule?.config?.lang || 'en',
34
+ fallbackLng: 'en',
35
+ debug: true,
36
+ returnObjects: true,
37
+ resources,
38
+ interpolation: {
39
+ escapeValue: false, // react already safe from xss
40
+ },
41
+ });
42
+
43
+ export default i18n;
@@ -0,0 +1,26 @@
1
+ import {
2
+ getAllPlayers,
3
+ createPlayer as createPlayerAPI,
4
+ getPlayer as getPlayerAPI,
5
+ } from '@brightcove/studio-api-services/api/players-api';
6
+ import { callAPI } from 'js/utils/call';
7
+ import {
8
+ GetPlayersPayload,
9
+ CreatePlayerPayload,
10
+ CreatePlayerResponse,
11
+ PlayerItem,
12
+ } from 'js/types/players';
13
+
14
+ export const getPlayers = async (): Promise<GetPlayersPayload> => {
15
+ return callAPI(getAllPlayers, {});
16
+ };
17
+
18
+ export const createPlayer = async (
19
+ payload: CreatePlayerPayload,
20
+ ): Promise<CreatePlayerResponse> => {
21
+ return callAPI(createPlayerAPI, payload);
22
+ };
23
+
24
+ export const getPlayer = async (playerId: string): Promise<PlayerItem> => {
25
+ return callAPI(getPlayerAPI, { playerId });
26
+ };
@@ -0,0 +1,10 @@
1
+ import { getShortenedUrl } from '@brightcove/studio-api-services/api/url-shortener-api';
2
+ import { callAPI } from 'js/utils/call';
3
+
4
+ export const shortenUrl = async ({
5
+ longUrl,
6
+ }: {
7
+ longUrl: string;
8
+ }): Promise<string> => {
9
+ return callAPI(getShortenedUrl, { longUrl });
10
+ };
@@ -0,0 +1,72 @@
1
+ // export payload that will be used to pass data into component
2
+ export interface VideoPayload {
3
+ videoId: string;
4
+ videoName: string;
5
+ accountId: string;
6
+ posterUrl?: string;
7
+ duration: number;
8
+ }
9
+
10
+ export interface PlayerPayload {
11
+ id: string;
12
+ configuration?: Record<string, unknown>;
13
+ name?: string;
14
+ accountId?: string;
15
+ embedCodeProperties?: EmbedCodeProperties;
16
+ isOutstreamPlayer?: boolean;
17
+ }
18
+
19
+ export interface ProjectPayload {
20
+ accountId: string;
21
+ videoId: string;
22
+ interactivityProjectId: string;
23
+ interactivityProjectName: string;
24
+ }
25
+
26
+ export interface LivePayload {
27
+ videoId: string;
28
+ accountId: string;
29
+ livePlaybackToken: string;
30
+ adConfigId: string;
31
+ }
32
+
33
+ export enum EmbedCodeModalTypes {
34
+ PLAYER = 'player',
35
+ VIDEO = 'video',
36
+ PROJECT = 'project',
37
+ LIVE = 'live',
38
+ }
39
+
40
+ export enum NoInteractivityPlayerModalTypes {
41
+ NO_PLAYER = 'no-player',
42
+ NO_PERMISSION = 'no-permission',
43
+ }
44
+
45
+ export type ModalDataPayload =
46
+ | VideoPayload
47
+ | PlayerPayload
48
+ | ProjectPayload
49
+ | LivePayload;
50
+
51
+ export enum EmbedCodeUnits {
52
+ PX = 'px',
53
+ EM = 'em',
54
+ PERCENT = '%',
55
+ }
56
+
57
+ export enum EmbedCodeAspectRatio {
58
+ FLUID = 'fluid',
59
+ CUSTOM = 'custom',
60
+ ONE_ONE = '1:1',
61
+ FOUR_THREE = '4:3',
62
+ SIXTEEN_NINE = '16:9',
63
+ NINE_SIXTEEN = '9:16',
64
+ }
65
+
66
+ export interface EmbedCodeProperties {
67
+ width: number;
68
+ height: number;
69
+ units: EmbedCodeUnits;
70
+ responsive: boolean;
71
+ aspectRatio: EmbedCodeAspectRatio;
72
+ }
@@ -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,8 @@
1
+ import 'react-i18next';
2
+ import { resources } from 'js/i18n';
3
+
4
+ declare module 'react-i18next' {
5
+ interface CustomTypeOptions {
6
+ resources: typeof resources.en;
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ import { StudioModule, StudioBrightcove } from 'types/studio';
2
+ declare global {
3
+ interface Window {
4
+ StudioModule: StudioModule;
5
+ brightcove: StudioBrightcove;
6
+ }
7
+ }
@@ -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,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
+ };